@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --cream: #fdf6ea;
  --cream-deep: #f6e8d6;
  --card: #fffdf8;
  --card-2: #fff8ef;
  --ink: #5d3a3c;
  --ink-soft: #8d6a67;
  --ink-faint: #b49a94;
  --maroon: #7b3f43;
  --maroon-deep: #a23f4f;
  --line-soft: #eeddcb;
  --line: #e3cdb8;
  --heart: #e63b4c;
  --heart-empty: #f3d9d6;
  --blue: #8fc4e8;
  --blue-deep: #5d9fd2;
  --blue-soft: #bfe4f6;
  --yellow: #e7c96e;
  --green: #b9e2c0;
  --pink: #f28ca6;
  --region-seam: rgba(255, 255, 255, .62);
  --shadow-soft: 0 1px 2px rgba(122, 83, 66, .05), 0 8px 20px rgba(122, 83, 66, .07);
  --shadow-card: 0 2px 0 #f1e1d0, 0 12px 26px rgba(122, 83, 66, .09);
  --radius: 20px;
  --font-head: 'Baloo 2', 'Nunito', system-ui, -apple-system, sans-serif;
  --font-body: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --cat-eye: #fff6e9;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, rgba(255, 255, 255, .95), transparent 42rem),
    var(--cream);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
h1, h2, h3, p { margin-top: 0; }
a { color: var(--maroon-deep); }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ */
/* Shell                                                               */
/* ------------------------------------------------------------------ */

.app {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 0;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 0 14px;
  border-bottom: 1.5px solid var(--line-soft);
  margin-bottom: 16px;
}

