/* ═══════════════════════════════════════════════════
   RoadWords - Dark Mode Driving Interface
   ═══════════════════════════════════════════════════ */

/* ─── CSS Variables / Design Tokens ─── */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-input: #1a1a25;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.1);

    --text-primary: #eeeef0;
    --text-secondary: #9898a6;
    --text-muted: #5a5a6e;

    --accent-indigo: #6366f1;
    --accent-purple: #a855f7;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;

    --gradient-primary: linear-gradient(135deg, #6366f1, #a855f7);
    --gradient-success: linear-gradient(135deg, #22c55e, #16a34a);
    --gradient-error: linear-gradient(135deg, #ef4444, #dc2626);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Screen Management ─── */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-slow), visibility var(--transition-slow);
    overflow-y: auto;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* ═══════════════════════════════════════
   SETUP SCREEN
   ═══════════════════════════════════════ */
.setup-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 24px 20px;
    gap: 32px;
}

.logo-area {
    text-align: center;
    animation: fadeInDown 0.6s ease;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.brand-mark {
    width: 86px;
    height: 86px;
    margin: 0 auto 14px;
    border-radius: 26px;
    background:
        radial-gradient(circle at top left, rgba(168, 85, 247, 0.32), transparent 55%),
        linear-gradient(155deg, rgba(99, 102, 241, 0.26), rgba(17, 17, 24, 0.95));
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 18px 40px rgba(0, 0, 0, 0.28);
    display: grid;
    place-items: center;
    position: relative;
}

.brand-mark-main {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -0.06em;
    color: var(--text-primary);
}

.brand-mark-sub {
    position: absolute;
    right: 10px;
    bottom: 10px;
    padding: 3px 7px;
    border-radius: 999px;
    background: rgba(10, 10, 15, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--accent-indigo);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.brand-kicker {
    color: var(--accent-indigo);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.18em;
    margin-bottom: 8px;
}

.logo-area h1 {
    font-size: 2.15rem;
    font-weight: 800;
    letter-spacing: -0.04em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.96rem;
    margin-top: 8px;
    font-weight: 400;
    max-width: 28ch;
    margin-inline: auto;
    line-height: 1.45;
}

/* ─── Setup Card ─── */
.setup-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    box-shadow: var(--shadow-card);
    animation: fadeInUp 0.6s ease 0.2s both;
}

.setup-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.setup-status {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 7px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.setup-note {
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.5;
    margin-bottom: 24px;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.input-group {
    margin-bottom: 24px;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper input {
    width: 100%;
    padding: 14px 48px 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.95rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.input-wrapper input:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

.input-wrapper .icon-btn {
    position: absolute;
    right: 8px;
}

.select-wrapper select {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.95rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
    appearance: none;
}

.select-wrapper select:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.hint {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 8px;
}

/* ─── Word Stats ─── */
.word-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat {
    text-align: center;
    padding: 12px 8px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-indigo);
}

.stat-label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

@media (max-width: 420px) {
    .word-stats {
        gap: 8px;
    }

    .stat {
        padding: 10px 6px;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.66rem;
    }
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    width: 100%;
    outline: none;
}

.btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--accent-indigo);
}

.btn-options {
    width: auto;
    flex-shrink: 0;
    padding-inline: 16px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.icon-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.setup-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ═══════════════════════════════════════
   SESSION SCREEN
   ═══════════════════════════════════════ */
.session-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.progress-bar-wrapper {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--gradient-primary);
    border-radius: 3px;
    transition: width var(--transition-slow);
}

.progress-text {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
}

/* ─── Session Main ─── */
.session-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 18px 16px 24px;
    gap: 16px;
    min-height: 0;
}

/* Direction Badge */
.direction-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    animation: fadeIn 0.3s ease;
}

.direction-badge.compact {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.76rem;
    gap: 8px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.direction-badge svg {
    width: 16px;
    height: 16px;
    color: var(--accent-indigo);
}

/* Word Card */
.word-card {
    position: relative;
    text-align: center;
    padding: 18px 18px 18px;
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glow);
    transition: all var(--transition-slow);
    overflow: hidden;
    isolation: isolate;
}

.word-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0;
    z-index: 0;
}

.word-card > * {
    position: relative;
    z-index: 1;
}

.word-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    padding-right: 96px;
}

.word-card.correct {
    border-color: var(--accent-green);
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.15);
}

.word-card.incorrect {
    border-color: var(--accent-red);
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.15);
}

.word-card.milestone-mastered {
    animation: wordMasteredPulse 0.82s ease-out;
}

.word-card.milestone-mastered::after {
    animation: wordMasteredGlow 0.82s ease-out;
}

.word-card.milestone-round {
    animation: roundCompletePulse 0.7s ease-out;
}

.word-card.milestone-round::after {
    animation: roundCompleteGlow 0.7s ease-out;
}

