/* Percentages — game-specific styles.
 * Mirrors Quick Math structure; the problem card holds a word-problem
 * question instead of a flat arithmetic expression, so the current-problem
 * row stacks the question above the answer instead of sitting on one line.
 */

.game-page {
    padding: 1.5rem 0 2rem;
    --jump-accent: var(--cat-memory);
}

.game-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0 0.25rem;
}

.game-head h1 {
    margin: 0;
    font-family: var(--font-hand);
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1.05;
}

.game-head .category {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--cat-memory-bg);
    color: var(--cat-memory);
}

.game-lede {
    color: var(--text-secondary);
    margin: 0 0 1.25rem;
    font-family: var(--font-hand);
    font-size: 1.25rem;
    line-height: 1.5;
}

/* Start panel */
.start-panel {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem 1.4rem;
    margin: 1rem 0 1.5rem;
    overflow: hidden;
}

.start-panel h2 {
    font-family: var(--font-hand);
    margin: 0 0 0.25rem;
    font-size: 1.8rem;
    color: var(--cat-memory);
    transform: rotate(-1deg);
    display: inline-block;
}
.start-panel h2::after { display: none; }

.panel-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem 1.25rem;
    margin: 0.25rem 0 1rem;
    align-items: start;
}
.panel-col { min-width: 0; }
@media (max-width: 640px) {
    .panel-grid { grid-template-columns: 1fr; gap: 0.5rem 1rem; }
}

.start-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
}
.start-footer .untimed-row { margin: 0; }

/* Circle pickers */
.circle-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.3rem 0 0;
}
.circle-pick { position: relative; cursor: pointer; }
.circle-pick input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.circle-pick > span {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg);
    border: 1.5px dashed var(--border-strong);
    font-family: var(--font-hand);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.05;
    color: var(--text);
    transition: all 0.18s ease;
    transform: rotate(var(--rot, 0));
    user-select: none;
    text-align: center;
    padding: 0.1rem 0.2rem;
}
.op-row .circle-pick > span { font-size: 0.95rem; }

.circle-pick:nth-child(1) > span { --rot: -5deg; }
.circle-pick:nth-child(2) > span { --rot: 4deg; }
.circle-pick:nth-child(3) > span { --rot: -3deg; }
.circle-pick:nth-child(4) > span { --rot: 6deg; }

