:root {
    color-scheme: light;
    --bg: #edf7f0;
    --card: #ffffff;
    --surface: #f4faf6;
    --hover: #e4f4e9;
    --border: #a8cfb5;
    --text: #173326;
    --muted: #526b5d;
    --accent: #267148;
    --accent-dark: #175434;
    --accent-soft: #dff2e5;
    --highlight: #f2bd3f;
    --correct: #16703b;
    --wrong: #ad3850;
}

body.music-theme {
    --bg: #f3effb;
    --surface: #f8f5fd;
    --hover: #ece3fa;
    --border: #c5afe4;
    --text: #30223d;
    --muted: #665673;
    --accent: #7245a5;
    --accent-dark: #55307e;
    --accent-soft: #eee4fa;
    --highlight: #e9ae32;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 12%, color-mix(in srgb, var(--highlight) 80%, transparent) 0 3px, transparent 4px),
        radial-gradient(circle at 86% 18%, color-mix(in srgb, var(--highlight) 70%, transparent) 0 3px, transparent 4px),
        radial-gradient(circle at 82% 86%, var(--accent-soft) 0, transparent 31%),
        var(--bg);
}

button,
input {
    font: inherit;
}

.container {
    width: 100%;
    max-width: 620px;
    position: relative;
    padding: 1.5rem;
    overflow: hidden;
    background: var(--card);
    border: 1px solid color-mix(in srgb, var(--border) 72%, white);
    border-radius: 1.35rem;
    box-shadow: 0 18px 42px -18px color-mix(in srgb, var(--accent) 42%, transparent);
}

.hidden {
    display: none !important;
}

.eyebrow {
    margin-bottom: .28rem;
    color: var(--accent);
    text-align: center;
    font-size: .75rem;
    font-weight: 850;
    letter-spacing: .15em;
}

h1 {
    margin-bottom: .3rem;
    color: var(--accent);
    text-align: center;
    font-size: clamp(1.8rem, 7vw, 2.35rem);
    line-height: 1.1;
}

.subtitle {
    margin: 0 auto 1.1rem;
    max-width: 34rem;
    color: var(--muted);
    text-align: center;
    font-size: .98rem;
    line-height: 1.48;
}

.topic-mascot {
    width: 8.5rem;
    height: 8.5rem;
    position: relative;
    display: grid;
    place-items: center;
    margin: .35rem auto 1rem;
    color: var(--text);
    background: linear-gradient(145deg, #fff, var(--accent-soft));
    border: 3px solid color-mix(in srgb, var(--border) 78%, white);
    border-radius: 50%;
    box-shadow: 0 12px 24px -16px var(--accent);
    font-size: 4.7rem;
    line-height: 1;
    animation: mascot-float 3.2s ease-in-out infinite;
}

.topic-mascot.small {
    width: 4.4rem;
    height: 4.4rem;
    margin: -.25rem auto .7rem;
    border-width: 2px;
    font-size: 2.35rem;
}

.topic-mascot::before,
.topic-mascot::after {
    content: "✦";
    position: absolute;
    color: var(--highlight);
    font-size: 1.2rem;
}

.hero-illustration {
    width: min(100%, 330px);
    max-height: 190px;
    display: block;
    margin: .45rem auto 1rem;
    object-fit: contain;
    background: var(--surface);
    border: 2px solid color-mix(in srgb, var(--border) 68%, white);
    border-radius: 1rem;
    box-shadow: 0 12px 24px -18px var(--accent);
}

.potato-theme .hero-illustration {
    width: min(100%, 390px);
    max-height: 260px;
}

.music-theme .hero-illustration {
    width: min(100%, 550px);
    max-height: 360px;
}

.topic-mascot::before {
    top: .6rem;
    left: -.2rem;
}

.topic-mascot::after {
    right: -.15rem;
    bottom: .8rem;
    font-size: .9rem;
}

.category-picker {
    margin: 0 0 1rem;
    padding: .9rem;
    border: 1px solid color-mix(in srgb, var(--border) 55%, white);
    border-radius: .9rem;
}

.category-picker legend {
    padding: 0 .38rem;
    color: var(--accent);
    font-size: .92rem;
    font-weight: 800;
}

.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .58rem;
}