@keyframes wordMasteredPulse {
    0% {
        transform: scale(1);
    }
    35% {
        transform: scale(1.022);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes wordMasteredGlow {
    0% {
        opacity: 0;
        background: rgba(34, 197, 94, 0);
    }
    35% {
        opacity: 1;
        background: rgba(34, 197, 94, 0.28);
    }
    100% {
        opacity: 0;
        background: rgba(34, 197, 94, 0);
    }
}

@keyframes roundCompletePulse {
    0% {
        transform: scale(1);
    }
    28% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes roundCompleteGlow {
    0% {
        opacity: 0;
        background:
            radial-gradient(circle at top, rgba(250, 204, 21, 0), transparent 55%),
            rgba(34, 197, 94, 0);
    }
    35% {
        opacity: 1;
        background:
            radial-gradient(circle at top, rgba(250, 204, 21, 0.18), transparent 55%),
            rgba(34, 197, 94, 0.22);
    }
    100% {
        opacity: 0;
        background:
            radial-gradient(circle at top, rgba(250, 204, 21, 0), transparent 55%),
            rgba(34, 197, 94, 0);
    }
}

.word-label {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    margin-bottom: 0;
}

.pronunciation-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-xl);
    font-size: 0.8rem;
    font-weight: 700;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.pronunciation-badge svg {
    width: 14px;
    height: 14px;
}

.pronunciation-badge.hidden {
    display: none;
}

.pronunciation-badge.excellent {
    color: var(--accent-green);
    border-color: rgba(34, 197, 94, 0.3);
    background: rgba(34, 197, 94, 0.1);
}

.pronunciation-badge.good {
    color: var(--accent-amber);
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.1);
}

.pronunciation-badge.poor {
    color: var(--accent-red);
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.1);
}

.word-text {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
    animation: wordAppear 0.4s ease;
}

.direction-progress {
    margin-top: 14px;
    display: grid;
    gap: 8px;
    text-align: left;
}

.direction-progress-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.direction-progress-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.direction-progress-value {
    font-size: 0.83rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

@keyframes wordAppear {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* Feedback Area */
.feedback-area {
    min-height: 48px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
    animation: fadeIn 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.feedback-main {
    color: var(--text-primary);
    font-weight: 600;
}

.feedback-answer {
    color: var(--text-primary);
    font-weight: 800;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
}

.feedback-subtle {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
}

/* Microphone Area */
.mic-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.mic-ring {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 2px solid var(--border-medium);
    transition: all var(--transition-normal);
    position: relative;
}

.mic-ring.listening {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.12);
    animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.12); }
    50% { box-shadow: 0 0 0 14px rgba(99, 102, 241, 0.06); }
}

.mic-ring.processing {
    border-color: var(--accent-amber);
    animation: none;
}

.mic-icon {
    width: 28px;
    height: 28px;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.mic-ring.listening .mic-icon {
    color: var(--accent-indigo);
}

.mic-status {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    text-align: center;
    max-width: 320px;
}

.mic-timer {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-indigo);
    font-variant-numeric: tabular-nums;
    min-height: 1em;
}

.last-metrics {
    width: auto;
    max-width: 400px;
    padding: 0.45rem 0.75rem;
    background-color: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    flex-wrap: wrap;
}

.last-metrics.hidden {
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    position: absolute;
}

@media (max-width: 420px), (max-height: 760px) {
    .session-header {
        padding: 12px 14px;
        gap: 10px;
    }

    .progress-text {
        font-size: 0.76rem;
    }

    .session-main {
        padding: 14px 12px 18px;
        gap: 12px;
    }

    .word-card {
        padding: 16px 14px;
        border-radius: 16px;
    }

    .word-card-top {
        padding-right: 0;
        align-items: center;
        flex-wrap: wrap;
    }

    .pronunciation-badge {
        position: static;
        margin: 0 auto 10px;
    }

    .word-text {
        font-size: 1.45rem;
    }

    .direction-progress-item {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .direction-progress-value {
        font-size: 0.8rem;
    }

    .feedback-area {
        min-height: 40px;
    }

    .mic-ring {
        width: 64px;
        height: 64px;
    }

    .mic-icon {
        width: 24px;
        height: 24px;
    }
}

/* ═══════════════════════════════════════
   OVERLAYS & TOASTS
   ═══════════════════════════════════════ */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border-medium);
    border-top-color: var(--accent-indigo);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.overlay p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.modal-overlay {
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 24px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-header p {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 400;
}

/* Toast */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 500;
    text-align: center;
    pointer-events: auto;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3s forwards;
    box-shadow: var(--shadow-card);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; visibility: hidden; }
}

.toast.success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--accent-green);
}

.toast.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--accent-red);
}

.toast.info {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--accent-indigo);
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 2px; }

/* ─── Responsive ─── */
@media (max-width: 380px) {
    .word-text { font-size: 1.6rem; }
    .logo-area h1 { font-size: 1.7rem; }
    .setup-card { padding: 20px 16px; }
    .setup-toolbar { flex-direction: column; }
    .btn-options { width: 100%; }
}

@media (min-height: 800px) {
    .session-main { gap: 36px; }
    .word-card { padding: 44px 28px; }
    .word-text { font-size: 2.2rem; }
}
