/* styles.css */

/* Sticky auth-bar is 56px (48px on phones). Reserve scroll-padding so anchor
   jumps and JS scrollTo({top:0}) don't park content under the bar. Visual
   critic 2026-05-16: prelude callouts and worked-step quote blocks were
   appearing flush against the bar in fullPage screenshots on tutorials and
   concept pages. */
html { scroll-padding-top: 72px; }
@media (max-width: 480px) { html { scroll-padding-top: 60px; } }

/* KaTeX display equations were rendering flush against surrounding prose
   on tutorial + concept pages (3★ design finding). Single global rule. */
.katex-display { margin: 12px 0; }

:root {
    --bg: #F2F2F2;
    --surface: #FFFFFF;
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --text: #1F2933;
    --text-secondary: #4B5563;
    --border: #E5E7EB;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 10px;
    --shadow: 0 4px 16px rgba(0,0,0,0.08);
}

/* Premium polish: cross-document View Transitions on browsers that support it
   (Chromium 126+ / Brave on Android). Falls back to a simple body fade-in
   everywhere else. */
@view-transition { navigation: auto; }

@keyframes pageFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

body {
    animation: pageFadeIn 0.18s ease-out both;
}

@media (prefers-reduced-motion: reduce) {
    body { animation: none; }
}

