:root {
  --jade: #7a52c7; --teal: #4a3278; --deep: #3d2a63; --cream: #fff8ec; --paper: #fffdf7; --ink: #2e2440;
  --red: #d9653b; --gold: #f2c14e; --sel: #ffe7a8; --tint: #f3edfb; --same: #dccdf3; --err: #ffd9cc; --orange: #e0873a; --sage: #6fa77a;
  --bs: 360px; --cs: 40px; --g: 8px; --fs: 15px; --pw: 300px;
  --font: "Segoe UI", "Trebuchet MS", 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: #b9a6e0 url(img/bg.webp) center / cover no-repeat; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
body::before { content: ""; position: fixed; inset: 0; background: linear-gradient(180deg, rgba(255,248,236,.05), rgba(61,42,99,.35)); pointer-events: 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; }
#board {
  width: 100%; height: 100%; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 3px; padding: 3px;
  background: var(--deep); border-radius: calc(var(--cs) * .14); box-shadow: 0 14px 30px rgba(61,42,99,.45), 0 0 0 5px #fff8ec, 0 0 0 9px rgba(217,101,59,.85);
}
.box { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 1px; background: #d6c8ec; }
.box:nth-child(1) { border-top-left-radius: calc(var(--cs) * .16); overflow: hidden; }
.box:nth-child(3) { border-top-right-radius: calc(var(--cs) * .16); overflow: hidden; }
.box:nth-child(7) { border-bottom-left-radius: calc(var(--cs) * .16); overflow: hidden; }
.box:nth-child(9) { border-bottom-right-radius: calc(var(--cs) * .16); overflow: hidden; }
.cell { background: var(--paper); position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; min-width: 0; min-height: 0; }
.cell .v { font-size: calc(var(--cs) * .6); font-weight: 600; line-height: 1; color: #7a52c7; font-family: Georgia, 'Times New Roman', serif; }
.cell.given .v { color: var(--ink); font-weight: 700; font-family: var(--font); }
.cell.hinted .v { color: #2f8a55; }
.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 var(--red); }
.cell.unit { background: #e4f3e2; }
.cell.flash { animation: flash .6s ease-out; }
.cell.pop .v { animation: pop .28s ease-out; }
@keyframes flash { 0% { background: #cdb8f2; } 100% { } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.18); } 100% { transform: scale(1); } }
.cell .n { position: absolute; inset: 6%; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.cell .n span { font-size: calc(var(--cs) * .24); line-height: 1; display: flex; align-items: center; justify-content: center; color: #7d6a99; font-weight: 600; }
.cell .n span.hl { color: #fff; background: var(--jade); border-radius: 30%; }

/* ---------- panel ---------- */
#panel { width: var(--pw); height: var(--bs); display: flex; flex-direction: column; gap: calc(var(--g) * .8); min-width: 0; }
#top { display: flex; align-items: center; gap: .5em; background: var(--deep); color: var(--cream); border-radius: 2em; padding: .35em .6em; box-shadow: 0 4px 12px rgba(0,0,0,.2); flex: none; }
.logo { display: flex; align-items: baseline; gap: .3em; color: var(--cream); margin-right: auto; white-space: nowrap; }
.logo b { font-size: 1.35em; letter-spacing: .06em; }
.logo small { font-size: .72em; opacity: .7; font-weight: 700; }
.tag { background: var(--jade); color: #fff; font-weight: 700; font-size: .82em; padding: .2em .6em; border-radius: 1em; white-space: nowrap; }
.tag { max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.tag.l0, .dl.l0 { background: #4f9a5f; } .tag.l1, .dl.l1 { background: #3a86b8; } .tag.l2, .dl.l2 { background: #8a5fd1; } .tag.l3, .dl.l3 { background: #d9653b; } .tag.l4, .dl.l4 { background: #a8283f; }
.dl { color: #fff !important; border-radius: 1em; margin: .1em .2em; font-weight: 700; }
.logo .sun { width: 1.25em; height: 1.25em; color: var(--gold); align-self: center; }
.stat { display: flex; align-items: center; gap: .25em; font-size: .9em; white-space: nowrap; color: var(--cream); }
.stat .lbl { font-size: .85em; opacity: .8; }
.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: rgba(255,248,236,.16); color: var(--cream); }
.ib svg { width: 1.2em; height: 1.2em; }
#coachBox { display: flex; align-items: center; gap: .5em; flex: none; min-height: 0; }
#hh { width: 4.2em; height: 4.2em; object-fit: contain; flex: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.3)); transition: transform .2s; }
#hh.bounce { animation: bounce .5s; }
@keyframes bounce { 30% { transform: translateY(-14%) scale(1.06); } 60% { transform: translateY(0) scale(.97); } }
#bubble > span { display: block; }
#bubble {
  flex: 1; background: var(--cream); border: 2px solid #cdb8f2; border-radius: .9em; padding: .45em .7em; font-size: .9em; line-height: 1.4; position: relative;
  box-shadow: 0 4px 12px rgba(0,0,0,.18); min-height: 2.6em; display: flex; align-items: center;
}
#bubble::before { content: ""; position: absolute; left: -.5em; top: 50%; margin-top: -.45em; border: .45em solid transparent; border-right-color: #cdb8f2; border-left: 0; }
#bubble b { color: var(--red); }
#tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4em; flex: none; }
.tool {
  position: relative; background: var(--cream); border-radius: .8em; padding: .35em .2em; display: flex; flex-direction: column; align-items: center; gap: .1em;
  color: var(--teal); font-weight: 700; font-size: .66em; box-shadow: 0 3px 0 #cdb8f2, 0 5px 10px rgba(61,42,99,.25); white-space: nowrap; min-width: 0;
}
.tool span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tool svg { width: 1.6em; height: 1.6em; }
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 #cdb8f2; }
.tool.off { opacity: .55; }
.tool i { position: absolute; top: -.35em; right: -.1em; font-style: normal; font-size: .72em; background: var(--red); color: #fff; border-radius: 1em; padding: .05em .45em; }
#notes.on { background: var(--jade); color: #fff; box-shadow: 0 3px 0 #4a3278; }
#notes.on i { background: var(--gold); color: var(--ink); }
#pad { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: .45em; flex: 1 1 auto; min-height: 0; }
.num {
  background: #fff; border-radius: .7em; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0;
  color: #fff8ec; background: linear-gradient(180deg, #e27a4e, #c9572f); border-radius: .5em; box-shadow: inset 0 0 0 3px rgba(255,248,236,.35), 0 4px 0 #8f3a1d, 0 6px 12px rgba(61,42,99,.3); position: relative;
}
.num { container-type: size; }
.num b { font-size: 1.75em; font-size: min(2.6em, 52cqmin); line-height: 1; font-weight: 700; }
.num small { font-size: .62em; font-size: max(.62em, min(1em, 14cqmin)); opacity: .85; color: #ffe7a8; }
.num:active { transform: translateY(2px); box-shadow: inset 0 0 0 3px rgba(255,248,236,.35), 0 2px 0 #8f3a1d; }
.num.done { opacity: .35; }
body.notes-on .num { color: var(--jade); background: #f6f0ff; box-shadow: inset 0 0 0 3px #cdb8f2, 0 4px 0 #9f86c9; }
body.notes-on .num small { color: var(--jade); }
#bottom { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4em; flex: none; }
.chip { background: var(--sage); color: #fff; font-weight: 700; border-radius: 2em; padding: .45em .3em; font-size: .85em; white-space: nowrap; box-shadow: 0 3px 8px rgba(0,0,0,.18); }
#dailyBtn { background: var(--gold); color: var(--ink); }
#statsBtn, #helpBtn { background: rgba(255,248,236,.95); color: var(--teal); }
.chip { overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* portrait: stack header, bubble, board, tools, pad, bottom */
body.port #app { flex-direction: column; justify-content: center; }
body.port #panel { display: contents; }
body.port #top { order: 1; width: var(--pw); }
body.port #coachBox { order: 2; width: var(--pw); }
body.port #boardWrap { order: 3; }
body.port #tools { order: 4; width: var(--pw); }
body.port #pad { order: 5; width: var(--pw); grid-template-columns: repeat(9, 1fr); flex: none; height: calc(var(--fs) * 3.6); }
body.port #bottom { order: 6; width: var(--pw); }
body.port #hh { width: 3.4em; height: 3.4em; }
body.port .num b { font-size: 1.6em; font-size: min(1.8em, 52cqmin); }
body.short #hh { display: none; }
body.short #bubble::before { display: none; }
body.short #bubble { min-height: 2.3em; padding: .3em .6em; font-size: .85em; }
body.tiny #coachBox { display: none; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 2vh 2vw; background: rgba(46,30,76,.55); }
.card {
  background: var(--cream); border-radius: 1.1em; width: min(46em, 96vw); max-height: 96vh; display: flex; flex-direction: column;
  box-shadow: 0 18px 50px rgba(0,0,0,.45); overflow: hidden; font-size: clamp(12px, min(2.3vh, 1.9vw) + 4px, 19px);
}
#cardBody { overflow-y: auto; padding: 1em 1.2em .6em; flex: 1 1 auto; min-height: 0; }
#cardFoot { flex: none; padding: .6em 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(--teal); font-size: 1.4em; }
.card p { margin: .3em 0; line-height: 1.55; }
.btn { background: var(--red); color: #fff; font-weight: 800; font-size: 1.05em; border-radius: 2em; padding: .6em 1.6em; box-shadow: 0 4px 0 #8f3a1d, 0 8px 16px rgba(0,0,0,.2); white-space: nowrap; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #8f3a1d; }
.btn.ghost { background: #fff; color: var(--teal); box-shadow: 0 4px 0 #cdb8f2; }
.row { display: flex; gap: .6em; justify-content: center; flex-wrap: wrap; }

.menu { display: grid; grid-template-columns: 11em 1fr; gap: 1em; align-items: center; }
.menu .hero { text-align: center; }
.menu .hero img { width: 9em; height: 9em; object-fit: contain; }
.menu .hero h1 { margin: 0; color: var(--teal); font-size: 1.9em; letter-spacing: .02em; line-height: 1.1; }
.menu .hero h1 small { display: block; font-size: .4em; letter-spacing: .02em; color: var(--red); }
.intro { font-size: .88em; color: #4a3f5e; }
.levels { display: grid; grid-template-columns: 1fr 1fr; gap: .5em; margin: .5em 0; }
.lv { background: #fff; border-radius: .8em; padding: .45em .7em .45em 2.4em; text-align: left; box-shadow: 0 3px 0 #d6c8ec; border: 2px solid transparent; position: relative; }
.lv i { position: absolute; left: .5em; top: 50%; transform: translateY(-50%); width: 1.5em; height: 1.5em; border-radius: 50%; color: #fff; font-style: normal; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .9em; }
.lv.l0 i { background: #4f9a5f; } .lv.l1 i { background: #3a86b8; } .lv.l2 i { background: #8a5fd1; } .lv.l3 i { background: #d9653b; } .lv.l4 i { background: #a8283f; }
.lv.l4 { grid-column: span 2; }
.lv b { display: block; font-size: 1em; color: var(--teal); }
.lv span { font-size: .75em; color: #6a5c82; display: block; line-height: 1.35; }
.lv em { font-style: normal; font-size: .72em; color: var(--red); font-weight: 700; }
.lv.l4 b { color: #a8283f; }
.lv:hover, .lv:focus-visible { border-color: var(--jade); }
.daily-cta { width: 100%; background: var(--gold); border-radius: .8em; padding: .55em .8em; font-weight: 800; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 3px 0 #d39a2a; }
.keys { grid-column: 1 / -1; font-size: .72em; color: #6a5c82; margin-top: .2em; line-height: 1.9; display: flex; flex-wrap: wrap; gap: .2em .8em; align-items: center; }
.opt { background: #fff; border: 1px solid #d6c8ec; border-radius: 1em; padding: .1em .7em; font-size: 1em; color: var(--teal); }
.opt b { color: var(--red); }
kbd { display: inline-block; background: #fff; border: 1px solid #d6c8ec; 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 #d6c8ec; position: relative; border: 2px solid transparent; }
.day b { display: block; font-size: 1.15em; color: var(--teal); }
.day span { display: block; font-size: .7em; color: #6a5c82; }
.day i { display: block; font-style: normal; font-size: .68em; font-weight: 700; color: var(--jade); margin-top: .15em; }
.day.today { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,200,87,.45), 0 0 16px rgba(255,200,87,.9); }
.day.today i { color: var(--red); }
.day span.dl { font-size: .62em; padding: 0 .2em; }
.day.solved { background: #e3f6ea; }
.day.solved b::after { content: " ✓"; color: var(--jade); font-size: .8em; }
.streak { display: flex; gap: 1em; justify-content: center; font-weight: 700; color: var(--teal); }
.streak b { color: var(--red); font-size: 1.3em; }

.guide ol { margin: .3em 0; padding-left: 1.4em; }
.guide li { margin: .45em 0; line-height: 1.5; }
.guide li b { color: var(--teal); }
.win { display: grid; grid-template-columns: 9em 1fr; gap: 1em; align-items: center; }
.win img { width: 9em; height: 9em; object-fit: contain; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .4em; margin: .5em 0; }
.stats div { background: #fff; border-radius: .6em; padding: .35em .6em; }
.stats small { display: block; font-size: .72em; color: #6a5c82; }
.stats b { color: var(--teal); font-size: 1.1em; }
.newbest { color: var(--red); font-weight: 800; }

@media (max-height: 520px) {
  .menu { grid-template-columns: 8em 1fr; gap: .7em; }
  .menu .hero img { width: 6.5em; height: 6.5em; }
  .menu .hero h1 { font-size: 1.7em; }
  .win { grid-template-columns: 6em 1fr; }
  .win img { width: 6em; height: 6em; }
  #cardBody { padding: .7em 1em .4em; }
  #cardFoot { padding: .4em 1em .6em; }
  .btn { padding: .45em 1.3em; }
}
@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: 5.5em; height: 5.5em; }
  .win { grid-template-columns: 5.5em 1fr; }
  .win img { width: 5.5em; height: 5.5em; }
  .week { gap: .25em; }
}

/* ---------- 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-radius: 1em; padding: .8em 1em; box-shadow: 0 14px 40px rgba(0,0,0,.5); 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.55; }
#coachCard p b { color: var(--red); }
#coachCard .btn { font-size: .95em; padding: .4em 1.2em; }
.coached { position: relative; z-index: 55; box-shadow: 0 0 0 4px var(--gold), 0 0 0 9999px rgba(40,26,66,.65) !important; border-radius: .8em; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 70; width: 100%; height: 100%; }

.daily-cta span { white-space: nowrap; }
.daily-cta { gap: .6em; }
body.short #top { gap: .35em; padding: .3em .45em; }
body.short .logo b { display: none; }
body.short .tool { font-size: .64em; padding: .3em .05em; }
body.short .stat { font-size: .82em; }
@media (max-height: 520px) {
  .lv .cl { display: none; }
  .lv { padding-top: .35em; padding-bottom: .35em; }
  .menu .intro { font-size: .8em; }
  .keys .ph { display: none; }
}
@media (min-aspect-ratio: 1/1) { .keys .ph { display: none; } }
body.short .chip { font-size: .74em; padding: .45em .2em; }

.tag { flex: none; }
.logo { min-width: 0; overflow: hidden; }
.tool svg { width: 2em; height: 2em; }
.logo b { font-size: 1.15em; }
.chip { font-size: .8em; }

/* stats table */
.st { width: 100%; border-collapse: separate; border-spacing: 0 .3em; font-size: .9em; }
.st th { text-align: left; font-size: .78em; color: #6a5c82; font-weight: 700; padding: 0 .4em; }
.st td { background: #fff; padding: .35em .4em; color: var(--teal); font-weight: 700; }
.st td:first-child { border-radius: .6em 0 0 .6em; } .st td:last-child { border-radius: 0 .6em .6em 0; }
.st .dl { display: inline-block; padding: .1em .6em; font-size: .85em; }
.card h2, .menu .hero h1 { font-family: Georgia, 'Times New Roman', serif; }
