:root {
    /* ---- Core palette: digital scoreboard / arcade-timer ---- */
    --bg: #0A0C10;
    --bg-2: #12151C;
    --card: #171B24;
    --line: #2B303C;
    --line-soft: #1E222C;
    --text: #EEF0F5;
    --text-dim: #7C8494;
    --accent: #FFB020;
    --accent-dim: #3A2A0C;
    --good: #35D07F;
    --good-dim: #103524;
    --bad: #FF4D5E;
    --bad-dim: #3A131A;
    --track: #1C2028;

    /* ---- Extra tokens (design-only, safe to introduce) ---- */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 24px -16px rgba(0, 0, 0, 0.7);
    --font-display: 'Chakra Petch', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --ease: cubic-bezier(.2, .7, .3, 1);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-display);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 32px 16px 48px;
    position: relative;
    overflow-x: hidden;
}

/* Faint dot-grid backdrop — a single quiet texture, not decoration piled on decoration */
.bg-grid {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: radial-gradient(var(--line-soft) 1px, transparent 1px);
    background-size: 22px 22px;
    -webkit-mask-image: radial-gradient(ellipse 70% 55% at 50% 0%, #000 0%, transparent 75%);
    mask-image: radial-gradient(ellipse 70% 55% at 50% 0%, #000 0%, transparent 75%);
    opacity: 0.6;
}

.app {
    width: 100%;
    max-width: 480px;
    position: relative;
    z-index: 1;
}

.mono {
    font-family: var(--font-mono);
}

h1,
h2,
h3 {
    font-weight: 700;
    margin: 0;
    font-family: var(--font-display);
}

.screen {
    display: none;
}

.screen.active {
    display: block;
    animation: screen-in .32s var(--ease);
}

@keyframes screen-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* ---- Header brand ---- */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(155deg, var(--accent), #E08E00);
    color: #241C05;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 14px -4px rgba(255, 176, 32, 0.55);
}

.brand-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
}

.brand-tag {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    border: 0.5px solid var(--line);
    padding: 4px 8px;
    border-radius: 999px;
}

/* ---- Setup screen ---- */
.setup-hero {
    margin-bottom: 30px;
}

.setup-hero h1 {
    font-size: 30px;
    line-height: 1.18;
    margin-bottom: 10px;
    letter-spacing: -0.01em;
}

.setup-hero p {
    color: var(--text-dim);
    font-size: 14.5px;
    line-height: 1.65;
    margin: 0;
    max-width: 40ch;
    font-family: system-ui, sans-serif;
}

.field-block {
    margin-bottom: 24px;
}

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.field-label span:first-child {
    font-size: 13px;
    color: var(--text-dim);
    font-family: system-ui, sans-serif;
}

.field-label span.value {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.chip-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    flex: 1 1 0;
    min-width: 56px;
    padding: 12px 6px;
    text-align: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: border-color .15s var(--ease), background .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}

.chip em {
    font-style: normal;
    opacity: 0.65;
    font-weight: 700;
}

.chip:hover {
    border-color: var(--line-soft);
    background: var(--bg-2);
    transform: translateY(-1px);
}

.chip:active {
    transform: translateY(0);
}

.chip.selected {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.chip.selected em {
    opacity: 1;
}

.custom-input-wrap {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.custom-input-wrap input {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 15px;
    padding: 10px 12px;
    outline: none;
    transition: border-color .15s var(--ease);
}

.custom-input-wrap input:focus-visible,
.custom-input-wrap input:focus {
    border-color: var(--accent);
}

.range-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-input-wrap input {
    flex: 1;
    min-width: 0;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 15px;
    padding: 10px 12px;
    outline: none;
    text-align: center;
    transition: border-color .15s var(--ease);
}

.range-input-wrap input:focus-visible,
.range-input-wrap input:focus {
    border-color: var(--accent);
}

.range-input-wrap .range-sep {
    font-size: 12.5px;
    color: var(--text-dim);
    flex-shrink: 0;
    font-family: system-ui, sans-serif;
}

.err-text {
    font-size: 13px;
    color: var(--bad);
    margin-top: 8px;
    display: none;
    font-family: system-ui, sans-serif;
}

.err-text.show {
    display: block;
    animation: shake .3s var(--ease);
}

@keyframes shake {

    25%,
    75% {
        transform: translateX(-3px);
    }

    50% {
        transform: translateX(3px);
    }
}

.start-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(155deg, var(--accent), #E08E00);
    color: #241C05;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-display);
    font-size: 16.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    margin-top: 6px;
    box-shadow: 0 10px 26px -12px rgba(255, 176, 32, 0.55);
    transition: transform .12s var(--ease), box-shadow .12s var(--ease);
}

.start-btn:hover {
    box-shadow: 0 12px 30px -10px rgba(255, 176, 32, 0.65);
}

.start-btn:active {
    transform: scale(0.98);
    box-shadow: 0 6px 16px -10px rgba(255, 176, 32, 0.5);
}

/* ---- Game screen ---- */
.game-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 12.5px;
    color: var(--text-dim);
    font-family: system-ui, sans-serif;
}

.game-top .mono {
    color: var(--text);
    font-weight: 700;
}

.progress-track {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--track);
    overflow: hidden;
    margin-bottom: 26px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #FFD27A);
    border-radius: 3px;
    transition: width .25s var(--ease);
}

.timer-track {
    width: 100%;
    height: 5px;
    border-radius: 2.5px;
    background: var(--track);
    overflow: hidden;
    margin-bottom: 30px;
}

.timer-fill {
    height: 100%;
    background: var(--good);
    border-radius: 2.5px;
    width: 100%;
    transition: background-color .2s var(--ease);
}

.timer-fill.warn {
    background: var(--accent);
}

.timer-fill.danger {
    background: var(--bad);
}

.question-box {
    text-align: center;
    margin-bottom: 34px;
}

.question-box .expr {
    font-family: var(--font-mono);
    font-size: 50px;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.question-box .feedback {
    height: 22px;
    margin-top: 10px;
    font-size: 13.5px;
    font-weight: 700;
    font-family: system-ui, sans-serif;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity .15s var(--ease), transform .15s var(--ease);
}

.question-box .feedback.show {
    opacity: 1;
    transform: none;
}

.question-box .feedback.good {
    color: var(--good);
}

.question-box .feedback.bad {
    color: var(--bad);
}

.answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.announce {
    display: none;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    opacity: 0;
    transition: opacity .18s var(--ease);
}

.announce.show {
    display: flex;
    opacity: 1;
}

.announce-num {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: 0.02em;
}

.answer-btn {
    padding: 22px 8px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 23px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    font-variant-numeric: tabular-nums;
    transition: border-color .1s var(--ease), background .1s var(--ease), transform .08s var(--ease), box-shadow .1s var(--ease);
}

.answer-btn:hover {
    border-color: var(--line-soft);
    background: var(--bg-2);
}

.answer-btn:active {
    transform: scale(0.97);
}

.answer-btn.correct {
    background: var(--good-dim);
    border-color: var(--good);
    color: var(--good);
    animation: pop .28s var(--ease);
}

.answer-btn.wrong {
    background: var(--bad-dim);
    border-color: var(--bad);
    color: var(--bad);
    animation: pop .28s var(--ease);
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.04);
    }

    100% {
        transform: scale(1);
    }
}

