/* Number Wilds — chunky outlined "sticker" UI to match the thick-outlined creature art. */
:root {
  --ink: #2b2140;
  --ink-soft: #5b5270;
  --paper: #fffaf0;
  --card: #ffffff;
  --sky: #bfe9ff;
  --sun: #ffd23f;
  --go: #4ade80;
  --go-dark: #15803d;
  --hint: #fbbf24;
  --hint-bg: #fff8e1;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --oops: #7c3aed;
  --oops-bg: #f3e8ff;
  --soft: #e0e7ff;
  --radius: 18px;
  --shadow: 0 5px 0 var(--ink);
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Nunito', system-ui, sans-serif;
  --icol: 380px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }   /* no rubber-banding the whole game */
body {
  font-family: var(--font); color: var(--ink); background: var(--sky);
  font-size: 18px; -webkit-font-smoothing: antialiased; overflow: hidden;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;                 /* a long press mid-drag must not pop iOS's menu */
}
#app { height: 100vh; height: 100dvh; overflow: auto; }
button { font-family: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; }
p { margin: 6px 0; line-height: 1.4; }
.muted { color: var(--ink-soft); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: center; }
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 1000; }
:focus-visible { outline: 4px solid #60a5fa; outline-offset: 3px; }

/* ---------- buttons ---------- */
.btn {
  font-size: 20px; font-weight: 600; padding: 12px 22px; min-height: 52px;
  background: var(--card); border: 3px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow);
  transition: transform .06s, box-shadow .06s, background .15s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; }