.category-grid label {
    position: relative;
    margin: 0;
}

.category-grid input {
    position: absolute;
    opacity: 0;
}

.category-grid span {
    min-height: 3.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: .68rem;
    color: var(--text);
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: .7rem;
    text-align: center;
    font-size: .88rem;
    font-weight: 750;
    line-height: 1.25;
    cursor: pointer;
}

.category-grid input:checked + span {
    color: var(--accent-dark);
    background: var(--accent-soft);
    border-color: var(--accent);
}

.category-grid input:focus-visible + span {
    outline: 3px solid var(--highlight);
    outline-offset: 2px;
}

.round-hint {
    margin: .1rem 0 .9rem;
    color: var(--muted);
    text-align: center;
    font-size: .82rem;
    line-height: 1.45;
}

.sound-library,
.sound-panel {
    margin: 0 0 1rem;
    padding: .95rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .9rem;
}

.sound-library summary {
    color: var(--accent);
    cursor: pointer;
    font-size: .98rem;
    font-weight: 800;
}

.sound-panel summary,
.visual-disclosure summary {
    color: var(--accent-dark);
    cursor: pointer;
    font-size: .9rem;
    font-weight: 800;
    line-height: 1.4;
}

.sound-library summary:focus-visible,
.sound-button:focus-visible,
.sound-panel summary:focus-visible,
.visual-disclosure summary:focus-visible {
    outline: 3px solid var(--highlight);
    outline-offset: 3px;
}

.sound-library > p,
.sound-panel > p {
    margin: .6rem 0 .8rem;
    color: var(--muted);
    font-size: .84rem;
    line-height: 1.45;
}

#sound-library-list h3,
.sound-panel h3 {
    margin: .85rem 0 .5rem;
    color: var(--accent);
    font-size: .91rem;
}

.sound-panel h3 {
    margin-top: 0;
}

.sound-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: .5rem;
}

.sound-button {
    min-height: 2.8rem;
    padding: .58rem .7rem;
    color: var(--accent-dark);
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: .65rem;
    cursor: pointer;
    font-weight: 750;
    text-align: left;
}

.sound-button:hover,
.sound-button[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.sound-library .sound-credit {
    margin-bottom: 0;
    font-size: .75rem;
}

.sound-credit a {
    color: var(--accent-dark);
}

.sound-status:empty {
    display: none;
}

.review-timeline {
    margin: 0 0 1rem;
    padding: .85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .9rem;
}

.review-timeline summary {
    color: var(--accent);
    cursor: pointer;
    font-weight: 800;
}

.review-timeline summary:focus-visible,
.review-timeline a:focus-visible {
    outline: 3px solid var(--highlight);
    outline-offset: 3px;
}

.review-timeline p {
    margin: .65rem 0;
    color: var(--muted);
    font-size: .84rem;
    line-height: 1.45;
}

.review-timeline img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: .65rem;
}

.review-timeline a {
    display: inline-block;
    margin-top: .6rem;
    color: var(--accent-dark);
    font-size: .84rem;
    font-weight: 750;
}

.btn {
    width: 100%;
    min-height: 3.15rem;
    margin-bottom: .55rem;
    padding: .85rem 1rem;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: .72rem;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 160ms ease, transform 160ms ease;
}

.btn:hover {
    background: var(--accent-dark);
}

.btn-secondary {
    color: var(--accent-dark);
    background: var(--accent-soft);
}

.btn-secondary:hover {
    background: color-mix(in srgb, var(--accent-soft) 78%, var(--border));
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-bottom: .7rem;
    font-size: .86rem;
    font-weight: 800;
}