.answer-btn[disabled] {
    cursor: default;
}

/* ---- Result screen ---- */
.result-hero {
    text-align: center;
    margin-bottom: 26px;
}

.result-hero .headline {
    font-size: 25px;
    margin-bottom: 6px;
    font-family: var(--font-display);
    font-weight: 700;
}

.result-hero .sub {
    color: var(--text-dim);
    font-size: 13.5px;
    font-family: system-ui, sans-serif;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 26px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-md);
    padding: 15px 16px;
    box-shadow: var(--shadow-card);
}

.stat-card .label {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-family: system-ui, sans-serif;
}

.stat-card .num {
    font-family: var(--font-mono);
    font-size: 21px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-card .num.good {
    color: var(--good);
}

.stat-card .num.bad {
    color: var(--bad);
}

.section-title {
    font-size: 13px;
    color: var(--text-dim);
    margin: 0 0 12px;
    font-family: system-ui, sans-serif;
    font-weight: 600;
}

.speed-note {
    font-size: 13.5px;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 22px;
    font-family: system-ui, sans-serif;
}

.speed-note b {
    color: var(--text);
    font-family: var(--font-mono);
}

.chart-wrap {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-md);
    padding: 14px 10px 8px;
    margin-bottom: 8px;
}

.chart-wrap svg {
    display: block;
    width: 100%;
    height: 130px;
}

