:root {
    color-scheme: light;
    --background: #f7f0e6;
    --foreground: #2d211b;
    --muted: #76675d;
    --primary: #ef7d32;
    --primary-strong: #d95f1b;
    --primary-ink: #2b170b;
    --card: #fffaf3;
    --card-strong: #ffffff;
    --border: #ded1c2;
    --soft: #ede2d5;
    --danger: #b63b32;
    --success: #347357;
    --focus: #855120;
    --shadow: 0 16px 40px rgb(58 37 24 / 12%);
    --font-display: "Trebuchet MS", "Arial Rounded MT Bold", sans-serif;
    --font-body: "Segoe UI", Arial, sans-serif;
    --page-gutter: clamp(1rem, 4vw, 1.5rem);
}

[data-theme="dark"] {
    color-scheme: dark;
    --background: #211a17;
    --foreground: #fff4e7;
    --muted: #c7b8aa;
    --primary: #ff9a52;
    --primary-strong: #ffb77f;
    --primary-ink: #2b170b;
    --card: #302621;
    --card-strong: #3a2e28;
    --border: #594940;
    --soft: #40342e;
    --danger: #ff8a80;
    --success: #7cc3a2;
    --focus: #ffc68f;
    --shadow: 0 18px 42px rgb(0 0 0 / 28%);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    min-height: 100%;
    background: var(--background);
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: var(--background);
    color: var(--foreground);
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    text-rendering: optimizeLegibility;
}

button,
input {
    color: inherit;
    font: inherit;
}