.round-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1.5px solid var(--line-soft);
  border-radius: 50%;
  background: var(--card);
  color: var(--maroon);
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 #f2e2d2, 0 4px 10px rgba(122, 83, 66, .05);
  transition: transform .15s, box-shadow .15s, background .15s;
}
.round-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 #f2e2d2, 0 7px 14px rgba(122, 83, 66, .07); }
.round-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #f2e2d2; }
.round-btn svg { width: 21px; height: 21px; }
.round-btn.soft { background: #fffaf4; color: var(--ink-soft); }
.round-btn.soft:hover { color: var(--maroon); }

.topbar-title { text-align: center; min-width: 0; }
.topbar-title h1 {
  font-family: var(--font-head);
  font-size: 25px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: .005em;
  color: var(--maroon);
  margin: 0;
}
.topbar-title span {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.account-btn .account-avatar {
  display: inline-grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 334px;
  gap: clamp(22px, 3vw, 40px);
  align-items: start;
}

.board-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ------------------------------------------------------------------ */
/* HUD + rule tabs                                                     */
/* ------------------------------------------------------------------ */

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(100%, 600px);
  margin: 0 auto 12px;
}

.hud-cats {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 4px 5px;
  border: 1.5px solid var(--line-soft);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 2px 0 #f2e2d2;
}
.hud-cat {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #fff3e4, #f0e1d0);
  border: 1.5px solid #f1dfca;
}
.hud-cat svg { width: 22px; height: 22px; color: #3f3338; }
.hud-cats strong {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  color: var(--maroon);
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}

.hud-hearts { display: inline-flex; align-items: center; gap: 5px; }
.heart {
  width: 27px;
  height: 27px;
  fill: var(--heart-empty);
  stroke: #fffdf8;
  stroke-width: 1.5;
  filter: drop-shadow(0 1px 0 rgba(122, 83, 66, .12));
  transition: fill .18s, transform .18s;
}
.heart.is-on { fill: var(--heart); }
.heart.is-on:first-of-type { animation: heartBeat 2.6s ease-in-out infinite; }
@keyframes heartBeat {
  0%, 88%, 100% { transform: scale(1); }
  92% { transform: scale(1.12); }
  96% { transform: scale(.98); }
}

.rule-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  width: min(100%, 600px);
  margin: 0 auto 14px;
}
.rule-tab {
  min-height: 52px;
  padding: 7px 8px;
  border: 1.5px solid var(--line-soft);
  border-radius: 11px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  box-shadow: 0 2px 0 #f2e2d2;
  transition: transform .15s, border-color .15s, color .15s, background .15s;
}
.rule-tab:hover { transform: translateY(-1px); border-color: #dcbfa9; color: var(--ink); }
.rule-tab.is-active {
  border-color: var(--maroon-deep);
  background: #fffaf4;
  color: var(--maroon);
  box-shadow: 0 2px 0 #ead2c5;
}
.rule-tab:focus-visible { outline: 2px solid var(--maroon-deep); outline-offset: 2px; }

/* ------------------------------------------------------------------ */
/* Board                                                               */
/* ------------------------------------------------------------------ */

.board-frame {
  width: min(100%, 600px);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 12px 28px rgba(122, 83, 66, .14), 0 2px 0 rgba(255, 255, 255, .6);
  position: relative;
}

.board {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  grid-auto-rows: minmax(0, 1fr);
  border-radius: 18px;
  overflow: hidden;
  background: #f5e8d7;
  isolation: isolate;
  touch-action: manipulation;
  user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0 solid var(--region-seam);
  background: var(--cell-bg, #f3e8da);
  appearance: none;
  -webkit-appearance: none;
  border-radius: 0;
  transition: filter .12s ease, box-shadow .12s ease, transform .12s ease;
  outline: none;
}
.cell:hover { filter: brightness(1.035) saturate(1.03); }
.cell:active { filter: brightness(.97); }
.cell:focus-visible { z-index: 4; box-shadow: inset 0 0 0 3px var(--maroon); }
.cell.is-empty { cursor: pointer; }

.cell .cat, .cell .xmark {
  pointer-events: none;
  display: block;
  position: relative;
  z-index: 1;
}
.cell .cat {
  width: 84%;
  height: 84%;
  color: #3a2f35;
  filter: drop-shadow(0 2px 1px rgba(74, 42, 46, .22)) drop-shadow(0 1px 0 rgba(255, 255, 255, .2));
}
.cell.has-cat::before {
  content: '';
  position: absolute;
  inset: 7%;
  border-radius: 14%;
  background: rgba(255, 255, 255, .18);
}
.cell .cat.enter { animation: catPop .34s cubic-bezier(.2, .9, .3, 1.35) both; }
.cell .xmark {
  width: 47%;
  height: 47%;
  color: #fff;
  opacity: .97;
  filter: drop-shadow(0 2px 1px rgba(96, 58, 55, .28));
}
.cell .xmark.enter { animation: markIn .18s ease both; }

.cell.is-given .cat { opacity: .94; }
.cell.is-conflict { box-shadow: inset 0 0 0 3px rgba(162, 63, 79, .85), inset 0 0 24px rgba(162, 63, 79, .18); z-index: 2; }
.cell.is-conflict .cat { animation: conflictShake .32s ease; }
.cell.is-hint { animation: hintPulse 1.4s ease-in-out 2; z-index: 3; }
.cell.is-last { box-shadow: inset 0 0 0 2px rgba(123, 63, 67, .28); }

@keyframes catPop {
  0% { transform: scale(.35) rotate(-10deg); opacity: .1; }
  68% { transform: scale(1.1) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
@keyframes markIn { from { transform: scale(.65) rotate(-7deg); opacity: 0; } to { transform: scale(1); opacity: .96; } }
@keyframes conflictShake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-6deg) scale(1.03); }
  75% { transform: rotate(6deg) scale(1.03); }
}
@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(231, 201, 110, .22); background-color: var(--cell-bg); }
  45% { box-shadow: inset 0 0 0 5px rgba(231, 201, 110, .95), inset 0 0 30px rgba(231, 201, 110, .35); filter: brightness(1.08); }
}

/* ------------------------------------------------------------------ */
/* Toolbar                                                             */
/* ------------------------------------------------------------------ */

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  width: min(100%, 600px);
  margin-top: 12px;
}

.mode-switch {
  display: inline-flex;
  padding: 4px;
  gap: 3px;
  background: var(--card);
  border: 1.5px solid var(--line-soft);
  border-radius: 999px;
  box-shadow: 0 2px 0 #f2e2d2;
}
.mode-switch button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink-faint);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, color .15s;
}
.mode-switch button .mode-icon { font-size: 14px; line-height: 1; }
.mode-switch #modeNote[aria-pressed='true'] { background: #ffe1e8; color: var(--maroon-deep); }
.mode-switch #modeCat[aria-pressed='true'] { background: #dcf6e6; color: #2f7450; }
.mode-switch button:hover { color: var(--ink); }

.controls { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  border: 1.5px solid var(--line-soft);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink-soft);
  box-shadow: 0 2px 0 #f2e2d2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform .14s, box-shadow .14s, background .14s, color .14s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 0 #f2e2d2; color: var(--ink); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #f2e2d2; }
