/**
 * Read Aloud
 *
 * Token-only styling (no hard-coded colors except color-mix() on tokens).
 * Follows the voice-recorder sibling conventions and the UI Direction Brief
 * for read-aloud (2026-09-23).
 */

/* ========================================
   App Page Layout
   ======================================== */

.app-page {
    padding: var(--space-4);
    padding-top: calc(var(--header-height) + var(--space-4));
    min-height: calc(100vh - var(--header-height));
}

/* ========================================
   App Container Centering (REQUIRED)
   ======================================== */

.read-aloud-container {
    width: 100%;
    max-width: var(--app-container-max);
    margin: 0 auto;
}

/* ========================================
   Tool
   ======================================== */

.read-aloud-tool {
    display: grid;
    gap: var(--space-6);
}

.read-aloud-tool:focus-visible {
    outline: none;
}

.read-aloud-note {
    margin: 0;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

.read-aloud-panel {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-lg);
    display: grid;
    gap: var(--space-5);
}

.read-aloud-panel-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.read-aloud-panel-header h2 {
    margin: 0;
    font-size: var(--font-size-lg);
}

.read-aloud-muted-hint {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    line-height: var(--line-height-normal);
}

/* Status pill (visible state indicator; text label, never color alone) */

.read-aloud-status {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    white-space: nowrap;
}

.read-aloud-status.is-playing {
    border-color: color-mix(in srgb, var(--color-primary) 55%, var(--color-border));
    background: color-mix(in srgb, var(--color-primary) 12%, transparent);
}

.read-aloud-status.is-paused {
    border-color: color-mix(in srgb, var(--color-warning) 55%, var(--color-border));
    background: color-mix(in srgb, var(--color-warning) 12%, transparent);
}

/* ========================================
   Input panel
   ======================================== */

.read-aloud-textarea {
    width: 100%;
    min-height: var(--app-input-min-height);
    max-height: 480px;
    overflow-y: auto;
    resize: vertical;
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.read-aloud-textarea:hover {
    border-color: var(--color-border-dark);
}

.read-aloud-textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.read-aloud-counters {
    display: flex;
    gap: var(--space-4);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.read-aloud-counters .is-long {
    color: var(--color-warning-text);
    font-weight: 600;
}

.read-aloud-empty-warning {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-error-text);
}

.read-aloud-empty-warning:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ========================================
   No-voices / Not-supported states
   ======================================== */

.read-aloud-no-voices {
    display: grid;
    gap: var(--space-2);
    justify-items: start;
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    border: 1px solid color-mix(in srgb, var(--color-warning) 45%, var(--color-border));
    background: color-mix(in srgb, var(--color-warning) 8%, transparent);
}

.read-aloud-no-voices .read-aloud-warning-message {
    margin: 0;
    color: var(--color-warning-text);
    font-weight: 700;
    line-height: var(--line-height-normal);
}

.read-aloud-not-supported {
    display: grid;
    gap: var(--space-4);
    justify-items: start;
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    border: 1px solid color-mix(in srgb, var(--color-error) 45%, var(--color-border));
    /* 4% (not 8%): keeps the tint subtle while letting --color-error-text
       clear WCAG 2.1 AA 4.5:1 in light theme and dark. */
    background: color-mix(in srgb, var(--color-error) 4%, transparent);
}

.read-aloud-not-supported .read-aloud-error-message {
    margin: 0;
    color: var(--color-error-text);
    font-weight: 700;
    line-height: var(--line-height-normal);
}

/* Muted hints sit on tinted warning/error backgrounds where --color-text-muted
   drops just below WCAG 2.1 AA 4.5:1 (light theme). Use primary text color
   inside the tinted state cards so the hint always clears AA. */
.read-aloud-no-voices .read-aloud-muted-hint,
.read-aloud-not-supported .read-aloud-muted-hint {
    color: var(--color-text);
}

/* ========================================
   Player controls
   ======================================== */

.read-aloud-controls-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) auto minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-4);
    align-items: end;
}

.read-aloud-field {
    display: grid;
    gap: var(--space-2);
    min-width: 0;
}

.read-aloud-label {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text);
}

