:root {
  --navy: #16365c; --sea: #1fa2c9; --sea2: #0d7fa6; --sun: #ffc83d; --coral: #ff6b5a; --mint: #2fc28a; --cream: #fffaf0;
  --card: rgba(255, 255, 255, .94); --line: 3px;
  font-size: clamp(12px, min(2.3vh, 1.7vw) + 5px, 26px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd8f3; color: var(--navy);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
#bg { position: fixed; inset: 0; background: url(img/bg.webp) center 30% / cover no-repeat; }
#bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,0) 40%, rgba(13,127,166,.25)); }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* header */
#top { display: flex; align-items: center; gap: .45rem; padding: .4rem .6rem; flex: none; }
.brand { background: var(--card); border: var(--line) solid var(--navy); border-radius: 999px; padding: .2rem .8rem; line-height: 1.05; box-shadow: 0 3px 0 var(--navy); }
.brand b { font-size: 1.05rem; color: var(--sea2); } .brand span { font-size: .7rem; margin-left: .3rem; font-weight: 700; }
.sp { flex: 1; }
.hbtn, .hstat { height: 2.4rem; min-width: 2.4rem; border-radius: 1.2rem; background: var(--card); border: var(--line) solid var(--navy); box-shadow: 0 3px 0 var(--navy);
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: 0 .5rem; font-weight: 800; }
.hbtn svg, .hstat svg { width: 1.35rem; height: 1.35rem; }
.hbtn.off { opacity: .45; }
.hbtn:active, .hstat:active, .big:active, .mid:active, .tile:active, .ans:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--navy); }
.hstat .lbl { font-size: .75rem; }

.screen { display: none; flex: 1; min-height: 0; }
.screen.on { display: flex; }
.card { background: var(--card); border: var(--line) solid var(--navy); border-radius: 1.2rem; box-shadow: 0 5px 0 var(--navy), 0 10px 24px rgba(10, 40, 80, .2); }