.circle-pick-oval > span {
    width: auto;
    height: auto;
    min-width: 68px;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-family: var(--font-hand);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.circle-pick:hover > span {
    transform: rotate(0) scale(1.06);
    color: var(--cat-memory);
    border-color: var(--cat-memory);
}
.circle-pick input:checked + span {
    border-style: solid;
    border-color: var(--cat-memory);
    background: var(--cat-memory-bg);
    color: var(--cat-memory);
    box-shadow: 0 2px 0 rgba(58, 123, 184, 0.12);
}
.circle-pick input:focus-visible + span {
    outline: 2px solid var(--cat-memory);
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .circle-pick > span { transform: none; transition: none; }
    .circle-pick:hover > span { transform: scale(1.06); }
}

/* Length circles */
.length-row .circle-pick > span { font-size: 1.2rem; }
.length-row .circle-pick > span strong {
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.25rem;
    line-height: 1;
}
.length-row .circle-pick > span small {
    font-family: var(--font-sans);
    font-size: 0.54rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 0.1rem;
    opacity: 0.7;
}

/* Op circle label + icon stack */
.op-row .circle-pick > span .op-icon {
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.3rem;
    line-height: 1;
    margin-bottom: 0.05rem;
}
.op-row .circle-pick > span .op-name {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.75;
    font-family: var(--font-sans);
}
.op-row .circle-pick input:checked + span .op-name { opacity: 1; }

.untimed-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
    font-family: var(--font-hand);
    font-size: 1.05rem;
    color: var(--text-secondary);
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 1.4rem;
    font-family: var(--font-hand);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    border: 2px solid var(--cat-memory);
    border-radius: 999px;
    background: var(--cat-memory);
    color: #fff;
    cursor: pointer;
    box-shadow: 3px 4px 0 rgba(58, 123, 184, 0.28);
    transform: rotate(-0.8deg);
    transition: transform 0.18s, box-shadow 0.15s, filter 0.15s;
}
.btn-primary:hover {
    filter: brightness(0.96);
    transform: rotate(0) translate(-1px, -1px);
    box-shadow: 4px 5px 0 rgba(58, 123, 184, 0.32);
}
.btn-primary:active {
    transform: rotate(0) translate(2px, 2px);
    box-shadow: 1px 1px 0 rgba(58, 123, 184, 0.25);
}
.btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 1rem;
    font-family: var(--font-hand);
    font-size: 1.15rem;
    font-weight: 600;
    border: 1.5px dashed var(--border-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transform: rotate(var(--btn-rot, 0.8deg));
    transition: transform 0.18s, border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-ghost:hover {
    transform: rotate(0) scale(1.03);
    border-style: solid;
    border-color: var(--cat-memory);
    color: var(--cat-memory);
    background: var(--cat-memory-bg);
}
.btn-ghost:focus-visible { outline: 2px solid var(--cat-memory); outline-offset: 3px; }
.btn-ghost:nth-of-type(odd)  { --btn-rot: -0.8deg; }
.btn-ghost:nth-of-type(even) { --btn-rot: 1deg; }

@media (prefers-reduced-motion: reduce) {
    .btn-primary,
    .btn-ghost { transform: none; }
}

/* Game area */
.game-area {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: transform 0.08s;
}

.play-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}
@media (min-width: 720px) {
    .play-grid {
        grid-template-columns: 1fr minmax(260px, 320px);
        gap: 1.75rem;
        align-items: start;
    }
}
.play-col { min-width: 0; }
.play-col-card { display: flex; flex-direction: column; gap: 0.5rem; }
.play-col-pad  { display: flex; flex-direction: column; gap: 1rem; }

.game-area.shake { animation: shake 0.35s; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
    .game-area.shake { animation: none; }
}

/* HUD */
.hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed var(--border);
    flex-wrap: wrap;
}
.hud-group {
    position: relative;
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}
.hud-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
}
.hud-value {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
}
.timer-low {
    color: var(--danger);
    animation: pulse 0.8s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
@media (prefers-reduced-motion: reduce) {
    .timer-low { animation: none; }
}
.score-bump { animation: scoreBump 0.35s ease-out; }
@keyframes scoreBump {
    0%   { transform: scale(1); color: var(--cat-memory); }
    40%  { transform: scale(1.35); color: var(--cat-memory); }
    100% { transform: scale(1); color: var(--text); }
}
@media (prefers-reduced-motion: reduce) {
    .score-bump { animation: none; }
}
.score-pop {
    position: absolute;
    top: -0.5em;
    left: 100%;
    margin-left: 0.2em;
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--cat-memory);
    opacity: 0;
    pointer-events: none;
}
.score-pop.pop-run { animation: popUp 0.9s ease-out forwards; }
@keyframes popUp {
    0%   { opacity: 0; transform: translateY(0); }
    25%  { opacity: 1; transform: translateY(-6px); }
    100% { opacity: 0; transform: translateY(-28px); }
}
@media (prefers-reduced-motion: reduce) {
    .score-pop.pop-run { animation: none; opacity: 0; }
}

.hud-streak .streak-value {
    color: var(--accent);
    font-family: var(--font-hand);
    font-size: 1.5rem;
    line-height: 1;
}
.hud-streak.streak-hot .streak-value {
    color: var(--cat-car);
    text-shadow: 0 0 8px rgba(212, 122, 60, 0.4);
}

.btn-end {
    margin-left: auto;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-end:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--bg-soft);
}
.btn-end:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

