:root {
  --ink: #26304f;
  --ink2: #5a6386;
  --card: #fffaf5;
  --line: #26304f;
  --mint: #5fd3a6;
  --mintD: #2fa47a;
  --peach: #ff9f7a;
  --pink: #ff8fa3;
  --lav: #a99bf2;
  --sun: #ffc94a;
  --sky: #6db8f2;
  --memory: #ff8fa3;
  --logic: #a99bf2;
  --math: #ffb347;
  --attention: #5fc8e8;
  --spatial: #5fd3a6;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--ink);
  background: #ffe2cf url(img/bg.jpg) center bottom / cover no-repeat;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* header */
#top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); flex: 0 0 auto; }
#title { flex: 1; margin: 0; font-size: 20px; font-weight: 900; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#title span { font-weight: 800; color: var(--mintD); font-size: .8em; margin-left: 4px; }
.iconbtn { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 14px; border: 2.5px solid var(--line); background: #fff; display: grid; place-items: center; padding: 0; box-shadow: 0 3px 0 var(--line); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.pill { height: 38px; padding: 0 12px; border-radius: 19px; background: #fff; border: 2.5px solid var(--line); display: flex; align-items: center; gap: 4px; font-size: 17px; box-shadow: 0 3px 0 var(--line); }
.flame { font-size: 16px; }

/* buttons */
.btn { border: 3px solid var(--line); border-radius: 18px; background: var(--mint); font-weight: 900; font-size: 18px; padding: 12px 20px; box-shadow: 0 5px 0 var(--line); transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.btn.big { font-size: 21px; padding: 14px 26px; }
.btn.huge { font-size: 34px; padding: 18px 64px; border-radius: 26px; background: var(--mint); box-shadow: 0 7px 0 var(--line); animation: breathe 2.2s ease-in-out infinite; }
.btn.ghost { background: #fff; }
@keyframes breathe { 50% { transform: scale(1.05); } }

/* cards */
.card { background: var(--card); border: 3px solid var(--line); border-radius: 22px; padding: 14px; box-shadow: 0 6px 0 rgba(38,48,79,.85); }
.card h2 { margin: 0 0 8px; font-size: 19px; font-weight: 900; }

/* overlay */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(255,233,220,.55); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); padding: 12px; }
#startPanel { background: rgba(255,236,224,.35); }
.startGrid { width: 100%; height: 100%; display: grid; grid-template-rows: 1fr auto 1fr; justify-items: center; text-align: center; }
.sTop { align-self: end; display: flex; flex-direction: column; align-items: center; padding-bottom: 18px; }
.sNoodle { width: min(190px, 26vh); height: auto; animation: bob 2.6s ease-in-out infinite; filter: drop-shadow(0 6px 0 rgba(38,48,79,.15)); }
.sTitle { margin: 4px 0 0; font-size: clamp(38px, 8vh, 62px); font-weight: 900; line-height: 1; color: var(--ink); text-shadow: 0 3px 0 #fff, 0 -3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff; }
.sSub { margin: 8px 0 0; font-size: 16px; font-weight: 700; color: var(--ink2); max-width: 420px; }
.sBot { align-self: start; padding-top: 22px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.sToday { margin: 0; font-weight: 800; font-size: 15px; }
.ctrls { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 14px; font-weight: 700; color: var(--ink2); max-width: 460px; }
.key { display: inline-block; font-style: normal; min-width: 24px; padding: 2px 6px; margin: 0 2px; border: 2px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); box-shadow: 0 2px 0 var(--line); font-size: 13px; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* hub */
#hub { flex: 1; overflow-y: auto; touch-action: pan-y; padding: 4px 12px 24px; -webkit-overflow-scrolling: touch; }
.hubGrid { max-width: 1100px; margin: 0 auto; display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .hubGrid { grid-template-columns: 1fr 1fr; } .gamesCard { grid-column: 1 / -1; } }
.wHead { display: flex; align-items: center; gap: 10px; }
.wHead p { margin: 0; color: var(--ink2); font-weight: 700; font-size: 14px; }
.wNoodle { width: 64px; height: auto; }
#wList { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 12px; }
.wItem { border: 2.5px solid var(--line); border-radius: 14px; padding: 8px 6px; text-align: center; background: #fff; font-weight: 800; font-size: 13px; position: relative; }
.wItem .ic { width: 38px; height: 38px; margin: 0 auto 4px; }
.wItem.done { background: #dff7ec; }
.wItem.done::after { content: "\2713"; position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; background: var(--mintD); color: #fff; border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px; }
.wItem small { display: block; font-weight: 700; color: var(--ink2); font-size: 11px; }
#wPlay { width: 100%; }
.streakRow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
#days { display: flex; gap: 5px; }
.day { width: 30px; text-align: center; font-size: 10px; font-weight: 800; color: var(--ink2); }
.day i { display: block; width: 24px; height: 24px; margin: 0 auto 2px; border-radius: 50%; border: 2px solid var(--line); background: #fff; }
.day.on i { background: var(--sun); }
.day.today i { box-shadow: 0 0 0 3px var(--mint); }
.streakTxt { font-weight: 800; font-size: 15px; }
.streakTxt span { color: var(--ink2); font-size: 12px; display: block; }
#totalScore { float: right; font-size: 24px; color: var(--mintD); }

/* charts */
.chart { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-items: end; height: 170px; padding: 4px 0; }
.chart.small { height: 130px; width: 100%; max-width: 380px; margin: 4px auto 6px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar .v { font-weight: 900; font-size: 14px; margin-bottom: 3px; }
.bar .col { width: 70%; max-width: 46px; border: 2.5px solid var(--line); border-radius: 10px 10px 4px 4px; transition: height .7s cubic-bezier(.2,1.3,.4,1); min-height: 6px; position: relative; }
.bar .col .up { position: absolute; top: -22px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 900; color: var(--mintD); white-space: nowrap; }
.bar .n { font-size: 11px; font-weight: 800; margin-top: 4px; color: var(--ink2); }
#histWrap { margin-top: 10px; }
.histLbl { font-size: 12px; font-weight: 800; color: var(--ink2); margin-bottom: 2px; }
#histChart svg { width: 100%; height: 70px; display: block; }

/* game cards */
#games { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gCard { border: 2.5px solid var(--line); border-radius: 16px; background: #fff; padding: 10px; text-align: left; display: flex; gap: 8px; align-items: center; box-shadow: 0 4px 0 var(--line); }
.gCard:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.gCard .ic { width: 44px; height: 44px; flex: 0 0 44px; }
.gCard b { display: block; font-size: 15px; }
.gCard small { display: block; font-size: 12px; font-weight: 700; color: var(--ink2); }
.ic { border-radius: 12px; border: 2.5px solid var(--line); display: grid; place-items: center; }
.ic svg { width: 70%; height: 70%; }

/* play */
#play { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 0 12px 10px; min-height: 0; position: relative; }
#hud { width: 100%; max-width: 640px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hudL, .hudR { display: flex; align-items: center; gap: 8px; }
.hudL b { font-size: 18px; }
.skillTag { font-size: 12px; font-weight: 900; padding: 3px 9px; border-radius: 10px; border: 2px solid var(--line); background: #fff; }
.hudR span { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 3px 9px; font-size: 14px; font-weight: 800; }
#timer { width: 100%; max-width: 640px; height: 18px; border: 2.5px solid var(--line); border-radius: 10px; background: #fff; margin: 8px 0 4px; position: relative; overflow: hidden; }
#timerFill { position: absolute; inset: 0; background: var(--mint); transform-origin: left; }
#timer.low #timerFill { background: var(--peach); }
#timerN { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 13px; font-weight: 900; }
#instr { margin: 4px 0 6px; font-weight: 800; font-size: 16px; text-align: center; background: rgba(255,255,255,.85); border-radius: 12px; padding: 4px 12px; max-width: 640px; }
#stage { flex: 1 1 auto; max-height: 500px; width: 100%; max-width: 640px; display: flex; align-items: center; justify-content: center; min-height: 0; position: relative; }
#answers { width: 100%; max-width: 640px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 8px; }
#answers.two { grid-template-columns: 1fr 1fr; }
#answers.three { grid-template-columns: repeat(3, 1fr); }
#answers.six { grid-template-columns: repeat(3, 1fr); }
.ans { border: 3px solid var(--line); border-radius: 18px; background: #fff; font-weight: 900; font-size: 28px; min-height: 66px; box-shadow: 0 5px 0 var(--line); position: relative; display: flex; align-items: center; justify-content: center; gap: 6px; }
.ans:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.ans .k { position: absolute; top: 3px; left: 7px; font-size: 11px; color: var(--ink2); font-weight: 800; }
.ans.ok { background: #c9f5df; animation: pop .3s; }
.ans.bad { background: #ffd3d3; animation: shake .35s; }
.ans.sw { min-height: 62px; }
.ans .dot { width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid var(--line); }
.ans.yes { background: #dff7ec; font-size: 24px; }
.ans.no { background: #ffe6dd; font-size: 24px; }
@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* question card */
.qCard { background: #fff; border: 3px solid var(--line); border-radius: 22px; padding: 18px 22px; box-shadow: 0 6px 0 var(--line); text-align: center; max-width: 100%; }
.qBig { font-size: clamp(34px, 9vw, 58px); font-weight: 900; letter-spacing: 1px; }
.seq { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.seq span { min-width: 54px; padding: 8px 8px; border: 2.5px solid var(--line); border-radius: 12px; background: #fff7ef; font-size: clamp(22px, 6vw, 32px); font-weight: 900; }
.seq span.q { background: var(--sun); }
.inkWord { font-size: clamp(48px, 13vw, 84px); font-weight: 900; letter-spacing: 2px; }

/* grids */
.grid { display: grid; gap: 8px; width: min(100%, 56vh, 460px); max-height: 100%; aspect-ratio: 1; }
.tile { border: 2.5px solid var(--line); border-radius: 12px; background: #fff; padding: 0; box-shadow: 0 3px 0 rgba(38,48,79,.7); transition: background .15s, transform .1s; }
.tile.lit { background: var(--sun); transform: scale(1.04); }
.tile.hit { background: var(--mint); }
.tile.miss { background: #ffb3b3; animation: shake .35s; }
.tile.show { background: #ffe9a8; }
.grid.locked .tile { cursor: default; }
.oddGrid .tile { box-shadow: none; border-width: 2px; border-radius: 10px; }
.oddGrid .tile.miss { outline: 4px solid #e5484d; }
.oddGrid .tile.reveal { outline: 5px solid var(--ink); }

/* turn match */
.turnWrap { display: flex; gap: 16px; align-items: center; justify-content: center; width: 100%; }
.turnBox { background: #fff; border: 3px solid var(--line); border-radius: 18px; padding: 10px; box-shadow: 0 5px 0 var(--line); width: min(42vw, 34vh, 230px); aspect-ratio: 1; }
.turnBox svg { width: 100%; height: 100%; display: block; }
.turnArrow { font-size: 30px; font-weight: 900; color: var(--ink2); }

/* coach */
#coach { position: absolute; right: 8px; bottom: 92px; display: flex; align-items: flex-end; flex-direction: row-reverse; gap: 2px; pointer-events: none; z-index: 2; }
#coachImg { width: 78px; height: auto; transition: transform .2s; }
#coachImg.jump { animation: jump .5s; }
@keyframes jump { 40% { transform: translateY(-16px) rotate(-6deg); } }
.bubble { background: #fff; border: 2.5px solid var(--line); border-radius: 14px; padding: 5px 10px; font-weight: 900; font-size: 14px; margin-bottom: 52px; opacity: 0; transition: opacity .2s; white-space: nowrap; }
.bubble.on { opacity: 1; }

/* result */
.panel { background: var(--card); border: 3px solid var(--line); border-radius: 26px; padding: 16px 20px 18px; width: min(440px, 100%); text-align: center; box-shadow: 0 8px 0 var(--line); max-height: 100%; overflow-y: auto; animation: panelIn .35s cubic-bezier(.2,1.4,.4,1); }
@keyframes panelIn { from { transform: scale(.85); opacity: 0; } }
.rNoodle { width: 110px; height: auto; margin-top: -4px; }
.rStep { margin: 0; font-weight: 800; color: var(--ink2); font-size: 14px; }
.panel h2 { margin: 2px 0; font-size: 28px; font-weight: 900; }
.rScore { font-size: 22px; font-weight: 800; }
.rScore b { font-size: 46px; color: var(--mintD); }
.rBest { margin: 0 0 6px; font-weight: 800; color: var(--ink2); }
.rBest.new { color: #e0663f; }
.rStats { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.rStats span { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 4px 10px; font-weight: 800; font-size: 14px; }
.rBtns { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.rBtns .btn { flex: 1; }

/* fx */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.float { position: absolute; font-weight: 900; font-size: 24px; color: var(--mintD); text-shadow: 0 2px 0 #fff; animation: floatUp .9s ease-out forwards; }
.float.bad { color: #e0663f; }
@keyframes floatUp { to { transform: translateY(-60px); opacity: 0; } }
.conf { position: absolute; width: 10px; height: 14px; border-radius: 3px; animation: fall 1.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
.go { position: absolute; left: 50%; top: 45%; transform: translate(-50%,-50%); font-size: 64px; font-weight: 900; color: #fff; -webkit-text-stroke: 3px var(--ink); animation: goIn .8s forwards; }
@keyframes goIn { 0% { transform: translate(-50%,-50%) scale(.4); opacity: 0; } 30% { transform: translate(-50%,-50%) scale(1.1); opacity: 1; } 100% { transform: translate(-50%,-50%) scale(1); opacity: 0; } }

@media (max-width: 520px) {
  #title { font-size: 17px; }
  #title span { display: none; }
  .ans { font-size: 24px; min-height: 60px; }
  #answers { gap: 7px; }
  #coachImg { width: 58px; }
  #coach { position: static; align-self: flex-end; margin-top: auto; flex: 0 0 auto; }
  .bubble { margin-bottom: 30px; font-size: 13px; }
  .btn.huge { font-size: 30px; padding: 16px 56px; }
}
@media (max-height: 560px) {
  .sNoodle { width: 110px; }
  .sTitle { font-size: 36px; }
  #coach { display: none; }
}