button {
    min-height: 44px;
    border: 0;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: .48;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

svg {
    width: 1.4rem;
    height: 1.4rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2,
h3,
legend {
    font-family: var(--font-display);
    letter-spacing: -.025em;
}

.symbol-library {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.skip-link {
    position: fixed;
    z-index: 100;
    top: .75rem;
    left: .75rem;
    padding: .7rem 1rem;
    border-radius: 12px;
    background: var(--foreground);
    color: var(--background);
    transform: translateY(-160%);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link:focus {
    transform: translateY(0);
}

.app-shell {
    width: min(100%, 30rem);
    min-height: 100dvh;
    margin: 0 auto;
    padding: 0 var(--page-gutter) calc(6.5rem + env(safe-area-inset-bottom));
}

.view {
    padding: max(1.25rem, env(safe-area-inset-top)) 0 2rem;
    animation: view-in 220ms ease-out;
}

.view[hidden] {
    display: none;
}

.brand-header,
.game-toolbar,
.section-header {
    margin-bottom: 2rem;
}

.brand-header {
    display: flex;
    align-items: center;
    gap: .85rem;
}

.brand-logo-title {
    flex: 0 0 auto;
}

.brand-logo {
    display: block;
    width: clamp(6.75rem, 30vw, 7.75rem);
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.brand-logo-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand-header > .eyebrow {
    max-width: 12rem;
    margin: 0;
    line-height: 1.4;
}

.brand-header h1,
.game-heading h1,
.section-header h1 {
    margin: 0;
    font-size: clamp(2rem, 9vw, 2.8rem);
    font-weight: 800;
    line-height: .95;
}

.eyebrow {
    margin-bottom: .2rem;
    color: var(--primary-strong);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.intro-copy h2,
.section-header h1 {
    margin-bottom: .5rem;
}

.intro-copy p,
.section-header > p:last-child,
.field-help {
    color: var(--muted);
}

.selection-tools,
.inline-actions,
.game-toolbar,
.progress-label,
.dialog-actions {
    display: flex;
    align-items: center;
}

.selection-tools {
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem 0 .75rem;
    color: var(--muted);
    font-size: .85rem;
    font-weight: 700;
}

.inline-actions {
    gap: .85rem;
}

.text-button {
    min-height: 44px;
    padding: 0;
    background: transparent;
    color: var(--primary-strong);
    font-weight: 700;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .7rem;
}

.category-button {
    display: flex;
    min-height: 78px;
    align-items: center;
    gap: .7rem;
    padding: .8rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    text-align: left;
    transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.category-button:hover {
    border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
    transform: translateY(-1px);
}

.category-button.is-selected {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 14%, var(--card));
}

.category-emoji {
    display: grid;
    width: 2.2rem;
    height: 2.2rem;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 12px;
    background: var(--soft);
    font-size: 1.2rem;
}

.category-name {
    overflow: hidden;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
}

.field-help {
    margin: .65rem 0 1.6rem;
    font-size: .78rem;
}

.mode-fieldset,
.settings-group {
    min-width: 0;
    margin: 0 0 1.5rem;
    padding: 0;
    border: 0;
}

.mode-fieldset legend,
.settings-group legend,
.category-breakdown h2 {
    margin-bottom: .7rem;
    font-size: 1rem;
    font-weight: 800;
}

.mode-tabs {
    display: grid;
    gap: .6rem;
}

.mode-tab {
    display: grid;
    grid-template-columns: 2.3rem 1fr;
    align-items: center;
    gap: .75rem;
    padding: .75rem .85rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    text-align: left;
}

.mode-tab.is-selected {
    border-color: var(--primary);
    box-shadow: inset 3px 0 0 var(--primary);
}

.mode-tab svg {
    color: var(--primary-strong);
}

.mode-tab strong,
.mode-tab small {
    display: block;
}

.mode-tab small {
    margin-top: .1rem;
    color: var(--muted);
    font-size: .76rem;
}

.primary-action,
.secondary-action,
.danger-action {
    display: inline-flex;
    width: 100%;
    min-height: 52px;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .75rem 1rem;
    border-radius: 9999px;
    font-weight: 800;
}

.primary-action {
    background: var(--primary);
    color: var(--primary-ink);
    box-shadow: 0 8px 0 var(--primary-strong);
    transition: box-shadow 120ms ease, transform 120ms ease;
}

.primary-action:not(:disabled):active {
    box-shadow: 0 3px 0 var(--primary-strong);
    transform: translateY(5px);
}

.secondary-action {
    border: 1px solid var(--border);
    background: var(--card);
}

.danger-action {
    background: var(--danger);
    color: #fff;
}

.game-toolbar {
    justify-content: space-between;
}

.game-heading {
    text-align: center;
}

.game-heading p {
    margin-bottom: 0;
    color: var(--primary-strong);
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
}

.game-heading h1 {
    font-size: 1.45rem;
}

.icon-button {
    display: grid;
    width: 46px;
    min-height: 46px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card);
}

.favorite-button[aria-pressed="true"] {
    border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
    color: var(--danger);
}

.favorite-button[aria-pressed="true"] svg {
    fill: currentColor;
}

.duel-score {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .65rem;
    margin-bottom: 1.2rem;
}

.duel-score[hidden],
.quick-progress[hidden] {
    display: none;
}

.player-score {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: .4rem;
    padding: .65rem .75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
}

.player-score span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-score.is-current {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 13%, var(--card));
}

.versus {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
}

.quick-progress {
    margin-bottom: 1.2rem;
}

.progress-label {
    justify-content: space-between;
    margin-bottom: .45rem;
    font-size: .82rem;
}

.progress-track {
    height: .45rem;
    overflow: hidden;
    border-radius: 99px;
    background: var(--soft);
}

.progress-track span {
    display: block;
    width: 20%;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}

.question-stage {
    display: grid;
    min-height: 25rem;
    align-content: center;
}

.question-status {
    min-height: 1.5rem;
    margin-bottom: .55rem;
    color: var(--muted);
    font-size: .78rem;
    text-align: center;
}

.question-card {
    min-height: 20rem;
    perspective: 900px;
}

.question-card-inner {
    position: relative;
    height: 100%;
    min-height: inherit;
    transform-style: preserve-3d;
}

.question-card.is-changing .question-card-inner {
    animation: card-turn 360ms ease both;
}

.question-card-face {
    display: flex;
    min-height: inherit;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: clamp(1.5rem, 7vw, 2.25rem);
    border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--border));
    border-radius: 24px;
    background: var(--card-strong);
    box-shadow: var(--shadow);
    text-align: center;
}

.question-category {
    padding: .38rem .7rem;
    border-radius: 99px;
    background: color-mix(in srgb, var(--primary) 16%, var(--card));
    color: var(--primary-strong);
    font-size: .74rem;
    font-weight: 800;
}

.question-text {
    margin: 1.5rem 0;
    font-family: var(--font-display);
    font-size: clamp(1.55rem, 7vw, 2.25rem);
    font-weight: 700;
    line-height: 1.18;
}

.question-meta {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    color: var(--muted);
    font-size: .76rem;
}

.question-meta svg {
    width: 1rem;
    height: 1rem;
}

.question-error,
.quick-finished,
.empty-state {
    padding: 2rem 1.25rem;
    text-align: center;
}

.question-error[hidden],
.quick-finished[hidden],
.empty-state[hidden] {
    display: none;
}

.question-error {
    color: var(--danger);
}

.completion-mark,
.empty-icon {
    display: grid;
    width: 3.5rem;
    height: 3.5rem;
    margin: 0 auto 1rem;
    place-items: center;
    border-radius: 50%;
    background: var(--soft);
    color: var(--primary-strong);
}

.game-actions {
    display: grid;
    gap: .75rem;
    margin-top: 1rem;
}

.bottom-nav {
    position: fixed;
    z-index: 20;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: min(100%, 32rem);
    margin: 0 auto;
    padding: .45rem max(.65rem, env(safe-area-inset-right)) max(.45rem, env(safe-area-inset-bottom)) max(.65rem, env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    background: var(--background);
    box-shadow: 0 -8px 28px rgb(52 34 22 / 8%);
}

.bottom-nav.is-hidden {
    display: none;
}

.bottom-nav button {
    display: flex;
    min-height: 54px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-size: .69rem;
    font-weight: 700;
}

.bottom-nav button.is-active {
    color: var(--primary-strong);
}

.bottom-nav button.is-active svg {
    fill: color-mix(in srgb, var(--primary) 28%, transparent);
}

.saved-list {
    display: grid;
    gap: .7rem;
}

.saved-question {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .8rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
}

.saved-question p {
    margin-bottom: .35rem;
    font-family: var(--font-display);
    font-weight: 700;
}

.saved-question small {
    color: var(--muted);
}

.saved-question button {
    width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: var(--soft);
    color: var(--danger);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
}

.stat-card {
    display: flex;
    min-height: 7.5rem;
    flex-direction: column;
    justify-content: space-between;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
}

.stat-card-featured {
    grid-column: 1 / -1;
    min-height: 10rem;
    border-color: var(--primary);
    background: var(--primary);
    color: var(--primary-ink);
}

.stat-card span {
    font-size: .82rem;
    font-weight: 700;
}

.stat-card strong {
    font-family: var(--font-display);
    font-size: 2.6rem;
    line-height: 1;
}

.category-breakdown {
    margin-top: 1.8rem;
}

.category-stat {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .3rem .8rem;
    margin-bottom: .9rem;
}

.category-stat-bar {
    grid-column: 1 / -1;
    height: .4rem;
    overflow: hidden;
    border-radius: 99px;
    background: var(--soft);
}

.category-stat-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}

.settings-stack {
    display: grid;
    gap: .4rem;
}

.settings-group {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
}

.segmented-control {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: .25rem;
    padding: .25rem;
    border-radius: 12px;
    background: var(--soft);
}

.segmented-control button {
    min-width: 0;
    border-radius: 12px;
    background: transparent;
    font-size: .82rem;
    font-weight: 700;
}

.segmented-control button[aria-pressed="true"] {
    background: var(--card-strong);
    box-shadow: 0 1px 5px rgb(52 34 22 / 12%);
}

.player-settings label {
    display: grid;
    gap: .35rem;
    margin-top: .8rem;
    color: var(--muted);
    font-size: .8rem;
    font-weight: 700;
}

.player-settings input {
    min-height: 46px;
    padding: .65rem .75rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--background);
}

.action-settings {
    padding: 0;
    overflow: hidden;
}

.settings-row {
    display: grid;
    width: 100%;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: .8rem;
    padding: .9rem 1rem;
    background: var(--card);
    text-align: left;
}

.settings-row + .settings-row {
    border-top: 1px solid var(--border);
}

.settings-row > span:nth-child(2) {
    min-width: 0;
}

.settings-row strong,
.settings-row small {
    display: block;
}

.settings-row small {
    color: var(--muted);
}

.row-icon {
    display: grid;
    width: 2.3rem;
    height: 2.3rem;
    place-items: center;
    border-radius: 12px;
    background: var(--soft);
}

.row-chevron {
    width: 1.1rem;
    color: var(--muted);
}

.settings-row-danger .row-icon,
.settings-row-danger strong {
    color: var(--danger);
}

.toast-region {
    position: fixed;
    z-index: 60;
    right: 1rem;
    bottom: calc(5.5rem + env(safe-area-inset-bottom));
    left: 1rem;
    pointer-events: none;
}

.toast {
    width: min(100%, 26rem);
    margin: .5rem auto 0;
    padding: .8rem 1rem;
    border-radius: 12px;
    background: var(--foreground);
    color: var(--background);
    box-shadow: var(--shadow);
    font-weight: 700;
    text-align: center;
    animation: toast-in 180ms ease-out;
}

.confirm-dialog {
    width: min(calc(100% - 2rem), 28rem);
    padding: 1.2rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    color: var(--foreground);
    box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
    background: rgb(22 14 10 / 60%);
}

.confirm-dialog h2 {
    margin-bottom: .45rem;
}

.confirm-dialog p {
    color: var(--muted);
}

.privacy-dialog ul {
    display: grid;
    gap: .65rem;
    margin: 1rem 0 1.25rem;
    padding-left: 1.25rem;
    color: var(--foreground);
}

.privacy-dialog li::marker {
    color: var(--primary);
}

.dialog-actions {
    gap: .65rem;
}

.dialog-actions button {
    flex: 1;
}

@keyframes view-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes card-turn {
    0% { opacity: .55; transform: rotateY(-8deg) scale(.98); }
    100% { opacity: 1; transform: rotateY(0) scale(1); }
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 48rem) {
    .app-shell {
        width: min(100%, 50rem);
    }

    .category-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .mode-tabs {
        grid-template-columns: repeat(3, 1fr);
    }

    .mode-tab {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
    }

    .question-stage,
    .game-actions,
    .game-toolbar,
    .duel-score,
    .quick-progress {
        width: min(100%, 32rem);
        margin-right: auto;
        margin-left: auto;
    }

    .bottom-nav {
        bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: 16px;
    }
}

@media (min-width: 75rem) {
    .app-shell {
        width: min(100%, 62rem);
    }

    .view-play {
        display: grid;
        grid-template-columns: 1.25fr .9fr;
        gap: 0 2.5rem;
    }

    .view-play .brand-header,
    .view-play .intro-copy,
    .view-play .selection-tools,
    .view-play .category-grid,
    .view-play .field-help {
        grid-column: 1;
    }

    .view-play .mode-fieldset,
    .view-play .primary-action {
        grid-column: 2;
    }

    .view-play .mode-fieldset {
        grid-row: 2 / span 4;
    }

    .view-play .mode-tabs {
        grid-template-columns: 1fr;
    }
}

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