/* Problem card */
.problem-wrap {
    display: flex;
    justify-content: center;
    padding: 0.75rem 0.25rem 1.25rem;
}
.problem-card {
    --card-bg: #fdf8ea;
    --card-ink: #1f2a3a;
    --card-rule: #d7cbaa;
    --rule-gap: 2rem;
    position: relative;
    width: min(440px, 100%);
    min-height: calc(var(--rule-gap) * 9);
    max-height: calc(var(--rule-gap) * 11);
    background:
        radial-gradient(circle at 5% 0%, rgba(139, 90, 43, 0.05) 0%, transparent 38%),
        radial-gradient(circle at 95% 100%, rgba(139, 90, 43, 0.05) 0%, transparent 38%),
        radial-gradient(circle at 80% 15%, rgba(0, 0, 0, 0.025) 0%, transparent 25%),
        linear-gradient(135deg, #fdf8ea 0%, #f5ecd4 100%);
    color: var(--card-ink);
    padding: 1.2rem 1.4rem 1.2rem;
    border-radius: 4px;
    box-shadow:
        0 1px 0 rgba(0, 0, 0, 0.04),
        0 12px 28px -14px rgba(0, 0, 0, 0.3),
        inset 0 0 0 1px rgba(0, 0, 0, 0.04);
    transform: rotate(-0.6deg);
    transition: transform 0.25s;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.problem-card:hover { transform: rotate(0); }
@media (prefers-reduced-motion: reduce) {
    .problem-card { transform: none; }
    .problem-card:hover { transform: none; }
}

:root[data-theme="dark"] .problem-card {
    --card-bg: #f3ead5;
    --card-ink: #1f2a3a;
    --card-rule: #c7b890;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) .problem-card {
        --card-bg: #f3ead5;
        --card-ink: #1f2a3a;
        --card-rule: #c7b890;
    }
}

/* Tape strip along the top */
.problem-card-tape {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%) rotate(-2deg);
    width: 80px;
    height: 20px;
    background: rgba(113, 166, 208, 0.35);
    border: 1px solid rgba(113, 166, 208, 0.55);
    border-radius: 2px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* History list */
.problem-history {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 0.15rem;
    overflow: hidden;
    flex: 1 1 auto;
    min-height: 0;
    color: var(--card-ink);
    mask-image: linear-gradient(to bottom, transparent 0%, black 35%, black 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 35%, black 100%);
}
.problem-history li {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.3em;
    opacity: 0.6;
    font-family: var(--font-hand);
    font-size: 1.2rem;
    line-height: 1.5;
    animation: historyIn 0.28s ease-out;
    flex-wrap: wrap;
}
@keyframes historyIn {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 0.55; }
}
.problem-history .h-expr  { color: inherit; }
.problem-history .h-eq    { opacity: 0.7; }
.problem-history .h-ans   { font-weight: 700; }
.problem-history li.correct .h-ans { color: #2a7a52; }
.problem-history li.wrong  .h-ans { color: #b04141; text-decoration: line-through; }
.problem-history li.wrong  .h-correct { color: #2a7a52; font-size: 0.9em; margin-left: 0.15em; }
.problem-history li.skip   .h-ans { color: #7a7668; font-style: italic; }
.problem-history li .h-mark { font-size: 0.9em; margin-left: 0.15em; }
@media (prefers-reduced-motion: reduce) {
    .problem-history li { animation: none; }
}

/* Current problem — stacked question over answer row */
.problem-current {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    padding-top: 0.45rem;
    border-top: 1.5px dashed var(--card-rule);
    margin-top: auto;
    min-height: calc(var(--rule-gap) * 3);
}
.problem-label {
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--card-ink);
    opacity: 0.6;
    text-align: center;
}
.problem-question {
    font-family: var(--font-hand);
    font-weight: 600;
    font-size: 1.55rem;
    line-height: 1.25;
    color: var(--card-ink);
    text-align: center;
    padding: 0.1rem 0.25rem;
    word-break: normal;
}
.problem-answer-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.25rem;
    padding-top: 0.2rem;
}
.problem-equals {
    font-family: var(--font-hand);
    font-weight: 600;
    font-size: 1.8rem;
    color: var(--card-ink);
    opacity: 0.75;
}
.dollar-prefix {
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 2rem;
    color: var(--cat-memory);
    line-height: 1;
    padding-right: 0.05em;
}
.problem-answer {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 2rem;
    color: var(--cat-memory);
    min-width: 3ch;
    border-bottom: 2px solid var(--cat-memory);
    padding: 0 0.25em 0.05em;
    white-space: nowrap;
    position: relative;
    line-height: 1.05;
}
.problem-answer.is-empty::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 0.9em;
    background: var(--cat-memory);
    margin-left: 0.1em;
    animation: caretBlink 1s steps(1) infinite;
    opacity: 0.8;
    align-self: center;
}
@keyframes caretBlink {
    50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .problem-answer.is-empty::after { animation: none; }
}

/* Keypad */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.55rem;
    max-width: 320px;
    margin: 0 auto;
    width: 100%;
}
.key {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text);
    background: var(--bg-soft);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.08s, background 0.15s, border-color 0.15s;
    font-family: inherit;
}
.key:hover { background: var(--surface); border-color: var(--cat-memory); }
.key:active { transform: translateY(1px) scale(0.97); }
.key:focus-visible { outline: 2px solid var(--cat-memory); outline-offset: 2px; }

