/* Andika, self-hosted (latin subset) so the app works offline and never reflows on a slow network */
@font-face { font-family: 'Andika'; font-style: normal; font-weight: 400; font-display: swap; src: url('fonts/andika-normal-400.woff2') format('woff2'); }
@font-face { font-family: 'Andika'; font-style: normal; font-weight: 700; font-display: swap; src: url('fonts/andika-normal-700.woff2') format('woff2'); }
@font-face { font-family: 'Andika'; font-style: italic; font-weight: 400; font-display: swap; src: url('fonts/andika-italic-400.woff2') format('woff2'); }
:root {
  --paper: #f8f5ef; --bg: #efeae1; --ink: #1e1c19; --muted: #6f695f; --line: #d9d2c5;
  --accent: #0e7c6b; --accent-ink: #fff; --warn: #c9531c; --good: #0e7c6b;
  --radius: 14px; --font: "Andika", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); color: var(--ink); background: var(--bg);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button {
  font: inherit; font-size: 16px; font-weight: 700; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-bottom-width: 4px; border-radius: 999px; padding: 10px 18px 9px; cursor: pointer; touch-action: manipulation;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, box-shadow 0.15s ease;
}
@media (hover: hover) { button:hover { transform: translateY(-1px); } button.primary:hover { box-shadow: 0 10px 22px rgba(14,124,107,0.34); } }
button:active { transform: translateY(3px); border-bottom-width: 1px; }
button.primary { background: linear-gradient(180deg, #17a08a, #0e7c6b); color: var(--accent-ink); border-color: #0a5c4f; box-shadow: 0 6px 16px rgba(14,124,107,0.28); }
button.primary:active { box-shadow: 0 2px 6px rgba(14,124,107,0.25); }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); border-bottom-width: 1px; }
button.quiet:active { transform: translateY(1px); }
button:disabled { transform: none; box-shadow: none; cursor: default; }
button.danger { color: var(--warn); }
button[hidden] { display: none; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.modes { display: inline-flex; gap: 10px; }
.modes .pill { display: inline-flex; align-items: stretch; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 0; overflow: hidden; }
.modes button { border: 0; background: transparent; padding: 8px 16px; color: var(--muted); box-shadow: none; display: inline-flex; align-items: center; gap: 7px; }
.modes button svg { width: 20px; height: 20px; flex: none; }
.modes button:hover, .modes button:active { transform: none; }
.modes button.active { background: var(--ink); color: #fff; }
.right { display: flex; align-items: center; gap: 8px; }
.streak { font-size: 15px; color: var(--muted); white-space: nowrap; }
.streak b { color: var(--ink); font-size: 17px; }

.main { flex: 1; display: flex; gap: 16px; padding: 0 20px 16px; min-height: 0; }
.letters[hidden] { display: none; }
.letters { width: 150px; flex: none; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 4px; }
.group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 6px; }
.group-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.letter {
  aspect-ratio: 1; padding: 0; border-radius: 12px; font-size: 22px; font-weight: 600; background: #fff; position: relative; border-bottom-width: 3px;
}
.lbadge { position: absolute; right: 3px; top: 3px; width: 14px; height: 14px; }
.lbadge svg { width: 100%; height: 100%; display: block; }
.lbadge.star { width: 16px; height: 16px; right: 2px; top: 2px; filter: drop-shadow(0 1px 1px rgba(120,70,0,0.3)); }
.letter.active .lbadge.check svg circle { fill: #fff; }
.letter.active .lbadge.check svg path { stroke: var(--ink); }
.letter.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 10px; }
.stage-head { display: flex; align-items: center; gap: 18px; }
.glyph { font-size: 44px; font-weight: 700; width: 56px; text-align: center; line-height: 1; }
.hint { flex: 1; margin: 0; color: var(--muted); font-size: 16px; }
.controls { display: flex; gap: 8px; }

.board-wrap { position: relative; flex: 1; min-height: 0; background: var(--paper); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 0 rgba(0,0,0,0.04); }
canvas#board { display: block; width: 100%; height: 100%; touch-action: none; }

.message {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: #fff; font-weight: 600; font-size: 17px; white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis;
}
.message.warn { background: var(--warn); }

.feedback {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: min(380px, calc(100% - 32px)); background: #fff; border: 2px solid var(--line);
  border-radius: 22px; padding: 16px 18px; box-shadow: 0 14px 40px rgba(30,28,25,0.16);
  animation: cardInSide 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes cardInSide { 0% { transform: translateY(-50%) scale(0.8); opacity: 0; } 100% { transform: translateY(-50%) scale(1); opacity: 1; } }
.board-wrap.words .feedback { transform-origin: top right; }
@keyframes cardIn { 0% { transform: scale(0.7) translateY(16px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }
.feedback.good { border-color: #bfe0d8; }
.fb-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.fb-mark { width: 48px; height: 48px; flex: none; }
.fb-mark svg { width: 100%; height: 100%; display: block; }
.fb-score { margin-left: auto; font-size: 14px; font-weight: 700; color: var(--muted); }
.fb-score::after { content: ' points'; font-weight: 500; }
.fb-grade { font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 12px; border-radius: 999px; background: #fbe9df; color: var(--warn); }
.feedback.good .fb-grade { background: #dff0eb; color: var(--good); }
.fb-actions .primary { animation: nudge 1.8s ease-in-out 0.8s 3; }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 15% { transform: translateY(-4px) rotate(-1.5deg); } 30% { transform: translateY(0); } 45% { transform: translateY(-3px) rotate(1.5deg); } 60% { transform: translateY(0); } }
.fb-issues { margin: 0 0 12px; padding-left: 18px; font-size: 17px; line-height: 1.4; }
.fb-issues li:first-child { font-weight: 700; }
.fb-issues li + li { margin-top: 4px; }
.fb-issues li.nice { list-style: none; margin-left: -18px; color: var(--good); font-weight: 600; }
.fb-issues li.warn { list-style: none; margin-left: -18px; color: var(--warn); font-weight: 600; }
.fb-actions { display: flex; gap: 8px; flex-wrap: wrap; }

dialog { border: 2px solid var(--line); border-radius: 24px; padding: 22px 24px; width: min(640px, 92vw); font-family: var(--font); color: var(--ink); background: var(--bg); box-shadow: 0 24px 60px rgba(30,28,25,0.25); }
dialog[open] { animation: dlgIn 0.4s cubic-bezier(0.2, 1.3, 0.4, 1); }
@keyframes dlgIn { 0% { transform: scale(0.85) translateY(20px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }
dialog::backdrop { background: rgba(30,28,25,0.4); backdrop-filter: blur(3px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.p-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin: 12px 0 18px; }
.p-cell { border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 12px; padding: 8px 6px; text-align: center; background: #fff; }
.p-cell.started { background: var(--paper); }
.p-cell.mastered { border-color: var(--good); background: #e8f3f0; }
.p-ch { font-size: 22px; font-weight: 600; }
.p-best { font-size: 14px; color: var(--muted); }
.p-n { font-size: 11px; color: var(--muted); }
.dlg-foot { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }

@media (max-width: 1000px) and (orientation: portrait), (max-width: 820px) {
  .main { flex-direction: column; }
  .main > .letters, .main > .letters.words, .main > .letters.mystery-aside, .main > .bosses-aside { width: 100%; max-height: 40vh; flex-direction: row; flex-wrap: wrap; overflow: auto; gap: 6px; padding-bottom: 2px; }
  .group { display: contents; }
  .group-label { display: none; }
  .group-row { display: contents; }
  .letter { width: 46px; height: 46px; font-size: 20px; }
  .words .letter { width: auto; height: auto; padding: 8px 12px; font-size: 15px; }
  .mystery-aside .myst-grid { width: 100%; }
  .stage-head { flex-wrap: wrap; row-gap: 6px; }
  .hint { flex-basis: 100%; order: 5; font-size: 15px; }
  .top { padding: 10px 16px; }
  .main { padding: 0 16px 12px; }
  .board-wrap { display: flex; flex-direction: column; }
  canvas#board { flex: 1; min-height: 0; }
  .feedback, .board-wrap.words .feedback { position: static; transform: none; width: auto; margin: 10px; animation: cardIn 0.35s ease-out; }
  .stamp, .board-wrap.words .stamp { width: 96px; height: 96px; right: 12px; top: 12px; left: auto; bottom: auto; }
}

/* template review sheet (?sheet) */
.sheet-body { display: block; padding: 20px; overflow: auto; height: auto; }
.sheet { display: grid; grid-template-columns: repeat(auto-fill, 200px); gap: 14px; }
.sheet-cell canvas { width: 200px; height: 250px; border-radius: 10px; }
.sheet-cap { text-align: center; font-size: 20px; margin-top: 4px; }

.glyph.word { font-size: 28px; width: auto; min-width: 56px; padding: 0 4px; letter-spacing: 0.02em; }
.redo-badge { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--warn); background: #fbe9df; padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.words .group-row { grid-template-columns: 1fr; }
.letters.words { width: 150px; }
.words .letter { aspect-ratio: auto; font-size: 16px; padding: 9px 8px; text-align: left; }
.fb-letters { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; font-size: 15px; color: var(--muted); }
.fb-letters span { display: inline-block; min-width: 30px; text-align: center; padding: 4px 6px; border-radius: 8px; background: var(--paper); font-weight: 600; color: var(--ink); }
.fb-letters span.bad { background: #fbe9df; color: var(--warn); }
@media (max-width: 1000px) and (orientation: portrait), (max-width: 820px) {
  .words .group-row { display: contents; }
}

/* in Words mode the word is centered low on the board, so the card moves to the top right */
.board-wrap.words .feedback { top: 16px; right: 16px; left: auto; bottom: auto; transform: none; animation: cardIn 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); width: min(380px, calc(100% - 32px)); }

/* coins and combo */
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }
.coins { display: inline-flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 700; padding: 6px 12px 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: 999px; }
.coins.bump { animation: bump 0.25s ease-out; }
.coin-icon { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe680, #f2b81c 65%, #b8780a); box-shadow: inset 0 0 0 2px rgba(120,70,0,0.25); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
.combo[hidden] { display: none; }
.combo { position: absolute; right: 16px; bottom: 16px; display: flex; align-items: baseline; gap: 8px; padding: 10px 16px; background: var(--ink); color: #fff; border-radius: 999px; font-size: 15px; box-shadow: 0 6px 20px rgba(30,28,25,0.18); }
.combo b { font-size: 17px; color: #ffd75e; }
.combo.pop { animation: comboPop 0.35s ease-out; }
.combo.break { animation: comboBreak 0.6s ease-in forwards; background: var(--warn); }
@keyframes comboPop { 0% { transform: scale(0.8); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes comboBreak { 0% { transform: translateX(0); opacity: 1; } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 100% { transform: translateX(0) translateY(20px); opacity: 0; } }
.jar-row { display: flex; gap: 20px; align-items: center; margin: 4px 0 8px; }
#jar { width: 220px; height: 280px; flex: none; }
.jar-info { font-size: 16px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.jar-balance b { font-size: 30px; color: var(--ink); }
.jar-full { font-size: 14px; max-width: 260px; }
.dlg-settings { display: flex; gap: 18px; }
@media (max-width: 820px) { .jar-row { flex-direction: column; align-items: flex-start; } }

/* shop */
#shop { width: min(760px, 94vw); max-height: 90vh; overflow: auto; }
#shop h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 8px; }
.shop-coins { display: inline-flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 700; margin-left: auto; margin-right: 12px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shop-item { border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 16px; padding: 10px; background: #fff; display: flex; flex-direction: column; gap: 6px; }
.shop-item canvas { width: 100%; height: 54px; border-radius: 8px; background: var(--paper); }
.shop-item .name { font-weight: 600; font-size: 15px; }
.shop-item .blurb { font-size: 12px; color: var(--muted); min-height: 15px; }
.shop-item button { padding: 7px 12px; font-size: 14px; }
.shop-item.equipped { border-color: var(--accent); box-shadow: 0 0 0 2px #dbeeea inset; }
.shop-item button.owned { background: var(--paper); }
.shop-item button.poor { color: var(--muted); background: var(--paper); border-color: transparent; }
.shop-item .price { display: inline-flex; align-items: center; gap: 5px; }
.shop-item .price .coin-icon { width: 12px; height: 12px; }

/* levels */
.level-btn { padding: 6px 12px; font-size: 14px; background: #fff; }
.dlg-sub { color: var(--muted); margin: 6px 0 14px; }
.level-list { display: flex; flex-direction: column; gap: 8px; }
.level-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 16px; padding: 14px 16px; background: #fff; }
.level-item.current { border-color: var(--accent); box-shadow: 0 0 0 2px #dbeeea inset; }
.level-item.locked { opacity: 0.6; }
.level-item .lv-name { font-weight: 700; font-size: 17px; }
.level-item .lv-blurb { grid-column: 1; font-size: 14px; color: var(--muted); }
.level-item .lv-bonus { grid-column: 2; grid-row: 1 / span 2; text-align: right; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.level-item .lv-bonus b { color: var(--ink); font-size: 15px; }
.level-item button { padding: 7px 14px; font-size: 14px; }
.lv-preview { display: flex; gap: 6px; align-items: flex-end; height: 22px; }
.lv-preview i { display: block; width: 3px; background: var(--line); border-radius: 2px; }

/* boss fights */
.boss { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.boss[hidden] { display: none; }
.boss-monster { width: 56px; height: 56px; flex: none; }
.boss-monster svg { width: 56px; height: 56px; display: block; }
.boss-monster.hit svg { animation: flinch 0.5s ease-out; }
.boss-monster.hit .pupil { transform: translateY(2px); }
.boss-monster.dead svg { animation: die 0.9s ease-in-out forwards; }
.boss-monster.heal svg { animation: puff 0.5s ease-out; }
@keyframes flinch { 0% { transform: translateX(0) rotate(0); } 20% { transform: translateX(-6px) rotate(-8deg); } 40% { transform: translateX(6px) rotate(8deg); } 60% { transform: translateX(-4px) rotate(-4deg); } 100% { transform: translateX(0) rotate(0); } }
@keyframes die { 0% { transform: scale(1) rotate(0); } 35% { transform: scale(1.3) rotate(-20deg); } 70% { transform: scale(0.9) rotate(200deg); } 100% { transform: scale(1) rotate(180deg); } }
@keyframes puff { 0% { transform: scale(1); } 50% { transform: scale(1.18); } 100% { transform: scale(1); } }
.boss-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.boss-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.boss-name span { color: var(--muted); font-size: 13px; }
.hp { position: relative; height: 14px; background: #e7e1d6; border-radius: 999px; overflow: hidden; max-width: 380px; }
.hp-fill { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, #d9432b, #f0783a); border-radius: 999px; transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.hp-chunk { position: absolute; top: 0; bottom: 0; background: #ffd75e; opacity: 0; border-radius: 999px; }
.hp-chunk.show { animation: chunk 0.6s ease-out forwards; }
@keyframes chunk { 0% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
.words .letter.boss-btn { font-weight: 700; }
.words .letter.boss-btn.beaten { background: #fbe9df; border-color: #e6b8a2; color: var(--warn); }
.words .letter.boss-btn.beaten::after { display: none; }
.words .letter.boss-btn.beaten svg { transform: rotate(180deg); }
.words .letter.boss-btn.beaten span { text-decoration: line-through; text-decoration-thickness: 2px; }
.monster .xeyes { display: none; }
.beaten .monster .eyes, .dead .monster .eyes { display: none; }
.beaten .monster .xeyes, .dead .monster .xeyes { display: block; }
.beaten .monster .mouth, .dead .monster .mouth { transform: scaleY(-1); transform-origin: 32px 44px; }
.words .letter.boss-btn.locked { color: var(--muted); background: var(--paper); opacity: 0.55; border-style: dashed; border-bottom-width: 1px; }
.hint[hidden] { display: none; }
@media (max-width: 1000px) and (orientation: portrait), (max-width: 820px) { .boss-monster, .boss-monster svg { width: 40px; height: 40px; } .hp { max-width: none; } }

/* robot reader */
.fb-robot { display: flex; align-items: center; gap: 10px; margin: 2px 0 10px; }
.fb-robot[hidden] { display: none; }
.robot-wrap { width: 48px; height: 48px; flex: none; }
.robot-wrap svg { width: 48px; height: 48px; display: block; }
.robot-wrap.happy svg { animation: hop 0.6s ease-out; }
.robot-wrap.happy .eye { fill: #5ee6c8; }
.robot-wrap.happy .antenna { fill: #5ee6c8; }
.robot-wrap.confused svg { animation: tilt 0.8s ease-in-out; }
.robot-wrap.confused .eye.left { r: 2.2; }
.robot-wrap.confused .eye { fill: #ffd75e; }
.robot-wrap.talking .mouth { animation: talk 0.25s ease-in-out 4; }
.robot-wrap.reading { animation: readPulse 0.55s ease-in-out infinite; transform-origin: 50% 60%; }
@keyframes readPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.09); } }
@keyframes hop { 0% { transform: translateY(0); } 30% { transform: translateY(-10px) scale(1.05); } 55% { transform: translateY(0); } 75% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
@keyframes tilt { 0% { transform: rotate(0); } 30% { transform: rotate(-12deg); } 70% { transform: rotate(10deg); } 100% { transform: rotate(0); } }
@keyframes talk { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(2.4); } }
.robot-wrap .mouth { transform-origin: 32px 44px; }
.bubble { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 15px; line-height: 1.3; }
.bubble::before { content: ""; position: absolute; left: -7px; top: 16px; width: 12px; height: 12px; background: var(--paper); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); }
.bubble .read { font-family: var(--font); font-size: 19px; font-weight: 700; letter-spacing: 0.1em; }
.bubble .read .bad { color: var(--warn); text-decoration: underline wavy; text-underline-offset: 3px; }

/* boss buttons with their monster */
.words .letter.boss-btn { display: flex; align-items: center; gap: 8px; }
.words .letter.boss-btn svg { flex: none; }
.words .letter.boss-btn.locked svg { filter: grayscale(1); opacity: 0.5; }

/* welcome / onboarding */
.welcome { position: absolute; inset: 0; display: flex; align-items: flex-start; justify-content: center; padding: 18px; pointer-events: none; }
.welcome[hidden] { display: none; }
.welcome-card { pointer-events: auto; display: flex; gap: 16px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 22px; padding: 18px 22px; max-width: 560px; box-shadow: 0 14px 40px rgba(30,28,25,0.16); animation: cardIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
.welcome-robot { flex: none; width: 84px; height: 84px; }
.welcome-robot svg { width: 84px; height: 84px; display: block; animation: hop 1.2s ease-in-out infinite; }
.welcome-text h1 { margin: 0 0 4px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.welcome-text p { margin: 0; font-size: 17px; color: var(--muted); line-height: 1.35; }
.welcome-form { margin-top: 12px; }
.welcome-form[hidden] { display: none; }
.welcome-form label { display: block; font-weight: 700; margin-bottom: 8px; }
.welcome-row { display: flex; gap: 8px; }
.welcome-row input { flex: 1; min-width: 0; font: inherit; font-size: 18px; font-weight: 600; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); }
.welcome-row input:focus { outline: none; border-color: var(--accent); }
body.onboarding .letters, body.onboarding .controls, body.onboarding .modes, body.onboarding .right, body.onboarding .stage-head { visibility: hidden; }
.player-line { color: var(--muted); font-size: 15px; margin: -6px 0 10px; }
.player-line b { color: var(--ink); }
@media (max-width: 820px) { .welcome-card { flex-direction: column; text-align: center; } .welcome-row { flex-direction: column; } }

/* welcome / onboarding */

/* header fits iPad portrait: brand hides, clusters wrap */
@media (max-width: 960px) {
  .top { flex-wrap: wrap; justify-content: center; gap: 8px 12px; padding: 10px 12px; }
  .brand { display: none; }
  .modes button { padding: 8px 14px; }
  .right { gap: 6px; }
  .right .quiet { padding-left: 10px; padding-right: 10px; }
}

/* family code sync */
.sync[hidden] { display: none; }
.sync { border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 16px; padding: 14px 16px; margin: 4px 0 16px; background: #fff; }
.sync-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.sync-head b { font-size: 16px; }
.sync-status { font-size: 13px; color: var(--muted); }
.sync-status.ok { color: var(--good); }
.sync-status.warn { color: var(--warn); }
.sync p { margin: 6px 0 10px; font-size: 14px; color: var(--muted); }
.sync-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sync-join { display: flex; gap: 6px; }
.sync-join input { font: inherit; font-size: 15px; font-weight: 600; padding: 8px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); width: 190px; text-transform: uppercase; }
.sync-join input:focus { outline: none; border-color: var(--accent); }
.sync-code { font-family: var(--font); font-size: 26px; font-weight: 800; letter-spacing: 0.06em; color: var(--ink); padding: 8px 0 2px; user-select: text; -webkit-user-select: text; }
.sync-on[hidden], .sync-off[hidden] { display: none; }

/* good / excellent stamp on the word board */
.stamp { position: absolute; right: 22px; top: 22px; width: 150px; height: 150px; pointer-events: none; filter: drop-shadow(0 10px 22px rgba(30,28,25,0.22)); }
.stamp[hidden] { display: none; }
.stamp svg { width: 100%; height: 100%; display: block; }
.stamp.show { animation: stampIn 0.7s cubic-bezier(0.2, 1.7, 0.4, 1); }
.stamp.star.show { animation: stampIn 0.7s cubic-bezier(0.2, 1.7, 0.4, 1), starSpin 2.4s ease-in-out 0.7s infinite; }
@keyframes stampIn { 0% { transform: scale(0.2) rotate(-25deg); opacity: 0; } 60% { transform: scale(1.12) rotate(4deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes starSpin { 0%, 100% { transform: rotate(-6deg) scale(1); } 50% { transform: rotate(6deg) scale(1.06); } }
.stamp .glint { animation: glint 1.6s ease-in-out infinite; transform-origin: center; }
@keyframes glint { 0%, 100% { opacity: 0.2; transform: scale(0.7); } 50% { opacity: 1; transform: scale(1.1); } }
.board-wrap.words .stamp { right: auto; top: auto; left: 22px; bottom: 22px; }

/* check / star on word buttons */
.words .letter:not(.boss-btn) { padding-right: 34px; }
.words .letter:not(.boss-btn)::after { display: none; }
.wbadge { position: absolute; right: 9px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); }
.wbadge svg { width: 100%; height: 100%; display: block; }
.wbadge.star { width: 22px; height: 22px; filter: drop-shadow(0 1px 1px rgba(120,70,0,0.3)); }

/* combo info */
.combo { position: absolute; }
.combo-info { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,0.55); background: transparent; color: #fff; font: 700 13px/1 Georgia, serif; font-style: italic; margin-left: 6px; align-self: center; box-shadow: none; }
.combo-info:hover { transform: none; background: rgba(255,255,255,0.15); }
.combo-info:active { transform: none; border-bottom-width: 2px; }
.combo-tip { position: absolute; right: 0; bottom: calc(100% + 10px); width: 260px; background: #fff; color: var(--ink); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: 15px; line-height: 1.5; font-weight: 500; box-shadow: 0 10px 30px rgba(30,28,25,0.18); animation: cardIn 0.3s cubic-bezier(0.2, 1.4, 0.4, 1); transform-origin: bottom right; }
.combo-tip[hidden] { display: none; }
.combo-tip b { display: block; margin-bottom: 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.combo-tip strong { color: var(--accent); }
.combo-tip::after { content: ""; position: absolute; right: 18px; bottom: -8px; width: 14px; height: 14px; background: #fff; border-right: 2px solid var(--line); border-bottom: 2px solid var(--line); transform: rotate(45deg); }

/* mystery board */
#mystery { width: min(720px, 94vw); }
.myst-board { display: flex; flex-wrap: wrap; gap: 14px 22px; justify-content: center; margin: 10px 0 8px; padding: 18px 12px; background: var(--paper); border-radius: 16px; border: 2px solid var(--line); }
.myst-word { display: flex; gap: 6px; }
.myst-tile { width: 36px; height: 46px; border-radius: 8px; background: #fff; border: 2px solid var(--line); border-bottom-width: 4px; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; color: var(--ink); }
.myst-tile.blank { background: #efeae1; color: transparent; }
.myst-tile.new { animation: tileFlip 0.5s ease-out; background: #dff0eb; border-color: #9fd3c6; }
@keyframes tileFlip { 0% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
.myst-status { text-align: center; color: var(--muted); font-size: 15px; min-height: 20px; margin-bottom: 10px; }
.myst-status b { color: var(--ink); }
.myst-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.myst-grid button { padding: 8px 0; font-size: 20px; border-radius: 10px; }
.myst-grid button.hit { background: #dff0eb; border-color: #9fd3c6; color: var(--good); }
.myst-grid button.miss { background: var(--paper); color: var(--muted); text-decoration: line-through; border-color: transparent; }
.myst-grid button:disabled { transform: none; }
.myst-solved { text-align: center; margin: 12px 0 4px; }
.myst-solved[hidden] { display: none; }
.myst-solved-text { font-size: 20px; font-weight: 800; color: var(--good); margin-bottom: 10px; }
.myst-parent { margin-top: 16px; font-size: 14px; color: var(--muted); }
.myst-parent summary { cursor: pointer; }
.myst-parent form { margin-top: 8px; }
.myst-parent input { width: 260px; text-transform: none; }
.myst-queue { margin: 6px 0 0; font-size: 13px; }
@media (max-width: 820px) { .myst-grid { grid-template-columns: repeat(7, 1fr); } .myst-tile { width: 30px; height: 40px; font-size: 22px; } }

/* quests */
#quests-btn { white-space: nowrap; }
.qcount { display: inline-block; margin-left: 4px; padding: 2px 7px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: 12px; color: var(--ink); }
.qcount.all { background: #dff0eb; border-color: #9fd3c6; color: var(--good); }
.quest-list { display: flex; flex-direction: column; gap: 10px; }
.quest { display: grid; grid-template-columns: 44px 1fr auto; gap: 4px 14px; align-items: center; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 16px; padding: 12px 16px; background: #fff; }
.quest.done { background: #eef7f4; border-color: #9fd3c6; }
.quest .q-icon { grid-column: 1; width: 44px; height: 44px; border-radius: 12px; background: var(--paper); display: flex; align-items: center; justify-content: center; font-size: 22px; grid-row: 1 / span 2; }
.quest.done .q-icon { background: var(--good); color: #fff; }
.quest .q-text { grid-column: 2; grid-row: 1; font-weight: 700; font-size: 16px; }
.quest .q-reward { grid-column: 3; grid-row: 1 / span 2; display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: var(--muted); }
.quest .q-reward .coin-icon { width: 14px; height: 14px; }
.quest .q-bar { grid-column: 2; height: 8px; background: var(--paper); border-radius: 999px; overflow: hidden; }
.quest .q-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.5s ease; }
.quest-all { text-align: center; padding: 10px; color: var(--muted); font-size: 14px; }
.quest-all b { color: var(--good); }

/* letter cards */
.p-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
.p-cell { position: relative; overflow: hidden; padding: 10px 6px 8px; border-width: 2px; border-bottom-width: 4px; }
.p-cell .p-tier { display: block; font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; color: var(--muted); font-weight: 700; }
.p-cell.t0 { background: var(--paper); color: var(--muted); border-style: dashed; }
.p-cell.t1 { background: linear-gradient(160deg, #f3d9c2, #c8865a); border-color: #9c5a2f; }
.p-cell.t2 { background: linear-gradient(160deg, #f4f4f4, #b9bcc2); border-color: #7d838c; }
.p-cell.t3 { background: linear-gradient(160deg, #ffe9a3, #e0a91d); border-color: #a8720a; }
.p-cell.t4 { background: linear-gradient(120deg, #ffd1e8, #d1e8ff, #d1ffe0, #fff3c2, #ffd1e8); background-size: 300% 300%; animation: holo 4s ease infinite; border-color: #b78ad6; }
.p-cell.t1 .p-tier, .p-cell.t3 .p-tier { color: rgba(60,30,0,0.7); }
.p-cell.t2 .p-tier { color: #4a4f57; }
.p-cell.t4 .p-tier { color: #6a3fa0; }
@keyframes holo { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

/* mystery mode: board strip above the writing area, alphabet in the left column */
.myst-strip { display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 6px; padding: 12px 16px 10px; background: #fff; border: 2px solid var(--line); border-radius: 16px; }
.myst-strip[hidden] { display: none; }
.myst-strip .myst-board { flex: 1; margin: 0; padding: 0; background: transparent; border: 0; justify-content: center; gap: 10px 18px; }
.myst-side { text-align: center; }
.myst-strip .myst-status { text-align: center; font-size: 14px; font-weight: 700; letter-spacing: 0.02em; color: var(--muted); margin-top: 2px; }
.myst-strip .myst-solved { text-align: center; }
.myst-strip .myst-solved-text { font-size: 15px; }
.myst-strip .myst-tile { width: 32px; height: 42px; font-size: 24px; }
.myst-strip .myst-solved-text { font-size: 16px; margin-bottom: 6px; }
.mystery-aside { width: 150px; }
.mystery-aside .myst-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mystery-aside .myst-grid button { aspect-ratio: 1; padding: 0; font-size: 20px; border-radius: 12px; border-bottom-width: 3px; }
.mystery-aside .myst-grid button.picked { background: var(--ink); color: #fff; border-color: var(--ink); }
.mystery-aside #myst-parent-btn { margin-top: 6px; font-size: 13px; }
@media (max-width: 820px) {
  .mystery-aside { width: auto; }
  .mystery-aside .myst-grid { grid-template-columns: repeat(13, 1fr); }
}

/* practice and play clusters in the nav */
/* the group name sits in a greyed block at the head of each pill, clearly not a button */
.modes-label { display: flex; align-items: center; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); background: #ebe6dc; padding: 0 12px 0 16px; margin: -4px 6px -4px 0; }
.modes .pill.play .modes-label { background: #ece4f7; color: #8a4bd6; }
.modes button.play.active { background: #8a4bd6; }
.bosses-aside .group-row { grid-template-columns: 1fr; }
@media (max-width: 960px) { .modes-label { padding: 0 10px; } .modes button { padding: 8px 12px; } }
.quest .q-go { grid-column: 3; grid-row: 1 / span 2; padding: 8px 16px; }

/* defeated boss screen */
.boss-done { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--paper); text-align: center; }
.boss-done[hidden] { display: none; }
.boss-done-monster svg { width: 180px; height: 180px; transform: rotate(180deg); animation: doneWobble 3s ease-in-out infinite; }
@keyframes doneWobble { 0%, 100% { transform: rotate(176deg); } 50% { transform: rotate(184deg); } }
.boss-done-title { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.boss-done-sub { font-size: 16px; color: var(--muted); margin-bottom: 6px; }

/* respect reduced motion: keep state changes, drop the perpetual and springy animations */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* header icon buttons: labels drop below 1300px so Shop and Progress always fit */
.iconbtn { display: inline-flex; align-items: center; gap: 6px; }
.iconbtn svg { width: 22px; height: 22px; }
@media (max-width: 1300px) { .iconbtn .lbl { display: none; } .iconbtn { padding-left: 8px; padding-right: 8px; } .brand { display: none; } .modes button { padding: 8px 14px; } .top { gap: 10px; } }

/* touch targets: nothing interactive under 44px */
button { min-height: 44px; }
.modes button { min-height: 40px; }
.letter { min-height: 44px; }
.combo-info { width: 30px; height: 30px; min-height: 30px; }
.level-btn { min-height: 36px; }
.quiet { min-height: 40px; }

/* reset needs a hold */
#reset { position: relative; overflow: hidden; }
#reset.holding::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(201,83,28,0.18); animation: hold 2s linear forwards; }
@keyframes hold { to { width: 100%; } }
.combo.break { animation: comboFade 0.8s ease-out forwards; background: var(--ink); }
@keyframes comboFade { 0% { opacity: 1; } 100% { opacity: 0; transform: translateY(12px); } }

/* Dot carries the hint */
.dot-line { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot-face { width: 40px; height: 40px; flex: none; }
.dot-face svg { width: 40px; height: 40px; display: block; }
.dot-face.happy svg { animation: hop 0.6s ease-out; }
.dot-face.happy .eye { fill: #5ee6c8; }
.dot-face.confused svg { animation: tilt 0.8s ease-in-out; }
.dot-face.confused .eye { fill: #ffd75e; }
.dot-face.talking .mouth { animation: talk 0.25s ease-in-out 4; transform-origin: 32px 44px; }
.dot-line .hint { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; color: var(--ink); font-size: 15px; line-height: 1.3; }
.dot-line .hint::before { content: ""; position: absolute; left: -7px; top: 14px; width: 12px; height: 12px; background: #fff; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); }
.dot-line .hint:empty { display: none; }
.dot-line .hint[hidden] { display: none; }

/* Today (home) screen */
.modes .pill.home { padding: 4px; }
.modes .homebtn.active { background: var(--accent); color: #fff; }
.home { flex: 1; display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow: auto; }
.home[hidden] { display: none; }
.home-head { display: flex; align-items: center; gap: 14px; }
.home-dot { width: 64px; height: 64px; flex: none; }
.home-dot svg { width: 64px; height: 64px; display: block; animation: hop 1.4s ease-in-out infinite; }
.home-title { margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.home-sub { margin: 2px 0 0; color: var(--muted); font-size: 17px; }
.home-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.home-card { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; padding: 18px 14px 16px; background: #fff; border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 22px; text-align: center; cursor: pointer; min-height: 220px; transition: transform 0.08s ease; }
.home-card:active { transform: translateY(3px); border-bottom-width: 2px; }
.home-card .hc-kind { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.home-card .hc-art { height: 96px; display: flex; align-items: center; justify-content: center; }
.home-card .hc-art svg { width: 84px; height: 84px; }
.home-card .hc-big { font-size: 64px; font-weight: 700; line-height: 1; color: var(--ink); }
.home-card .hc-word { font-size: 34px; font-weight: 700; line-height: 1.1; color: var(--ink); }
.home-card .hc-tiles { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.home-card .hc-tiles i { display: block; width: 14px; height: 18px; border-radius: 3px; background: #efeae1; border: 1px solid var(--line); }
.home-card .hc-tiles i.on { background: #dff0eb; border-color: #9fd3c6; }
.home-card .hc-line { font-size: 15px; color: var(--muted); }
.home-card.play { border-color: #d9c8f0; }
.home-card.done { opacity: 0.7; }
.home-quests { align-self: flex-start; font-size: 15px; }
@media (max-width: 1000px) and (orientation: portrait), (max-width: 820px) { .home-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .home-cards { grid-template-columns: 1fr; } }

/* milestone moment */
.moment { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(248,245,239,0.94); text-align: center; animation: cardIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); cursor: pointer; }
.moment[hidden] { display: none; }
.moment-art { width: 160px; height: 160px; display: flex; align-items: center; justify-content: center; }
.moment-art svg { width: 100%; height: 100%; }
.moment-art .p-cell { width: 120px; height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 64px; font-weight: 700; animation: tileFlip 0.7s ease-out; }
.moment-title { font-size: 36px; font-weight: 800; letter-spacing: -0.02em; }
.moment-sub { font-size: 18px; color: var(--muted); }
.moment-tap { margin-top: 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.moment .lines { width: 160px; }
.moment .lines line { stroke: #b7ae9e; stroke-width: 2; }
.moment .lines .shrink { animation: shrinkLines 1.6s ease-in-out infinite alternate; transform-origin: 80px 80px; }
@keyframes shrinkLines { from { transform: scale(1); } to { transform: scale(0.6); } }

.stage-head[hidden], .board-wrap[hidden] { display: none; }

/* Today cards are the quests */
.homebtn .qcount { margin-left: 4px; }
.home-card { position: relative; }
.home-card .hc-task { font-size: 16px; font-weight: 700; color: var(--ink); line-height: 1.25; }
.home-card .hc-bar { width: 100%; height: 8px; background: var(--paper); border-radius: 999px; overflow: hidden; margin-top: auto; }
.home-card .hc-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.5s ease; }
.home-card.play .hc-fill { background: #8a4bd6; }
.home-card .hc-reward { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; color: var(--muted); }
.home-card .hc-reward .coin-icon { width: 12px; height: 12px; }
.home-card.done { opacity: 1; background: #eef7f4; border-color: #9fd3c6; }
.home-card.done .hc-fill { background: var(--good); }
.home-card .hc-check { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; }
.home-card .hc-check svg { width: 100%; height: 100%; }
.home-foot { margin: 0; color: var(--muted); font-size: 15px; }
.home-foot b { color: var(--good); }

/* boss landing */
.boss-landing { position: absolute; inset: 0; overflow: auto; padding: 18px 20px; background: var(--paper); }
.boss-landing[hidden] { display: none; }
.bl-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.bl-dot { width: 56px; height: 56px; flex: none; }
.bl-dot svg { width: 56px; height: 56px; display: block; }
.bl-title { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.bl-rules { margin: 4px 0 0; font-size: 15px; color: var(--muted); line-height: 1.4; max-width: 640px; }
.bl-rules b { color: var(--ink); }
.bl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.bl-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 12px 12px; background: #fff; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 18px; text-align: center; }
.bl-card .monster { width: 72px; height: 72px; }
.bl-card.beaten { background: #fbe9df; border-color: #e6b8a2; }
.bl-card.beaten .monster { transform: rotate(180deg); }
.bl-card.beaten .monster .eyes { display: none; } .bl-card.beaten .monster .xeyes { display: block; }
.bl-card.locked { background: var(--paper); }
.bl-card.locked .monster { filter: grayscale(1); opacity: 0.55; }
.bl-card.ready { border-color: #b8a5e0; }
.bl-name { font-size: 17px; font-weight: 800; }
.bl-sub { font-size: 13px; color: var(--muted); }
.bl-letters { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.bl-letters button { width: 30px; height: 30px; min-height: 30px; padding: 0; font-size: 15px; border-radius: 8px; border-bottom-width: 3px; }
.bl-letters button.ok { background: #dff0eb; border-color: #9fd3c6; color: var(--good); }
.bl-card .primary { padding: 8px 18px; font-size: 15px; margin-top: 2px; }
.bl-card .bl-final { font-size: 12px; color: var(--muted); }

/* the boss that just went down flips over on the landing page */
.bl-card.just .monster { animation: die 0.9s ease-in-out forwards; }
.bl-card.just { animation: cardIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