.read-aloud-select {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: var(--font-size-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.read-aloud-select:hover {
    border-color: var(--color-border-dark);
}

.read-aloud-select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.read-aloud-select[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Sliders (voice-recorder-slider token pattern) */

.read-aloud-slider-field {
    grid-template-columns: auto 1fr;
    grid-template-areas:
        "label value"
        "slider slider";
    column-gap: var(--space-2);
    align-items: center;
}

.read-aloud-slider-label {
    grid-area: label;
}

.read-aloud-slider-value {
    grid-area: value;
    justify-self: end;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.read-aloud-slider {
    grid-area: slider;
    width: 100%;
    margin: var(--space-2) 0 0;
    height: calc(var(--space-4) + var(--space-2));
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

.read-aloud-slider::-webkit-slider-runnable-track {
    height: calc(var(--space-2) + var(--space-1));
    border-radius: var(--radius-full);
    background: var(--color-border);
}

.read-aloud-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: calc(var(--space-4) + var(--space-2));
    height: calc(var(--space-4) + var(--space-2));
    margin-top: calc((var(--space-2) + var(--space-1)) / -2);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border-dark);
    background: var(--color-primary);
    transition: box-shadow var(--transition-fast), background var(--transition-fast);
}

.read-aloud-slider:hover::-webkit-slider-thumb {
    background: var(--color-primary-dark);
}

.read-aloud-slider:focus-visible {
    outline: none;
}

.read-aloud-slider:focus-visible::-webkit-slider-thumb {
    box-shadow: var(--focus-ring);
}

.read-aloud-slider::-moz-range-track {
    height: calc(var(--space-2) + var(--space-1));
    border-radius: var(--radius-full);
    background: var(--color-border);
}

.read-aloud-slider::-moz-range-thumb {
    width: calc(var(--space-4) + var(--space-1));
    height: calc(var(--space-4) + var(--space-1));
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border-dark);
    background: var(--color-primary);
    transition: box-shadow var(--transition-fast), background var(--transition-fast);
}

.read-aloud-slider:hover::-moz-range-thumb {
    background: var(--color-primary-dark);
}

.read-aloud-slider:focus-visible::-moz-range-thumb {
    box-shadow: var(--focus-ring);
}

.read-aloud-slider[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Playback actions (single morphing Play button + Stop) */

.read-aloud-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.read-aloud-actions .btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Progress */

.read-aloud-progress-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.read-aloud-progress {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    height: calc(var(--space-2) + var(--space-1));
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    overflow: hidden;
}

.read-aloud-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    transition: width var(--transition-fast);
}

.read-aloud-progress-readout {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* ========================================
   Highlight mirror
   ======================================== */

.read-aloud-mirror-hint {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.read-aloud-mirror {
    max-height: 320px;
    overflow-y: auto;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-size: var(--font-size-lg);
    line-height: var(--line-height-relaxed);
}

.read-aloud-sentence {
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.read-aloud-sentence:hover {
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.read-aloud-sentence:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Spoken word: bold is the non-color cue, the tint is secondary. */

.read-aloud-highlight {
    background: color-mix(in srgb, var(--color-primary) 25%, transparent);
    color: inherit;
    font-weight: 700;
}

/* Sentence-level fallback: whole active sentence tinted + bolded word list
   is replaced by a stronger sentence tint (non-color cue = bold on all words
   is too heavy, so the tint is made clearly stronger than hover). */

.read-aloud-sentence.is-active-sentence {
    background: color-mix(in srgb, var(--color-primary) 16%, transparent);
}

.read-aloud-mirror.is-empty {
    color: var(--color-text-muted);
    font-size: var(--font-size-base);
}

/* ========================================
   [hidden] overrides
   The display values above would override the UA [hidden] rule, so the
   hidden state must win explicitly (scoped, per codebase convention).
   ======================================== */

.read-aloud-panel[hidden],
.read-aloud-mirror[hidden],
#read-aloud-tool[hidden],
#read-aloud-no-voices[hidden],
#read-aloud-not-supported[hidden],
#read-aloud-empty-warning[hidden],
.read-aloud-actions .btn[hidden] {
    display: none;
}

/* ========================================
   Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .read-aloud-progress-fill,
    .read-aloud-sentence,
    .read-aloud-slider,
    .read-aloud-textarea,
    .read-aloud-select {
        transition: none;
    }

    .read-aloud-slider::-webkit-slider-thumb,
    .read-aloud-slider::-moz-range-thumb {
        transition: none;
    }
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
    .read-aloud-controls-row {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .read-aloud-voice-field,
    .read-aloud-preview-field {
        grid-column: 1 / -1;
    }

    .read-aloud-mirror {
        max-height: min(50vh, 320px);
    }

    .read-aloud-actions .btn {
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .read-aloud-controls-row {
        grid-template-columns: minmax(0, 1fr);
    }

    .read-aloud-voice-field,
    .read-aloud-preview-field,
    .read-aloud-slider-field {
        grid-column: auto;
    }

    .read-aloud-progress-row {
        flex-direction: column;
        align-items: stretch;
    }

    .read-aloud-actions .btn {
        width: 100%;
    }
}