.key-back { color: var(--text-muted); font-size: 1.3rem; }
.key-back:hover { color: var(--danger); border-color: var(--danger); }
.key-dot { font-size: 1.6rem; color: var(--cat-memory); font-weight: 800; }
.key-slash { font-size: 1.8rem; color: var(--cat-memory); font-weight: 800; }
.key-space { font-size: 1.6rem; color: var(--text-muted); font-weight: 700; }
.key-enter {
    color: #fff;
    background: var(--cat-memory);
    border-color: var(--cat-memory);
    font-family: var(--font-hand);
    font-size: 1.6rem;
    font-weight: 700;
}
.key-enter:hover { filter: brightness(0.92); background: var(--cat-memory); color: #fff; }

/* Action row / feedback */
.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.25rem 0 0;
    justify-content: center;
}
.feedback {
    min-height: 1.5rem;
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
    margin: 0.25rem 0 0.5rem;
    color: transparent;
    transition: color 0.2s;
}
.feedback-right { color: var(--success); font-size: 1.4rem; }
.feedback-wrong { color: var(--danger); }
.feedback-skip  { color: var(--text-muted); }

/* Countdown */
.countdown {
    text-align: center;
    font-family: var(--font-hand);
    font-size: 4rem;
    font-weight: 600;
    color: var(--cat-memory);
    padding: 2rem 0;
    line-height: 1;
}

/* Handle dialog */
.handle-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.handle-dialog[hidden] { display: none; }
.handle-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 380px;
    width: 100%;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.4);
}
.handle-card h3 {
    margin: 0 0 0.35rem;
    font-family: var(--font-hand);
    font-size: 1.6rem;
}
.handle-card p {
    margin: 0 0 1rem;
    color: var(--text-secondary);
    font-size: 0.92rem;
}
.handle-card input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    font-size: 1rem;
    font-family: inherit;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    margin-bottom: 0.5rem;
}
.handle-card input:focus { outline: 2px solid var(--cat-memory); outline-offset: 1px; }
.handle-error {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 1.2em;
    margin: 0 0 0.6rem;
}
.handle-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Summary */
.summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}
.summary h2 {
    font-family: var(--font-hand);
    font-size: 2rem;
    margin: 0 0 0.25rem;
    padding: 0;
}
.summary h2::after { display: none; }
.summary-score {
    font-family: var(--font-mono);
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--cat-memory);
    line-height: 1;
    margin: 0.5rem 0 0.25rem;
}
.summary-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 1rem;
}
.summary-meta {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin: 0.5rem 0 1rem;
    color: var(--text-secondary);
    font-size: 0.92rem;
}
.summary-meta span strong {
    color: var(--text);
    font-family: var(--font-mono);
}
.summary-best-flag {
    color: var(--accent);
    font-family: var(--font-hand);
    font-size: 1.25rem;
    font-weight: 600;
    min-height: 1.5em;
    margin: 0.25rem 0 0.5rem;
}
.summary-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}
.share-note {
    margin-top: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    min-height: 1.2em;
}

