/* ==========================================================
   1234math — shared brand layer
   Colors, fonts and the small set of UI pieces every game uses:
   HUD numbers, corner bar (home + settings), settings sheet,
   toggles, start hint and end card.
   Fonts: <link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@700;800;900&display=swap" rel="stylesheet">
   ========================================================== */

:root {
    /* Brand palette */
    --coral:  #FF8A65;
    --green:  #81C784;
    --yellow: #FFE566;
    --sky:    #7FB4C6;
    --navy:   #3A6077;
    --pink:   #C2648A;

    /* Derived neutrals (all from navy) */
    --navy-deep: #2E4F62;
    --navy-ink:  #1F3542;
    --line:      rgba(255, 255, 255, 0.14);
    --text:      #FFFFFF;
    --text-dim:  rgba(255, 255, 255, 0.62);

    /* Per-game accent, set with <body data-game="..."> */
    --accent: var(--sky);

    --font-display: 'Fredoka One', 'Nunito', system-ui, sans-serif;
    --font-ui: 'Nunito', system-ui, sans-serif;

    --radius-lg: 24px;
    --radius-md: 16px;
    --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

body[data-game="plus"]      { --accent: var(--yellow); }
body[data-game="tables"]    { --accent: var(--green); }
body[data-game="fractions"] { --accent: var(--coral); }
body[data-game="numbers"]   { --accent: var(--sky); }

/* ---------- HUD ---------- */
.hud {
    position: fixed;
    inset: 0 0 auto 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 18px 22px;
    pointer-events: none;
    z-index: 20;
    opacity: 0;
    transition: opacity .4s ease;
}
.hud.visible { opacity: 1; }

/* Primary number: the thing you are collecting / scoring */
.hud-primary {
    font-family: var(--font-display);
    font-size: clamp(34px, 6.5vmin, 60px);
    line-height: 1;
    color: var(--text);
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
    font-variant-numeric: tabular-nums;
}

/* Secondary number: level / round / table */
.hud-secondary {
    text-align: right;
    font-family: var(--font-ui);
    line-height: 1;
}
.hud-secondary .hud-label svg { width: clamp(16px, 2.6vmin, 22px); height: auto; display: inline-block; }
.hud-secondary .hud-label {
    display: block;
    font-weight: 800;
    font-size: clamp(11px, 1.8vmin, 14px);
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 4px;
}
.hud-secondary .hud-value {
    font-weight: 900;
    font-size: clamp(26px, 5vmin, 44px);
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.hud-lives {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}
.hud-lives svg { width: clamp(16px, 2.6vmin, 22px); height: auto; display: block; }

/* ---------- Corner bar: home + settings ---------- */
.corner-bar {
    position: fixed;
    left: 16px;
    bottom: 16px;
    display: flex;
    gap: 10px;
    z-index: 60;
    transition: opacity .35s ease;
}
.corner-bar.hidden { opacity: 0; pointer-events: none; transition: none; }

.corner-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    border: 2px solid var(--line);
    background: rgba(31, 53, 66, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    transition: transform .2s var(--ease-spring), background .2s ease, border-color .2s ease;
}
.corner-btn:hover { transform: scale(1.08); background: rgba(31, 53, 66, 0.8); border-color: rgba(255,255,255,.3); }
.corner-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.corner-btn img { width: 34px; height: 34px; image-rendering: pixelated; border-radius: 8px; display: block; }
.corner-btn svg { width: 24px; height: 24px; display: block; }

@media (max-width: 700px) {
    /* Stack on phones: settings above home, so the bar stays narrow */
    .corner-bar { flex-direction: column-reverse; }
    .corner-btn { width: 44px; height: 44px; border-radius: 12px; }
    .corner-btn img { width: 28px; height: 28px; }
    .corner-btn svg { width: 20px; height: 20px; }
}

/* ---------- Settings sheet ---------- */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 36, 46, 0.55);
    display: grid;
    place-items: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    padding: 16px;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
    width: min(380px, 100%);
    background: var(--navy-deep);
    border: 2px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 22px 22px 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
    transform: translateY(12px) scale(.97);
    transition: transform .3s var(--ease-spring);
    color: var(--text);
    font-family: var(--font-ui);
}
.sheet-backdrop.open .sheet { transform: none; }

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.sheet-title { color: var(--accent); display: grid; }
.sheet-title svg { width: 28px; height: 28px; }
.sheet-close {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,.08);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: grid; place-items: center;
}
.sheet-close:hover { background: rgba(255,255,255,.16); }

.setting-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 14px 4px;
    border-top: 1px solid var(--line);
}
.setting-row:first-of-type { border-top: none; }

.setting-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    transition: opacity .25s ease;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    padding: 4px;
    -webkit-tap-highlight-color: transparent;
}
.setting-opt.off { opacity: .35; }
.setting-opt .opt-icon { height: 40px; display: grid; place-items: center; }
.setting-opt .opt-icon img { image-rendering: pixelated; }
.setting-opt .opt-label {
    font-weight: 800;
    font-size: 13px;
    letter-spacing: .04em;
}