.chart-wrap svg rect {
    transition: opacity .12s var(--ease);
}

.chart-wrap svg rect:hover {
    opacity: 0.75;
}

.legend-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 11.5px;
    color: var(--text-dim);
    margin-bottom: 24px;
    font-family: system-ui, sans-serif;
}

.legend-row .ldot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.stacked-bar {
    display: flex;
    height: 14px;
    border-radius: 7px;
    overflow: hidden;
    background: var(--track);
    margin-bottom: 10px;
}

.stacked-bar>div {
    height: 100%;
    transition: width .3s var(--ease);
}

.highlight-list {
    margin-bottom: 22px;
}

.highlight-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 14px;
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 8px;
    font-family: system-ui, sans-serif;
}

.highlight-row:last-child {
    margin-bottom: 0;
}

.highlight-row .hlabel {
    color: var(--text-dim);
}

.highlight-row .hval {
    font-family: var(--font-mono);
    font-weight: 700;
}

.miss-list {
    margin-bottom: 26px;
}

.miss-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line-soft);
    font-size: 13.5px;
    font-family: system-ui, sans-serif;
}

.miss-row:last-child {
    border-bottom: none;
}

.miss-row .mexpr {
    font-family: var(--font-mono);
    font-weight: 700;
    flex-shrink: 0;
}

.miss-row .mdetail {
    color: var(--text-dim);
    font-size: 12.5px;
    text-align: right;
}

.miss-empty {
    color: var(--text-dim);
    font-size: 13.5px;
    font-family: system-ui, sans-serif;
}

.table-list {
    margin-bottom: 26px;
}

.table-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line-soft);
}

.table-row:last-child {
    border-bottom: none;
}

.table-row .tnum {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-2);
    border: 1px solid var(--line-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 13.5px;
    flex-shrink: 0;
}

.table-row .tbar-wrap {
    flex: 1;
}

.table-row .tbar-track {
    height: 6px;
    border-radius: 3px;
    background: var(--track);
    overflow: hidden;
}

.table-row .tbar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--good);
    transition: width .3s var(--ease);
}

.table-row .tpct {
    width: 42px;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-dim);
    flex-shrink: 0;
}

.table-row.empty .tpct {
    color: var(--text-dim);
    opacity: 0.5;
}

.badge-row {
    display: flex;
    gap: 8px;
    margin-bottom: 26px;
    flex-wrap: wrap;
}

.badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    flex: 1 1 auto;
    font-family: system-ui, sans-serif;
    border: 1px solid transparent;
}

.badge.best {
    background: var(--good-dim);
    color: var(--good);
    border-color: rgba(53, 208, 127, 0.25);
}

.badge.worst {
    background: var(--bad-dim);
    color: var(--bad);
    border-color: rgba(255, 77, 94, 0.25);
}

.badge b {
    font-family: var(--font-mono);
}

.retry-btn {
    width: 100%;
    padding: 15px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 10px;
    transition: border-color .15s var(--ease), background .15s var(--ease), transform .1s var(--ease);
}

.retry-btn:hover {
    border-color: var(--line-soft);
    background: var(--bg-2);
}

.retry-btn:active {
    transform: scale(0.98);
}

.retry-btn.primary {
    background: linear-gradient(155deg, var(--accent), #E08E00);
    color: #241C05;
    border: none;
    box-shadow: 0 10px 26px -12px rgba(255, 176, 32, 0.5);
}

/* ---- Footer ---- */
.site-footer {
    max-width: 480px;
    margin: 34px auto 0;
    padding: 18px 4px 0;
    border-top: 1px solid var(--line-soft);
    position: relative;
    z-index: 1;
}

.site-footer p {
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.6;
    font-family: system-ui, sans-serif;
    margin: 0;
}

/* ---- Focus visibility for accessibility ---- */
button:focus-visible,
.chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---- Slightly roomier desktop presentation ---- */
@media (min-width: 640px) {
    body {
        justify-content: center;
        padding: 48px 24px;
    }

    .app {
        background: var(--bg-2);
        border: 1px solid var(--line-soft);
        border-radius: 22px;
        padding: 32px 30px 34px;
        box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.6);
    }

    .site-footer {
        padding-left: 0;
        padding-right: 0;
    }
}