/* Leaderboard (local) */
.leaderboard {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}
.leaderboard-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.local-best-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.local-best-list li {
    display: grid;
    grid-template-columns: 2.5rem 1fr auto auto 3rem;
    gap: 0.75rem;
    align-items: center;
    padding: 0.55rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
.local-best-list li:last-child { border-bottom: none; }
.local-best-list li.empty {
    display: block;
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
}
.local-best-list .rank {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-weight: 600;
}
.local-best-list .handle { font-weight: 500; }
.local-best-list .diff,
.local-best-list .date {
    font-size: 0.78rem;
    color: var(--text-muted);
}
.local-best-list .score {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--cat-memory);
    text-align: right;
}

.game-page .section-heading .section-hint {
    font-family: var(--font-hand);
    font-size: 1rem;
}

/* Content sections */
.game-content { margin-top: 2.25rem; }
.game-content section { margin-bottom: 2rem; }
.game-content h2 { margin-top: 0; }

.game-page .section-heading h2 {
    font-family: var(--font-hand);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
}
.game-content h3 {
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.7rem;
    line-height: 1.15;
    margin: 1.4em 0 0.3em;
    color: var(--text);
}
.game-content p,
.game-content ul,
.game-content ol.walkthrough + p {
    font-size: 1.02rem;
    line-height: 1.65;
    color: var(--text-secondary);
}
.game-content p strong { color: var(--text); }

.panel-subhead {
    font-family: var(--font-hand);
    font-size: 1.1rem;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
    font-weight: 600;
    margin: 0.9rem 0 0.2rem;
}

.start-panel::before {
    content: "%  %  %";
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    font-family: var(--font-hand);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--cat-memory);
    opacity: 0.22;
    letter-spacing: 0.15em;
    pointer-events: none;
    transform: rotate(-4deg);
}
@media (max-width: 560px) {
    .start-panel::before { display: none; }
}

/* Step walkthroughs */
.walkthrough {
    list-style: none;
    counter-reset: wstep;
    padding: 0;
    margin: 0.5rem 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.walkthrough li {
    counter-increment: wstep;
    position: relative;
    padding: 0.5rem 0.85rem 0.5rem 2.75rem;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    line-height: 1.5;
}
.walkthrough li::before {
    content: counter(wstep);
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.8rem;
    height: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--cat-memory-bg);
    color: var(--cat-memory);
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.05rem;
    border: 1.5px dashed var(--cat-memory);
}
.walkthrough strong {
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 1.02em;
}

/* Callout */
.callout {
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    margin: 1rem 0;
    line-height: 1.55;
}
.callout-gotcha {
    background: #eef4fb;
    border: 1px solid #9ec3e4;
    color: #24456b;
}
:root[data-theme="dark"] .callout-gotcha {
    background: #1f2c3c;
    border-color: #3e5b7c;
    color: #bfd4ea;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) .callout-gotcha {
        background: #1f2c3c;
        border-color: #3e5b7c;
        color: #bfd4ea;
    }
}
.callout strong { font-weight: 700; }

.ftc-disclosure {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.9rem;
    margin: 1rem 0;
    border: 1px solid var(--border);
}

.affiliate-links {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
}
.affiliate-links li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.affiliate-links li:last-child { border-bottom: none; }
.affiliate-links a { font-weight: 500; }
.affiliate-links .blurb {
    display: block;
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-top: 0.15rem;
}

