/* KeyQuest — UI styles. Chunky, rounded, friendly; every interactive element has a
   tactile pressed state and a visible keyboard focus ring. */
:root {
  --ink: #2a2346;
  --ink-2: #5a5380;
  --paper: #ffffff;
  --cream: #fff8ec;
  --orange: #ff8a3d;
  --orange-d: #d9661c;
  --purple: #7a5cff;
  --purple-d: #5639d6;
  --teal: #2fc68c;
  --teal-d: #1f9a6a;
  --yellow: #ffd23f;
  --yellow-d: #d9a400;
  --pink: #ff6f9a;
  --blue: #4fa8ff;
  --red: #ff5f6a;
  --panel-shadow: 0 10px 0 rgba(42, 35, 70, .18), 0 24px 50px rgba(42, 35, 70, .25);
  --radius: 26px;
  --ts: 1;            /* text scale setting */
  --kb-h: 0px;
  font-size: calc(16px * var(--ts));
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #6cc8ff; }
body {
  font-family: Fredoka, 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font-family: inherit; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#game { position: absolute; left: 0; top: 0; display: block; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

/* ---------- Keyboard panel ---------- */
#kb-panel { display: none; background: linear-gradient(#3b3366, #2a2346); padding: 10px 16px 14px; box-shadow: 0 -6px 0 rgba(0,0,0,.15) inset; }
body.kb-on #kb-panel { display: block; }
#kb { position: relative; max-width: 900px; margin: 0 auto; }
.kb-board { display: flex; flex-direction: column; gap: 5px; position: relative; z-index: 1; }
.kb-row { display: flex; gap: 5px; }
.kb-key {
  position: relative; height: clamp(26px, 4.6vh, 44px); border-radius: 9px;
  background: #f4f0ff; color: #3a3358; display: flex; align-items: center; justify-content: center;
  font-family: Lexend, Fredoka, sans-serif; font-weight: 600; font-size: clamp(11px, 1.9vh, 17px);
  box-shadow: 0 4px 0 #b9b0e0, inset 0 -3px 0 color-mix(in srgb, var(--fc) 55%, transparent);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.kb-key.special { font-size: clamp(9px, 1.4vh, 12px); color: #8a83aa; background: #e2dcf7; }
.kb-key .kb-shift { position: absolute; top: 2px; left: 5px; font-size: .62em; opacity: .55; }
.kb-key.bump::after { content: ''; position: absolute; bottom: 7px; width: 12px; height: 3px; border-radius: 2px; background: #9a92c4; }
.kb-key.target { background: var(--fc); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--fc) 60%, #000), 0 0 0 4px rgba(255,255,255,.9), 0 0 24px 6px var(--fc); animation: keyPulse 1s ease-in-out infinite; z-index: 2; }
.kb-key.target .kb-label { text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.kb-key.down { transform: translateY(3px); box-shadow: 0 1px 0 #b9b0e0; background: #c8ffe6; }
.kb-key.wrong { background: #ffd9dc; animation: shake .35s; }
.kb-key.wrong::before { content: '✕'; position: absolute; top: -18px; color: #ff5f6a; font-weight: 700; font-size: 16px; }
#kb.finger-colors .kb-key:not(.special) { background: color-mix(in srgb, var(--fc) 45%, #fff); color: var(--ink); }
.kb-key.heat { background: color-mix(in srgb, #3fd49a calc(var(--heat) * 100%), #ff9f6a); color: #fff; }
@keyframes keyPulse { 50% { transform: translateY(-2px) scale(1.06); } }
@keyframes shake { 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.kb-hands { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; overflow: visible; opacity: 0; transition: opacity .25s; }
#kb.show-hands .kb-hands { opacity: 1; }
.kb-hands .palm { fill: rgba(255, 214, 180, .16); stroke: rgba(255,255,255,.25); stroke-width: 2; }
.kb-hands .finger { stroke: rgba(255, 214, 180, .22); stroke-linecap: round; transition: all .18s ease-out; }
.kb-hands .tip { fill: rgba(255, 214, 180, .25); transition: all .18s ease-out; }
.kb-hands .finger.on { stroke: var(--fc); opacity: .5; }
.kb-hands .tip.on { fill: rgba(255,255,255,.18); stroke: #fff; stroke-width: 4; filter: drop-shadow(0 0 4px var(--fc)); }
.kb-caption { position: absolute; z-index: 4; left: 50%; top: -46px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 999px; padding: 6px 16px 6px 6px; font-weight: 600; box-shadow: 0 4px 0 rgba(0,0,0,.15); white-space: nowrap; opacity: 0; transition: opacity .2s, transform .2s; }
#kb.show-hands .kb-caption:not(:empty) { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.kb-cap-key { background: var(--ink); color: #fff; border-radius: 8px; min-width: 30px; padding: 2px 8px; text-align: center; font-family: Lexend, sans-serif; }
.kb-cap-dot { width: 24px; height: 24px; border-radius: 50%; color: #fff; display: inline-grid; place-items: center; font-size: 13px; }
.kb-cap-shift { color: var(--ink-2); }

/* ---------- Screens ---------- */
#screens { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.screen { position: absolute; inset: 0; pointer-events: auto; display: flex; flex-direction: column; animation: screenIn .35s cubic-bezier(.2,.9,.3,1.2); overflow: hidden; }
.screen.leaving { animation: screenOut .2s ease-in forwards; }
@keyframes screenIn { from { opacity: 0; transform: translateY(18px) scale(.98); } }
@keyframes screenOut { to { opacity: 0; transform: translateY(-10px) scale(.98); } }
.reduced * { animation-duration: .01s !important; transition-duration: .01s !important; }
.scrim { background: linear-gradient(rgba(42,35,70,.15), rgba(42,35,70,.45)); }

.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 20px; flex-wrap: wrap; }
.topbar .grow { flex: 1; }
.title-h { font-size: 2rem; font-weight: 700; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.2); margin: 0; }

/* chips in top bar */
.chip { display: inline-flex; align-items: center; gap: 8px; background: #fff; border-radius: 999px; padding: 6px 14px 6px 6px; font-weight: 700; font-size: 1.1rem; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.chip .ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; }
.chip.coins .ico { background: var(--yellow); }
.chip.streak .ico { background: #ffe1c4; }
.chip.level { padding-right: 16px; }
.chip.level .lv { background: var(--purple); color: #fff; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; }
.xpbar { width: 120px; height: 12px; border-radius: 99px; background: #ece7ff; overflow: hidden; }
.xpbar > i { display: block; height: 100%; background: linear-gradient(90deg, #a48bff, var(--purple)); border-radius: 99px; transition: width .8s cubic-bezier(.2,.9,.3,1); }

/* buttons */
.btn {
  --c: var(--orange); --cd: var(--orange-d);
  appearance: none; border: 0; cursor: pointer; color: #fff; font-weight: 700; font-size: 1.15rem;
  background: var(--c); border-radius: 18px; padding: 12px 22px; box-shadow: 0 6px 0 var(--cd);
  transform: translateY(0); transition: transform .08s, box-shadow .08s, filter .15s; display: inline-flex; align-items: center; gap: 10px; justify-content: center;
  text-shadow: 0 2px 0 rgba(0,0,0,.15); position: relative;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-2px); box-shadow: 0 8px 0 var(--cd); }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--cd); }
.btn:focus-visible, .card:focus-visible, .node:focus-visible, .item:focus-visible, .tab:focus-visible { outline: 4px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 8px var(--purple); }
.btn.big { font-size: 1.6rem; padding: 18px 40px; border-radius: 24px; box-shadow: 0 8px 0 var(--cd); }
.btn.purple { --c: var(--purple); --cd: var(--purple-d); }
.btn.teal { --c: var(--teal); --cd: var(--teal-d); }
.btn.yellow { --c: var(--yellow); --cd: var(--yellow-d); color: var(--ink); text-shadow: none; }
.btn.white { --c: #fff; --cd: #cfc8ea; color: var(--ink); text-shadow: none; }
.btn.ghost { --c: rgba(255,255,255,.2); --cd: rgba(0,0,0,.15); }
.btn.round { width: 52px; height: 52px; padding: 0; border-radius: 50%; font-size: 1.4rem; }
.btn[disabled] { filter: grayscale(.8) brightness(.95); cursor: not-allowed; }
.btn .kbd { font-size: .75rem; background: rgba(0,0,0,.18); border-radius: 6px; padding: 2px 6px; }

.panel { background: var(--paper); border-radius: var(--radius); box-shadow: var(--panel-shadow); padding: 22px; }
.panel h2 { margin: 0 0 12px; font-size: 1.5rem; }
.muted { color: var(--ink-2); }
.center { display: flex; align-items: center; justify-content: center; }
.col { display: flex; flex-direction: column; }
.row { display: flex; gap: 12px; align-items: center; }
.wrap { flex-wrap: wrap; }
.scroll { overflow: auto; scrollbar-width: thin; }

/* ---------- Title ---------- */
.logo { font-size: clamp(3rem, 9vw, 6.5rem); font-weight: 700; letter-spacing: 1px; display: flex; gap: .06em; justify-content: center; }
.logo span { display: inline-block; background: #fff; color: var(--orange); border-radius: .22em; padding: 0 .16em; box-shadow: 0 .09em 0 #e2d6ff, 0 .2em .3em rgba(0,0,0,.18); animation: bob 2.4s ease-in-out infinite; }
.logo span:nth-child(2n) { color: var(--purple); animation-delay: -.4s; }
.logo span:nth-child(3n) { color: var(--teal); animation-delay: -.8s; }
@keyframes bob { 50% { transform: translateY(-.08em) rotate(-2deg); } }
.tagline { color: #fff; font-size: 1.5rem; font-weight: 600; text-shadow: 0 2px 0 rgba(0,0,0,.2); text-align: center; }
.press-hint { color: #fff; font-weight: 600; opacity: .9; animation: blink 1.6s infinite; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
@keyframes blink { 50% { opacity: .45; } }

/* ---------- Home ---------- */
.home-grid { flex: 1; display: grid; grid-template-columns: minmax(260px, 340px) 1fr minmax(260px, 340px); gap: 20px; padding: 0 20px 20px; min-height: 0; }
.home-left, .home-right { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.home-center { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 6vh; gap: 14px; }
.play-card { text-align: center; }
.play-card .lesson-name { font-size: 1.35rem; font-weight: 700; }
.play-card .world-name { color: var(--ink-2); font-weight: 600; }
.menu-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { appearance: none; border: 0; cursor: pointer; background: #fff; border-radius: 20px; padding: 14px 10px; box-shadow: 0 6px 0 #d8d0f2; font-family: inherit; font-weight: 700; font-size: 1.05rem; color: var(--ink); display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .08s, box-shadow .08s; position: relative; }
.tile:hover { transform: translateY(-3px) rotate(-1deg); box-shadow: 0 9px 0 #d8d0f2; }
.tile:active { transform: translateY(4px); box-shadow: 0 2px 0 #d8d0f2; }
.tile:focus-visible { outline: 4px solid var(--purple); outline-offset: 2px; }
.tile .emo { font-size: 2rem; line-height: 1; }
.tile .sub { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.badge-dot { position: absolute; top: 8px; right: 10px; background: var(--red); color: #fff; border-radius: 99px; font-size: .75rem; padding: 2px 7px; }
.goal { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 2px dashed #eee8ff; }
.goal:last-child { border-bottom: 0; }
.goal .check { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #d8d0f2; display: grid; place-items: center; flex: none; font-weight: 700; }
.goal.done .check { background: var(--teal); border-color: var(--teal); color: #fff; }
.goal .txt { flex: 1; font-weight: 600; font-size: .95rem; }
.goal .bar { height: 8px; background: #eee8ff; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.goal .bar i { display: block; height: 100%; background: var(--teal); }

/* ---------- World map ---------- */
.map-worlds { display: flex; gap: 10px; padding: 0 20px; overflow-x: auto; }
.world-tab { appearance: none; border: 0; cursor: pointer; font-family: inherit; font-weight: 700; background: rgba(255,255,255,.7); border-radius: 16px; padding: 10px 14px; font-size: 1rem; color: var(--ink); white-space: nowrap; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.world-tab.on { background: #fff; transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,.15); }
.world-tab.locked { opacity: .6; }
.map-body { flex: 1; min-height: 0; position: relative; }
.map-path { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.world-banner { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); text-align: center; }
.world-banner h2 { margin: 0; font-size: 2.2rem; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.3), 0 0 18px rgba(30,40,90,.45); }
.world-banner p { margin: 4px 0 0; color: #fff; font-weight: 600; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.node { position: absolute; width: 80px; height: 80px; margin: -40px 0 0 -40px; z-index: 1; border-radius: 50%; border: 0; cursor: pointer; font-family: inherit; background: #fff; box-shadow: 0 8px 0 #cfc8ea, 0 12px 20px rgba(0,0,0,.2); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; color: var(--ink); transition: transform .12s; }
.node:hover:not(.locked) { transform: translateY(-4px) scale(1.06); }
.node .n-ico { font-size: 1.7rem; line-height: 1; }
.node .n-stars { font-size: .85rem; letter-spacing: -1px; margin-top: 3px; }
.node.current { background: var(--orange); color: #fff; box-shadow: 0 8px 0 var(--orange-d), 0 0 0 6px rgba(255,255,255,.7), 0 14px 26px rgba(0,0,0,.25); animation: nodePulse 1.4s ease-in-out infinite; }
.node.done { background: #fffbe6; }
.node.boss { width: 104px; height: 104px; margin: -52px 0 0 -52px; }
.node.locked { background: #d9d4ea; color: #8a83aa; cursor: not-allowed; box-shadow: 0 6px 0 #b4adce; }
@keyframes nodePulse { 50% { transform: scale(1.07); } }
.node-label { position: absolute; z-index: 1; transform: translate(-50%, 48px); background: rgba(42,35,70,.85); color: #fff; padding: 4px 10px; border-radius: 10px; font-weight: 600; font-size: .85rem; white-space: nowrap; pointer-events: none; }
.node-label.boss { transform: translate(-50%, 60px); }
.lesson-pop { position: absolute; z-index: 5; width: min(360px, 90vw); }
.lesson-pop .keys { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.keycap { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 8px; border-radius: 9px; background: #f4f0ff; font-family: Lexend, sans-serif; font-weight: 700; box-shadow: 0 4px 0 #cfc8ea; }
.keycap.new { background: var(--yellow); box-shadow: 0 4px 0 var(--yellow-d); }

/* ---------- Results ---------- */
.results { margin: auto; width: min(640px, 94vw); max-height: 94%; display: flex; flex-direction: column; }
.results .panel { padding: 26px 28px; overflow: auto; }
.res-title { text-align: center; font-size: 2.3rem; font-weight: 700; margin: 0; }
.res-sub { text-align: center; color: var(--ink-2); font-weight: 600; margin-top: 2px; }
.stars { display: flex; justify-content: center; gap: 10px; margin: 14px 0; }
.star { font-size: 64px; filter: grayscale(1) opacity(.3); transform: scale(.6); transition: all .4s cubic-bezier(.2,1.6,.4,1); }
.star.on { filter: none; transform: scale(1) rotate(-8deg); }
.star.on:nth-child(2) { transform: scale(1.25) translateY(-10px); }
.star.on:nth-child(3) { transform: scale(1) rotate(8deg); }
.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0 16px; }
.stat { background: #f7f4ff; border-radius: 16px; padding: 10px 6px; text-align: center; }
.stat .v { font-size: 1.6rem; font-weight: 700; }
.stat .l { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.rewards { display: flex; flex-direction: column; gap: 8px; }
.reward-row { display: flex; align-items: center; gap: 12px; background: #fff8e6; border-radius: 14px; padding: 8px 12px; font-weight: 600; animation: popIn .4s backwards; }
.reward-row .emo { font-size: 1.6rem; }
.reward-row .amt { margin-left: auto; font-weight: 700; }
.reward-row.ach { background: #f0ebff; }
.reward-row.unlock { background: #e4fff2; }
@keyframes popIn { from { opacity: 0; transform: scale(.8) translateY(10px); } }
.tip-box { background: #eaf6ff; border-radius: 14px; padding: 10px 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; margin-top: 10px; }

/* ---------- Shop / wardrobe ---------- */
.shop { flex: 1; display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; padding: 0 20px 20px; min-height: 0; }
.preview { display: flex; flex-direction: column; align-items: center; justify-content: space-between; }
.preview canvas { width: 100%; max-width: 340px; aspect-ratio: 1; border-radius: 22px; background: radial-gradient(circle at 50% 60%, #fff6e0, #ffd9b0); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { appearance: none; border: 0; cursor: pointer; font-family: inherit; font-weight: 700; font-size: 1rem; border-radius: 14px; padding: 8px 14px; background: #f1edff; color: var(--ink); }
.tab.on { background: var(--purple); color: #fff; box-shadow: 0 4px 0 var(--purple-d); }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.item { appearance: none; border: 3px solid transparent; cursor: pointer; font-family: inherit; background: #f7f4ff; border-radius: 18px; padding: 8px 8px 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink); position: relative; transition: transform .1s; }
.item:hover { transform: translateY(-3px); }
.item canvas { width: 100%; aspect-ratio: 1; border-radius: 12px; background: #fff; }
.item .nm { font-weight: 700; font-size: .92rem; text-align: center; }
.item .pr { font-weight: 700; font-size: .9rem; color: #b07a00; }
.item.equipped { border-color: var(--teal); background: #e9fff5; }
.item.equipped::after { content: '✓ Wearing'; position: absolute; top: 6px; left: 6px; background: var(--teal); color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 8px; font-weight: 700; }
.item.locked { opacity: .75; }
.item.locked .pr { color: var(--ink-2); }
.item.new::before { content: 'NEW'; position: absolute; top: 6px; right: 6px; background: var(--red); color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 8px; font-weight: 700; }

/* ---------- Lists (leaderboard, achievements) ---------- */
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: #f7f4ff; border-radius: 16px; padding: 8px 14px; font-weight: 600; }
.lb-row.you { background: #fff1d6; outline: 3px solid var(--orange); }
.lb-rank { width: 40px; text-align: center; font-weight: 700; font-size: 1.2rem; }
.lb-row.r1 { background: linear-gradient(90deg, #fff3b8, #fff8de); }
.lb-row.r1 .lb-rank, .lb-row.r2 .lb-rank, .lb-row.r3 .lb-rank { font-size: 1.6rem; }
.lb-av { width: 44px; height: 44px; border-radius: 50%; flex: none; }
.lb-name { flex: 1; }
.lb-bot { font-size: .75rem; color: var(--ink-2); font-weight: 600; }
.lb-val { font-weight: 700; font-size: 1.1rem; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin-bottom: 16px; }
.pod { text-align: center; font-weight: 700; }
.pod .blk { border-radius: 14px 14px 0 0; color: #fff; font-size: 1.8rem; display: grid; place-items: center; width: 110px; }
.pod canvas { width: 96px; height: 96px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.ach { display: flex; gap: 12px; align-items: center; background: #f7f4ff; border-radius: 18px; padding: 12px; }
.ach .medal { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem; flex: none; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); }
.ach.t1 .medal { background: #f1c49a; } .ach.t2 .medal { background: #dfe5f2; } .ach.t3 .medal { background: #ffd23f; }
.ach.locked { opacity: .55; } .ach.locked .medal { filter: grayscale(1); }
.ach .an { font-weight: 700; } .ach .ad { font-size: .85rem; color: var(--ink-2); font-weight: 500; }

/* ---------- Profile ---------- */
.profile { flex: 1; display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px; padding: 0 20px 20px; min-height: 0; }
.big-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.mini-kb { margin-top: 12px; }
.mini-kb .kb-key { height: 34px; }
.finger-bars { display: flex; gap: 6px; align-items: flex-end; height: 120px; margin-top: 10px; }
.finger-bars .fb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; font-size: .75rem; font-weight: 600; }
.finger-bars .fb i { width: 100%; border-radius: 8px 8px 4px 4px; display: block; min-height: 4px; }
.spark { width: 100%; height: 120px; }

/* ---------- Settings / forms ---------- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 2px dashed #eee8ff; font-weight: 600; }
.set-row:last-child { border-bottom: 0; }
.seg { display: inline-flex; flex-wrap: wrap; background: #f1edff; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { appearance: none; border: 0; cursor: pointer; font-family: inherit; font-weight: 700; padding: 8px 12px; border-radius: 10px; background: transparent; color: var(--ink); font-size: .95rem; }
.seg button.on { background: #fff; box-shadow: 0 3px 0 #d8d0f2; color: var(--purple); }
input[type=range] { accent-color: var(--purple); width: 180px; }
.toggle { appearance: none; width: 58px; height: 32px; border-radius: 99px; background: #d9d4ea; position: relative; cursor: pointer; transition: background .2s; flex: none; }
.toggle::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.toggle:checked { background: var(--teal); } .toggle:checked::after { left: 30px; }
.toggle:focus-visible, input[type=range]:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.text-in { font-family: inherit; font-size: 1.3rem; font-weight: 600; border: 3px solid #d8d0f2; border-radius: 14px; padding: 10px 14px; width: 100%; color: var(--ink); }
.text-in:focus { outline: none; border-color: var(--purple); }

/* ---------- Run HUD ---------- */
.hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-prog { flex: 1; max-width: 520px; background: rgba(255,255,255,.9); border-radius: 18px; padding: 8px 14px; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.hud-prog .nm { font-weight: 700; font-size: .95rem; display: flex; justify-content: space-between; gap: 10px; }
.hud-prog .track { height: 12px; background: #ece7ff; border-radius: 99px; margin-top: 6px; position: relative; overflow: visible; }
.hud-prog .track i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #ffb070, var(--orange)); border-radius: 99px; transition: width .3s; }
.hud-prog .track .fox { position: absolute; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: var(--orange); border: 3px solid #fff; transition: left .3s; }
.hud-prog .track .ghost { position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: rgba(120,140,200,.6); border: 2px solid #fff; }
.hud-prog .track .flag { position: absolute; right: -6px; top: -10px; font-size: 18px; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; margin-left: auto; }
.hud-combo { background: rgba(255,255,255,.92); border-radius: 18px; padding: 6px 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 0 rgba(0,0,0,.12); min-width: 120px; justify-content: center; transition: transform .15s; }
.hud-combo .num { font-size: 1.6rem; }
.hud-combo .flame { font-size: 1.5rem; transition: transform .2s; }
.hud-combo.hot { background: linear-gradient(90deg, #ffe08a, #ffb070); }
.hud-combo.pop { animation: comboPop .4s; }
@keyframes comboPop { 40% { transform: scale(1.3) rotate(-4deg); } }
.chip.bump { animation: comboPop .25s; }
.hud-timer { background: #fff; border-radius: 18px; padding: 6px 14px; font-weight: 700; font-size: 1.4rem; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.hud-timer.low { background: #ffe1d1; color: #c4471a; }
.hud-hearts { font-size: 1.6rem; letter-spacing: 2px; filter: drop-shadow(0 2px 0 rgba(0,0,0,.2)); }
.hud-sentence { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); background: rgba(255,255,255,.92); border-radius: 16px; padding: 8px 18px; font-family: Lexend, sans-serif; font-weight: 600; font-size: 1.2rem; max-width: 90%; text-align: center; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.hud-sentence .done { color: var(--teal-d); }
.hud-sentence .cur { background: #fff1c4; border-radius: 6px; padding: 0 4px; }
.hud-sentence .todo { color: #8a83aa; }
.hud-banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); text-align: center; pointer-events: none !important; animation: bannerIn 2.8s cubic-bezier(.2,1.2,.4,1) forwards; z-index: 5; }
.hb-icon { font-size: 3.4rem; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0,0,0,.2)); }
.hb-title { font-size: clamp(2rem, 5vw, 3.6rem); font-weight: 700; color: #fff; text-shadow: 0 4px 0 rgba(42,35,70,.45), 0 0 24px rgba(42,35,70,.35); white-space: nowrap; }
.hb-sub { font-size: 1.3rem; font-weight: 600; color: #fff; text-shadow: 0 2px 0 rgba(42,35,70,.5); }
@keyframes bannerIn { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.8); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 18% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%); } }
.kit-say { position: absolute; left: 16px; top: 78px; display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 18px; padding: 4px 16px 4px 4px; font-weight: 700; font-size: 1.1rem; box-shadow: 0 4px 0 rgba(0,0,0,.12); max-width: min(520px, 70vw); opacity: 0; transform: translateY(-8px) scale(.96); transition: opacity .25s, transform .25s; pointer-events: none; }
.kit-say canvas { width: 44px; height: 44px; border-radius: 50%; background: #ffe9d2; flex: none; }
.kit-say.show { opacity: 1; transform: none; }
.caps-warn { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: #ffe1d1; color: #c4471a; font-weight: 700; padding: 8px 16px; border-radius: 14px; box-shadow: 0 4px 0 rgba(0,0,0,.12); }

/* overlays (pause, intro) */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(42,35,70,.45); z-index: 20; pointer-events: auto; animation: screenIn .25s; }
.overlay .panel { width: min(560px, 92vw); text-align: center; }
.intro-keys { display: flex; justify-content: center; gap: 18px; margin: 16px 0; }
.intro-key { width: 96px; height: 96px; border-radius: 22px; display: grid; place-items: center; font-family: Lexend, sans-serif; font-size: 3rem; font-weight: 700; color: #fff; box-shadow: 0 8px 0 rgba(0,0,0,.2); position: relative; animation: bob 1.6s infinite; }
.intro-key small { position: absolute; bottom: -30px; left: 50%; transform: translateX(-50%); font-family: Fredoka, sans-serif; font-size: .85rem; color: var(--ink); white-space: nowrap; }
.intro-key.got { animation: none; outline: 5px solid var(--teal); }
.intro-key.got::after { content: '✓'; position: absolute; top: -12px; right: -12px; background: var(--teal); width: 32px; height: 32px; border-radius: 50%; font-size: 1.2rem; display: grid; place-items: center; }

/* toasts */
#toasts { position: absolute; top: 84px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { background: #fff; border-radius: 18px; padding: 10px 18px 10px 10px; box-shadow: 0 6px 0 rgba(0,0,0,.15), 0 12px 24px rgba(0,0,0,.2); display: flex; align-items: center; gap: 10px; font-weight: 700; animation: toastIn .4s cubic-bezier(.2,1.4,.4,1), toastOut .3s 3.2s forwards; }
.toast .emo { width: 42px; height: 42px; border-radius: 50%; background: #ffe9a8; display: grid; place-items: center; font-size: 1.5rem; }
.toast small { display: block; font-weight: 500; color: var(--ink-2); }
@keyframes toastIn { from { transform: translateY(-30px) scale(.8); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-20px); opacity: 0; } }

/* onboarding speech */
.speech { position: relative; background: #fff; border-radius: 24px; padding: 18px 22px; font-size: 1.35rem; font-weight: 600; box-shadow: var(--panel-shadow); max-width: 520px; }
.speech::after { content: ''; position: absolute; bottom: -18px; left: 50%; margin-left: -14px; border: 14px solid transparent; border-top-color: #fff; border-bottom: 0; }
.speech.left::after { bottom: 24px; left: -16px; margin: 0; border: 14px solid transparent; border-right-color: #fff; border-left: 0; }
.tagline { text-shadow: 0 2px 0 rgba(0,0,0,.25), 0 0 12px rgba(40,60,120,.35); }
.name-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.name-field .row { gap: 8px; flex-wrap: nowrap; }
.name-field .text-in { flex: 1; min-width: 0; font-size: 1.1rem; }
.name-field .btn { flex: none; }
.name-msg { min-height: 1.4em; margin-top: 6px; font-weight: 600; font-size: .95rem; color: var(--ink-2); }
.name-msg.bad { color: #d4486b; }
.name-or { margin: 16px 0 8px; font-weight: 700; color: var(--ink-2); }

/* posture / tutor */
.tutor-steps { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.tutor-steps i { width: 12px; height: 12px; border-radius: 50%; background: #d8d0f2; }
.tutor-steps i.on { background: var(--purple); }

@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; overflow: auto; }
  .home-center { order: -1; min-height: 46vh; }
  .shop, .profile { grid-template-columns: 1fr; overflow: auto; }
  .statgrid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-height: 640px) {
  .kb-key { height: 24px; }
}
.reduced .hud-banner { animation: none !important; }

/* short screens: compact overlays, and keep the sentence ribbon clear of Kit's tips */
@media (max-height: 700px) {
  .overlay .panel { padding: 14px 18px; }
  .overlay h2 { font-size: 1.2rem; margin-bottom: 4px; }
  .overlay p { margin: 6px 0; font-size: .95rem !important; }
  .intro-keys { margin: 8px 0 26px; }
  .intro-key { width: 64px; height: 64px; font-size: 2rem; border-radius: 16px; }
  .intro-key small { bottom: -24px; font-size: .75rem; }
  .overlay p[style] { margin-top: 18px !important; }
}
@media (max-width: 1000px) { .hud-sentence { top: 136px; } }
@media (max-height: 700px) { .hb-icon { display: none; } .hb-title { font-size: 2rem; } .hb-sub { font-size: 1rem; } }

/* world records (profile) */
.world-recs { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.wrec { background: linear-gradient(160deg, color-mix(in srgb, var(--wc) 30%, #fff), #fff 70%); border-radius: 16px; padding: 10px 12px; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--wc) 40%, #fff); }
.wrec.locked { opacity: .55; filter: grayscale(.6); }
.wrec-top { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.wrec-ico { font-size: 1.3rem; }
.wrec-name { font-size: .95rem; }
.wrec-stars { color: #b07a00; font-weight: 700; margin: 4px 0; }
.wrec-row { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.wrec-row b { color: var(--ink); }
.wrec-bar { height: 6px; background: #eee8ff; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.wrec-bar i { display: block; height: 100%; background: var(--teal); }
@media (max-width: 900px) {
  .profile .panel.scroll, .shop .panel.scroll { overflow: visible; }
  .profile, .shop { align-content: start; }
}
