/* Read Page Widget - Standalone & Prettier */
/* Now uses CSS variables for theming */

#read-widget-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    /* Start hidden below */
    width: 90%;
    max-width: 500px;

    /* Theming with CSS Variables */
    background: var(--bg-color, #e6e6e6);
    color: var(--text-color, #222);

    /* Glassmorphism effect - handled carefully to respect theme color */
    /* We use a high opacity background to ensure legibility against any page background, 
       but keep backdrop-filter for the "feel" */
    background: linear-gradient(to bottom,
            color-mix(in srgb, var(--bg-color, #fff), transparent 10%) 0%,
            color-mix(in srgb, var(--bg-color, #fff), transparent 5%) 100%);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);

    border: 1px solid var(--text-color);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        0 2px 10px rgba(0, 0, 0, 0.05);
    border-radius: 24px;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

/* Ensure shadow is visible in dark modes */
@media (prefers-color-scheme: dark) {
    #read-widget-container {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

#read-widget-container.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}



/* Controls Row */
.rw-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rw-btn-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rw-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.rw-btn:hover {
    background: var(--link-color);
    /* Use link color for hover state for contrast */
    color: var(--bg-color);
    transform: scale(1.1);
}

.rw-btn.primary {
    width: 48px;
    height: 48px;
    background: var(--text-color);
    color: var(--bg-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.rw-btn.primary:hover {
    transform: scale(1.1);
    opacity: 0.9;
}

/* Speed Display */
.rw-speed-display {
    font-family: var(--font-mono, monospace);
    color: var(--text-color);
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    opacity: 0.8;
}

/* Close Button */
.rw-close-btn {
    padding: 8px;
    /* Square padding */
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.05);
    /* Slight background */
    border-radius: 50%;
    /* Circle */
    color: #ff3b30 !important;
    /* System Red */
    border: none;
    margin-left: auto;
    /* Push to right */
}

.rw-close-btn:hover {
    background: rgba(255, 59, 48, 0.1);
    /* No rotation */
}

/* Dark mode close button adjustment */
@media (prefers-color-scheme: dark) {
    .rw-close-btn {
        background: rgba(255, 255, 255, 0.1);
        color: #ff453a !important;
    }

    .rw-close-btn:hover {
        background: rgba(255, 69, 58, 0.2);
    }
}

/* Progress Wrapper */
.rw-progress-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 8px;
    /* Use more width (less padding) */
    width: 100%;
    box-sizing: border-box;
}

/* Progress Bar */
.rw-progress-container {
    /* width: 100%; removed */
    flex: 1;
    /* Allow it to fill space */
    position: relative;
    height: 14px;
    /* Taller hit area matches thumb */
    cursor: pointer;
    display: flex;
    align-items: center;
}

.rw-progress-track {
    position: absolute;
    left: 0;
    width: 100%;
    height: 8px;
    /* Taller visible track (was 6px) */
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

.rw-progress-bar {
    position: absolute;
    left: 0;
    height: 8px;
    /* Match track */
    background: var(--link-color, #007aff);
    width: 0%;
    border-radius: 8px;
    z-index: 2;
    /* transition: width 0.1s linear; */
    /* Smooth */
}

/* Draggable Thumb */
.rw-progress-thumb {
    width: 14px;
    height: 14px;
    background: var(--bg-color, #fff);
    /* Match background (hollow look) */
    border: 2px solid var(--link-color, #007aff);
    border-radius: 50%;
    position: absolute;
    right: -7px;
    /* Center thumb on end of bar */
    top: 50%;
    transform: translateY(-50%) scale(0);
    /* Hidden by default */
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 3;
}

.rw-progress-container:hover .rw-progress-thumb {
    transform: translateY(-50%) scale(1);
    /* Show on hover */
}

.rw-progress-container:active .rw-progress-thumb {
    transform: translateY(-50%) scale(1.1);
    /* Slight grow on drag */
    cursor: grabbing;
    background: var(--link-color, #007aff);
    /* Fill on drag? Optional. Keeping hollow per request "circle to move across" */
}

/* Time Display */
.rw-time-display {
    font-family: var(--font-mono, monospace);
    font-size: 0.75rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-color);
    opacity: 0.7;
    min-width: 45px;
    text-align: right;
    user-select: none;
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .rw-progress-track {
        background: rgba(255, 255, 255, 0.15);
    }

    .rw-progress-thumb {
        background: #2c2c2e;
        border-color: var(--link-color, #0a84ff);
    }
}

/* Highlight Styles */
.rw-spotlight {
    transition: all 0.3s ease;
    background-color: rgba(255, 255, 0, 0.1);
    /* Subtle yellow tint */
    border-radius: 8px;
    box-shadow: 0 0 0 4px rgba(255, 255, 0, 0.1);
}

/* Dark mode spotlight adjustment */
@media (prefers-color-scheme: dark) {
    .rw-spotlight {
        background-color: rgba(255, 255, 255, 0.05);
        box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
    }
}

.rw-word-active {
    background-color: #ffeb3b;
    color: #000;
    /* Ensure text is readable */
    border-radius: 2px;
}

/* Secondary Action Button (Highlight Toggle) */
.rw-btn.secondary-action {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.rw-btn.secondary-action.active {
    opacity: 1;
    color: var(--text-color);
}

.rw-btn.secondary-action:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
    transform: none;
    /* simpler hover */
}

/* Speed Toggle Button */
.rw-btn.speed-btn {
    width: 60px;
    /* Fixed width to prevent layout jump */
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.8;
    font-family: var(--font-mono, monospace);
    /* Restore mono font */
    border-radius: 1000px;
    /* Pill shape requested by user */
}

.rw-btn.speed-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}