.kb-hints {
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
}
.kb-hints kbd {
    font-family: var(--font-mono);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

@media (max-width: 560px) {
    .kb-hints { display: none; }
    .local-best-list li {
        grid-template-columns: 2rem 1fr auto 3rem;
    }
    .local-best-list .date { display: none; }
    .key { font-size: 1.25rem; }
    .problem-question { font-size: 1.35rem; }
}

/* ---------- Fractions-specific additions ---------- */

/* Panel note under the difficulty picker */
.panel-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0.5rem 0 0;
    line-height: 1.35;
    font-family: var(--font-sans);
}

/* Answer input — legacy fractions rule, not used in Memory Sprint. */

/* Feedback flash: full-width green ring on correct, matching Tape Measure */
.game-area.flash-right {
    animation: flashRight 0.7s ease-out;
}
@keyframes flashRight {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); background-color: transparent; }
    20%  { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.45); background-color: rgba(16, 185, 129, 0.07); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
    .game-area.flash-right { animation: none; }
}

.feedback-right { font-size: 2.4rem; animation: feedbackPop 0.4s ease-out; }
@keyframes feedbackPop {
    0%   { transform: scale(0.6); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .feedback-right { animation: none; }
}

/* Hide surfaces cleanly */
#keypadWrap[hidden], #chipWrap[hidden], #showStage[hidden],
#recallArea[hidden], #digitRecall[hidden], #wordRecall[hidden] {
    display: none !important;
}

/* ---------- Memory Sprint: SHOW PHASE ---------- */

.show-stage {
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.5rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0.25rem 0 0.75rem;
    position: relative;
    overflow: hidden;
}
.show-label {
    font-family: var(--font-hand);
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    letter-spacing: 0.01em;
    text-align: center;
}
.show-item-wrap {
    min-height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 1rem;
}
.show-item {
    font-family: var(--font-mono);
    font-size: 3.6rem;
    font-weight: 600;
    color: var(--cat-memory);
    letter-spacing: 0.02em;
    padding: 0.25rem 1rem;
    text-align: center;
    opacity: 0;
    line-height: 1;
    display: inline-block;
    transition: none;
    word-break: keep-all;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.show-item.item-pop {
    animation: itemPop 0.35s ease-out forwards;
}
/* Words are typed in the Caveat hand font for a friendlier read */
.show-item:not(:empty):is([data-kind="word"]),
.show-item {
    /* default, overridden by JS via dataset if we add kind later */
}
@keyframes itemPop {
    0%   { opacity: 0; transform: scale(0.7); }
    40%  { opacity: 1; transform: scale(1.08); }
    100% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .show-item.item-pop { animation: none; opacity: 1; }
}
.show-item.word-item { font-family: var(--font-hand); font-size: 3.2rem; letter-spacing: 0; }

/* Ready-phase "Get ready — Digits · 6 items" text is smaller and muted so it
 * reads as meta-info rather than being mistaken for a real show item. */
.show-item.ready-text {
    font-family: var(--font-hand);
    font-size: 2rem;
    color: var(--text);
    opacity: 0.85;
    letter-spacing: 0.01em;
}

.show-progress {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}
.progress-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
}
.progress-dot.done {
    background: var(--cat-memory);
    transform: scale(1.15);
}

/* ---------- Memory Sprint: RECALL PHASE ---------- */

.recall-area {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1rem 1.25rem;
    margin: 0.25rem 0 0.75rem;
    min-height: 140px;
}
.recall-label {
    font-family: var(--font-hand);
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-align: center;
    letter-spacing: 0.01em;
}

/* Digit recall */
.digit-recall {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.digit-slots {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
    margin: 0.25rem 0 0.5rem;
}
.digit-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.3rem;
    height: 2.9rem;
    font-family: var(--font-mono);
    font-size: 1.9rem;
    font-weight: 600;
    color: var(--text);
    background: var(--bg-soft);
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    line-height: 1;
}
.digit-slot.filled {
    border-style: solid;
    border-color: var(--cat-memory);
    background: var(--surface);
}
.digit-slot.cursor {
    border-color: var(--cat-memory);
    animation: slotBlink 1s ease-in-out infinite;
}
@keyframes slotBlink {
    0%, 100% { border-color: var(--cat-memory); }
    50%      { border-color: var(--border); }
}
@media (prefers-reduced-motion: reduce) {
    .digit-slot.cursor { animation: none; }
}

