/* ============================================================
 * SHELL SKIN — shared chrome for the game portfolio.
 * Each game re-themes through CSS custom properties:
 *   --acc (accent), --acc2, --bg, --ink, --panel, --font
 * ============================================================ */

:root {
  --acc: #8FC1FF;
  --acc2: #F4C64F;
  --ink: #EAF1FF;
  --dim: #9FB2D4;
  --panel: rgba(13, 17, 30, 0.86);
  --bg: #0B0F1C;
  --font: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  --radius: 16px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

.game-root { position: fixed; inset: 0; }

canvas.stage {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* ---------------- top bar ---------------- */
.topbar {
  position: absolute; top: var(--sat); left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 10px 16px;
  z-index: 30;
  pointer-events: none;
}
.topbar .brand {
  font-weight: 800; letter-spacing: .18em; text-transform: uppercase;
  font-size: 13px; color: var(--acc);
  text-shadow: 0 0 14px color-mix(in srgb, var(--acc) 55%, transparent);
  margin-right: auto;
  pointer-events: none;
}
.iconbtn {
  pointer-events: auto;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.iconbtn:hover { border-color: var(--acc); transform: translateY(-1px); }
.iconbtn:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn.muted { color: var(--dim); }

/* ---------------- screens ---------------- */
.screen {
  position: absolute; inset: 0;
  z-index: 40;
  display: none;
  padding: calc(var(--sat) + 20px) 20px calc(var(--sab) + 20px);
  overflow-y: auto;
  background:
    radial-gradient(120% 90% at 50% -10%, color-mix(in srgb, var(--acc) 16%, transparent), transparent 60%),
    color-mix(in srgb, var(--bg) 88%, black);
  backdrop-filter: blur(8px);
}
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; animation: screenIn .45s cubic-bezier(.22,1.2,.36,1); }
.screen.active.scroll { justify-content: flex-start; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

.kicker {
  font-size: 11px; letter-spacing: .34em; text-transform: uppercase;
  color: var(--acc); font-weight: 800;
}
h1.title {
  margin: 2px 0 0;
  font-size: clamp(34px, 8vw, 64px);
  line-height: .95;
  letter-spacing: .01em;
  text-align: center;
  text-shadow: 0 6px 30px color-mix(in srgb, var(--acc) 35%, transparent);
}
h1.title em { font-style: normal; color: var(--acc2); }
.tagline { margin: 0; color: var(--dim); text-align: center; max-width: 46ch; font-size: clamp(14px, 2.5vw, 16px); line-height: 1.55; }

.btnrow { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.btn {
  appearance: none; border: 1px solid rgba(255,255,255,.16);
  background: var(--panel); color: var(--ink);
  font: 700 15px/1 var(--font);
  letter-spacing: .06em;
  padding: 15px 26px;
  min-height: 48px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .16s cubic-bezier(.34,1.56,.64,1), box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
.btn:hover { transform: translateY(-2px); border-color: var(--acc); }
.btn:focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; }
.btn.primary {
  background: linear-gradient(135deg, var(--acc), color-mix(in srgb, var(--acc) 55%, var(--acc2)));
  color: #0A1020;
  border: none;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--acc) 40%, transparent);
}
.btn.primary:hover { box-shadow: 0 14px 40px color-mix(in srgb, var(--acc) 55%, transparent); }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(0) scale(.98); }

.statcard {
  display: flex; gap: 22px; flex-wrap: wrap; justify-content: center;
  background: var(--panel); border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius); padding: 14px 22px;
}
.statcard .stat { text-align: center; min-width: 74px; }
.statcard .stat b { display: block; font-size: 22px; color: var(--acc2); }
.statcard .stat span { font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }

.beststat { font-size: 12.5px; color: var(--dim); letter-spacing: .12em; text-transform: uppercase; }
.beststat b { color: var(--ink); }

/* how to play */
.howto { max-width: 640px; width: 100%; display: grid; gap: 12px; }
.howto .hrow {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--panel); border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius); padding: 14px 16px;
}
.howto .hrow .hkey {
  flex: 0 0 auto; min-width: 46px; height: 40px; padding: 0 10px;
  display: grid; place-items: center;
  border-radius: 10px; border: 1px solid rgba(255,255,255,.22);
  font: 700 13px/1 var(--font); color: var(--acc);
  background: rgba(255,255,255,.04);
}
.howto .hrow p { margin: 2px 0 0; color: var(--dim); font-size: 14px; line-height: 1.5; }
.howto .hrow p b { color: var(--ink); }