/* start */
#start { padding: 0 .7rem .7rem; }
.startWrap { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: .8rem; align-items: stretch; max-width: 1500px; margin: 0 auto; width: 100%; }
.hero { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); align-items: center; gap: .3rem .7rem; padding: .7rem .9rem; min-height: 0; overflow: hidden; }
.hero h1 { grid-column: 1 / -1; text-align: center; }
.heroImg { height: min(52vh, 21rem); max-width: 36vw; max-height: 100%; object-fit: contain; flex: none; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-1.5deg); } }
.heroTxt { min-width: 0; display: flex; flex-direction: column; gap: .55rem; }
h1 { margin: 0; font-size: 2.4rem; line-height: 1; color: var(--sea2); letter-spacing: -.5px; text-shadow: 0 2px 0 #fff; }
.intro { margin: 0; font-size: .92rem; line-height: 1.35; font-weight: 600; }
.big { background: var(--sun); border: var(--line) solid var(--navy); border-radius: 1rem; box-shadow: 0 4px 0 var(--navy); font-weight: 900; font-size: 1.35rem;
  padding: .55rem 1.2rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.big svg { width: 1.4rem; height: 1.4rem; }
.play { align-self: flex-start; min-width: 9rem; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.keys { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .72rem; font-weight: 700; opacity: .85; }
.kbd { display: inline-block; font-style: normal; min-width: 1.3em; padding: 0 .25em; margin-right: .15em; border: 2px solid var(--navy); border-bottom-width: 3px; border-radius: .3em; background: #fff; text-align: center; font-size: .9em; }
.picker { padding: .7rem .8rem; display: flex; flex-direction: column; gap: .55rem; min-height: 0; overflow: hidden; }
.pickHead { font-weight: 900; font-size: 1.05rem; }
.groups { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; }
.gbtn { border: var(--line) solid var(--navy); border-radius: .8rem; background: #fff; padding: .25rem 0; font-weight: 900; line-height: 1; box-shadow: 0 3px 0 var(--navy); }
.gbtn small { display: block; font-size: .6rem; font-weight: 700; margin-bottom: .1rem; }
.gbtn b { font-size: 1.35rem; }
.gbtn.on { background: var(--sea); color: #fff; }
.tiles { display: grid; grid-template-rows: repeat(3, minmax(0, 1fr)); gap: .45rem; flex: 1; min-height: 0; }
.tile { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .6rem; text-align: left; background: #fff; border: var(--line) solid var(--navy); border-radius: 1rem;
  box-shadow: 0 3px 0 var(--navy); padding: .3rem .6rem; min-height: 0; }
.tile.sel { background: #e6f8ff; outline: 3px solid var(--sun); outline-offset: 1px; }
.tile .ico { width: 2.8rem; height: 2.8rem; border-radius: .8rem; display: grid; place-items: center; border: 2px solid var(--navy); }
.tile .ico svg { width: 2.1rem; height: 2.1rem; }
.tile b { display: block; font-size: 1.05rem; } .tile small { display: block; font-size: .75rem; font-weight: 600; opacity: .85; }
.tile .k { font-size: .65rem; opacity: .6; font-weight: 800; }
.st3 { display: flex; gap: 1px; } .st3 svg { width: 1.05rem; height: 1.05rem; }

/* play */
#play { flex-direction: column; padding: 0 .6rem .6rem; gap: .4rem; }
.hud { display: flex; align-items: center; gap: .45rem; flex: none; }
.pill { background: var(--card); border: var(--line) solid var(--navy); border-radius: 999px; padding: .2rem .7rem; font-weight: 800; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 3px 0 var(--navy); }
.pill.score { font-size: 1.05rem; color: var(--sea2); min-width: 3.5rem; text-align: center; }
.timer { flex: 1; height: 1.4rem; background: var(--card); border: var(--line) solid var(--navy); border-radius: 999px; position: relative; overflow: hidden; min-width: 4rem; }
.timer i { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(90deg, var(--mint), #7be0b5); transition: width .25s linear; }
.timer i.low { background: linear-gradient(90deg, var(--coral), #ffa194); }
.timer span { position: relative; display: block; text-align: center; font-weight: 900; font-size: .8rem; line-height: 1.1rem; }
.qbar { display: flex; align-items: center; gap: .5rem; background: var(--card); border: var(--line) solid var(--navy); border-radius: 1rem; padding: .25rem .7rem; flex: none; box-shadow: 0 3px 0 var(--navy); min-height: 3rem; }
.qLotte { height: 2.7rem; flex: none; transition: transform .2s; }
.qLotte.yay { animation: yay .5s; } .qLotte.oops { animation: oops .4s; }
@keyframes yay { 40% { transform: translateY(-8px) rotate(-8deg) scale(1.1); } }
@keyframes oops { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.qtxt { flex: 1; min-width: 0; }
.q { font-size: 1.55rem; font-weight: 900; line-height: 1.1; }
.hint { font-size: .75rem; font-weight: 700; opacity: .8; }
.streak { font-weight: 900; color: var(--coral); font-size: 1rem; white-space: nowrap; }
.body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: .45rem; }
.stage { flex: 1; min-height: 0; position: relative; border-radius: 1rem; overflow: hidden; border: var(--line) solid var(--navy); background: rgba(255,255,255,.35); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.answers { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; }
.answers.hide { display: none; }
.ans { position: relative; background: #fff; border: var(--line) solid var(--navy); border-radius: 1rem; box-shadow: 0 4px 0 var(--navy); font-weight: 900; font-size: 1.45rem; min-height: 3.3rem; padding: .2rem .3rem; line-height: 1.05; }
.ans.small { font-size: 1rem; }
.ans .kk { position: absolute; left: .35rem; top: .15rem; font-size: .6rem; opacity: .45; }
.ans.ok { background: var(--mint); color: #fff; } .ans.bad { background: var(--coral); color: #fff; }
.answers.pad { grid-template-columns: repeat(6, 1fr); }
.answers.pad .ans { min-height: 2.7rem; font-size: 1.3rem; }
.answers.pad .ans.go { background: var(--sun); grid-column: span 2; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1; margin: 0 .1em; font-size: .95em; }
.frac span:first-child { border-bottom: .12em solid currentColor; padding: 0 .15em .05em; }
.frac span:last-child { padding-top: .05em; }

/* end */
#end { align-items: center; justify-content: center; padding: .4rem .7rem .8rem; }
.endcard { width: min(40rem, 100%); max-height: 100%; display: flex; flex-direction: column; padding: .8rem 1rem; min-height: 0; }
.endScroll { display: flex; gap: 1rem; align-items: center; overflow: auto; min-height: 0; }
.endImg { height: 9rem; flex: none; }
.endInfo { flex: 1; min-width: 0; }
h2 { margin: 0 0 .2rem; font-size: 1.7rem; color: var(--sea2); }
.stars3 { display: flex; gap: .3rem; margin: .2rem 0; } .stars3 svg { width: 2.6rem; height: 2.6rem; }
.stars3 svg.got { animation: pop .45s backwards; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } }
#endText { margin: .2rem 0; font-weight: 700; font-size: 1rem; }
.extra { margin: .2rem 0; font-weight: 700; color: #b8540d; font-size: .9rem; min-height: 1em; }
.endBtns { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; padding-top: .6rem; flex: none; }
.mid { background: #fff; border: var(--line) solid var(--navy); border-radius: 1rem; box-shadow: 0 4px 0 var(--navy); font-weight: 900; font-size: 1.05rem; padding: .5rem .9rem; }
.mid.ghost { background: #e6f8ff; }

/* sticker map */
.modal { position: fixed; inset: 0; background: rgba(10, 40, 80, .45); display: none; align-items: center; justify-content: center; padding: .6rem; z-index: 20; }
.modal.on { display: flex; }
.sheet { width: min(46rem, 100%); max-height: 92vh; display: flex; flex-direction: column; padding: .7rem .9rem; }
.sheetHead h2 { margin: 0; font-size: 1.4rem; } .sheetHead p { margin: .1rem 0 .4rem; font-size: .8rem; font-weight: 700; }
.map { overflow: auto; min-height: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .5rem; padding: .2rem; }
.isle { background: linear-gradient(180deg, #ffe9a8, #f6d27a); border: var(--line) solid var(--navy); border-radius: 2rem 1.4rem 2.2rem 1.2rem; padding: .35rem .5rem .5rem; text-align: center; }
.isle b { display: block; font-size: .9rem; }
.isle .stk { display: flex; justify-content: center; gap: .3rem; margin-top: .25rem; }
.sticker { width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 3px dashed rgba(22,54,92,.35); display: grid; place-items: center; background: rgba(255,255,255,.4); }
.sticker svg { width: 1.8rem; height: 1.8rem; }
.sticker.got { border: 3px solid #fff; box-shadow: 0 0 0 2px var(--navy); }
.sticker.gold { box-shadow: 0 0 0 3px #e3a600, 0 0 10px #ffd34d; }
.sticker.no svg { opacity: .2; filter: grayscale(1); }
.sheetFoot { display: flex; justify-content: center; padding-top: .5rem; flex: none; }

#toast { position: fixed; left: 50%; top: 22%; transform: translate(-50%, 0) scale(.6); opacity: 0; pointer-events: none; background: var(--sun); border: var(--line) solid var(--navy); border-radius: 1rem;
  font-weight: 900; font-size: 1.4rem; padding: .4rem 1rem; z-index: 30; transition: opacity .2s, transform .25s; box-shadow: 0 4px 0 var(--navy); white-space: nowrap; }
#toast.on { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* landscape with room: answers to the right of the stage for the numpad */
@media (min-aspect-ratio: 4/3) {
  .body.padMode { flex-direction: row; }
  .body.padMode .answers.pad { grid-template-columns: repeat(3, 1fr); width: min(17rem, 34%); align-content: center; }
  .body.padMode .answers.pad .ans.go { grid-column: span 3; }
}

/* short frames (store page window) */
@media (max-height: 560px) {
  :root { font-size: clamp(11px, min(2.5vh, 1.6vw) + 3px, 16px); }
  #top { padding: .3rem .5rem; }
  .hbtn, .hstat { height: 2.1rem; min-width: 2.1rem; }
  .heroImg { height: min(62vh, 15rem); }
  h1 { font-size: 1.8rem; }
  .intro { font-size: .82rem; }
  .big { font-size: 1.15rem; padding: .4rem 1rem; }
  .q { font-size: 1.3rem; }
  .qbar { min-height: 2.4rem; padding: .15rem .6rem; }
  .qLotte { height: 2.2rem; }
  .ans { min-height: 2.6rem; font-size: 1.25rem; }
  .answers.pad .ans { min-height: 2.1rem; font-size: 1.1rem; }
  .endImg { height: 7rem; }
  .stars3 svg { width: 2.1rem; height: 2.1rem; }
  #play { gap: .3rem; }
  .body { gap: .3rem; }
}
@media (max-height: 420px) {
  .heroImg { height: 38vh; }
  .play { min-width: 0; }
  .intro { font-size: .74rem; }
  .startWrap { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: .6rem; }
  .brand span, .hstat .lbl { display: none; }
  .hbtn, .hstat { height: 1.9rem; min-width: 1.9rem; }
  .hint { display: none; }
  .keys { display: none; }
  .tile small { font-size: .68rem; }
  .tile .ico { width: 2.2rem; height: 2.2rem; } .tile .ico svg { width: 1.7rem; height: 1.7rem; }
  .endImg { height: 5rem; }
  .ans { min-height: 2.3rem; }
  .answers.pad .ans { min-height: 1.8rem; }
}

/* portrait phones */
@media (max-aspect-ratio: 4/5) {
  :root { font-size: clamp(12px, 3.6vw, 18px); }
  .brand span { display: none; }
  #start { padding: 0 .5rem .5rem; }
  .startWrap { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: .5rem; }
  .hero { padding: .5rem .6rem; }
  .heroImg { height: 7.5rem; max-width: 34vw; max-height: none; }
  h1 { font-size: 1.75rem; }
  .intro { font-size: .8rem; }
  .keys { display: none; }
  .groups { gap: .25rem; } .gbtn b { font-size: 1.15rem; }
  .q { font-size: 1.3rem; }
  .answers { grid-template-columns: repeat(2, 1fr); }
  .answers.pad { grid-template-columns: repeat(3, 1fr); }
  .answers.pad .ans.go { grid-column: span 3; }
  .ans .kk { display: none; }
  .endScroll { flex-direction: column; text-align: center; gap: .3rem; }
  .endImg { height: 7rem; } .stars3 { justify-content: center; }
  .endBtns .big { width: 100%; }
}
