:root {
  --cobalt: #1d4fa3; --navy: #142b5c; --sky: #2a6be0; --lemon: #ffd43b; --lemon2: #fff3b0; --terra: #e8673a; --terra2: #b9471f;
  --cream: #fffaf0; --paper: #fffdf7; --ink: #142b5c; --mint: #4cc38a; --red: #d63c2f;
  --sel: #ffe066; --tint: #e6eefc; --same: #c4d8ff; --err: #ffd9d2;
  --bs: 360px; --cs: 40px; --g: 8px; --fs: 15px; --pw: 300px;
  --font: "Trebuchet MS", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--ink); font-size: var(--fs);
  background: #f3efe6 url(img/bg.webp) center / cover no-repeat; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; gap: var(--g); padding: var(--g); justify-content: center; align-items: center; }

/* ---------- board ---------- */
#boardWrap { width: var(--bs); height: var(--bs); flex: none; position: relative; order: -1; }
#board {
  width: 100%; height: 100%; display: grid; background: var(--paper); border: 3px solid var(--navy); border-radius: calc(var(--bs) * .02); overflow: hidden;
  box-shadow: 0 0 0 calc(var(--g) * .7) var(--terra), 0 0 0 calc(var(--g) * .7 + 3px) var(--terra2), 0 14px 30px rgba(60,30,10,.35);
}
.cell { position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; min-width: 0; min-height: 0;
  border-right: 1px solid #b7c6e6; border-bottom: 1px solid #b7c6e6; background: var(--paper); }
.cell[data-br] { border-right: 3px solid var(--navy); }
.cell[data-bb] { border-bottom: 3px solid var(--navy); }
#board[data-n="4"] .cell, #board[data-n="6"] .cell { border-color: #9fb3dd; }
#board[data-n="4"] .cell[data-br], #board[data-n="6"] .cell[data-br] { border-right-color: var(--navy); }
#board[data-n="4"] .cell[data-bb], #board[data-n="6"] .cell[data-bb] { border-bottom-color: var(--navy); }
.cell .v { font-size: calc(var(--cs) * .64); font-weight: 700; line-height: 1; color: var(--sky); }
#board[data-n="4"] .cell .v, #board[data-n="6"] .cell .v { font-size: calc(var(--cs) * .55); }
.cell.given { background: #f6f1e4; }
.cell.given .v { color: var(--navy); font-weight: 800; }
.cell.hinted .v { color: var(--terra2); }
.cell.wrong .v { color: var(--red); }
.cell.tint { background: var(--tint); }
.cell.same { background: var(--same); }
.cell.conf { background: var(--err); }
.cell.sel { background: var(--sel); box-shadow: inset 0 0 0 3px #e0a800; }
.cell.unit { background: #fff1c9; }
.cell.flash { animation: flash .6s ease-out; }
.cell.pop .v { animation: pop .28s ease-out; }
@keyframes flash { 0% { background: #a6f0c9; } 100% { } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.cell .n { position: absolute; inset: 5%; display: grid; grid-auto-rows: 1fr; }
.cell .n span { font-size: calc(var(--cs) * .25); line-height: 1; display: flex; align-items: center; justify-content: center; color: #5b6b8f; font-weight: 700; }
#board[data-n="4"] .cell .n span, #board[data-n="6"] .cell .n span { font-size: calc(var(--cs) * .2); }
.cell .n span.hl { color: #fff; background: var(--sky); border-radius: 30%; }

/* ---------- panel (one white card) ---------- */
#panel {
  width: var(--pw); height: var(--bs); display: flex; flex-direction: column; gap: calc(var(--g) * .7); min-width: 0;
  background: rgba(255,250,240,.94); border-radius: 1.1em; padding: calc(var(--g) * .9); box-shadow: 0 10px 28px rgba(60,30,10,.25); border: 2px solid #fff;
}
#top { display: flex; align-items: center; gap: .45em; flex: none; }
.logo { display: flex; align-items: center; gap: .3em; color: var(--cobalt); margin-right: auto; white-space: nowrap; min-width: 0; overflow: hidden; }
.logo b { font-size: 1.2em; font-weight: 800; }
.lemon { width: 1.05em; height: .8em; background: var(--lemon); border-radius: 50%; border: 2px solid #c79a00; flex: none; transform: rotate(-20deg); }
.tag { background: var(--cobalt); color: #fff; font-weight: 700; font-size: .8em; padding: .2em .6em; border-radius: 1em; white-space: nowrap; flex: none; max-width: 10em; overflow: hidden; text-overflow: ellipsis; }
.tag.l0, .tag.l1 { background: var(--mint); } .tag.l2 { background: var(--sky); } .tag.l3 { background: var(--cobalt); } .tag.l4 { background: var(--terra); }
.stat { display: flex; align-items: center; gap: .2em; font-size: .9em; white-space: nowrap; color: var(--navy); font-weight: 700; }
.ico { width: 1.1em; height: 1.1em; }
.snd { display: flex; gap: .2em; }
.ib { width: 2em; height: 2em; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--tint); color: var(--cobalt); }
.ib svg { width: 1.2em; height: 1.2em; }
#coachBox { display: flex; align-items: center; gap: .4em; flex: none; min-height: 0; }
#tita { width: 4.4em; height: 4.4em; object-fit: contain; flex: none; filter: drop-shadow(0 3px 3px rgba(0,0,0,.25)); }
#tita.bounce { animation: bounce .5s; }
@keyframes bounce { 30% { transform: translateY(-12%) rotate(-4deg); } 60% { transform: translateY(0) rotate(2deg); } }
#bubble > span { display: block; }
#bubble {
  flex: 1; background: #fff; border: 2px solid var(--lemon); border-radius: 1em; padding: .4em .65em; font-size: .9em; line-height: 1.38; position: relative;
  min-height: 2.6em; display: flex; align-items: center;
}
#bubble::before { content: ""; position: absolute; left: -.55em; top: 50%; margin-top: -.45em; border: .45em solid transparent; border-right-color: var(--lemon); border-left: 0; }
#bubble b { color: var(--terra2); }
#tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45em; flex: none; }
.tool {
  position: relative; background: #fff; border-radius: .8em; padding: .3em .2em; display: flex; flex-direction: column; align-items: center; gap: .05em;
  color: var(--cobalt); font-weight: 700; font-size: .72em; box-shadow: 0 3px 0 #c9d3ea; border: 1.5px solid #dfe6f5; white-space: nowrap; min-width: 0;
}
.tool span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tool svg { width: 2em; height: 2em; }
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 #c9d3ea; }
.tool i { position: absolute; top: -.4em; right: -.1em; font-style: normal; font-size: .8em; background: var(--terra); color: #fff; border-radius: 1em; padding: .05em .45em; }
#notes.on { background: var(--lemon); color: var(--navy); box-shadow: 0 3px 0 #c79a00; border-color: #e0b400; }
#notes.on i { background: var(--navy); }
#pad { display: grid; grid-template-columns: repeat(5, 1fr); grid-auto-rows: 1fr; gap: .45em; flex: 1 1 auto; min-height: 0; }
#pad[data-n="6"] { grid-template-columns: repeat(3, 1fr); }
#pad[data-n="4"] { grid-template-columns: repeat(2, 1fr); }
.num {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; position: relative; container-type: size;
  color: var(--navy); border-radius: .8em; border: 2px solid var(--cobalt);
  background: linear-gradient(135deg, #fff 0 46%, #e9f0ff 46% 54%, #fff 54%);
  box-shadow: 0 3px 0 var(--cobalt), 0 5px 10px rgba(20,43,92,.18);
}
.num b { font-size: 1.8em; font-size: min(2.6em, 56cqmin); line-height: 1; font-weight: 800; }
.num small { font-size: .62em; font-size: max(.62em, min(1em, 15cqmin)); color: var(--terra2); font-weight: 700; }
.num:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--cobalt); }
.num:hover { background: #fff7cf; }
.num.done { opacity: .35; }
body.notes-on .num { border-style: dashed; color: #6b5a00; background: var(--lemon2); }
#bottom { display: grid; grid-template-columns: 1fr 1.3fr 1.2fr; gap: .4em; flex: none; }
.chip { background: var(--tint); color: var(--cobalt); font-weight: 700; border-radius: 2em; padding: .45em .3em; font-size: .8em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#dailyBtn { background: var(--lemon); color: var(--navy); }

/* portrait: header, bubble, board, tools, pad, bottom */
body.port #app { flex-direction: column; justify-content: center; }
body.port #panel { display: contents; }
body.port #top, body.port #coachBox, body.port #tools, body.port #pad, body.port #bottom { width: var(--pw); }
body.port #top { order: 1; background: rgba(255,250,240,.94); border-radius: 1em; padding: .3em .5em; }
body.port #coachBox { order: 2; }
body.port #boardWrap { order: 3; margin: calc(var(--g) * .5) 0; }
body.port #tools { order: 4; }
body.port #pad { order: 5; grid-template-columns: repeat(var(--padn, 9), 1fr); flex: none; height: calc(var(--fs) * 3.4); }
body.port #pad[data-n="6"] { --padn: 6; } body.port #pad[data-n="4"] { --padn: 4; }
body.port #bottom { order: 6; }
body.port #tita { width: 3.4em; height: 3.4em; }
body.port .num b { font-size: 1.6em; font-size: min(1.9em, 56cqmin); }
body.short #tita { width: 3em; height: 3em; }
body.short #bubble { min-height: 2.3em; padding: .3em .55em; font-size: .84em; }
body.short #top { gap: .3em; }
body.short .logo b, body.narrow .logo b { display: none; }
body.short .tool { font-size: .66em; padding: .25em .05em; }
body.short .stat { font-size: .82em; }
body.short .chip { font-size: .72em; padding: .4em .2em; }
body.tiny #tita { display: none; }
body.tiny #bubble::before { display: none; }
body.port.tiny #bubble { min-height: 0; font-size: .8em; padding: .25em .5em; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 2vh 2vw; background: rgba(20,43,92,.45); }
.card {
  background: var(--cream); border-radius: 1.2em; width: min(46em, 96vw); max-height: 96vh; display: flex; flex-direction: column; border: 3px solid #fff;
  box-shadow: 0 18px 50px rgba(20,43,92,.45); overflow: hidden; font-size: clamp(11px, min(2.3vh, 1.9vw) + 4px, 19px);
}
.card::before { content: ""; display: block; height: .5em; flex: none; background: repeating-linear-gradient(90deg, var(--cobalt) 0 1em, #fff 1em 1.3em, var(--sky) 1.3em 2.3em, #fff 2.3em 2.6em); }
#cardBody { overflow-y: auto; padding: .9em 1.2em .5em; flex: 1 1 auto; min-height: 0; }
#cardFoot { flex: none; padding: .5em 1.2em .9em; display: flex; gap: .6em; justify-content: center; flex-wrap: wrap; }
#cardFoot:empty { display: none; }
.card h2 { margin: 0 0 .3em; color: var(--cobalt); font-size: 1.4em; }
.card p { margin: .3em 0; line-height: 1.5; }
.btn { background: var(--terra); color: #fff; font-weight: 800; font-size: 1.05em; border-radius: 2em; padding: .6em 1.6em; box-shadow: 0 4px 0 var(--terra2), 0 8px 16px rgba(0,0,0,.15); white-space: nowrap; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--terra2); }
.btn.ghost { background: #fff; color: var(--cobalt); box-shadow: 0 4px 0 #c9d3ea; }
.row { display: flex; gap: .6em; justify-content: center; flex-wrap: wrap; }

.menu { display: grid; grid-template-columns: 10em 1fr; gap: .4em 1em; align-items: center; }
.menu .hero { text-align: center; }
.menu .hero img { width: 8.5em; height: 8.5em; object-fit: contain; }
.menu .hero h1 { margin: 0; color: var(--cobalt); font-size: 1.75em; line-height: 1.05; }
.menu .hero h1 small { display: block; font-size: .5em; color: var(--terra); margin-top: .15em; }
.intro { font-size: .86em; color: #3b4a6b; }
.grp { margin: .35em 0; }
.gl { display: block; font-size: .72em; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--terra2); margin-bottom: .2em; }
.levels { display: grid; gap: .45em; }
.levels.slider { grid-template-columns: repeat(3, 1fr); position: relative; }
.levels.kids { grid-template-columns: 1fr 1fr; }
.lv { background: #fff; border-radius: .8em; padding: .4em .6em; text-align: left; box-shadow: 0 3px 0 #c9d3ea; border: 2px solid #dfe6f5; position: relative; min-width: 0; }
.lv b { display: block; font-size: 1em; color: var(--cobalt); }
.lv span { font-size: .72em; color: #56627f; display: block; line-height: 1.3; }
.lv em { font-style: normal; font-size: .72em; color: var(--terra2); font-weight: 700; }
.slider .lv::before { content: ""; display: block; height: .35em; border-radius: 1em; margin-bottom: .3em; background: var(--mint); width: 33%; }
.slider .lv.l3::before { width: 66%; background: var(--sky); }
.slider .lv.l4::before { width: 100%; background: var(--terra); }
.kids .lv { background: #f2fbf6; border-color: #c8ecd8; box-shadow: 0 3px 0 #a8dcc0; }
.kids .lv b { color: #1f7a4f; }
.lv:hover, .lv:focus-visible { border-color: var(--lemon); }
.daily-cta { width: 100%; margin-top: .45em; background: var(--lemon); border-radius: .8em; padding: .5em .8em; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: .6em; box-shadow: 0 3px 0 #c79a00; color: var(--navy); }
.daily-cta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.keys { grid-column: 1 / -1; font-size: .72em; color: #56627f; line-height: 1.9; display: flex; flex-wrap: wrap; gap: .1em .8em; align-items: center; }
.opt { background: #fff; border: 1px solid #c9d3ea; border-radius: 1em; padding: .1em .7em; font-size: 1em; color: var(--cobalt); }
.opt b { color: var(--terra2); }
kbd { display: inline-block; background: #fff; border: 1px solid #c9d3ea; border-bottom-width: 3px; border-radius: .35em; padding: 0 .4em; font-family: inherit; font-size: .95em; line-height: 1.5; color: var(--ink); }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .4em; margin: .6em 0; }
.day { background: #fff; border-radius: .7em; padding: .4em .1em; text-align: center; box-shadow: 0 3px 0 #c9d3ea; border: 2px solid transparent; min-width: 0; }
.day b { display: block; font-size: 1em; color: var(--cobalt); white-space: nowrap; }
.day span { display: block; font-size: .72em; color: #56627f; }
.day i { display: block; font-style: normal; font-size: .66em; font-weight: 700; color: var(--sky); margin-top: .15em; }
.day.today { border-color: var(--lemon); background: #fffbe6; box-shadow: 0 0 0 3px rgba(255,212,59,.5), 0 0 16px rgba(255,190,0,.8); }
.day.today i { color: var(--terra2); }
.day.solved { background: #e5f7ed; }
.day.solved b::after { content: " ✓"; color: #1f7a4f; }
.streak { display: flex; gap: 1em; justify-content: center; font-weight: 700; color: var(--cobalt); }
.streak b { color: var(--terra); font-size: 1.3em; }

.guide ol { margin: .3em 0; padding-left: 1.4em; }
.guide li { margin: .4em 0; line-height: 1.45; }
.guide li b { color: var(--cobalt); }
.win { display: grid; grid-template-columns: 8em 1fr; gap: 1em; align-items: center; }
.win img { width: 8em; height: 8em; object-fit: contain; }
.stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .4em; margin: .5em 0; }
.stats div { background: #fff; border-radius: .6em; padding: .3em .55em; border: 1.5px solid #dfe6f5; }
.stats small { display: block; font-size: .72em; color: #56627f; }
.stats b { color: var(--cobalt); font-size: 1.1em; }
.newbest { color: var(--terra2); font-weight: 800; }

@media (min-aspect-ratio: 1/1) { .keys .ph { display: none; } }
@media (max-height: 520px) {
  .menu { grid-template-columns: 7em 1fr; gap: .3em .7em; }
  .menu .hero img { width: 6em; height: 6em; }
  .menu .hero h1 { font-size: 1.45em; }
  .menu .intro { font-size: .78em; margin: .1em 0; }
  .lv span { display: none; }
  .lv { padding: .3em .55em; }
  .grp { margin: .2em 0; }
  .win { grid-template-columns: 6em 1fr; }
  .win img { width: 6em; height: 6em; }
  #cardBody { padding: .6em 1em .3em; }
  #cardFoot { padding: .35em 1em .55em; }
  .btn { padding: .42em 1.3em; }
  .keys { line-height: 1.6; }
}
@media (max-width: 560px) and (orientation: portrait) {
  .menu { grid-template-columns: 1fr; gap: .2em; }
  .menu .hero { display: flex; align-items: center; justify-content: center; gap: .6em; }
  .menu .hero img { width: 5em; height: 5em; }
  .win { grid-template-columns: 5em 1fr; }
  .win img { width: 5em; height: 5em; }
  .stats { grid-template-columns: 1fr 1fr; }
  .week { gap: .25em; }
  .day b { font-size: .85em; }
  .lv span { font-size: .68em; }
}

/* ---------- coach marks ---------- */
#coach { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
#coachCard {
  pointer-events: auto; position: absolute; left: 50%; transform: translateX(-50%); bottom: 3vh; width: min(26em, 92vw);
  background: var(--cream); border: 3px solid var(--lemon); border-radius: 1em; padding: .8em 1em; box-shadow: 0 14px 40px rgba(0,0,0,.45); font-size: clamp(12px, min(2.3vh, 1.9vw) + 4px, 18px);
}
#coachCard.top { bottom: auto; top: 3vh; }
#coachCard.mid { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
#coachCard p { margin: 0 0 .6em; line-height: 1.5; }
#coachCard p b { color: var(--terra2); }
#coachCard .btn { font-size: .95em; padding: .4em 1.2em; }
.coached { position: relative; z-index: 55; box-shadow: 0 0 0 4px var(--lemon), 0 0 0 9999px rgba(20,43,92,.6) !important; border-radius: .8em; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 70; width: 100%; height: 100%; }

/* landscape: the pad stops growing on big screens; the extra room goes to Tita */
body.land #pad { max-height: calc(var(--pw) * .64); }
body.land #coachBox { flex: .001 1 auto; }
body.land #tita { width: auto; height: 100%; aspect-ratio: 1; min-height: 4.4em; max-height: 17em; max-width: 36%; }
body.land.short #tita { min-height: 3em; }