.category-badge {
    max-width: 62%;
    overflow: hidden;
    color: var(--accent);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.progress-bar {
    width: 100%;
    height: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
    background: var(--accent-soft);
    border-radius: 99px;
}

.progress-fill {
    width: 0;
    height: 100%;
    background: var(--highlight);
    border-radius: inherit;
    transition: width 260ms ease;
}

.answer-feedback {
    margin-top: .85rem;
    padding: .9rem 1rem;
    border: 1px solid;
    border-left-width: 5px;
    border-radius: .75rem;
    font-weight: 700;
    line-height: 1.45;
}

.answer-feedback:empty {
    display: none;
}

.answer-feedback.correct {
    color: var(--correct);
    background: color-mix(in srgb, var(--correct) 10%, var(--card));
    border-color: color-mix(in srgb, var(--correct) 45%, var(--border));
    border-left-color: var(--correct);
}

.answer-feedback.wrong {
    color: var(--wrong);
    background: color-mix(in srgb, var(--wrong) 9%, var(--card));
    border-color: color-mix(in srgb, var(--wrong) 42%, var(--border));
    border-left-color: var(--wrong);
}

.question-visual {
    margin: 0 0 1rem;
    padding: .55rem;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--border) 58%, white);
    border-radius: 1rem;
    text-align: center;
}

.question-visual img {
    width: 100%;
    max-height: 265px;
    display: block;
    object-fit: contain;
    border-radius: .7rem;
}

.potato-theme .question-visual img {
    max-height: 300px;
}

.potato-theme .numbered-visual-frame {
    position: relative;
    width: 100%;
    margin-inline: auto;
}

.potato-theme .numbered-visual .numbered-visual-frame {
    width: min(100%, 450px);
}

.potato-theme .numbered-visual .numbered-visual-frame img {
    height: auto;
    max-height: none;
}

.number-highlight {
    position: absolute;
    z-index: 1;
    width: 6.6%;
    aspect-ratio: 1;
    box-sizing: border-box;
    border: clamp(2px, .35vw, 4px) solid #b24212;
    border-radius: 50%;
    background: transparent;
    box-shadow: 0 0 0 3px #fff9d8, 0 0 13px 7px #ffd760;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.number-highlight.pulse {
    animation: number-highlight-pulse .7s ease-in-out 2;
}

@keyframes number-highlight-pulse {
    50% { box-shadow: 0 0 0 6px #fff9d8, 0 0 21px 14px #ffd760; }
}

.music-theme .question-visual img {
    max-height: 360px;
}

.question-visual figcaption {
    padding: .45rem .35rem .1rem;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
    line-height: 1.35;
}

.answer-visual {
    margin: .75rem 0 0;
}

.question-card {
    margin-bottom: .85rem;
    padding: 1.1rem 1.2rem;
    text-align: left;
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--border) 52%, white);
    border-radius: 1rem;
}

.question-card h2 {
    color: var(--accent);
    font-size: clamp(1.25rem, 5vw, 1.85rem);
    line-height: 1.25;
}

.options-grid {
    display: grid;
    gap: .7rem;
}

.option-btn {
    min-height: 3.45rem;
    position: relative;
    padding: .82rem 3.1rem .82rem .95rem;
    color: var(--text);
    background: #fff;
    border: 2px solid var(--border);
    border-radius: .75rem;
    text-align: left;
    font-size: 1rem;
    font-weight: 720;
    line-height: 1.3;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.option-btn:hover:not([disabled]) {
    background: var(--hover);
    border-color: var(--accent);
}

.option-btn.correct {
    color: #104e29;
    background: #dcfce7 !important;
    border-color: var(--correct) !important;
    animation: answer-pop 320ms ease-out;
}

.option-btn.correct::after {
    content: "✓";
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    font-size: 1.45rem;
    font-weight: 900;
}

.option-btn.wrong {
    color: #8e1d33;
    background: #fff1f2 !important;
    border-color: var(--wrong) !important;
    animation: answer-shake 320ms ease-in-out;
}

.option-btn.wrong::after {
    content: "×";
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    font-size: 1.45rem;
    font-weight: 900;
}

.next-wrap {
    margin-top: .85rem;
}

.sound-panel,
.visual-disclosure {
    margin: .7rem 0 0;
    padding: .75rem .95rem;
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--border) 68%, white);
    border-radius: .75rem;
}