/* Word recall */
.picked-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.4rem;
    justify-content: flex-start;
    align-items: center;
    min-height: 2.4rem;
    padding: 0.3rem 0.25rem;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 0.5rem;
}
.picked-hint {
    font-family: var(--font-hand);
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 0 0.25rem;
}
.picked-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.18rem 0.55rem 0.2rem 0.4rem;
    background: var(--cat-memory-bg);
    color: var(--cat-memory);
    border-radius: 999px;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid var(--cat-memory);
}
.picked-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.3rem;
    border-radius: 999px;
    background: var(--cat-memory);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
}
.picked-word {
    letter-spacing: 0.01em;
}

/* Word chip pool (right column) */
.chip-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.word-pool {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
    align-content: start;
}
@media (max-width: 480px) {
    .word-pool { grid-template-columns: repeat(2, 1fr); }
}
.word-chip {
    position: relative;
    appearance: none;
    background: var(--bg-soft);
    border: 1.5px dashed var(--border);
    border-radius: 0.6rem;
    padding: 0.55rem 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: transform 0.08s, background 0.15s, border-color 0.15s, color 0.15s;
    line-height: 1.15;
    text-align: center;
    word-break: break-word;
}
.word-chip:hover:not(.picked) {
    background: var(--surface);
    border-color: var(--cat-memory);
    color: var(--cat-memory);
}
.word-chip:active { transform: translateY(1px) scale(0.98); }
.word-chip.picked {
    background: var(--cat-memory);
    border-color: var(--cat-memory);
    border-style: solid;
    color: #fff;
    cursor: default;
}
.word-chip .chip-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    height: 1.2rem;
    border-radius: 999px;
    background: #fff;
    color: var(--cat-memory);
    font-size: 0.7rem;
    font-weight: 800;
    margin-left: 0.2rem;
}
.word-chip:focus-visible {
    outline: 3px solid var(--cat-memory);
    outline-offset: 2px;
}
.btn-submit-words {
    padding: 0.55rem 1rem;
    font-size: 0.95rem;
}

/* History list tweak: Memory Sprint has a tag prefix (D8 / W6) */
.problem-history .h-tag {
    display: inline-block;
    min-width: 2.2rem;
    padding: 0.1rem 0.35rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--cat-memory);
    background: var(--cat-memory-bg);
    border-radius: 0.35rem;
    text-align: center;
    margin-right: 0.4rem;
}

/* Summary recap tweaks for Memory Sprint */
.summary-recap-list li .recap-detail {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.2rem 0.6rem;
    margin: 0.3rem 0 0.2rem 1.75rem;
    font-family: var(--font-sans);
    font-size: 0.88rem;
    color: var(--text-secondary);
}
.summary-recap-list li .recap-pair {
    display: contents;
}
.summary-recap-list li .recap-key {
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.72rem;
    align-self: center;
}
.summary-recap-list li .recap-val {
    font-family: var(--font-mono);
    word-break: break-word;
}
/* Theme the op-icon for digits mode (small stacked digits) */
.op-row .circle-pick .op-icon {
    letter-spacing: 0.02em;
    font-family: var(--font-mono);
    font-size: 1rem;
}

/* HUD additions: Length + Best fit cleanly */
.hud-group .hud-value { white-space: nowrap; }

/* Personal-best strip above the start panel — the "beat your record" hook */
.pb-strip {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.75rem 0 -0.5rem;
    padding: 0.55rem 1rem;
    background: var(--cat-memory-bg);
    border: 1px dashed var(--cat-memory);
    border-radius: 999px;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}
.pb-strip-label {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--cat-memory);
    letter-spacing: 0.01em;
}
.pb-strip-value {
    font-family: var(--font-hand);
    font-size: 1.4rem;
    color: var(--cat-memory);
    line-height: 1;
}

