:root {
  --cobalt: #1f4fa8; --navy: #14336f; --ink: #1b2a4a; --cream: #fff8e6; --paper: #fffdf6; --lemon: #ffd23f; --lemon2: #ffe98a;
  --terra: #d9653b; --terra2: #a8441f; --sea: #2bb3b1; --tint: #eaf1ff; --same: #cfe0ff; --err: #ffd9cf; --sel: #ffec8f; --red: #d9453b;
  --bs: 360px; --cs: 40px; --g: 8px; --fs: 15px; --pw: 300px;
  --font: "Trebuchet MS", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", 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: #7cc6ef 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,230,.08), rgba(20,51,111,.28)); 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: cream paper in a majolica tile frame ---------- */
#boardWrap {
  width: var(--bs); height: var(--bs); flex: none; position: relative; border-radius: calc(var(--cs) * .22); padding: calc(var(--cs) * .14);
  background:
    radial-gradient(circle at 50% 50%, var(--lemon) 0 14%, transparent 15%) 0 0 / calc(var(--cs) * .5) calc(var(--cs) * .5),
    radial-gradient(circle at 50% 50%, #fff 0 34%, transparent 36%) 0 0 / calc(var(--cs) * .5) calc(var(--cs) * .5),
    var(--cobalt);
  box-shadow: 0 14px 34px rgba(20,51,111,.45), inset 0 0 0 2px rgba(255,255,255,.6);
}
#board {
  width: 100%; height: 100%; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 3px; padding: 3px;
  background: var(--navy); border-radius: calc(var(--cs) * .1);
}
.box { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 1px; background: #c3d2ee; }
.box:nth-child(1) { border-top-left-radius: calc(var(--cs) * .1); overflow: hidden; }
.box:nth-child(3) { border-top-right-radius: calc(var(--cs) * .1); overflow: hidden; }
.box:nth-child(7) { border-bottom-left-radius: calc(var(--cs) * .1); overflow: hidden; }
.box:nth-child(9) { border-bottom-right-radius: calc(var(--cs) * .1); overflow: hidden; }
.box:nth-child(even) .cell { background: #fff4dc; }
.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) * .62); font-weight: 700; line-height: 1; color: var(--cobalt); font-family: var(--font); }
.cell.given .v { color: var(--ink); font-family: var(--serif); font-weight: 700; }
.cell.hinted .v { color: var(--sea); }
.cell.wrong .v { color: var(--red); }
.box .cell.tint { background: var(--tint); }
.box .cell.same { background: var(--same); }
.box .cell.conf { background: var(--err); }
.box .cell.sel { background: var(--sel); box-shadow: inset 0 0 0 2.5px var(--terra); }
.box .cell.unit { background: #fff1b8; }
.cell.flash { animation: flash .6s ease-out; }
.cell.pop .v { animation: pop .3s ease-out; }
@keyframes flash { 0% { background: #bff0ee; } 100% { } }
@keyframes pop { 0% { transform: scale(.4) rotate(-12deg); } 70% { transform: scale(1.2) rotate(4deg); } 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: #6b7590; font-weight: 700; }
.cell .n span.hl { color: #fff; background: var(--terra); border-radius: 50%; }
#pauseCover { position: absolute; inset: calc(var(--cs) * .14); border-radius: calc(var(--cs) * .1); background: var(--cream); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3em; z-index: 3; cursor: pointer; }
#pauseCover b { font-family: var(--serif); font-size: 2em; color: var(--cobalt); }
#pauseCover span { color: var(--terra2); font-weight: 700; }

/* ---------- 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: .45em; background: var(--cobalt); color: #fff; border-radius: 2em; padding: .3em .4em .3em .7em; box-shadow: 0 4px 12px rgba(20,51,111,.35), inset 0 -3px 0 rgba(0,0,0,.18); flex: none; }
.logo { display: flex; align-items: center; gap: .3em; margin-right: auto; white-space: nowrap; min-width: 0; overflow: hidden; }
.logo b { font-family: var(--serif); font-size: 1.2em; font-style: italic; letter-spacing: .02em; }
.logo .lemon { width: 1.3em; height: 1.3em; flex: none; }
.tag { background: var(--lemon); color: var(--ink); font-weight: 800; font-size: .8em; padding: .2em .65em; border-radius: 1em; white-space: nowrap; max-width: 9em; overflow: hidden; text-overflow: ellipsis; flex: none; }
.tag.l0, .dl.l0 { background: #57c27a; color: #fff; } .tag.l1, .dl.l1 { background: var(--sea); color: #fff; } .tag.l2, .dl.l2 { background: var(--lemon); color: var(--ink); }
.tag.l3, .dl.l3 { background: var(--terra); color: #fff; } .tag.l4, .dl.l4 { background: #8e2f6b; color: #fff; }
.dl { border-radius: 1em; margin: .1em .2em; font-weight: 700; padding: 0 .5em; }
.stat { display: flex; align-items: center; gap: .25em; font-size: .9em; white-space: nowrap; }
.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,255,255,.18); color: #fff; }
.ib svg { width: 1.15em; height: 1.15em; }
body.paused #pause { background: var(--lemon); color: var(--ink); }
#coachBox { display: flex; align-items: center; gap: .5em; flex: none; min-height: 0; }
#mc { width: 4.4em; height: 4.4em; object-fit: contain; flex: none; filter: drop-shadow(0 3px 4px rgba(20,51,111,.35)); }
#mc.bounce { animation: bounce .5s; }
@keyframes bounce { 30% { transform: translateY(-14%) rotate(-6deg); } 60% { transform: translateY(0) rotate(3deg); } }
#bubble > span { display: block; }
#bubble {
  flex: 1; background: var(--cream); border: 2px solid var(--lemon); border-radius: 1em; padding: .4em .7em; font-size: .9em; line-height: 1.4; position: relative;
  box-shadow: 0 4px 12px rgba(20,51,111,.2); 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); }
#pad { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: .45em; flex: 1 1 auto; min-height: 0; }
.num {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; position: relative;
  color: var(--cobalt); background: var(--paper); border-radius: .5em; border: 2px solid var(--cobalt);
  box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 5px var(--lemon2), 0 4px 0 var(--navy), 0 6px 10px rgba(20,51,111,.25);
  container-type: size;
}
.num b { font-size: 1.75em; font-size: min(2.6em, 52cqmin); line-height: 1; font-weight: 800; font-family: var(--serif); }
.num small { font-size: .62em; font-size: max(.62em, min(1em, 14cqmin)); color: var(--terra); font-weight: 700; }
.num:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 5px var(--lemon2), 0 1px 0 var(--navy); }
.num.done { opacity: .35; }
body.notes-on .num { color: var(--terra2); border-color: var(--terra); background: #fff3e8; box-shadow: inset 0 0 0 3px #fff3e8, inset 0 0 0 5px #ffd3b8, 0 4px 0 var(--terra2); }
#tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4em; flex: none; }
.tool {
  position: relative; background: var(--cobalt); border-radius: .7em; padding: .3em .1em; display: flex; flex-direction: column; align-items: center; gap: .05em;
  color: #fff; font-weight: 700; font-size: .66em; box-shadow: 0 3px 0 var(--navy), 0 5px 10px rgba(20,51,111,.25); 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 var(--navy); }
.tool.off { opacity: .55; }
.tool i { position: absolute; top: -.35em; right: -.1em; font-style: normal; font-size: .72em; background: var(--terra); color: #fff; border-radius: 1em; padding: .05em .45em; }
#notes.on { background: var(--terra); box-shadow: 0 3px 0 var(--terra2); }
#notes.on i { background: var(--lemon); color: var(--ink); }
#hint { background: var(--sea); box-shadow: 0 3px 0 #1b7f7e, 0 5px 10px rgba(20,51,111,.25); }
#bottom { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4em; flex: none; }
.chip { background: var(--cream); color: var(--cobalt); font-weight: 800; border-radius: .6em; padding: .45em .3em; font-size: .8em; white-space: nowrap; box-shadow: 0 3px 0 #d8c9a3; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#dailyBtn { background: var(--lemon); color: var(--ink); box-shadow: 0 3px 0 #c99a00; }

/* portrait: header, bubble, board, pad, tools, 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 #pad { order: 4; width: var(--pw); grid-template-columns: repeat(9, 1fr); flex: none; height: calc(var(--fs) * 3.6); gap: .3em; }
body.port #tools { order: 5; width: var(--pw); }
body.port #bottom { order: 6; width: var(--pw); }
body.port #mc { width: 3.4em; height: 3.4em; }
body.port .num b { font-size: 1.6em; font-size: min(1.8em, 52cqmin); }
body.short #mc { 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; }
body.short #top { gap: .3em; padding: .25em .3em .25em .5em; }
body.short .logo b { display: none; }
body.short .tool { font-size: .6em; padding: .3em .05em; }
body.short .stat { font-size: .82em; }
body.short .chip { font-size: .72em; padding: .45em .2em; }
body.short .ib { width: 1.8em; height: 1.8em; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 2vh 2vw; background: rgba(20,51,111,.55); }
.card {
  background: var(--cream); border-radius: 1.2em; width: min(46em, 96vw); max-height: 96vh; display: flex; flex-direction: column;
  box-shadow: 0 18px 50px rgba(0,0,0,.4), inset 0 0 0 4px var(--cobalt), inset 0 0 0 7px var(--lemon2); overflow: hidden; font-size: clamp(12px, min(2.3vh, 1.9vw) + 4px, 19px);
}
#cardBody { overflow-y: auto; padding: 1em 1.3em .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(--cobalt); font-size: 1.4em; font-family: var(--serif); }
.card p { margin: .3em 0; line-height: 1.55; }
.btn { background: var(--terra); color: #fff; font-weight: 800; font-size: 1.05em; border-radius: .8em; padding: .6em 1.6em; box-shadow: 0 4px 0 var(--terra2), 0 8px 16px rgba(0,0,0,.18); 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 #c3d2ee; }
.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(--cobalt); font-size: 1.8em; line-height: 1.1; font-family: var(--serif); font-style: italic; }
.menu .hero h1 small { display: block; font-size: .42em; font-style: normal; font-family: var(--font); color: var(--terra); font-weight: 800; letter-spacing: .04em; text-transform: uppercase; margin-top: .3em; }
.intro { font-size: .88em; color: #3a4766; }
.levels { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: .5em; margin: .5em 0; }
.lv { background: #fff; border-radius: .7em; padding: .45em .7em .45em 2.5em; text-align: left; box-shadow: 0 3px 0 #c3d2ee; 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: .35em; color: #fff; font-style: normal; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .9em; }
.lv.l0 i { background: #57c27a; } .lv.l1 i { background: var(--sea); } .lv.l2 i { background: #e3b300; } .lv.l3 i { background: var(--terra); } .lv.l4 i { background: #8e2f6b; }
.lv.l4 { grid-column: span 2; }
.lv b { display: block; font-size: 1em; color: var(--cobalt); }
.lv span { font-size: .75em; color: #556080; display: block; line-height: 1.35; }
.lv em { font-style: normal; font-size: .72em; color: var(--terra2); font-weight: 700; }
.lv.l4 b { color: #8e2f6b; }
.lv:hover, .lv:focus-visible { border-color: var(--cobalt); }
.daily-cta { width: 100%; background: var(--lemon); border-radius: .7em; padding: .55em .8em; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: .6em; box-shadow: 0 3px 0 #c99a00; }
.daily-cta span { white-space: nowrap; }
.keys { grid-column: 1 / -1; font-size: .72em; color: #556080; margin-top: .2em; line-height: 1.9; display: flex; flex-wrap: wrap; gap: .2em .8em; align-items: center; }
.opt { background: #fff; border: 1px solid #c3d2ee; 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 #c3d2ee; 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 #c3d2ee; position: relative; border: 2px solid transparent; min-width: 0; }
.day b { display: block; font-size: 1.15em; color: var(--cobalt); }
.day span { display: block; font-size: .7em; color: #556080; }
.day i { display: block; font-style: normal; font-size: .68em; font-weight: 700; color: var(--cobalt); margin-top: .15em; }
.day.today { border-color: var(--lemon); box-shadow: 0 0 0 3px rgba(255,210,63,.5), 0 0 16px rgba(255,210,63,.95); }
.day.today i { color: var(--terra2); }
.day span.dl { font-size: .62em; padding: 0 .2em; overflow: hidden; text-overflow: ellipsis; }
.day.solved { background: #e4f7ea; }
.day.solved b::after { content: " ✓"; color: #2f9a55; font-size: .8em; }
.streak { display: flex; gap: 1em; justify-content: center; font-weight: 700; color: var(--cobalt); flex-wrap: wrap; }
.streak b { color: var(--terra2); font-size: 1.3em; }
table.st { width: 100%; border-collapse: separate; border-spacing: 0 .25em; margin: .4em 0; font-size: .9em; }
table.st th { font-size: .78em; color: #556080; text-align: center; font-weight: 700; }
table.st td { background: #fff; text-align: center; padding: .3em .2em; font-weight: 700; color: var(--cobalt); }
table.st td:first-child { border-radius: .6em 0 0 .6em; text-align: left; }
table.st td:last-child { border-radius: 0 .6em .6em 0; }

.guide ol { margin: .3em 0; padding-left: 1.4em; }
.guide li { margin: .45em 0; line-height: 1.5; }
.guide li b { color: var(--cobalt); }
.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: #556080; }
.stats b { color: var(--cobalt); font-size: 1.1em; }
.newbest { color: var(--terra2); 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.55em; }
  .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; }
  .lv .cl { display: none; }
  .lv { padding-top: .35em; padding-bottom: .35em; }
  .menu .intro { font-size: .8em; }
  .keys .ph { display: none; }
}
@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; }
  table.st { font-size: .8em; }
}
@media (min-aspect-ratio: 1/1) { .keys .ph { display: none; } }

/* ---------- 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,.45), inset 0 0 0 3px var(--lemon); 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(--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,51,111,.62) !important; border-radius: .8em; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 70; width: 100%; height: 100%; }
body.land .logo b { display: none; }
body.land .logo { margin-right: auto; }