.btn-big { font-size: 24px; padding: 14px 30px; min-height: 64px; }
.btn-go { background: var(--go); }
.btn-soft { background: var(--soft); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; font-size: 17px; padding: 8px 10px; min-height: 44px; }
.btn-hint { background: var(--sun); display: inline-flex; gap: 10px; align-items: center; }
.btn.on { background: var(--sun); }
.hint-dots { display: inline-flex; gap: 4px; }
.hint-dots .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.hint-dots .dot.used { background: var(--ink); }
.icon-btn { width: 48px; height: 48px; font-size: 24px; border-radius: 14px; border: 3px solid var(--ink); background: var(--card); box-shadow: 0 3px 0 var(--ink); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.link-btn { display: block; margin: 14px auto 0; background: none; border: none; text-decoration: underline; font-size: 16px; color: var(--ink-soft); padding: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border: 3px solid var(--ink); border-radius: 999px; background: var(--card); font-weight: 600; font-size: 17px; }
.chip.coins { background: #fff3b0; }
.chip.streak { background: #ffe1cc; }
.badge { display: inline-block; font-size: 15px; font-weight: 600; padding: 4px 10px; border-radius: 999px; border: 2px solid var(--ink); margin-bottom: 6px; }
.badge.review { background: #e0f2fe; }
.badge.strike-flavor { background: #fef3c7; }
.hp-num { font-size: 14px; font-weight: 600; color: var(--ink-soft); text-align: right; font-variant-numeric: tabular-nums; }
.strike-note { font-size: 22px; font-weight: 700; color: var(--oops); margin-top: 6px; }
.why { max-width: 760px; margin: 0 auto; }
.why-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.why-q { font-size: 24px; font-weight: 600; }
.why .choices { grid-template-columns: 1fr; }
.why .choice { font-size: 20px; min-height: 56px; text-align: left; justify-content: flex-start; }
.why .btn-big { display: block; margin: 12px auto 0; }
/* Seductive-details effect: keep the screen calm while she is actually thinking.
   Idle bobbing, sparkles and scenery motion pause during a problem; celebration comes after. */
.battle.solving .creature { animation: none !important; }
.battle.solving .arena::after { content: ''; position: absolute; inset: 0; background: rgba(255,250,240,.35); pointer-events: none; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--paper); border-bottom: 3px solid var(--ink); position: relative; z-index: 5; }
.topbar-title { flex: 1; font-size: 22px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.spacer { width: 48px; }

/* ---------- creatures ---------- */
.creature { position: relative; display: inline-block; aspect-ratio: 1; }
.creature img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.creature .hat { position: absolute; height: auto; filter: drop-shadow(0 2px 0 rgba(0,0,0,.15)); }
.creature.silhouette img:not(.hat) { filter: brightness(0) opacity(.35); }
.creature.silhouette .hat { display: none; }

/* ---------- title ---------- */
.title-screen, .starter-screen, .area-screen, .tired-screen { min-height: 100%; background-size: cover; background-position: center; display: flex; flex-direction: column; }
.title-screen { align-items: center; justify-content: center; padding: 20px; }
.title-card { background: rgba(255,250,240,.93); border: 4px solid var(--ink); border-radius: 32px; box-shadow: 0 8px 0 var(--ink); padding: 30px 40px; text-align: center; max-width: 720px; width: 100%; }
.logo { font-size: clamp(56px, 9vw, 96px); font-weight: 700; letter-spacing: 1px; line-height: .95; margin-bottom: 8px; }
.logo span { display: block; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.logo span:first-child { color: var(--sun); }
.logo span:last-child { color: var(--go); }
.tagline { font-size: 22px; }
.title-mons { display: flex; justify-content: center; gap: 4px; margin: 16px 0 22px; }
.title-mon { width: clamp(80px, 12vw, 120px); animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

/* ---------- starter ---------- */
.starter-screen { align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.starter-wrap { max-width: 1020px; width: 100%; }
.mentor-talk { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.mentor-img { width: 120px; height: 120px; object-fit: contain; flex: none; animation: bob 2.6s ease-in-out infinite; }
.bubble { background: var(--card); border: 3px solid var(--ink); border-radius: 22px; padding: 14px 20px; font-size: 21px; box-shadow: var(--shadow); position: relative; }
.bubble::before { content: ''; position: absolute; left: -14px; top: 40%; border: 12px solid transparent; border-right-color: var(--ink); border-left: 0; }
.starter-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.starter-card { background: var(--card); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 6px 0 var(--ink); padding: 14px; text-align: center; transition: transform .15s; }
.starter-card .creature { width: 70%; }
.starter-card:hover { transform: translateY(-4px); }
.starter-card.picked { background: var(--glow); transform: translateY(-6px) scale(1.03); box-shadow: 0 10px 0 var(--ink), 0 0 0 6px var(--el); }
.starter-name { font-size: 28px; font-weight: 700; }
.el-tag { display: inline-block; background: var(--el); color: #fff; font-weight: 600; font-size: 15px; padding: 2px 12px; border-radius: 999px; border: 2px solid var(--ink); -webkit-text-stroke: .5px var(--ink); }
.starter-blurb { font-size: 17px; min-height: 48px; }
.starter-bottom { display: flex; gap: 14px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
/* ---------- players ---------- */
.players-screen { min-height: 100%; background-size: cover; background-position: center; display: flex; align-items: center; justify-content: center; padding: 20px; }
.players-card { background: rgba(255,250,240,.95); border: 4px solid var(--ink); border-radius: 30px; box-shadow: 0 8px 0 var(--ink); padding: 26px 30px; max-width: 900px; width: 100%; text-align: center; }
.players-title { font-size: clamp(34px, 5vw, 48px); }
.players-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin: 18px 0 10px; }
.player-card { background: #fff; border: 4px solid var(--ink); border-radius: 24px; box-shadow: 0 6px 0 var(--ink); padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.player-card:hover { transform: translateY(-3px); }
.player-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.player-card.on { background: #fef3c7; }
.player-face { width: 110px; height: 110px; display: grid; place-items: center; }
.player-face .creature { width: 100%; }
.player-q, .player-plus { font-size: 60px; font-weight: 700; color: var(--ink-soft); }
.player-name { font-size: 24px; font-weight: 700; }
.player-meta { font-size: 15px; color: var(--ink-soft); }
.player-meta.small { font-size: 13px; }
.player-add { border-style: dashed; background: #f8fafc; }
.player-rows { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.player-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.player-row .creature { width: 48px; }

/* ---------- grade picker ---------- */
.grade-pick { margin-bottom: 14px; }
.grade-label { font-size: 20px; font-weight: 600; margin-bottom: 6px; text-align: center; }
.grade-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.grade-card { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; text-align: left; padding: 12px 16px; background: var(--card);
  border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); }
.grade-card.on { background: var(--sun); }
.grade-card:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.grade-name { font-size: 24px; font-weight: 700; }
.grade-blurb { font-size: 15px; color: var(--ink-soft); }
.grade-progress { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.grade-chip { font-size: 17px; font-weight: 600; padding: 8px 12px; border: 3px solid var(--ink); border-radius: 14px; background: #ede9fe; box-shadow: 0 3px 0 var(--ink); }
.grade-switch { text-align: center; }
.grade-switch .grade-row { margin: 14px 0; }
.name-input { font-family: inherit; font-size: 22px; padding: 12px 18px; border: 3px solid var(--ink); border-radius: 16px; width: 240px; user-select: text; -webkit-user-select: text; }

/* ---------- map ---------- */
.map-screen { height: 100%; display: flex; flex-direction: column; }
.map-body { flex: 1; display: flex; min-height: 0; }
.map-scroll { flex: 1; display: flex; min-height: 0; min-width: 0; }
.map-side { width: 250px; flex: none; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--paper); border-right: 3px solid var(--ink); overflow-y: auto; }
.partner-card { display: flex; gap: 10px; align-items: center; background: var(--card); border: 3px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; text-align: left; }
.partner-card .creature { width: 84px; flex: none; }
.pc-name { font-size: 20px; font-weight: 700; }
.pc-lv { font-size: 16px; color: var(--ink-soft); }
.xpbar { height: 12px; width: 110px; background: #eee; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.xpbar.big { width: 100%; height: 18px; margin-top: 6px; }
.xpfill { height: 100%; background: linear-gradient(90deg, #60a5fa, #a78bfa); transition: width 1.1s ease-out; }
.energy { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; font-size: 26px; }
.energy .bolt.used { filter: grayscale(1); opacity: .3; }
.tired-note { background: var(--oops-bg); border: 3px solid var(--ink); border-radius: 14px; padding: 10px; font-size: 16px; }
.bonus-note { background: #fff3b0; border: 3px solid var(--ink); border-radius: 14px; padding: 10px; font-size: 16px; font-weight: 600; animation: pop .4s; }
.map-trail { position: absolute; inset: 0; pointer-events: none; }
.map-trail svg { width: 100%; height: 100%; display: block; }
.side-btn { font-size: 20px; font-weight: 600; padding: 12px; border: 3px solid var(--ink); border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--ink); text-align: left; }
.side-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.side-btn.small { font-size: 16px; margin-top: auto; background: var(--soft); }
.map {
  flex: 1; position: relative; overflow: hidden; min-height: 520px;
  background:
    radial-gradient(ellipse 30% 22% at 22% 30%, #9fdc8a 0 60%, transparent 62%),
    radial-gradient(ellipse 34% 26% at 64% 22%, #b6e39a 0 60%, transparent 62%),
    radial-gradient(ellipse 26% 30% at 84% 52%, #d9f0ff 0 58%, transparent 60%),
    radial-gradient(ellipse 36% 26% at 44% 58%, #c7e89f 0 60%, transparent 62%),
    radial-gradient(ellipse 30% 22% at 20% 70%, #f5dea0 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 20% at 70% 84%, #d6c8f5 0 60%, transparent 62%),
    linear-gradient(#7cc8f0, #9ad8f7);
}
.map-node { position: absolute; transform: translate(-50%, -50%); background: none; border: none; padding: 0; display: flex; flex-direction: column; align-items: center; width: 130px; }
.node-img { width: 96px; height: 96px; border-radius: 50%; border: 4px solid var(--ink); background-size: cover; background-position: center; box-shadow: 0 5px 0 var(--ink); display: grid; place-items: center; transition: transform .15s; }
.map-node:hover .node-img { transform: scale(1.08); }
.map-node.priority .node-img { box-shadow: 0 5px 0 var(--ink), 0 0 0 6px var(--c), 0 0 26px 8px var(--c); animation: glow 2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 5px 0 var(--ink), 0 0 0 6px var(--c), 0 0 10px 2px var(--c); } }
.map-node.locked .node-img { filter: grayscale(.9) brightness(.8); }
.lock { font-size: 34px; }
.node-label { margin-top: 6px; background: var(--card); border: 3px solid var(--ink); border-radius: 999px; padding: 2px 10px; font-weight: 600; font-size: 15px; white-space: nowrap; max-width: 128px; overflow: hidden; text-overflow: ellipsis; }
.node-icon { margin-right: 4px; }
.node-stars { font-size: 15px; color: #d97706; -webkit-text-stroke: .4px var(--ink); background: rgba(255,255,255,.8); border-radius: 999px; padding: 0 6px; margin-top: 2px; }

/* ---------- area menu ---------- */
.area-screen { overflow: auto; }
.area-card { margin: 24px auto; width: min(760px, calc(100% - 32px)); background: rgba(255,250,240,.95); border: 4px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--ink); padding: 22px; }
.area-head { display: flex; gap: 14px; align-items: center; }
.area-icon { font-size: 54px; }
.area-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.area-team { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.team-pick { position: relative; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 2px; box-shadow: 0 3px 0 var(--ink); }
.team-pick .creature { width: 56px; }
.team-el { position: absolute; right: -6px; bottom: -6px; font-size: 15px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 0 4px; }
.team-el.good { background: #bbf7d0; }
.team-el.bad { background: #fee2e2; }
.area-mons { display: flex; gap: 12px; margin: 10px 0 16px; flex-wrap: wrap; }
.mini-mon { display: flex; flex-direction: column; align-items: center; font-size: 15px; font-weight: 600; }
.mini-mon .creature { width: 76px; }
.area-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.area-btn { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; text-align: left; align-items: center; padding: 16px; border: 3px solid var(--ink); border-radius: 20px; box-shadow: var(--shadow); background: var(--card); min-height: 96px; }
.area-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.area-btn:disabled { opacity: .5; }
.ab-icon { grid-row: span 2; font-size: 42px; }
.ab-title { font-size: 24px; font-weight: 700; }
.ab-sub { font-size: 16px; color: var(--ink-soft); }
.battle-btn { background: #ffe4b5; }
.single-btn { background: #fff0f5; }
.dojo-btn { background: #e0f2fe; }
.guardian-btn { background: #fde68a; }
.speed-btn { background: #fbcfe8; }

/* ---------- battle ---------- */
.battle { height: 100%; display: grid; grid-template-rows: auto minmax(200px, 38vh) 1fr; transition: grid-template-rows .35s; }
.battle.solving { grid-template-rows: auto minmax(150px, 25vh) 1fr; }
.battle.solving.has-visual { grid-template-rows: auto minmax(104px, 16vh) 1fr; }
.battle.solving .hud { transform: scale(.85); }
.battle.solving .hud-me { transform-origin: top left; }
.battle.solving .hud-wild { transform-origin: top right; }
.battle.solving .spot-me { left: 26%; }
.battle.solving .spot-wild { right: 26%; }
.spot { transition: left .35s, right .35s; }
@media (max-width: 1100px) {
  .node-img { width: 76px; height: 76px; }
  .node-label { font-size: 13px; padding: 1px 8px; }
  .map-node { width: 110px; }
}
.arena { position: relative; background-size: cover; background-position: center 70%; overflow: hidden; border-bottom: 3px solid var(--ink); }
.arena.shake { animation: shake .35s; }
@keyframes shake { 20% { transform: translate(-6px, 2px); } 40% { transform: translate(6px, -2px); } 60% { transform: translate(-4px, 1px); } 80% { transform: translate(3px, 0); } }
.spot { position: absolute; display: flex; justify-content: center; }
.spot .shadow { position: absolute; bottom: 2%; left: 15%; right: 15%; height: 14%; background: rgba(0,0,0,.18); border-radius: 50%; }
.spot-wild { right: 14%; bottom: 6%; height: 64%; aspect-ratio: 1; }
.spot-me { left: 14%; bottom: 3%; height: 68%; aspect-ratio: 1; }
.spot .creature { height: 100%; }
.creature.me { transform: scaleX(-1); }
.creature.enter-right { animation: enterRight .6s ease-out; }
.creature.enter-left { animation: enterLeft .6s ease-out; }
@keyframes enterRight { from { transform: translateX(120%); opacity: 0; } }
@keyframes enterLeft { from { transform: scaleX(-1) translateX(120%); opacity: 0; } }
.creature.wild:not(.faint) { animation: idle 2.4s ease-in-out infinite; }
.creature.wild.enter-right { animation: enterRight .6s ease-out, idle 2.4s 0.6s ease-in-out infinite; }
@keyframes idle { 50% { transform: translateY(-5px) scale(1.01); } }
.creature.hit { animation: hit .45s !important; }
@keyframes hit { 0% { filter: brightness(3); transform: translateX(0); } 25% { transform: translateX(16px) rotate(4deg); } 50% { filter: brightness(1.6); transform: translateX(-10px) rotate(-3deg); } 100% { filter: none; transform: none; } }
.creature.me.fizzle { animation: fizzle .7s; }
@keyframes fizzle { 0% { transform: scaleX(-1); } 20% { transform: scaleX(-1) scale(1.1, .88); } 40% { transform: scaleX(-1) rotate(-8deg) translateY(-8px); } 60% { transform: scaleX(-1) rotate(6deg); } 80% { transform: scaleX(-1) rotate(-3deg); } 100% { transform: scaleX(-1); } }
.creature.me.bump { animation: bump .4s; }
@keyframes bump { 30% { transform: scaleX(-1) translateX(14px); filter: brightness(1.5); } 100% { transform: scaleX(-1); } }
.creature.wild.faint { animation: faint 1s forwards !important; }
@keyframes faint { to { transform: translateY(40%) scale(.8); opacity: 0; filter: grayscale(1); } }
.hud { position: absolute; background: rgba(255,255,255,.95); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); padding: 6px 12px; min-width: 220px; }
.hud-wild { right: 14px; top: 12px; }
.hud-me { left: 14px; top: 12px; }
.hud-tag { font-size: 13px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .5px; }
.hud-name { font-size: 20px; font-weight: 700; display: flex; justify-content: space-between; gap: 10px; }
.hud-name .lv { font-size: 16px; color: var(--ink-soft); }
.hpbar { height: 16px; background: #e5e7eb; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.hpfill { height: 100%; width: 100%; background: linear-gradient(#6ee7a0, #22c55e); transition: width .6s ease-out; }
.hpfill.low { background: linear-gradient(#fcd34d, #f59e0b); }
.super-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 14px; font-weight: 600; }
.super-pips { display: flex; gap: 4px; }
.pip { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.pip.on { background: radial-gradient(circle at 35% 35%, #fff9c4, #fbbf24); box-shadow: 0 0 8px #fbbf24; }

/* ---------- enemy intent + tactics ---------- */
.intent { margin-top: 6px; font-size: 15px; font-weight: 600; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px; background: #f3f4f6; }
.intent-windup { background: #ffe0e0; animation: pulse 1.1s ease-in-out infinite; }
.intent-harden { background: #e0e7ff; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.team-row { display: flex; gap: 6px; margin-top: 6px; }
.team-dot { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; display: grid; place-items: center; font-size: 13px; opacity: .45; }
.team-dot.on { opacity: 1; background: var(--el); box-shadow: 0 0 0 3px #fff inset; }
.matchup { display: inline-block; font-size: 17px; font-weight: 600; margin-left: 10px; padding: 2px 12px; border-radius: 999px; border: 2px solid var(--ink); }
.matchup.super { background: #fde68a; }
.matchup.weak { background: #e5e7eb; }
.tactics { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 12px; }
.tactic { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; text-align: left; align-items: center;
  padding: 10px 14px; min-height: 68px; border: 3px dashed var(--ink); border-radius: 18px; background: #fff; }
.tactic:hover { background: #f8fafc; }
.tactic:active { transform: translateY(3px); }
.t-icon { grid-row: span 2; font-size: 30px; }
.t-name { font-size: 20px; font-weight: 700; }
.t-sub { font-size: 14px; color: var(--ink-soft); }
.creature.charged { filter: drop-shadow(0 0 14px #fde047); }
.swap { text-align: center; }
.swap-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 14px 0; }
.swap-card { background: #fff; border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); padding: 10px; }
.swap-card .creature { width: 92px; }
.swap-card.current { opacity: .55; }
.swap-name { font-size: 19px; font-weight: 700; }
.swap-el { font-size: 14px; color: var(--ink-soft); }
.swap-tag { font-size: 14px; font-weight: 600; border-radius: 999px; padding: 1px 8px; display: inline-block; margin-top: 4px; background: #eef2ff; }
.swap-tag.good { background: #bbf7d0; }
.swap-tag.bad { background: #fee2e2; }

.panel { background: var(--paper); overflow: hidden; padding: 14px 18px; position: relative; }
.panel.slide-in { animation: slideIn .3s ease-out; }
@keyframes slideIn { from { transform: translateY(20px); opacity: .3; } }
.panel-msg { font-size: 24px; font-weight: 600; margin-bottom: 12px; }
.panel-msg.big { font-size: 30px; text-align: center; margin-top: 30px; animation: slideIn .3s ease-out; }
.choose { max-width: 900px; margin: 0 auto; }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.move {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left;
  padding: 14px 18px; min-height: 90px; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink);
  background: linear-gradient(135deg, var(--glow), #fff 70%); position: relative; overflow: hidden;
}
.move::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: var(--el); border-right: 3px solid var(--ink); }
.move:hover { transform: translateY(-2px); }
.move:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.move-key { grid-row: span 2; margin-left: 8px; width: 32px; height: 32px; border-radius: 10px; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 700; background: #fff; }
.move-name { font-size: 26px; font-weight: 700; }
.move-kind { font-size: 17px; font-weight: 500; }
.move-power { grid-row: 1 / span 2; grid-column: 3; font-size: 22px; color: #f59e0b; -webkit-text-stroke: .6px var(--ink); }
.move.super { grid-column: span 2; background: linear-gradient(90deg, #fde68a, #fbcfe8, #bfdbfe, #fde68a); background-size: 300% 100%; animation: rainbow 2s linear infinite; }
@keyframes rainbow { to { background-position: 300% 0; } }
.move-legend { display: flex; gap: 24px; justify-content: center; margin-top: 14px; font-size: 16px; color: var(--ink-soft); }

.problem { display: grid; grid-template-columns: 1fr var(--icol); gap: 18px; height: 100%; }
.round-wrap { height: 100%; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.round-host { flex: 1; min-height: 0; overflow-y: auto; }
.round-badge { background: #ede9fe; align-self: flex-start; }
.problem.wide { grid-template-columns: 1fr; grid-template-rows: 1fr auto; gap: 10px; }
.problem.wide .icol { order: 2; }
.problem.wide .qcard { position: static; }
.linepad svg { width: 100%; max-height: 150px; touch-action: none; cursor: pointer; }
.gridpad svg { width: 100%; max-width: 360px; align-self: center; touch-action: none; cursor: crosshair; border-radius: 10px; }
.grid-bottom { grid-template-columns: 1fr auto; }
.grid-bottom .pad-display { font-size: 26px; text-align: center; }
.grid-bottom .pad-display.empty { font-size: 18px; }
.nl-svg { width: 100%; max-width: 640px; }
.visual svg { display: block; margin: 0 auto; }
.qcol { overflow-y: auto; padding: 4px 8px 20px 2px; min-height: 0; }
.icol { display: flex; flex-direction: column; justify-content: flex-start; min-height: 0; }
.move-banner { display: inline-block; font-size: 15px; font-weight: 600; padding: 3px 12px; border-radius: 999px; background: var(--el); color: #fff; border: 2px solid var(--ink); margin-bottom: 8px; -webkit-text-stroke: .4px var(--ink); }
.qcard { position: sticky; top: 0; z-index: 2; background: var(--card); border: 3px solid var(--ink); border-radius: 20px; padding: 16px 20px; box-shadow: 0 4px 0 var(--ink); }
.question { font-size: clamp(24px, 2.6vw, 34px); font-weight: 500; line-height: 1.35; }
.qprompt { font-size: 20px; margin-top: 6px; color: var(--ink-soft); }
.feedback { min-height: 12px; margin: 10px 0 6px; font-size: 20px; border-radius: 14px; }
.feedback.good { background: var(--good-bg); border: 3px solid var(--good); padding: 10px 14px; animation: pop .3s; }
.feedback.oops { background: var(--oops-bg); border: 3px solid #a78bfa; padding: 10px 14px; animation: pop .3s; }
.fizzle-line { font-weight: 700; color: var(--oops); }
@keyframes pop { from { transform: scale(.94); opacity: .4; } }
.tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.hints { display: flex; flex-direction: column; gap: 10px; }
.hint-card { display: flex; gap: 12px; background: var(--hint-bg); border: 3px solid var(--hint); border-radius: 18px; padding: 10px 14px; animation: pop .35s; }
.hint-owl { width: 64px; height: 64px; object-fit: contain; flex: none; }
.hint-body { flex: 1; min-width: 0; }
.hint-title { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: #b45309; }
.hint-text { font-size: 21px; line-height: 1.4; }

/* fractions in text */
.mixed { display: inline-flex; align-items: center; gap: 2px; vertical-align: middle; }
.whole { margin-right: 2px; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: .82em; line-height: 1.05; margin: 0 2px; }
.frac .num { border-bottom: 3px solid currentColor; padding: 0 4px; }
.frac .den { padding: 0 4px; }
sup { font-size: .6em; }
.op { font-size: .82em; color: #6d3fd4; padding: 0 .12em; vertical-align: .04em; }

/* ---------- answer inputs ---------- */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choices.long { grid-template-columns: 1fr; }
.choice { position: relative; min-height: 84px; font-size: 30px; font-weight: 600; background: var(--card); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); padding: 10px 14px 10px 40px; display: flex; align-items: center; justify-content: center; }
.choices.long .choice { font-size: 22px; min-height: 64px; }
.choice:hover:not(:disabled) { background: #f0f9ff; }
.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.choice-key { position: absolute; left: 8px; top: 8px; font-size: 13px; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--ink-soft); display: grid; place-items: center; color: var(--ink-soft); }
.choice.ruled-out { opacity: .35; text-decoration: line-through; text-decoration-thickness: 3px; box-shadow: 0 2px 0 var(--ink); transform: translateY(3px); }
.choice.right { background: var(--good-bg); border-color: var(--good); animation: pop .3s; }

.numpad { background: #f1ecff; border: 3px solid var(--ink); border-radius: 20px; padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 4px 0 var(--ink); }
.pad-top { display: flex; gap: 8px; align-items: center; }
.pad-display { flex: 1; font-size: 38px; font-weight: 600; text-align: right; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 4px 14px; min-height: 60px; line-height: 48px; overflow: hidden; }
.pad-display.empty { color: #c4b5fd; }
.pad-unit { font-size: 18px; font-weight: 600; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { font-size: 28px; font-weight: 600; min-height: 56px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink); }
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: #fef3c7; }
.key-gap { display: block; }
.pad-bottom { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.key-back { background: #fde2e4; }
.key-go { background: var(--go); font-size: 30px; }
.key-small { font-size: 16px; min-height: 44px; padding: 0 10px; white-space: nowrap; }
.key-small.on { background: var(--sun); }
.nudge { animation: nudge .35s; }
@keyframes nudge { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.frac-editor { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px; min-height: 116px; }
.frac-sign { font-size: 36px; font-weight: 700; }
.frac-stack { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.frac-bar { width: 100%; height: 4px; background: var(--ink); border-radius: 2px; }
.frac-box { min-width: 76px; height: 46px; font-size: 30px; font-weight: 600; border: 3px dashed #a78bfa; border-radius: 10px; background: #faf5ff; padding: 0 8px; }
.frac-box.empty { color: #c4b5fd; font-size: 22px; }
.frac-box.focus { border-style: solid; border-color: var(--ink); background: #fef9c3; box-shadow: 0 0 0 3px #fde047; }
.frac-whole .frac-box { height: 62px; font-size: 34px; }

/* ---------- visual models ---------- */
.visual { margin-top: 10px; }
.visual-caption { font-size: 20px; margin-top: 8px; text-align: center; }
.area-grid { display: grid; gap: 0; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; background: var(--ink); max-width: 640px; min-height: 150px; }
.area-grid > div { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 6px; }
.area-corner, .area-head, .area-side { background: #f5f3ff; font-weight: 700; font-size: 20px; }
.area-head { border-left: 2px solid var(--ink); }
.area-side { border-top: 2px solid var(--ink); }
.area-cell { border-left: 2px solid var(--ink); border-top: 2px solid var(--ink); animation: cellIn .4s backwards; }
@keyframes cellIn { from { opacity: 0; transform: scale(.7); } }
.area-eq { font-size: 14px; color: var(--ink-soft); }
.area-val { font-size: 22px; font-weight: 700; }

/* ---------- modal / dialog ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(43,33,64,.45); display: grid; place-items: center; z-index: 500; padding: 16px; animation: fadeIn .2s; }
.modal-back.closing { animation: fadeOut .2s forwards; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
.modal { background: var(--paper); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink); padding: 22px 26px; max-width: 620px; width: 100%; max-height: calc(100dvh - 40px); overflow-y: auto; animation: pop .25s; }
.modal-back.wide .modal { max-width: 860px; }
.dialog { display: flex; gap: 16px; align-items: flex-start; font-size: 20px; }
.confirm { text-align: center; }
.explain-head { display: flex; gap: 14px; align-items: center; }
.explain-owl { width: 90px; height: 90px; object-fit: contain; }
.explain-q { font-size: 24px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 10px 14px; margin: 10px 0; }
.explain-text { font-size: 20px; }
.steps { font-size: 23px; line-height: 1.6; padding-left: 30px; }
.steps li { animation: stepIn .4s backwards; }
@keyframes stepIn { from { opacity: 0; transform: translateX(-12px); } }
.explain-answer { font-size: 26px; margin: 12px 0; text-align: center; background: var(--good-bg); border: 3px solid var(--good); border-radius: 14px; padding: 8px; }
.explain .btn-big { display: block; margin: 12px auto 0; }

/* ---------- toast / float text ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; background: var(--card); border: 3px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 20px; font-size: 19px; z-index: 900; transition: all .3s; max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.float-text { position: fixed; z-index: 1001; transform: translate(-50%, -50%); font-size: 38px; font-weight: 700; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; pointer-events: none; animation: floatUp 1.3s ease-out forwards; white-space: nowrap; }
.float-text.crit { font-size: 46px; color: var(--sun); }
.float-text.soft { color: #e9d5ff; font-size: 30px; }
.float-text.dmg-soft { color: #fecaca; font-size: 30px; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 0) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -20px) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -90px) scale(1); } }

/* ---------- attack fx ---------- */
.fx-orb { position: fixed; width: 54px; height: 54px; border-radius: 50%; z-index: 999; pointer-events: none; background: radial-gradient(circle, #fff 0 25%, var(--g) 45%, var(--c) 70%, transparent 72%); box-shadow: 0 0 30px 10px var(--c); }
.fx-orb.beam { width: 90px; height: 30px; border-radius: 20px; }
.fx-wave { position: fixed; width: 150px; height: 130px; z-index: 999; pointer-events: none; border-radius: 50% 50% 10% 10%; background: linear-gradient(var(--g), var(--c)); border: 3px solid var(--ink); opacity: .9; }
.fx-bolt { position: fixed; width: 18px; height: 220px; z-index: 999; pointer-events: none; transform-origin: top; background: linear-gradient(var(--g), var(--c)); clip-path: polygon(40% 0, 100% 0, 60% 45%, 100% 45%, 20% 100%, 40% 55%, 0 55%); filter: drop-shadow(0 0 10px var(--c)); }
.fx-ring { position: fixed; width: 120px; height: 120px; border-radius: 50%; border: 12px solid var(--c); z-index: 999; pointer-events: none; }

/* ---------- results ---------- */
.results { max-width: 760px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }
.win-title { font-size: 34px; text-align: center; }
.results-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.res-row { font-size: 21px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 14px; animation: slideIn .3s ease-out; }
.res-row.pop { background: #fef9c3; }
.res-sub { font-size: 15px; color: var(--ink-soft); }
.results-buttons { margin-top: 10px; }
.evolve, .befriend { text-align: center; }
.evolve-back .modal { background: radial-gradient(circle, #fffbe6, #fde68a); }
.evolve-stage { position: relative; width: 260px; height: 260px; margin: 10px auto; }
.evolve-stage .creature { position: absolute; inset: 0; width: 100%; }
.evo-from { animation: evoOut 2.6s forwards; }
.evo-to { opacity: 0; animation: evoIn 2.6s forwards; }
@keyframes evoOut { 0% { filter: brightness(1); } 20%, 30%, 40%, 50%, 60% { filter: brightness(0) invert(1); } 25%, 35%, 45%, 55% { filter: brightness(1); } 70% { filter: brightness(0) invert(1); opacity: 1; transform: scale(1.1); } 80%, 100% { opacity: 0; transform: scale(.2); } }
@keyframes evoIn { 0%, 70% { opacity: 0; transform: scale(.2); filter: brightness(0) invert(1); } 85% { opacity: 1; transform: scale(1.15); filter: brightness(0) invert(1); } 100% { opacity: 1; transform: scale(1); filter: none; } }
.evolve-done { opacity: 0; font-size: 22px; font-weight: 600; }
.evolve .btn { visibility: hidden; }
.modal.done .evolve-done { opacity: 1; transition: opacity .4s; }
.modal.done .btn { visibility: visible; }
.befriend-glow { width: 220px; margin: 0 auto; border-radius: 50%; background: radial-gradient(circle, #fff 0 40%, #fbcfe8 60%, transparent 70%); animation: bob 2s ease-in-out infinite; }
.befriend-glow .creature { width: 100%; }

/* ---------- tired ---------- */
.tired-screen { align-items: center; justify-content: center; padding: 20px; }
.tired-card { background: rgba(255,250,240,.95); border: 4px solid var(--ink); border-radius: 30px; box-shadow: 0 8px 0 var(--ink); padding: 26px; text-align: center; max-width: 600px; }
.sleeper { position: relative; width: 200px; margin: 0 auto; }
.sleeper .creature { width: 100%; animation: breathe 3s ease-in-out infinite; filter: saturate(.8); }
@keyframes breathe { 50% { transform: scale(1.03, .97); } }
.zzz { position: absolute; right: 0; top: 10%; font-size: 30px; font-weight: 700; animation: zzz 3s infinite; opacity: 0; }
.zzz.z2 { animation-delay: 1s; } .zzz.z3 { animation-delay: 2s; font-size: 40px; }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(30px, -60px); } }
.teach-back { background: #e0f2fe; border: 3px solid var(--ink); border-radius: 16px; padding: 10px 14px; margin: 10px 0; font-size: 18px; text-align: left; }
.teach-title { font-weight: 700; margin-bottom: 2px; }
.name-fields { display: flex; flex-direction: column; gap: 8px; }
.name-input.wide { width: 340px; font-size: 18px; }
.starters li { margin: 6px 0; }
.big-note { font-size: 22px; font-weight: 600; background: #fff3b0; border: 3px solid var(--ink); border-radius: 16px; padding: 10px; }

/* ---------- scratch paper ---------- */
.scratch { position: fixed; left: 0; top: 0; bottom: 0; right: calc(var(--icol) + 36px); z-index: 400; background: #fffef7;
  border-right: 4px solid var(--ink); display: flex; flex-direction: column; }
.scratch-bar { display: flex; gap: 8px; align-items: center; padding: 10px; background: var(--paper); border-bottom: 3px solid var(--ink); flex-wrap: wrap; }
.scratch-q { flex: 1; font-size: 22px; font-weight: 600; min-width: 180px; }
.scratch-tool { font-size: 17px; padding: 8px 14px; min-height: 44px; }
.scratch-tool.on { background: var(--sun); }
.scratch-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none;
  background-image: linear-gradient(#e0e7ff 1px, transparent 1px), linear-gradient(90deg, #e0e7ff 1px, transparent 1px);
  background-size: 32px 32px; }
.scratch-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.scratch-ink { cursor: crosshair; }
.scratch-tokens { position: absolute; inset: 0; pointer-events: none; }
.scratch-stage.tokens-live .scratch-tokens { pointer-events: auto; }
.scratch-token { position: absolute; width: 32px; height: 32px; display: grid; place-items: center;
  font-size: 23px; font-weight: 600; color: var(--ink); border-radius: 8px; background: rgba(255,255,255,.75); }
.scratch-stage.tokens-live .scratch-token { cursor: grab; box-shadow: inset 0 0 0 2px #c7d2fe; }
.scratch-token.ghost { position: fixed; z-index: 1002; pointer-events: none; background: var(--sun); box-shadow: 0 4px 0 var(--ink); transform: scale(1.15); }
.scratch-trayrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--paper); border-top: 3px solid var(--ink); flex-wrap: wrap; }
.tray-label { font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.scratch-tray { display: flex; gap: 6px; flex-wrap: wrap; }
.scratch-tray.dim { opacity: .75; }
.tray-key { width: 46px; height: 46px; font-size: 24px; font-weight: 700; font-family: inherit; background: #fff;
  border: 3px solid var(--ink); border-radius: 12px; box-shadow: 0 3px 0 var(--ink); touch-action: none; }
.tray-key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: #fef3c7; }
.tray-key.picked { background: var(--sun); box-shadow: 0 3px 0 var(--ink), 0 0 0 4px #fde68a; transform: translateY(-2px); }
.scratch-token.work-right { color: var(--good); background: #dcfce7; box-shadow: inset 0 0 0 2px #4ade80; }
.scratch-token.step-done { animation: stepPop .55s; }
@keyframes stepPop { 0% { transform: scale(1); } 35% { transform: scale(1.45); color: #b45309; background: #fde68a; } 100% { transform: scale(1); } }
.charge { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--paper); border-bottom: 3px solid var(--ink); }
.charge-track { flex: 1; height: 18px; background: #eee; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; }
.charge-fill { height: 100%; width: 0; background: linear-gradient(90deg, #fde047, #fb923c); transition: width .35s ease-out; }
.charge.full .charge-fill { background: linear-gradient(90deg, #4ade80, #fde047); animation: rainbow 1.2s linear infinite; background-size: 200% 100%; }
.charge-text { font-size: 16px; font-weight: 600; white-space: nowrap; }
.work-nudge { display: none; position: absolute; left: 12px; bottom: 76px; max-width: 460px; gap: 10px; align-items: center;
  background: var(--hint-bg); border: 3px solid var(--hint); border-radius: 18px; padding: 8px 12px; font-size: 18px; }
.work-nudge.show { display: flex; animation: pop .3s; }
.work-nudge .hint-owl { width: 46px; height: 46px; }
.charge-chip { display: block; font-size: 17px; font-weight: 600; color: #b45309; margin: 4px 0; }
.charge-chip.full { color: var(--good); }
.scratch-preview { position: absolute; width: 32px; height: 32px; display: grid; place-items: center; pointer-events: none;
  font-size: 23px; font-weight: 600; color: var(--ink); opacity: .38; border-radius: 8px; background: #fef9c3; box-shadow: inset 0 0 0 2px #fbbf24; }
.scratch-stage:not(.tokens-live) .scratch-preview { display: none; }

/* ---------- the balance mat (js/ui/balance.js) ---------- */
.balance { position: fixed; left: 0; top: 0; bottom: 0; right: calc(var(--icol) + 36px); z-index: 400; background: #fffef7;
  border-right: 4px solid var(--ink); display: flex; flex-direction: column; }
.mat-banner { padding: 8px 12px; font-size: 18px; font-weight: 600; background: var(--paper); border-bottom: 3px solid var(--ink); }
.mat-banner.warn { background: #fee2e2; color: #b91c1c; }
.mat-banner.win { background: #dcfce7; color: #166534; }
.mat { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding: 14px;
  background-image: linear-gradient(#e0e7ff 1px, transparent 1px), linear-gradient(90deg, #e0e7ff 1px, transparent 1px);
  background-size: 32px 32px; }
.mat-side { min-height: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 10px; border: 4px dashed #c7d2fe; border-radius: 22px; background: rgba(255,255,255,.72); cursor: pointer; }
.mat-side:hover { border-color: var(--sky); background: #fff; }
.mat-terms { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.mat-chip { font-size: 30px; font-weight: 700; padding: 10px 16px; border: 3px solid var(--ink); border-radius: 16px;
  background: #fef9c3; box-shadow: 0 3px 0 var(--ink); }
.mat-chip.chip-x { background: #ddd6fe; }
.mat-chip.chip-neg { background: #fecaca; }
.mat-chip.chip-new { animation: pop .3s; box-shadow: 0 3px 0 var(--ink), 0 0 0 4px #fde68a; }
.mat-chip.chip-zero.chip-new { animation: pop .3s; box-shadow: 0 3px 0 var(--ink), 0 0 0 4px #d1d5db; }
.mat-op { font-size: 26px; font-weight: 700; padding: 6px 14px; border: 3px solid var(--ink); border-radius: 999px; background: #bfdbfe; }
.mat-sign { font-size: 46px; font-weight: 700; }
.mat.unbalanced .mat-sign { color: #b91c1c; }
/* the side she just played on dips, the other rises — never a claim about weight, just "this
   side changed and the other did not" */
.mat.unbalanced .mat-side.changed { transform: translateY(10px); border-color: var(--sun); border-style: solid; }
.mat.unbalanced .mat-side:not(.changed) { transform: translateY(-10px); }
.mat-side { transition: transform .25s ease-out; }
.mat.solved .mat-side { border-color: var(--good); background: #f0fdf4; }
.mat-sign.shake { animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.mat-log { padding: 8px 14px; background: var(--paper); border-top: 3px solid var(--ink); min-height: 34px; }
.mat-line { font-size: 19px; color: var(--ink-soft); }
.mat-line.now { font-size: 24px; font-weight: 700; color: var(--ink); }
.mat-trayrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--paper); border-top: 3px solid var(--ink); flex-wrap: wrap; }
.mat-tray { display: flex; gap: 8px; flex-wrap: wrap; }
.mat-tile { min-width: 62px; height: 52px; padding: 0 12px; font-size: 24px; font-weight: 700; font-family: inherit; background: #fff;
  border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }
.mat-tile[data-kind="add"] { background: #ecfdf5; }
.mat-tile[data-kind="mul"], .mat-tile[data-kind="div"] { background: #eff6ff; }
.mat-tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.mat-tile.picked { background: var(--sun); box-shadow: 0 3px 0 var(--ink), 0 0 0 4px #fde68a; transform: translateY(-2px); }
.balance.picking .mat-side { border-color: var(--sun); border-style: solid; }
.mat-tile.dim { opacity: .4; }
.mat-tile.ghost { position: fixed; z-index: 1002; pointer-events: none; background: var(--sun); transform: scale(1.1); }
.mat-chip.chip-zero { background: #e5e7eb; color: var(--ink-soft); border-style: dashed; cursor: pointer; animation: zeroPulse 1.6s ease-in-out infinite; }
@keyframes zeroPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.mat-chip.over { box-shadow: 0 3px 0 var(--ink), 0 0 0 5px #fde68a; transform: scale(1.06); }
.mat-side.over { border-color: var(--sun); border-style: solid; background: #fffbeb; }

/* ---------- setting up a word problem (js/ui/setup.js) ---------- */
.setupq { position: fixed; left: 0; top: 0; bottom: 0; right: calc(var(--icol) + 36px); z-index: 400; background: #fffef7;
  border-right: 4px solid var(--ink); display: flex; flex-direction: column; }
.setup-story { padding: 18px 20px; font-size: 25px; line-height: 1.75; flex: 1; min-height: 0; overflow: auto; }
.setup-story.locked { opacity: .85; }
.pill { font: inherit; font-weight: 700; color: var(--ink); background: #fef9c3; border: 3px solid var(--ink);
  border-radius: 12px; padding: 1px 10px; margin: 0 2px; box-shadow: 0 3px 0 var(--ink); cursor: pointer; }
.pill:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.pill.used { background: #ddd6fe; }
.pill:disabled { cursor: default; }
.setup-linerow { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--paper);
  border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink); min-height: 56px; }
.setup-line { font-size: 30px; font-weight: 700; letter-spacing: .5px; }
.setup-line.good { color: var(--good); }
.setup-line.shake { animation: shake .4s; }
.setup-solve { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 20px; }
.setup-step { font-size: 17px; color: var(--ink-soft); }
.setup-step.done { color: var(--good); font-weight: 600; }
.setup-bar { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px; background: var(--paper); border-top: 3px solid var(--ink); }
.setup-key { width: 58px; height: 52px; font-size: 26px; font-weight: 700; font-family: inherit; background: #fff;
  border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }
.setup-key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.setup-key:disabled { opacity: .45; }
.setup-key.key-eq { background: #e0f2fe; }
.setup-key.key-unknown { background: #ede9fe; }
.setup-key.key-back { background: #fee2e2; }

/* ---------- the family code (js/ui/players.js) ---------- */
.players-links { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.family-box { max-width: 520px; }
.family-box h2 { margin: 0 0 6px; }
.family-note { color: var(--ink-soft); font-size: 16px; margin: 0 0 14px; }
.family-code { font-size: 30px; font-weight: 700; letter-spacing: 1px; text-align: center; padding: 12px;
  background: #fef9c3; border: 3px dashed var(--ink); border-radius: 16px; margin-bottom: 14px; user-select: all; }
.field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-weight: 600; font-size: 15px; }
.field-row .field { font: inherit; font-size: 18px; font-weight: 600; padding: 8px 10px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; }
.family-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; }
.family-status { font-size: 15px; font-weight: 600; color: var(--good); min-height: 20px; }
.family-status.bad { color: #b91c1c; }

/* ---------- smaller screens (tablet portrait / small laptop) ---------- */
@media (max-width: 900px) {
  :root { --icol: 320px; }
  .map-side { width: 200px; }
  .starter-cards { grid-template-columns: 1fr; }
  .starter-card { display: grid; grid-template-columns: 120px 1fr; text-align: left; align-items: center; column-gap: 12px; }
  .starter-card .creature { width: 120px; grid-row: span 3; }
  .area-options { grid-template-columns: 1fr; }
  .move-name { font-size: 22px; }
}
@media (max-height: 760px) {
  .battle { grid-template-rows: auto minmax(170px, 32vh) 1fr; }
  .key { min-height: 48px; }
  .choice { min-height: 70px; font-size: 26px; }
  .pad-display { min-height: 52px; line-height: 40px; font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- the grown-ups area ----------
   Plain markup that never had a stylesheet: tiles of numbers, a row of tabs, and cards around each
   section. Same shapes as the rest of the game so it does not look like a different program. */
.parent-screen { height: 100%; overflow: auto; background: var(--paper); }
.parent { max-width: 1000px; margin: 0 auto; padding: 14px 18px 40px; }
.parent-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 16px; }
.parent-tabs .tab { font: inherit; font-size: 16px; font-weight: 600; padding: 8px 14px; background: #fff;
  border: 3px solid var(--ink); border-radius: 999px; box-shadow: 0 3px 0 var(--ink); }
.parent-tabs .tab.on { background: var(--sun); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: #fff; border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink); padding: 12px 14px; }
.tile-label { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.tile-value { font-size: 30px; font-weight: 700; line-height: 1.15; }
.tile-sub { font-size: 13px; color: var(--ink-soft); }
.panel-card { background: #fff; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 4px 0 var(--ink);
  padding: 14px 16px; margin-bottom: 16px; overflow-x: auto; }
.panel-card h3 { margin: 0 0 10px; font-size: 20px; }
.panel-card table { border-collapse: collapse; width: 100%; font-size: 15px; }
.panel-card th, .panel-card td { text-align: left; padding: 6px 8px; border-bottom: 2px solid #eee; white-space: nowrap; }
.panel-card svg { max-width: 100%; height: auto; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }

img { -webkit-user-drag: none; user-drag: none; }

/* ---------- phones ----------
   The battle is built as two columns, question beside keypad, which is right for a laptop and
   hopeless on a phone. Here everything stacks: the question on top, the answering underneath, the
   working pads over the whole screen, and the world map becomes something you swipe sideways. */
@media (max-width: 700px) {
  :root { --icol: 0px; }

  .topbar { padding: 6px 10px; gap: 8px; }
  .topbar-title { font-size: 18px; }
  .coin-pill, .btn-icon { transform: scale(.9); }

  /* the arena gives up height so the question and the keypad both fit */
  .battle { grid-template-rows: auto minmax(110px, 20vh) 1fr; }
  /* while she is answering, the creatures step aside completely: on a phone those 90 points are
     the difference between a word problem fitting and being cut in half. They are back the moment
     she answers. */
  .battle.solving, .battle.solving.has-visual { grid-template-rows: auto 0 1fr; }
  .battle.solving .arena { border-bottom: none; }
  .hud { transform: scale(.72); max-width: 46%; }
  .hud-me { transform-origin: top left; }
  .hud-wild { transform-origin: top right; }

  .panel { padding: 10px 12px; }
  .problem { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: 8px; }
  .qcol { overflow-y: auto; }
  .problem .icol { order: 2; }
  .problem .qcard { position: static; }
  .question { font-size: clamp(20px, 5.4vw, 26px); }
  .qprompt { font-size: 17px; }
  .qcol { padding: 2px 2px 8px; }

  /* one move per row: two columns cut "Volt Arc" in half on a phone */
  .panel { overflow: auto; }
  .moves { grid-template-columns: 1fr; gap: 8px; }
  .move { padding: 10px 14px 10px 20px; min-height: 62px; grid-template-rows: auto; }
  .move-name { font-size: 20px; }
  .move-kind { font-size: 14px; grid-row: 1; }
  .move-power { grid-row: 1; font-size: 19px; }
  .move.super { grid-column: span 1; }
  .move-key { display: none; }                 /* no keyboard to shortcut from */
  .move-legend { gap: 12px; font-size: 13px; margin-top: 8px; flex-wrap: wrap; }

  .choice { min-height: 66px; font-size: 24px; padding-left: 30px; }
  .choices.long .choice { font-size: 18px; min-height: 56px; }
  /* the keypad gives the question every point it can spare — a word problem needs the room, and
     44pt keys are still a comfortable thumb target */
  .pad-display { font-size: 26px; min-height: 44px; line-height: 34px; }
  .pad { gap: 6px; }
  .pad-bottom { gap: 6px; }
  .key { min-height: 44px; font-size: 22px; box-shadow: 0 3px 0 var(--ink); }
  .key-go { font-size: 22px; }
  .icol { gap: 6px; }
  .tools { gap: 8px; }
  .tools .btn { font-size: 15px; padding: 8px 12px; }

  /* the world map: full width, swiped sideways, so the islands keep their shape */
  .map-body { flex-direction: column; }
  /* the side panel becomes a strip above the map: two short rows, nothing hidden off to the side */
  .map-side { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px;
    border-right: none; border-bottom: 3px solid var(--ink); overflow: visible; }
  .map-side > * { flex: 0 0 auto; }
  .map-side .side-btn, .map-side .grade-chip { font-size: 13px; padding: 7px 10px; min-height: 38px; border-radius: 12px; }
  .map-side .side-btn.small { font-size: 12px; }
  .map-side .bonus-note, .map-side .tired-note { font-size: 12px; padding: 4px 8px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .map-side .energy { transform: scale(.8); transform-origin: left center; }
  .map-side .bubble, .map-side .partner-card { display: none; }
  .map-scroll { flex: 1; min-height: 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
  .map { min-width: 760px; min-height: 100%; }
  .map-node { width: 104px; }
  .node-img { width: 74px; height: 74px; border-width: 3px; }
  .node-label { font-size: 13px; padding: 1px 8px; }
  .node-stars { font-size: 12px; }

  .players-card, .title-card { padding: 18px 14px; }
  .players-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .modal { padding: 16px 14px; border-radius: 20px; }
  .field-row .field { font-size: 16px; }

  /* the working pads take the whole screen instead of sitting beside the keypad */
  .scratch, .balance, .setupq { right: 0; border-right: none; }
  .scratch-bar { padding: 6px 8px; gap: 6px; }
  .scratch-q { font-size: 16px; flex: 1 0 100%; }   /* its own line, buttons underneath */
  .scratch-bar .btn, .scratch-tool { font-size: 14px; padding: 7px 10px; min-height: 40px; }
  .scratch-trayrow, .mat-trayrow, .setup-bar { padding: 6px 8px; gap: 6px; }
  .tray-key { width: 38px; height: 38px; font-size: 20px; border-width: 2px; }
  .tray-label { display: none; }
  .charge-text { font-size: 14px; white-space: normal; }

  .mat { padding: 8px 6px; gap: 6px; }
  .mat-side { min-height: 110px; padding: 8px 4px; border-width: 3px; border-radius: 16px; }
  .mat-chip { font-size: 20px; padding: 6px 10px; border-radius: 12px; }
  .mat-op { font-size: 18px; padding: 4px 10px; }
  .mat-sign { font-size: 30px; }
  .mat-tile { min-width: 48px; height: 44px; font-size: 19px; padding: 0 8px; }
  .mat-line { font-size: 15px; }
  .mat-line.now { font-size: 19px; }
  .mat-banner, .setup-line, .family-status { font-size: 15px; }

  .setup-story { font-size: 19px; line-height: 1.7; padding: 12px; }
  .pill { padding: 1px 7px; border-width: 2px; }
  .setup-linerow { padding: 8px 12px; min-height: 46px; }
  .setup-line { font-size: 22px; }
  .setup-key { width: 44px; height: 44px; font-size: 21px; }
  .setup-solve { padding: 8px 12px; }
  .setup-solve .btn { font-size: 15px; }
  .scratch-stage, .mat { background-size: 26px 26px; }     /* matches CELL in js/ui/scratch.js */
  .scratch-token { width: 26px; height: 26px; font-size: 19px; }
  .scratch-preview { width: 26px; height: 26px; font-size: 19px; }
  .work-nudge { left: 8px; right: 8px; bottom: 64px; max-width: none; font-size: 15px; }

  /* a phone's notch and home bar: keep the bars and trays clear of both */
  .topbar { padding-top: calc(6px + env(safe-area-inset-top)); padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }
  .scratch-bar { padding-top: calc(6px + env(safe-area-inset-top)); }
  .scratch-trayrow, .mat-trayrow, .setup-bar { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .icol, .panel { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  /* no double-tap zoom lag on things you tap hundreds of times */
  button, .pill, .mat-chip, .map-node { touch-action: manipulation; }

  .parent { padding: 10px 12px 30px; }
  .parent-tabs { gap: 6px; margin: 8px 0 12px; }
  .parent-tabs .tab { font-size: 14px; padding: 7px 11px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 8px 10px; border-radius: 14px; }
  .tile-value { font-size: 22px; }
  .tile-label { font-size: 12px; }
  .panel-card { padding: 10px 12px; }
  .panel-card h3 { font-size: 17px; }
  .panel-card table { font-size: 13px; }
}

/* ---------- a phone turned sideways ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .battle { grid-template-rows: auto minmax(56px, 18vh) 1fr; }
  .hud { transform: scale(.68); }
  .hud-me { transform-origin: top left; }
  .hud-wild { transform-origin: top right; }
  .panel { overflow: auto; }                       /* four moves are taller than a sideways phone */
  .moves { gap: 8px; }
  .move { padding: 7px 10px; }
  .panel-msg { font-size: 19px; margin-bottom: 8px; }
  /* every pixel goes to the question. The arena's row collapses to nothing rather than the arena
     being display:none — taking it out of the grid would let the panel fall into its place. */
  .battle.solving, .battle.solving.has-visual { grid-template-rows: auto 0 1fr; }
  .battle.solving .arena { border-bottom: none; }
  .topbar { padding: 4px 10px; }
  .topbar-title { font-size: 16px; }
  .panel { padding: 8px 12px; }
  .question { font-size: clamp(18px, 3.4vw, 24px); }
  .key { min-height: 40px; font-size: 20px; }
  .pad-display { min-height: 42px; font-size: 24px; line-height: 34px; }
  .choice { min-height: 52px; font-size: 20px; }
  .move-name { font-size: 17px; }
  .move-kind { display: none; }
  .scratch-bar, .mat-banner, .setup-linerow { padding-top: 4px; padding-bottom: 4px; }
  .mat-side { min-height: 84px; }
  .setup-story { font-size: 17px; line-height: 1.5; padding: 8px 12px; }
}