.sound-panel .sound-buttons {
    margin-top: .75rem;
}

.result-card {
    margin: 1rem 0;
    padding: 1.1rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--border) 52%, white);
    border-radius: .9rem;
    text-align: center;
}

.result-card strong {
    display: block;
    margin-bottom: .35rem;
    color: var(--accent);
    font-size: 1.2rem;
}

.result-card p {
    color: var(--muted);
    line-height: 1.45;
}

.back-link {
    display: block;
    margin-top: .8rem;
    color: var(--muted);
    text-align: center;
    text-decoration: none;
    font-size: .86rem;
}

.back-link:hover {
    color: var(--accent);
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .4rem 1.2rem;
    margin-top: 1rem;
    text-align: center;
}

.footer-links a {
    color: var(--accent-dark);
    font-size: .86rem;
    text-decoration: underline;
    text-underline-offset: .18em;
}

.footer-links a:focus-visible,
.privacy-content a:focus-visible {
    outline: 3px solid var(--accent-dark);
    outline-offset: 3px;
}

.privacy-content {
    max-width: 720px;
}

.privacy-content h1,
.privacy-content .subtitle {
    text-align: left;
}

.privacy-content .subtitle {
    margin-bottom: 1.3rem;
}

.privacy-content section + section {
    margin-top: 1.2rem;
}

.privacy-content h2 {
    margin-bottom: .35rem;
    color: var(--accent);
    font-size: 1.12rem;
}

.privacy-content p {
    line-height: 1.55;
}

.privacy-content p + p {
    margin-top: .6rem;
}

.privacy-content section a {
    color: var(--accent-dark);
    text-decoration: underline;
}

.btn:active,
.option-btn:active:not([disabled]) {
    transform: scale(.985);
}

.btn:focus-visible,
.option-btn:focus-visible {
    outline: 3px solid var(--highlight);
    outline-offset: 3px;
}

@keyframes mascot-float {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-7px) rotate(1deg); }
}

@keyframes answer-pop {
    0%, 100% { transform: scale(1); }
    45% { transform: scale(1.025); }
}

@keyframes answer-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@media (max-width: 520px) {
    .container { padding: 1.1rem; }
    .category-grid { grid-template-columns: 1fr; }
    .category-grid span { min-height: 3.3rem; }
    .topic-mascot { width: 7.3rem; height: 7.3rem; font-size: 4rem; }
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #0c2015;
        --card: #132d20;
        --surface: #0f261a;
        --hover: #1e4932;
        --border: #538768;
        --text: #f1fbf4;
        --muted: #c5dacb;
        --accent: #80d5a1;
        --accent-dark: #a5e7bd;
        --accent-soft: #214b32;
        --highlight: #ffd166;
        --correct: #64db8f;
        --wrong: #fb8297;
    }

    body.music-theme {
        --bg: #1c1427;
        --card: #291c38;
        --surface: #21162e;
        --hover: #422c59;
        --border: #8462aa;
        --text: #fbf7ff;
        --muted: #d7c8e3;
        --accent: #d1adf5;
        --accent-dark: #e3cafb;
        --accent-soft: #47315e;
    }

    .container,
    .question-card,
    .result-card,
    .category-picker {
        border-color: color-mix(in srgb, var(--border) 70%, transparent);
    }

    .topic-mascot {
        background: linear-gradient(145deg, var(--surface), var(--accent-soft));
        border-color: var(--border);
    }

    .option-btn {
        color: var(--text);
        background: var(--surface);
    }

    .option-btn.correct {
        color: #ecfff2;
        background: #14532d !important;
    }

    .option-btn.wrong {
        color: #fff1f3;
        background: #7f1d2d !important;
    }

    .btn {
        color: #10271a;
    }

    body.music-theme .btn {
        color: #251632;
    }

    .btn.btn-secondary,
    body.music-theme .btn.btn-secondary {
        color: var(--text);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
    }
}