.btn:disabled { opacity: .45; transform: none; box-shadow: 0 2px 0 #f2e2d2; }
.btn svg { width: 15px; height: 15px; }
#btnUndo svg { color: #b86278; }
#btnReset svg { color: #6aa6d4; }
#btnHint svg { color: #c49a29; }
.btn.primary {
  background: var(--maroon);
  color: #fff8ef;
  border-color: var(--maroon);
  box-shadow: 0 3px 0 #5e2f33, 0 8px 18px rgba(94, 47, 51, .18);
}
.btn.primary:hover { box-shadow: 0 4px 0 #5e2f33, 0 10px 20px rgba(94, 47, 51, .2); color: #fff; }
.btn.primary:active { box-shadow: 0 1px 0 #5e2f33; }
.btn.pink { background: var(--pink); }
.btn.small { padding: 6px 10px; font-size: 11px; border-radius: 11px; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--cream-deep); border-color: var(--line-soft); transform: none; box-shadow: none; }

.hint-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: rgba(196, 154, 41, .14);
  font-size: 10px;
  color: #98731a;
}

.board-footnote {
  width: min(100%, 600px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 11px;
  font-size: 11.5px;
  color: var(--ink-faint);
}
.board-footnote kbd {
  display: inline-block;
  border: 1px solid var(--line-soft);
  border-bottom-width: 2px;
  background: var(--card);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
  color: var(--ink-soft);
}
.board-footnote strong { color: var(--ink-soft); }

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 16px;
}

.panel, .ai-card {
  background: rgba(255, 253, 248, .94);
  border: 1.5px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}

.ai-card {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 100% 0%, rgba(242, 140, 166, .16), transparent 9rem),
    radial-gradient(circle at 0% 100%, rgba(143, 196, 232, .15), transparent 10rem),
    linear-gradient(145deg, #fffdf8, #fff7f2 58%, #fbf4ff);
}
.ai-card::after {
  content: '✦';
  position: absolute;
  right: 16px;
  top: 12px;
  color: var(--yellow);
  font-size: 18px;
  transform: rotate(12deg);
}
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #ecd597;
  background: linear-gradient(135deg, #fff7dc, #ffedb9);
  color: #96711d;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.ai-badge .status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(231, 201, 110, .2);
}
.ai-badge.live { border-color: #a7ddbd; background: linear-gradient(135deg, #e9fbf0, #d3f5e1); color: #2e7550; }
.ai-badge.live .status-dot { background: #3f9d6d; box-shadow: 0 0 0 3px rgba(63, 157, 109, .16); }
.ai-card h2 {
  font-family: var(--font-head);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.005em;
  line-height: 1.12;
  color: var(--maroon);
  margin-bottom: 5px;
}
.ai-card .chapter-intro { color: var(--ink-soft); font-size: 12px; margin-bottom: 12px; }
.ai-card .chapter-intro:empty { display: none; }

.chapter-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.chapter-dots button {
  width: 25px;
  height: 25px;
  border: 1.5px solid var(--line-soft);
  background: #fffaf4;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  color: var(--ink-faint);
  transition: transform .14s, border-color .14s, background .14s;
}
.chapter-dots button:hover { transform: translateY(-2px); border-color: #dcbfa9; color: var(--ink); }
.chapter-dots button.done { background: #eaf8ef; border-color: #bfe4cd; color: #377a55; }
.chapter-dots button.current {
  background: var(--maroon);
  border-color: var(--maroon);
  color: #fff8ef;
  box-shadow: 0 2px 0 #5e2f33;
}
.chapter-dots button.locked { opacity: .42; }

.panel h3 {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.005em;
  color: var(--maroon);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.panel h3 svg { width: 16px; height: 16px; color: var(--maroon-deep); }

.level-card { display: grid; gap: 10px; }
.level-eyebrow {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: #fffaf4;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--maroon-deep);
}
.level-flavor { margin: 0; color: var(--ink-soft); font-size: 12px; }

.stats-panel {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  border-top: 1px dashed var(--line-soft);
  padding-top: 10px;
}
.stat { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line-soft); padding-left: 11px; }
.stat span { font-size: 9.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); }
.stat strong { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--maroon); }
.stat:nth-child(1) strong { color: #4c87b4; }
.stat:nth-child(2) strong { color: #a87613; }
.stat:nth-child(3) strong { color: #b64f75; }

.tip-panel {
  background:
    radial-gradient(circle at 100% 100%, rgba(231, 201, 110, .18), transparent 9rem),
    linear-gradient(135deg, rgba(185, 226, 192, .2), transparent 68%),
    var(--card);
}
.tip-panel .tip-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #2f7c55;
  margin-bottom: 6px;
}
.tip-panel .tip-head svg { width: 15px; height: 15px; color: #3f9d6d; }
.tip-panel p { margin: 0; font-size: 12px; color: var(--ink-soft); }
.tip-panel p::before { content: '“'; font-family: var(--font-head); font-size: 20px; color: #6cc492; line-height: 0; margin-right: 2px; }

/* ------------------------------------------------------------------ */
/* Level strip                                                         */
/* ------------------------------------------------------------------ */

.chapter-strip {
  margin-top: 22px;
  background: var(--card);
  border: 1.5px solid var(--line-soft);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.chapter-strip .strip-label {
  flex: 0 0 auto;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  line-height: 1.3;
}
.chapter-strip .strip-label strong { display: block; color: var(--maroon); font-size: 11.5px; letter-spacing: 0; text-transform: none; }
.strip-levels { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: thin; }
.strip-level {
  flex: 1 0 40px;
  min-width: 40px;
  height: 34px;
  border: 1.5px solid var(--line-soft);
  background: #fffaf4;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  transition: transform .14s, background .14s, border-color .14s;
}
.strip-level:hover { transform: translateY(-2px); border-color: #dcbfa9; }
.strip-level.current {
  background: var(--maroon);
  border-color: var(--maroon);
  color: #fff8ef;
  box-shadow: 0 2px 0 #5e2f33;
}
.strip-level.done { background: #eaf8ef; border-color: #bfe4cd; color: #377a55; }
.strip-level.locked { opacity: .42; }
.strip-level .mini-stars { font-size: 7px; letter-spacing: -1px; line-height: 1; color: var(--yellow); }

/* ------------------------------------------------------------------ */
/* Cat banner                                                          */
/* ------------------------------------------------------------------ */

.cat-banner {
  position: relative;
  height: 164px;
  margin: 30px calc(50% - 50vw) 0;
  width: 100vw;
  overflow: hidden;
}
.cat-banner::before {
  content: '';
  position: absolute;
  left: -15%;
  right: -15%;
  bottom: -124px;
  height: 250px;
  border-radius: 50% 50% 0 0;
  background: var(--blue-soft);
}
.cat-banner-hill {
  position: absolute;
  left: 50%;
  bottom: -108px;
  width: 300px;
  height: 210px;
  transform: translateX(-50%);
  border-radius: 46% 46% 42% 42%;
  background: var(--blue-deep);
}
.ear {
  position: absolute;
  top: -46px;
  width: 92px;
  height: 92px;
  background: var(--blue-deep);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.ear-l { left: 30px; transform: rotate(-9deg); }
.ear-r { right: 30px; transform: rotate(9deg); }
.cat-banner strong {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 30px;
  z-index: 2;
  text-align: center;
  font-family: var(--font-head);
  font-size: clamp(27px, 4.4vw, 40px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: .005em;
  color: #fff;
  text-shadow: 0 3px 0 #4a8fc7, 0 8px 16px rgba(56, 105, 150, .22);
}

/* ------------------------------------------------------------------ */
/* Toast / loading                                                     */
/* ------------------------------------------------------------------ */

.toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  background: var(--maroon);
  color: #fff8ef;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 10px 26px rgba(94, 47, 51, .26);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(90%, 430px);
  text-align: center;
  z-index: 8;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: #9e3f4a; }

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(253, 246, 234, .94);
  backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility .25s;
}
.loading-screen.show { opacity: 1; visibility: visible; }
.loading-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 30px; }
.loading-cat {
  width: 86px;
  height: 86px;
  border: 1.5px solid var(--line-soft);
  border-radius: 26px;
  background: linear-gradient(145deg, #fff1e1, #ffe8e2 52%, #e8f8ef);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 0 #f0dfcf, 0 16px 30px rgba(122, 83, 66, .13);
  animation: bob 1.4s ease-in-out infinite;
}
.loading-cat svg { width: 58px; height: 58px; color: #3a2f35; }
.loading-screen h2 { font-family: var(--font-head); font-size: 26px; color: var(--maroon); margin: 0; }
.loading-screen p { margin: 0; color: var(--ink-soft); font-size: 12.5px; min-height: 19px; }
.loading-dots { display: flex; gap: 5px; }
.loading-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--pink); animation: dotBounce 1s infinite; }
.loading-dots i:nth-child(2) { animation-delay: .15s; background: var(--green); }
.loading-dots i:nth-child(3) { animation-delay: .3s; background: var(--yellow); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }
@keyframes dotBounce { 0%, 70%, 100% { transform: translateY(0); } 35% { transform: translateY(-6px); } }

/* ------------------------------------------------------------------ */
/* Account gate / login                                                */
/* ------------------------------------------------------------------ */

.account-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  overflow: auto;
  background:
    radial-gradient(circle at 16% 14%, rgba(242, 140, 166, .16), transparent 24rem),
    radial-gradient(circle at 86% 22%, rgba(143, 196, 232, .16), transparent 24rem),
    var(--cream);
}

@media (max-height: 620px) {
  .account-screen { place-items: start center; }
}

.account-card {
  width: min(460px, 100%);
  padding: 28px 28px 24px;
  border: 1.5px solid var(--line-soft);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 24px 56px rgba(122, 83, 66, .16), 0 3px 0 #f0dfcf;
  text-align: center;
}

.account-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-head);
  font-size: 24px;
  font-weight: 700;
  color: var(--maroon);
  margin-bottom: 14px;
}
.account-brand .brand-cat {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line-soft);
  border-radius: 14px;
  background: linear-gradient(145deg, #fff1e1, #ffe8e2 55%, #e8f8ef);
  box-shadow: 0 3px 0 #f0dfcf;
}
.account-brand .brand-cat svg { width: 27px; height: 27px; color: #3a2f35; }

.account-card h2 {
  font-family: var(--font-head);
  font-size: 29px;
  font-weight: 700;
  color: var(--maroon);
  margin: 0 0 5px;
}
.account-lead { margin: 0; color: var(--ink-soft); font-size: 12.5px; }

.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.account-choice {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 17px 12px 13px;
  border: 1.5px solid var(--line-soft);
  border-radius: 17px;
  background: #fffaf4;
  color: var(--ink);
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 2px 0 #f2e2d2;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.account-choice:hover {
  transform: translateY(-3px);
  border-color: #dcbfa9;
  box-shadow: 0 4px 0 #f2e2d2;
}
.account-choice-emoji { font-size: 36px; line-height: 1; filter: drop-shadow(0 3px 3px rgba(122, 83, 66, .12)); }
.account-choice small { font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); }

.account-form { display: grid; gap: 9px; margin-top: 6px; text-align: left; }
.account-form h3 { font-family: var(--font-head); font-size: 23px; color: var(--maroon); margin: 0; text-align: center; }
.account-form > p { text-align: center; color: var(--ink-soft); font-size: 12.5px; margin: 0 0 8px; }
.account-form .field { margin-bottom: 0; }
.account-back {
  justify-self: start;
  border: 0;
  background: transparent;
  padding: 2px 0;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-faint);
}
.account-back:hover { color: var(--ink); }
.account-error { min-height: 17px; margin: 0; font-size: 12px; font-weight: 700; color: #b34d63; text-align: center; }
.account-error:empty { min-height: 0; }
.account-submit { width: 100%; margin-top: 2px; }
.account-footnote { margin: 18px 0 0; font-size: 10.5px; color: var(--ink-faint); }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.account-form.shake { animation: shake .4s; }

.account-current {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--line-soft);
  background: #fffaf4;
  border-radius: 13px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.account-current .account-avatar {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--line-soft);
  border-radius: 11px;
  background: linear-gradient(145deg, #fff1e1, #ffe8e2);
  font-size: 19px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.account-current-text { flex: 1; display: grid; text-align: left; }
.account-current-text strong { font-size: 13px; color: var(--maroon); }
.account-current-text small { color: var(--ink-faint); font-size: 10.5px; }
.account-password summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
.account-note {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1.5px dashed var(--line-soft);
  border-radius: 12px;
  background: #fffaf4;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}
.account-note code {
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(123, 63, 67, .08);
  color: var(--maroon);
  font-size: 10px;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ */
/* Dialogs                                                             */
/* ------------------------------------------------------------------ */

dialog {
  border: 1.5px solid var(--line-soft);
  border-radius: 24px;
  background: var(--card);
  color: var(--ink);
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  box-shadow: 0 26px 64px rgba(94, 47, 51, .22), 0 3px 0 #f0dfcf;
  overflow: auto;
}
dialog::backdrop { background: rgba(82, 48, 50, .32); backdrop-filter: blur(4px); }
.dialog-inner { padding: 24px 26px 26px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dialog-head h2 { font-family: var(--font-head); font-size: 28px; font-weight: 700; color: var(--maroon); line-height: 1.05; margin: 0 0 4px; }
.dialog-head p { margin: 0; color: var(--ink-soft); font-size: 12.5px; }
.dialog-close {
  border: 1.5px solid var(--line-soft);
  background: #fff3f4;
  border-radius: 10px;
  width: 33px; height: 33px;
  display: grid; place-items: center;
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
  color: var(--maroon-deep);
}
.dialog-close:hover { background: #ffe4e7; }

.rule-cards { display: grid; gap: 10px; }
.rule-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  align-items: center;
  background: #fff7f5;
  border: 1.5px solid #f3d4d7;
  border-radius: 16px;
  padding: 12px;
}
.rule-card:nth-child(2) { background: #f5fbff; border-color: #cfe6f5; }
.rule-card:nth-child(3) { background: #f2fbf5; border-color: #c7e8d3; }
.rule-card h3 { font-family: var(--font-head); font-size: 17px; color: var(--maroon); margin: 0 0 3px; }
.rule-card p { margin: 0; color: var(--ink-soft); font-size: 12px; }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); width: 54px; height: 54px; border: 1.5px solid var(--line-soft); border-radius: 11px; overflow: hidden; background: #fff; }
.mini-grid i { border: .5px solid rgba(94, 47, 51, .12); display: grid; place-items: center; font-size: 9px; color: var(--ink); font-style: normal; }
.mini-grid i.cat { background: #f7cdd7; }
.mini-grid i.on { background: #e2f3e6; }
.mini-grid i.x { color: var(--ink-faint); font-size: 13px; }

.controls-help { margin-top: 17px; border-top: 1px dashed var(--line-soft); padding-top: 14px; }
.controls-help h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); margin-bottom: 8px; }
.controls-help p { font-size: 12px; color: var(--ink-soft); margin: 0 0 7px; }
.controls-help kbd {
  display: inline-block;
  border: 1px solid var(--line-soft);
  border-bottom-width: 2px;
  background: var(--card);
  border-radius: 5px;
  padding: 0 4px;
  font-family: inherit;
  font-size: 10px;
}

.settings-section + .settings-section { margin-top: 20px; padding-top: 17px; border-top: 1px dashed var(--line-soft); }
.settings-section h3 { font-family: var(--font-head); font-size: 18px; color: var(--maroon); margin-bottom: 4px; }
.settings-section > p { font-size: 12px; color: var(--ink-soft); margin-bottom: 12px; }
.field { display: grid; gap: 5px; margin-bottom: 10px; }
.field label { font-size: 10.5px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); }
.field input, .field select {
  width: 100%;
  border: 1.5px solid var(--line-soft);
  background: var(--cream);
  border-radius: 11px;
  padding: 9px 11px;
  font-size: 13px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--maroon-deep); box-shadow: 0 0 0 3px rgba(162, 63, 79, .1); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.key-status {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid var(--line-soft);
  background: #fffaf4;
  border-radius: 11px;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 11px;
}
.key-status .status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); flex: 0 0 auto; }
.key-status.ok { border-color: #bfe4cd; background: #edfaf2; color: #2e7550; }
.key-status.ok .status-dot { background: #3f9d6d; }
.key-status.warn { border-color: #ecd597; background: #fff9e6; color: #8b6820; }
.key-status.warn .status-dot { background: var(--yellow); }
.key-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.switch-row span { font-size: 12.5px; font-weight: 700; }
.switch-row small { display: block; font-weight: 500; color: var(--ink-faint); font-size: 11px; }
.switch { position: relative; width: 41px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: #e8dacb; border: 1.5px solid #dbc9b7; transition: background .18s; }
.switch i::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 2.5px; left: 3px; transition: transform .18s; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.switch input:checked + i { background: linear-gradient(135deg, #68c996, #8de0b3); border-color: #59ad82; }
.switch input:checked + i::after { transform: translateX(16px); }

.map-chapters { display: grid; gap: 17px; }
.map-chapter h3 { font-family: var(--font-head); font-size: 17px; color: var(--maroon); margin: 0 0 8px; }
.map-chapter h3 small { font-family: var(--font-body); font-size: 9.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); margin-left: 6px; }
.map-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.map-level {
  aspect-ratio: 1;
  border: 1.5px solid var(--line-soft);
  background: #fffaf4;
  border-radius: 9px;
  font-size: 10.5px;
  font-weight: 800;
  color: var(--ink-soft);
  position: relative;
  display: grid;
  place-items: center;
  transition: transform .12s, background .12s;
}
.map-level:hover { transform: translateY(-2px); border-color: #dcbfa9; }
.map-level.done { background: #eaf8ef; border-color: #bfe4cd; color: #377a55; }
.map-level.current { background: var(--maroon); border-color: var(--maroon); color: #fff8ef; box-shadow: 0 2px 0 #5e2f33; }
.map-level.locked { opacity: .4; cursor: not-allowed; }
.map-level .map-star { position: absolute; bottom: 2px; font-size: 6px; color: var(--yellow); letter-spacing: -1px; }

.win-card {
  text-align: center;
  padding: 30px 28px 28px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 10%, rgba(242, 140, 166, .16), transparent 12rem),
    radial-gradient(circle at 90% 86%, rgba(185, 226, 192, .2), transparent 12rem),
    linear-gradient(160deg, #fffdf8, #fff8f1 54%, #fbf4ff);
}
.win-card::before {
  content: '✦  ✧  ✦';
  position: absolute;
  inset: 14px 18px auto;
  color: var(--yellow);
  font-size: 14px;
  letter-spacing: 9px;
  opacity: .7;
}
.win-cat {
  width: 98px; height: 98px;
  margin: 0 auto 15px;
  border: 1.5px solid var(--line-soft);
  border-radius: 30px;
  background: linear-gradient(145deg, #fff1e1, #ffe8e2 52%, #e8f8ef);
  display: grid; place-items: center;
  box-shadow: 0 4px 0 #f0dfcf, 0 16px 30px rgba(122, 83, 66, .12);
  animation: winBounce .6s cubic-bezier(.2,.9,.3,1.3) both;
}
.win-cat svg { width: 68px; height: 68px; color: #3a2f35; }
@keyframes winBounce { 0% { transform: scale(.4) rotate(-10deg); opacity: 0; } 70% { transform: scale(1.08) rotate(3deg); opacity: 1; } 100% { transform: scale(1); } }
.win-card h2 { font-family: var(--font-head); font-size: 33px; color: var(--maroon); margin-bottom: 5px; }
.win-card > p { color: var(--ink-soft); font-size: 13px; margin-bottom: 15px; }
.win-stars { display: flex; justify-content: center; gap: 7px; margin-bottom: 16px; }
.win-stars span { font-size: 31px; color: #eadccd; line-height: 1; }
.win-stars span.on { color: var(--yellow); animation: starIn .45s cubic-bezier(.2,.9,.3,1.5) both; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
.win-stats { display: flex; justify-content: center; gap: 22px; margin-bottom: 20px; }
.win-stats div { display: flex; flex-direction: column; gap: 2px; }
.win-stats span { font-size: 9.5px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-faint); }
.win-stats strong { font-size: 22px; color: var(--maroon); font-variant-numeric: tabular-nums; }
.win-actions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }
.win-quote { font-family: var(--font-head); font-style: italic; font-size: 13px; color: var(--ink-soft); margin: 0 0 18px; }

.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 120; overflow: hidden; }
.confetti {
  position: absolute;
  top: -30px;
  width: 12px;
  height: 15px;
  border-radius: 3px;
  opacity: .9;
  animation: confettiFall linear forwards;
}
.confetti.paw { width: auto; height: auto; background: none !important; font-size: 18px; animation-name: confettiPaw; }
@keyframes confettiFall {
  to { transform: translate3d(var(--dx), 108vh, 0) rotate(var(--rot)); opacity: .2; }
}
@keyframes confettiPaw {
  to { transform: translate3d(var(--dx), 108vh, 0) rotate(var(--rot)); opacity: .15; }
}

/* ------------------------------------------------------------------ */
/* States and responsive                                               */
/* ------------------------------------------------------------------ */

.is-busy .board, .is-busy .controls { pointer-events: none; opacity: .55; }

.empty-hint {
  color: var(--ink-faint);
  font-size: 11.5px;
  text-align: center;
  padding: 18px 10px;
}

@media (min-width: 1180px) {
  .board-frame { width: min(600px, calc(100vh - 320px)); min-width: 430px; }
  .board-column { align-items: center; }
  .hud, .rule-tabs { width: min(600px, calc(100vh - 320px)); min-width: 430px; }
  .board-toolbar, .board-footnote { width: min(600px, calc(100vh - 320px)); min-width: 430px; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .ai-card { grid-column: 1 / -1; }
  .chapter-strip { margin-top: 20px; }
  .board-frame { width: min(100%, 600px); }
  .hud, .rule-tabs, .board-toolbar, .board-footnote { width: min(100%, 600px); }
}

@media (max-width: 680px) {
  .app { width: calc(100% - 24px); padding-bottom: 0; }

  .topbar {
    position: sticky;
    top: max(6px, env(safe-area-inset-top));
    z-index: 40;
    gap: 8px;
    margin: 6px 0 12px;
    padding: 8px 0 9px;
    border-bottom: 1.5px solid var(--line-soft);
    background: rgba(253, 246, 234, .9);
    backdrop-filter: blur(14px);
  }
  .round-btn { width: 40px; height: 40px; }
  .round-btn svg { width: 19px; height: 19px; }
  #btnRules, #btnAccount { display: none; }
  .topbar-title h1 { font-size: 21px; }
  .topbar-title span { font-size: 10.5px; }

  .hud { margin-bottom: 10px; }
  .hud-cat { width: 29px; height: 29px; }
  .hud-cat svg { width: 20px; height: 20px; }
  .hud-cats { padding: 3px 12px 3px 4px; }
  .hud-cats strong { font-size: 17px; }
  .heart { width: 24px; height: 24px; }

  .rule-tabs { gap: 5px; margin-bottom: 11px; }
  .rule-tab { min-height: 54px; padding: 6px 5px; font-size: 10.5px; border-radius: 10px; }

  .board-frame { border-radius: 17px; }
  .board { border-radius: 15px; }
  .cell .xmark { width: 50%; height: 50%; }

  .board-toolbar { gap: 7px; margin-top: 10px; }
  .mode-switch { flex: 1 1 auto; justify-content: center; }
  .mode-switch button { flex: 1; justify-content: center; padding: 6px 8px; font-size: 10.5px; }
  .controls { flex: 1 1 auto; justify-content: flex-end; gap: 5px; }
  .controls .btn { padding: 6px 9px; font-size: 10.5px; }
  .controls .btn svg { width: 14px; height: 14px; }
  .controls .hint-count { min-width: 16px; height: 16px; font-size: 8.5px; }

  .board-footnote { justify-content: center; gap: 8px; margin-top: 9px; font-size: 10px; }
  .board-footnote .desktop-tip { display: none; }

  .sidebar { grid-template-columns: 1fr; gap: 12px; }
  .panel, .ai-card { padding: 15px 16px; border-radius: 18px; }
  .ai-card h2 { font-size: 20px; }
  .chapter-dots button { width: 25px; height: 25px; }
  .level-card { gap: 9px; }

  .chapter-strip { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; margin-top: 18px; }
  .strip-levels { width: 100%; gap: 4px; }
  .strip-level { flex: 1 1 0; min-width: 0; height: 32px; }
  .chapter-strip .strip-label { display: flex; justify-content: space-between; align-items: baseline; }

  .cat-banner { height: 138px; margin-top: 22px; }
  .cat-banner::before { bottom: -140px; height: 240px; }
  .cat-banner-hill { bottom: -122px; width: 250px; height: 200px; }
  .ear { top: -40px; width: 76px; height: 76px; }
  .ear-l { left: 26px; }
  .ear-r { right: 26px; }
  .cat-banner strong { bottom: 24px; font-size: 27px; }

  .dialog-inner { padding: 20px 18px 22px; }
  .account-card { padding: 22px 18px 20px; }
  .account-card h2 { font-size: 26px; }
  .account-choice { padding: 15px 8px 12px; }
  .account-choice-emoji { font-size: 31px; }
  .win-card { padding: 26px 18px 22px; }
  .win-stats { gap: 15px; }
}

@media (max-width: 420px) {
  .board-toolbar { flex-direction: column; align-items: stretch; }
  .mode-switch, .controls { width: 100%; }
  .controls .btn { flex: 1; justify-content: center; }
  .rule-tab { font-size: 10px; }
  .topbar-title h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