/* Segmented control (ranges etc.) */
.setting-segments {
    grid-column: 1 / -1;
    display: flex;
    background: rgba(0,0,0,.18);
    border-radius: 14px;
    padding: 4px;
    gap: 4px;
}
.setting-segments button {
    flex: 1;
    border: none;
    background: none;
    color: var(--text-dim);
    font-family: var(--font-ui);
    font-weight: 900;
    font-size: 14px;
    padding: 9px 0;
    border-radius: 10px;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}
.setting-segments button.on { background: var(--accent); color: var(--navy-ink); }
.setting-caption {
    grid-column: 1 / -1;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: -4px;
}

/* ---------- Toggle ----------
   A choice between two equal modes, not on/off:
   each side has its own color, the knob carries the chosen icon,
   and it can be tapped or dragged. */
.toggle {
    --tg-left: var(--sky);
    --tg-right: var(--accent);
    --tg-travel: 40px;
    position: relative;
    width: 84px;
    height: 44px;
    border-radius: 999px;
    border: 2px solid rgba(255,255,255,.28);
    background: var(--tg-left);
    cursor: grab;
    padding: 0;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    transition: background .25s ease;
}
.toggle.on { background: var(--tg-right); }
.toggle.dragging { cursor: grabbing; }
.toggle:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
    overflow: hidden;
    pointer-events: none;
    transition: transform .3s var(--ease-spring);
}
.toggle.on .toggle-knob { transform: translateX(var(--tg-travel)); }
.toggle.dragging .toggle-knob { transition: none; }

/* The chosen icon, scaled down from the 40px option icon */
.knob-icon {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    display: grid;
    place-items: center;
    transform: scale(.62);
}
.knob-icon img { image-rendering: pixelated; }

/* ---------- Start hint ---------- */
.start-hint {
    position: fixed;
    left: 50%;
    transform: translate(-50%, 0);
    z-index: 30;
    pointer-events: none;
    font-family: var(--font-ui);
    font-weight: 800;
    font-size: clamp(14px, 2.4vmin, 18px);
    color: var(--navy-ink);
    background: var(--accent);
    padding: 9px 18px;
    border-radius: 999px;
    box-shadow: 0 6px 18px rgba(0,0,0,.22);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity .3s ease;
}
.start-hint.visible { opacity: 1; animation: hintBob 2.4s ease-in-out infinite; }
.start-hint kbd {
    font-family: var(--font-ui);
    font-weight: 900;
    font-size: .9em;
    min-width: 1.7em;
    padding: 2px 6px;
    border-radius: 7px;
    background: rgba(31,53,66,.14);
    border: 2px solid rgba(31,53,66,.25);
    text-align: center;
}
@keyframes hintBob {
    0%, 100% { transform: translate(-50%, 0); }
    50%      { transform: translate(-50%, -4px); }
}

/* ---------- End card ---------- */
.end-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(20, 36, 46, 0.6);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
    padding: 16px;
}
.end-backdrop.open { opacity: 1; pointer-events: auto; cursor: pointer; }

.end-card {
    width: min(360px, 100%);
    text-align: center;
    background: var(--navy-deep);
    border: 2px solid var(--line);
    border-radius: 28px;
    padding: 28px 24px 22px;
    color: var(--text);
    font-family: var(--font-ui);
    box-shadow: 0 24px 60px rgba(0,0,0,.35);
    transform: scale(.92);
    transition: transform .4s var(--ease-spring);
}
.end-backdrop.open .end-card { transform: none; }

.end-title { color: var(--yellow); margin: -4px 0 14px; }
.end-title svg { width: 44px; height: 44px; }
.end-stats {
    display: flex;
    justify-content: center;
    gap: 28px;
    margin-bottom: 22px;
}
.end-stat .end-value {
    display: block;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.end-stat.primary .end-value {
    font-family: var(--font-display);
    font-size: 64px;
    color: var(--accent);
}
.end-stat.secondary .end-value {
    font-family: var(--font-ui);
    font-weight: 900;
    font-size: 40px;
    color: var(--text);
    padding-top: 14px;
}
.end-stat .end-icon {
    display: flex;
    justify-content: center;
    margin-top: 8px;
    color: var(--text-dim);
}
.end-stat .end-icon svg { width: 22px; height: 22px; }
.end-again {
    display: inline-grid;
    place-items: center;
    width: 64px;
    height: 64px;
    color: var(--navy-ink);
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.end-again svg { width: 32px; height: 32px; }
.end-backdrop.ready .end-again { animation: againPulse 1.8s ease-in-out infinite; }
@keyframes againPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.end-backdrop:not(.ready) .end-again { opacity: .4; }

@media (prefers-reduced-motion: reduce) {
    .start-hint.visible { animation: none; }
    .toggle-knob, .sheet, .end-card, .corner-btn { transition: none; }
}