/* settings */
.settings { width: min(420px, 92vw); display: grid; gap: 14px; }
.settings .srow {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--panel); border: 1px solid rgba(255,255,255,.1);
  padding: 13px 16px; border-radius: var(--radius);
}
.settings label { font-size: 13.5px; font-weight: 700; letter-spacing: .04em; }
.settings .vol { display: flex; align-items: center; gap: 10px; }
.settings .vol span { font-size: 10.5px; color: var(--dim); letter-spacing: .14em; text-transform: uppercase; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 120px; height: 5px; border-radius: 3px;
  background: rgba(255,255,255,.18); outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--acc); border: 3px solid #0A1020;
  box-shadow: 0 0 10px color-mix(in srgb, var(--acc) 70%, transparent);
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--acc); border: 3px solid #0A1020; }
.settings select {
  background: #131A2C; color: var(--ink); border: 1px solid rgba(255,255,255,.2);
  border-radius: 10px; padding: 8px 10px; font: 600 13px var(--font);
}
.switch { position: relative; width: 50px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0; border-radius: 999px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2);
  transition: background .18s ease; pointer-events: none;
}
.switch i:after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .18s cubic-bezier(.34,1.56,.64,1);
}
.switch input:checked + i { background: color-mix(in srgb, var(--acc) 70%, #0A1020); }
.switch input:checked + i:after { transform: translateX(22px); }
.switch input:focus-visible + i { outline: 2px solid var(--acc); outline-offset: 2px; }

.dangerlink { background: none; border: none; color: #E4737C; font: 600 12.5px var(--font); letter-spacing: .08em; cursor: pointer; padding: 8px; }
.dangerlink:hover { text-decoration: underline; }

/* ---------------- HUD ---------------- */
.hud {
  position: absolute; inset: 0;
  z-index: 20;
  pointer-events: none;
  padding: calc(var(--sat) + 64px) 16px calc(var(--sab) + 96px);
  display: flex; flex-direction: column;
}
.hud .hud-top { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.hud .chip {
  background: var(--panel); border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px; padding: 8px 13px;
  font: 800 14px/1.2 var(--font);
  letter-spacing: .04em;
}
.hud .chip small { display: block; font: 700 9.5px/1 var(--font); letter-spacing: .2em; text-transform: uppercase; color: var(--dim); margin-bottom: 4px; }
.hud .chip .acc { color: var(--acc2); }
.hud .meter {
  width: min(210px, 34vw); height: 9px; border-radius: 6px;
  background: rgba(255,255,255,.12); overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
}
.hud .meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--acc), var(--acc2)); border-radius: 6px; transition: width .12s linear; }
.hud .hud-bottom { margin-top: auto; display: flex; justify-content: center; }

.kit-toast {
  position: fixed; top: calc(var(--sat) + 66px); left: 50%;
  transform: translate(-50%, -8px);
  z-index: 60;
  background: var(--panel); border: 1px solid color-mix(in srgb, var(--acc) 45%, transparent);
  color: var(--ink); font: 800 14px var(--font); letter-spacing: .05em;
  padding: 11px 20px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.kit-toast.on { opacity: 1; transform: translate(-50%, 0); }

/* countdown */
.countdown {
  position: absolute; inset: 0; z-index: 35;
  display: grid; place-items: center; pointer-events: none;
  font: 900 clamp(70px, 18vw, 150px)/1 var(--font);
  color: var(--ink);
  text-shadow: 0 0 40px color-mix(in srgb, var(--acc) 60%, transparent), 0 8px 24px rgba(0,0,0,.5);
}
.countdown span { animation: cdPop .9s cubic-bezier(.22,1.4,.36,1); display: block; }
@keyframes cdPop { 0% { transform: scale(2.2); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(.9); opacity: 0; } }

/* ---------------- touch controls ---------------- */
.touchui { position: absolute; inset: 0; z-index: 25; pointer-events: none; display: none; }
body.touch .touchui { display: block; }
.joy {
  position: absolute; left: max(18px, env(safe-area-inset-left, 0px));
  bottom: calc(var(--sab) + 18px);
  width: 118px; height: 118px; border-radius: 50%;
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.22);
  pointer-events: auto;
  touch-action: none;
  backdrop-filter: blur(4px);
}
.joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--acc) 85%, #fff), var(--acc) 60%, color-mix(in srgb, var(--acc) 55%, #000));
  transform: translate(-50%, -50%);
  margin: -26px 0 0 -26px;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
}
.tbtns { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(var(--sab) + 16px); display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.tbtn {
  pointer-events: auto; touch-action: none;
  min-width: 64px; height: 64px; padding: 0 14px;
  border-radius: 50%;
  background: var(--panel); border: 1.5px solid rgba(255,255,255,.25);
  color: var(--ink);
  display: grid; place-items: center;
  font: 800 12px/1.1 var(--font); letter-spacing: .08em; text-transform: uppercase; text-align: center;
  transition: transform .12s ease, background .12s ease;
}
.tbtn.wide { border-radius: 999px; }
.tbtn.pressing { transform: scale(.92); background: color-mix(in srgb, var(--acc) 30%, var(--panel)); border-color: var(--acc); }
.tbtn.primary { background: color-mix(in srgb, var(--acc) 26%, var(--panel)); border-color: color-mix(in srgb, var(--acc) 60%, transparent); }

/* ---------------- mascot dock ---------------- */
.game-root .mascot-dock {
  position: absolute; z-index: 28;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: calc(var(--sab) + 96px);
  display: flex; justify-content: flex-end;
  transition: opacity .3s ease;
}
body.touch .game-root .mascot-dock {
  right: auto;
  left: max(12px, env(safe-area-inset-left, 0px));
  bottom: calc(var(--sab) + 148px);
  --msc-size: 96px;
}
.game-root .mascot-dock.tucked { opacity: .55; }
.game-root .mascot-dock.tucked:hover { opacity: 1; }

/* ---------------- results ---------------- */
.medal {
  width: 92px; height: 92px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 40px;
  background: radial-gradient(circle at 32% 28%, color-mix(in srgb, var(--acc2) 90%, #fff), var(--acc2) 55%, color-mix(in srgb, var(--acc2) 60%, #7a5a00));
  box-shadow: 0 14px 40px color-mix(in srgb, var(--acc2) 35%, transparent), inset 0 -6px 14px rgba(0,0,0,.25);
  animation: medalIn .7s cubic-bezier(.34,1.56,.64,1);
}
@keyframes medalIn { from { transform: scale(0) rotate(-30deg); } to { transform: scale(1) rotate(0); } }

/* ---------------- loading veil ---------------- */
.veil {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; gap: 14px;
  background: var(--bg);
  transition: opacity .5s ease;
}
.veil.off { opacity: 0; pointer-events: none; }
.veil .v-inner { display: grid; gap: 14px; justify-items: center; }
.veil .v-title { font: 800 13px var(--font); letter-spacing: .34em; text-transform: uppercase; color: var(--acc); }
.veil .v-bar { width: 180px; height: 4px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
.veil .v-bar i { display: block; height: 100%; width: 40%; border-radius: 3px; background: var(--acc); animation: vSlide 1.1s ease-in-out infinite; }
@keyframes vSlide { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }

/* ---------------- motion & responsive ---------------- */
@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  .btn, .iconbtn { transition: none; }
  .medal { animation: none; }
}
body.rm .btn, body.rm .iconbtn { transition: none; }

@media (max-width: 620px) {
  .game-root .mascot-dock { --msc-size: 96px; bottom: calc(var(--sab) + 150px); }
  .hud { padding: calc(var(--sat) + 58px) 12px calc(var(--sab) + 100px); }
  .hud .chip { font-size: 12.5px; padding: 7px 11px; }
  h1.title { font-size: clamp(30px, 9vw, 44px); }
}
@media (max-height: 480px) and (orientation: landscape) {
  .game-root .mascot-dock { --msc-size: 74px; bottom: calc(var(--sab) + 84px); }
  .joy { width: 96px; height: 96px; }
  .tbtn { min-width: 56px; height: 56px; }
  .hud { padding-bottom: calc(var(--sab) + 84px); }
}

/* ---------------- learn layer ---------------- */
.learn-card {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 14px); z-index: 70;
  transform: translate(-50%, 24px);
  width: min(560px, calc(100vw - 24px));
  background: var(--panel); border: 1px solid color-mix(in srgb, var(--acc) 40%, transparent);
  border-radius: 18px; padding: 16px 18px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s cubic-bezier(.34,1.4,.64,1);
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
  backdrop-filter: blur(8px);
}
.learn-card.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.learn-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.learn-tag { font-size: 10px; font-weight: 800; letter-spacing: .22em; text-transform: uppercase; color: var(--acc2); }
.learn-timer { font-size: 11px; font-weight: 800; color: var(--acc); }
.learn-q { margin: 0 0 12px; font-size: 15px; line-height: 1.5; font-weight: 700; }
.learn-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 520px) { .learn-choices { grid-template-columns: 1fr; } }
.learn-choice {
  display: flex; gap: 9px; align-items: baseline; text-align: left;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.16);
  color: var(--ink); border-radius: 12px; padding: 11px 12px;
  font: 600 13px/1.4 var(--font); cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.learn-choice:hover { border-color: var(--acc); transform: translateY(-1px); }
.learn-choice:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.learn-choice b { color: var(--acc); font-size: 11px; }
.learn-choice.right { border-color: #6BE29A; background: rgba(107,226,154,.12); }
.learn-choice.wrong { border-color: #E4737C; background: rgba(228,115,124,.12); }
.learn-why { margin: 12px 0 0; font-size: 13px; line-height: 1.55; color: var(--dim); border-top: 1px solid rgba(255,255,255,.1); padding-top: 10px; }
.learn-why { color: var(--ink); }
.learn-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.learn-skip { background: none; border: none; color: var(--dim); font: 700 12px var(--font); letter-spacing: .1em; text-transform: uppercase; cursor: pointer; padding: 6px 8px; }
.learn-skip:hover { color: var(--ink); }

/* codex */
.codex { width: min(620px, 92vw); display: grid; gap: 8px; margin-top: 4px; }
.codex-track { margin: 14px 0 2px; font-size: 11px; letter-spacing: .26em; text-transform: uppercase; color: var(--acc); }
.codex-card { background: var(--panel); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 10px 14px; }
.codex-card summary { cursor: pointer; font-size: 13.5px; line-height: 1.45; list-style: none; display: flex; gap: 10px; align-items: baseline; }
.codex-card summary::-webkit-details-marker { display: none; }
.cx-stars { color: var(--acc2); font-size: 11px; letter-spacing: .12em; flex: 0 0 auto; }
.cx-why { margin: 8px 0 2px; font-size: 13px; color: var(--dim); line-height: 1.55; border-top: 1px dashed rgba(255,255,255,.12); padding-top: 8px; }
.codex-note { text-align: center; color: #6E7FA3; font-size: 12px; margin: 16px 0 0; }

/* ---------------- animator polish ---------------- */
/* menu title: slow float + living glow */
.screen.active h1.title { animation: titleFloat 7s ease-in-out infinite; }
@keyframes titleFloat {
  0%, 100% { transform: translateY(0); text-shadow: 0 6px 30px color-mix(in srgb, var(--acc) 30%, transparent); }
  50% { transform: translateY(-5px); text-shadow: 0 14px 44px color-mix(in srgb, var(--acc) 55%, transparent); }
}
/* primary button breathes — the eye lands on Play */
.btn.primary { animation: playPulse 2.6s ease-in-out infinite; }
@keyframes playPulse {
  0%, 100% { box-shadow: 0 10px 30px color-mix(in srgb, var(--acc) 35%, transparent); }
  50% { box-shadow: 0 14px 44px color-mix(in srgb, var(--acc) 60%, transparent); }
}
/* learn card verdict flashes */
.learn-card.right-flash { animation: rightGlow .9s ease-out; }
@keyframes rightGlow { 0% { box-shadow: 0 0 0 0 rgba(107,226,154,.7); } 100% { box-shadow: 0 0 0 26px rgba(107,226,154,0); } }
.learn-card.wrong-flash { animation: wrongGlow .9s ease-out; }
@keyframes wrongGlow { 0% { box-shadow: 0 0 0 0 rgba(228,115,124,.7); } 100% { box-shadow: 0 0 0 26px rgba(228,115,124,0); } }
/* card collapses to a lingering concept bar (spaced reinforcement) */
.learn-card.bar { width: auto; max-width: min(480px, calc(100vw - 24px)); padding: 9px 16px; border-radius: 999px; }
.learn-card.bar .learn-bar { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.learn-bar .learn-term { font-size: 14px; color: var(--ink); }
.learn-bar .learn-note { font-size: 11px; color: var(--dim); }
@media (max-width: 620px) { .learn-card.bar { bottom: calc(var(--sab) + 158px); } }
body.rm .screen.active h1.title, body.rm .btn.primary { animation: none; }
@media (prefers-reduced-motion: reduce) { .screen.active h1.title, .btn.primary { animation: none; } }

/* byline */
.byline { margin: 4px 0 0; font-size: 12.5px; color: var(--dim); letter-spacing: .04em; }
.byline b { color: var(--ink); }
.byline a { color: var(--acc); }

/* PB confetti */
.confetti { position: fixed; inset: 0; z-index: 85; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; display: block; border-radius: 2px;
  opacity: .95;
  animation: confettiFall linear forwards;
  transform: rotate(0deg);
}
@keyframes confettiFall {
  0% { transform: translateY(-4vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(108vh) rotate(var(--rx, 360deg)); opacity: .6; }
}