/* Unified button system */
.btn {
    display: inline-block;
    padding: 10px 20px;
    font-size: 1em;
    font-family: var(--font);
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background-color 0.2s ease, transform 0.05s ease;
    line-height: 1.4;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary { background-color: var(--primary); color: #FFFFFF; }
.btn-primary:hover { background-color: var(--primary-hover); }

.btn-secondary { background-color: var(--border); color: var(--text); }
.btn-secondary:hover { background-color: #D1D5DB; }

.btn-accent { background-color: var(--warning); color: #FFFFFF; }
.btn-accent:hover { background-color: #D97706; }

.btn-outline {
    background-color: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:hover {
    background-color: var(--primary);
    color: #FFFFFF;
}

.btn-lg { padding: 14px 28px; font-size: 1.15em; }
.btn-sm { padding: 6px 14px; font-size: 0.85em; }

body {
    background-color: var(--bg);
    font-family: var(--font);
    margin: 0;
    /* padding-top is set by auth.css (56px / 48px responsive) so the fixed
       auth-bar doesn't overlap content. Don't reset to 0 here. */
}

.container {
    text-align: center;
    padding: 20px;
}

.title h1 {
    font-size: 2.5em;
    color: var(--text);
    font-family: var(--font);
    font-weight: 700;
}

.emphasize {
    color: #B91C1C; /* refined deep red */
}

.game-button {
    padding: 20px;
    font-size: 1.5em;
    background-color: var(--primary);
    color: #FFFFFF;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.05s ease;
}

.game-button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.bottom-buttons {
    margin-top: 40px;
}

.bottom-buttons button {
    margin: 0 10px;
    padding: 10px 20px;
    font-size: 1.2em;
    background-color: #E5E7EB; /* light grey */
    color: #111827; /* near-black text */
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.05s ease;
}

.bottom-buttons button:hover {
    background-color: #D1D5DB; /* slightly darker grey */
    transform: translateY(-1px);
}

.sound-toggle {
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    margin-right: 10px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #9CA3AF; /* muted grey */
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: #FFFFFF;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #10B981; /* emerald when ON */
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Enlarged username input */
.username-input {
    width: 250px;
    height: 40px;
    font-size: 18px;
    padding: 5px;
    border-radius: 5px;
    margin-top: 15px;
    border: 1px solid #D1D5DB;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Top leaderboard button */
.top-buttons {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.leaderboard-button {
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    background-color: #2563EB; /* same primary blue */
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    transition: background-color 0.2s ease, transform 0.05s ease;
}

.leaderboard-button:hover {
    background-color: #1D4ED8;
    transform: translateY(-1px);
}

.section-label {
    color: #4B5563;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 24px 0 0 0;
}

.game-grid {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.game-button {
    min-width: 160px;
    font-size: 1.2em;
}

.best-scores {
    margin-top: 20px;
    color: #374151; /* slate */
    font-weight: bold;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#best-streak {
    color: #d97706;
    font-size: 1.05em;
}

.password-upgrade {
    margin: 18px auto 0;
    padding: 14px 16px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    width: min(460px, calc(100% - 40px));
    text-align: left;
}

.password-title {
    font-weight: 700;
    color: #1f2933;
    margin-bottom: 8px;
    text-align: center;
}

.password-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin: 0;
}

.password-input {
    flex: 1 1 220px;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
}

.password-button {
    padding: 10px 14px;
    background-color: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    flex: 0 0 auto;
}

.password-button:hover {
    background-color: #1d4ed8;
}

.forgot-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 13px;
}

.site-footer {
    margin-top: 32px;
    padding: 12px 16px;
    text-align: center;
    font-size: 13px;
    color: #4b5563;
}

.site-footer a {
    color: #2563eb;
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

    .leaderboard-username-link {
        color: inherit;
        text-decoration: none;
    }

    .leaderboard-username-link:hover {
        text-decoration: underline;
    }
.leaderboard-container {
    position: relative;
    margin-top: 24px;
}

.leaderboard-inner.blurred {
    filter: blur(4px);
    pointer-events: none;
    user-select: none;
}

.leaderboard-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.leaderboard-overlay-card {
    background: rgba(15, 23, 42, 0.9);
    color: #f9fafb;
    padding: 20px 24px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    max-width: 360px;
    text-align: center;
}

.leaderboard-overlay-card h2 {
    font-size: 18px;
    margin-bottom: 8px;
}

.leaderboard-overlay-card p {
    font-size: 14px;
    margin-bottom: 14px;
}

.overlay-button {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    background: #0ea5e9;
    color: white;
    text-decoration: none;
    font-weight: 600;
}

/* ── Question of the Day ── */
.qotd-card {
    margin: 20px auto 8px;
    padding: 20px 24px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    max-width: 640px;
    text-align: left;
}

.qotd-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.qotd-title {
    margin: 0;
    font-size: 1.1em;
    color: #1f2933;
}

.qotd-difficulty {
    /* WCAG fix: #d97706 on white = 3.19:1, fails 4.5. Use amber-700 (#b45309) = 4.71:1 */
    color: #b45309;
    font-size: 0.9em;
    letter-spacing: 1px;
}

.qotd-prompt {
    font-size: 1em;
    color: #374151;
    line-height: 1.5;
    margin: 8px 0 16px;
}

.qotd-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.qotd-option {
    padding: 10px 14px;
    font-size: 0.95em;
    background: #f3f4f6;
    color: #1f2933;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

.qotd-option:hover:not(:disabled) {
    background: #e5e7eb;
    border-color: #9ca3af;
}

/* Distinct active/selected state — Batch 7 of AI-review punch-list,
   3-star "answer rows look visually identical with no obvious selected state". */
.qotd-option-active {
    background: #DBEAFE !important;
    border-color: #2563EB !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
    color: #1e40af !important;
    font-weight: 600;
}

.qotd-option:disabled {
    cursor: default;
    opacity: 0.85;
}

.qotd-option-correct {
    background: #d1fae5 !important;
    border-color: #10b981 !important;
    color: #065f46;
    font-weight: 600;
}

.qotd-option-wrong {
    background: #fee2e2 !important;
    border-color: #ef4444 !important;
    color: #991b1b;
}

.qotd-hints {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

/* Hint buttons — Batch 7 punch-list: AI critic 4-star "render as nearly-white
   pill buttons with grey text; from a distance they look like additional answer
   options on top of the four real options". Restyled as outlined ghost buttons
   that DON'T look like answer options. */
.qotd-hint-btn {
    /* WCAG fix: tap target was ~30px high. Bump to meet 44px touch-target floor. */
    padding: 8px 14px;
    min-height: 36px;
    font-size: 0.78em;
    font-weight: 600;
    background: transparent;
    color: #2563EB;
    border: 1.5px dashed #93C5FD;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}

.qotd-hint-btn:hover {
    background: #EFF6FF;
    border-color: #2563EB;
}

@media (prefers-color-scheme: dark) {
    /* WCAG: #2563EB on slate-800 = 4.04:1, fails 4.5. Use #93C5FD = 9.32:1. */
    .qotd-hint-btn {
        color: #93C5FD;
        border-color: #1e3a8a;
    }
    .qotd-hint-btn:hover {
        background: #1e3a8a;
        border-color: #60a5fa;
        color: #BFDBFE;
    }
}

.qotd-hint-used {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

/* Silent gating per pedagogy memory: no cost label is shown. The button
 * just disables when the user is broke, and a CTA points back to earning. */
.qotd-hint-locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.qotd-hint-broke-note {
    margin-top: 10px;
    font-size: 0.85em;
    color: #6b7280;
    flex-basis: 100%;
}

.qotd-hint-broke-note a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}

.qotd-hint-free-cue {
    margin-top: 10px;
    font-size: 0.82em;
    color: #b45309;
    font-style: italic;
    flex-basis: 100%;
}

.qotd-hint-text {
    margin-top: 10px;
}

.qotd-hint-item {
    padding: 6px 0;
    font-size: 0.9em;
    color: #374151;
    line-height: 1.4;
}

.qotd-result {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    font-size: 0.95em;
    line-height: 1.5;
}

.qotd-correct-msg {
    color: #059669;
    font-weight: 700;
}

.qotd-wrong-msg {
    color: #dc2626;
    font-weight: 700;
}

.qotd-notes {
    color: #6b7280;
    font-style: italic;
}

.qotd-tutorial-cta {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed #e5e7eb;
    font-size: 0.92em;
}

.qotd-tutorial-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}
.qotd-tutorial-link:hover { text-decoration: underline; }

/* ── Responsive ── */
@media (max-width: 600px) {
    .title h1 { font-size: 1.8em; }
    .game-button { font-size: 1.1em; padding: 14px; }
    .bottom-buttons { flex-direction: column; gap: 12px; }
    .bottom-buttons button { width: 100%; padding: 14px 20px; font-size: 1em; margin: 0; }
}

@media (max-width: 480px) {
    .container { padding: 12px; }
    .title h1 { font-size: 1.6em; }
    .username-input { width: 100%; max-width: 320px; font-size: 16px; height: 44px; }
    .game-button { font-size: 1em; padding: 14px; min-width: 120px; }
    .password-upgrade { width: calc(100% - 20px); }
    .password-form { flex-direction: column; }
    .password-input { flex: 1 1 100%; font-size: 16px; min-height: 44px; }
    .password-button { width: 100%; padding: 12px 14px; }
    .qotd-card { padding: 16px; max-width: 100%; }
    .qotd-option { padding: 12px 14px; }
    .qotd-hints { flex-direction: column; }
}

/* ── Accessibility: focus-visible ring ── */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ── Accessibility: reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Premium polish bundle (2026-05-07) ───────────────────────────────────
   Tabular nums, active states, tap targets, top progress bar, dark mode.
   Single-source: applies everywhere styles.css is imported.
*/

/* Tabular nums on common numeric displays (rating, score, timer, streak). */
.tabular-nums,
.session-recap-rating-value,
.session-recap-stat-value,
.timer-display,
.score-display,
#timer, #score, #streak,
.streak-count,
.coin-balance {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* Pressed-button feel — depth + scale on tap. Applies to every button class. */
button:active:not(:disabled),
.btn:active:not(:disabled),
.game-button:active:not(:disabled),
.game-card:active,
a.btn:active {
    transform: translateY(1px) scale(0.98);
    transition: transform 0.06s ease;
}

/* Mobile tap target floor — Material guideline of 48dp on game-relevant
   buttons. Doesn't override smaller utility buttons (sm class etc). */
@media (pointer: coarse) {
    .btn:not(.btn-sm),
    .game-button,
    .leaderboard-button,
    .password-button,
    button[type="submit"]:not(.btn-sm) {
        min-height: 48px;
        min-width: 48px;
    }
}

/* ── Top page-load progress bar ──────────────────────────────────────── */
.cx-top-progress {
    position: fixed;
    top: 0; left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    z-index: 10000;
    transition: width 0.2s ease, opacity 0.3s ease;
    pointer-events: none;
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.4);
}
.cx-top-progress.cx-done { opacity: 0; }

/* ── Countdown urgency: last-30-seconds red shift on game timers ─────── */
.timer-display.urgent,
.timer-urgent {
    color: #DC2626 !important;
    animation: timerPulse 0.9s ease-in-out infinite;
}
@keyframes timerPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}

/* ── Dark mode (system preference) ───────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --text: #f1f5f9;
        --text-secondary: #94a3b8;
        --border: #334155;
        --shadow: 0 4px 16px rgba(0,0,0,0.4);
    }
    body { color: var(--text); }
    /* Auth bar uses its own bg in auth.css; soften it for dark */
    .auth-bar { background: rgba(15, 23, 42, 0.92) !important; backdrop-filter: blur(8px); }
    .game-card,
    .puzzle-card,
    .session-recap-card {
        background: var(--surface) !important;
        border-color: var(--border) !important;
        color: var(--text) !important;
    }
    .session-recap-stat-value { color: #f1f5f9 !important; }
    .session-recap-stat-label,
    .session-recap-title { color: #94a3b8 !important; }
    .seq-prompt { background: #0b1220 !important; color: #f1f5f9 !important; }
    .puzzle-option { background: #0b1220 !important; color: #f1f5f9 !important; border-color: #334155 !important; }
    .puzzle-option.selected { background: #1e3a8a !important; }
    .qotd-card { background: var(--surface) !important; }
    /* WCAG fix: QOTD title + prompt were #1f2933 / #374151 on dark surface (#1e293b) */
    .qotd-title { color: #f1f5f9 !important; }
    .qotd-prompt { color: #cbd5e1 !important; }
    .qotd-difficulty { color: #fbbf24 !important; }  /* amber-400 — 4.5:1 on #1e293b */
    .qotd-option { background: #0b1220 !important; color: #f1f5f9 !important; }
    /* WCAG fix: hardcoded heading colors invisible on dark bg (#0f172a) */
    h1, h2, h3, h4 { color: var(--text); }
    /* WCAG fix: subtitle/meta secondary text was #4b5563 (2.36:1) on dark */
    .tx-subtitle, .tx-meta, .tx-category-blurb,
    .qs-subtitle, .tut-subtitle,
    p.section-label, p.muted {
        color: var(--text-secondary) !important;  /* #94a3b8 — 4.55:1 on #0f172a */
    }
    /* WCAG fix: section headings (tx-section-title h2) were #1f2933 on dark */
    .tx-section-title { color: #f1f5f9 !important; }
    /* WCAG fix: emphasize .X was #B91C1C (2.76:1) on dark bg — fails 3:1 for large text */
    .emphasize { color: #f87171 !important; }  /* red-400 — 4.79:1 on #0f172a */
    /* WCAG fix: footer secondary text rgb(75,85,99) = 2.36:1 on #0f172a */
    .footer-text, footer p, .site-footer, .site-footer p, .contact-blurb { color: #94a3b8 !important; }
    /* WCAG fix: blue links rgb(37,99,235) = 3.45:1 on dark bg — use lighter blue */
    a.tx-link, .tx-link, .site-footer a { color: #60a5fa !important; }
    /* WCAG fix: sequence game subtitle + puzzle-progress on dark surface */
    .seq-game-subtitle, #puzzle-progress { color: #cbd5e1 !important; }
    input[type="text"], input[type="number"], input[type="password"], input[type="email"], textarea {
        background: #0b1220;
        color: #f1f5f9;
        border-color: #334155;
    }
    input[type="text"]::placeholder, input[type="email"]::placeholder { color: #64748b; }
}

/* WCAG fix: disabled primary button — browser grays bg to ~gray-400, white text fails.
   Force slate text on the grayed bg so contrast holds when button is disabled. */
.btn-primary:disabled {
    color: #1f2937;
    opacity: 0.55;
}

/* ── Glossary tooltips ──────────────────────────────────────────────────────
 * Usage: <span class="gloss" data-def="plain English definition">term</span>
 * Tooltip is positioned by polish.js. Works on hover (desktop) + tap (mobile).
 */
.gloss {
    cursor: help;
    border-bottom: 1.5px dotted currentColor;
    text-decoration: none;
}

#cx-gloss-tip {
    display: none;
    position: absolute;
    max-width: 280px;
    padding: 8px 12px;
    background: #1e293b;
    color: #f1f5f9;
    font-size: 13px;
    line-height: 1.5;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    pointer-events: none;
    white-space: normal;
    font-family: 'Inter', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
    .gloss { border-bottom-color: #94a3b8; }
    #cx-gloss-tip { background: #0f172a; border: 1px solid #334155; }
}
