/* NIGHTWATCH: a lamp-lit keep under a cold, starry sky. Tokens first. */
:root {
  color-scheme: dark;
  --ink: #070a14;
  --ink-2: #0c1220;
  --panel: #141a2c;
  --panel-2: #1a2238;
  --line: #2a3558;
  --line-strong: #3d4c78;
  --text: #e9ecf5;
  --muted: #9aa3bf;
  --amber: #e8b04a;
  --amber-2: #ffe0a0;
  --amber-ink: #241703;
  --ember: #ff8c42;
  --green: #8fd3a6;
  --red: #ef8d84;
  --red-ink: #8e2f2a;
  --stone: #161c2e;
  --stone-2: #1e2640;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
  --radius: 16px;
  --font: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", "Segoe UI Mono", ui-monospace, monospace;
  --max: 1180px;
  --focus: 2px solid var(--amber);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html {
  background: var(--ink);
  scroll-padding-top: 76px;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font: 16px/1.5 var(--sans);
  background-color: var(--ink);
  background-image:
    radial-gradient(ellipse 90% 48% at 50% -12%, rgba(232, 176, 74, 0.16), transparent 58%),
    radial-gradient(ellipse 55% 38% at 50% 112%, rgba(36, 48, 110, 0.38), transparent 62%),
    radial-gradient(ellipse at 50% 40%, transparent 42%, rgba(0, 0, 0, 0.32) 100%),
    radial-gradient(1px 1px at 8% 12%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1px 1px at 18% 28%, rgba(255, 255, 255, 0.32), transparent),
    radial-gradient(1.5px 1.5px at 27% 8%, rgba(255, 248, 220, 0.62), transparent),
    radial-gradient(1px 1px at 36% 42%, rgba(255, 255, 255, 0.28), transparent),
    radial-gradient(1px 1px at 48% 16%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 62% 24%, rgba(255, 255, 255, 0.26), transparent),
    radial-gradient(1.5px 1.5px at 73% 11%, rgba(255, 248, 220, 0.48), transparent),
    radial-gradient(1px 1px at 84% 32%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(1px 1px at 92% 18%, rgba(255, 255, 255, 0.24), transparent),
    radial-gradient(1px 1px at 14% 62%, rgba(255, 255, 255, 0.22), transparent),
    radial-gradient(1px 1px at 33% 78%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(1.5px 1.5px at 55% 68%, rgba(255, 248, 220, 0.28), transparent),
    radial-gradient(1px 1px at 71% 82%, rgba(255, 255, 255, 0.22), transparent),
    radial-gradient(1px 1px at 88% 58%, rgba(255, 255, 255, 0.32), transparent),
    radial-gradient(1px 1px at 6% 88%, rgba(255, 255, 255, 0.2), transparent),
    radial-gradient(1px 1px at 96% 90%, rgba(255, 255, 255, 0.25), transparent);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: rgba(232, 176, 74, 0.34); color: #fff8ee; }
a { color: var(--amber); }
button, summary { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: var(--focus); outline-offset: 2px; }
.cell:focus { outline: none; }
.cell:focus-visible { outline: none; }
[hidden] { display: none !important; }
h1, h2, .stamp, .stat b, .fact b, .creature-name b { font-family: var(--font); font-weight: 500; }
.sprite { display: block; }

/* ---------- chrome ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 6px 12px 4px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: rgba(7, 10, 20, 0.9);
  border-bottom: 1px solid rgba(232, 176, 74, 0.28);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(12px);
}
.brand {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  padding: 4px 2px 4px 20px;
  color: var(--amber-2);
  font-family: var(--font);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.2em;
  text-decoration: none;
}
.brand::before {
  content: "";
  position: absolute;
  top: 13px;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber-2);
  box-shadow: inset -3px -2px 0 0 var(--ink), 0 0 10px rgba(255, 224, 160, 0.55);
  animation: moon 5s ease-in-out infinite;
}
@keyframes moon {
  0%, 100% { box-shadow: inset -3px -2px 0 0 var(--ink), 0 0 8px rgba(255, 224, 160, 0.4); }
  50% { box-shadow: inset -3px -2px 0 0 var(--ink), 0 0 14px rgba(255, 224, 160, 0.85); }
}
.brand:hover { color: #fff6d8; }
.brand small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.topnav { display: flex; flex: 1 1 220px; flex-wrap: wrap; align-items: center; }
.topnav a, .topnav button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}
.topnav a:hover, .topnav button:hover { color: var(--text); background: rgba(233, 236, 245, 0.06); }
.topnav a.active {
  color: var(--amber-2);
  box-shadow: inset 0 -2px 0 var(--amber);
}
.topnav .up { color: var(--muted); }
#mute[aria-pressed="true"] { color: var(--muted); text-decoration: line-through; }
main { max-width: var(--max); margin: 0 auto; padding: 18px 12px 40px; }
.kicker {
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.kicker::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  vertical-align: 1px;
}

/* ---------- home ---------- */
.hero { max-width: 760px; padding: 28px 0 12px; }
.hero h1 {
  margin: 8px 0 14px;
  font-size: clamp(34px, 7vw, 60px);
  letter-spacing: -0.02em;
  line-height: 1.04;
  text-shadow: 0 2px 28px rgba(0, 0, 0, 0.45);
}
.hero p { margin: 0 0 18px; color: var(--muted); font-size: 18px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-top: 8px; }
.mode {
  position: relative;
  display: block;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(232, 176, 74, 0.09), transparent 44%),
    var(--panel);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}
.mode::before {
  content: "";
  position: absolute;
  top: 0;
  left: 18px;
  right: 18px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
}
.mode h2 { margin: 6px 0; font-size: 24px; }
.mode p { margin: 0; color: var(--muted); font-size: 14.5px; }
.mode .tag {
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.status-line { margin: 12px 0 0; color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--amber); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  border-color: #ffe0a0;
  background: linear-gradient(180deg, #ffd072, #d9962e);
  color: var(--amber-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 2px 0 rgba(0, 0, 0, 0.35), 0 8px 18px rgba(232, 176, 74, 0.18);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 8px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.25); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- the watch ---------- */
.watch { min-width: 0; }
.night-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  align-items: flex-end;
  margin-bottom: 12px;
}
.night-title { min-width: 0; flex: 1 1 240px; }
.night-title h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 5vw, 36px);
  line-height: 1.1;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
}
.night-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.progress { font-size: 13px; }
.progress b { color: var(--text); font-size: 18px; margin-left: 4px; font-family: var(--font); }

.yard { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.boardwrap { min-width: 0; max-width: 100%; }
.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 6px;
  border: 1px solid #44507a;
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(255, 160, 60, 0.1), transparent 58%),
    linear-gradient(180deg, #12182a, #0a0e1a);
  box-shadow: var(--shadow), inset 0 0 70px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(232, 176, 74, 0.1);
}
.cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1px solid #2a3450;
  border-radius: 5px;
  background-color: var(--stone);
  background-image: radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.035), transparent 58%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  touch-action: manipulation;
  user-select: none;
  overflow: visible;
}
.cell:hover { border-color: var(--line-strong); background-color: var(--stone-2); }
.cell.courtyard {
  background-color: #1a2234;
  background-image: radial-gradient(circle, rgba(232, 176, 74, 0.42) 1.05px, transparent 1.5px);
  background-size: 7px 7px;
  border-style: dotted;
  border-color: rgba(232, 176, 74, 0.45);
}
.cell.heart {
  border-color: rgba(255, 140, 66, 0.7);
  background: radial-gradient(circle at 50% 55%, rgba(255, 140, 66, 0.42), rgba(255, 140, 66, 0.07) 72%);
  box-shadow: 0 0 20px rgba(255, 140, 66, 0.4), inset 0 0 12px rgba(255, 180, 80, 0.2);
}
.cell.lit {
  background-color: #3a2d16;
  background-image: radial-gradient(circle at 50% 50%, rgba(255, 210, 110, 0.28), transparent 70%);
  border-color: rgba(255, 207, 92, 0.55);
  box-shadow: inset 0 0 14px rgba(255, 207, 92, 0.32);
}
.cell.lit::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffe0a0;
  box-shadow: 0 0 6px #ffd27a;
  pointer-events: none;
}
.cell.courtyard.lit {
  background-color: #3a2d16;
  background-image:
    radial-gradient(circle at 50% 50%, rgba(255, 210, 110, 0.28), transparent 70%),
    radial-gradient(circle, rgba(232, 176, 74, 0.5) 1.05px, transparent 1.5px);
  background-size: auto, 7px 7px;
  border-style: dotted;
  border-color: rgba(255, 207, 92, 0.7);
}
.cell.heart.lit {
  background: radial-gradient(circle at 50% 55%, rgba(255, 150, 70, 0.5), rgba(255, 140, 66, 0.1) 72%);
}
.cell.spawn::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px dashed rgba(233, 236, 245, 0.32);
  border-radius: 4px;
  pointer-events: none;
}
.cell.has-wall { background-color: #222838; }
.cell.has-pit {
  background-color: #0a0c14;
  border-color: #4a4336;
}
.cell.has-lantern { box-shadow: 0 0 16px rgba(255, 200, 80, 0.32); }
.cell.pending {
  border-style: dashed;
  border-width: 2px;
  border-color: var(--amber);
  box-shadow: 0 0 0 1px var(--amber) inset;
}
.cell.pending:not(.lit)::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 1px var(--ink);
  pointer-events: none;
}
.cell.hinted {
  animation: pulse 1.2s ease-in-out 3;
  box-shadow: 0 0 0 2px var(--amber) inset;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--amber) inset; }
  50% { box-shadow: 0 0 0 3px var(--amber) inset, 0 0 16px var(--amber); }
}
.cell.cursor {
  outline: 2px solid rgba(233, 236, 245, 0.7);
  outline-offset: -2px;
  z-index: 2;
}
.cell.crumbling {
  background-image: repeating-linear-gradient(-32deg, transparent, transparent 4px, rgba(255, 140, 66, 0.16) 4px, rgba(255, 140, 66, 0.16) 5px);
}
.cell.crumbling .piece .sprite { opacity: 0.78; filter: grayscale(0.2); }
.cell.crumbling .piece::after {
  content: "";
  position: absolute;
  top: 16%;
  bottom: 16%;
  left: 46%;
  width: 0;
  border-left: 2px dashed var(--ember);
  transform: rotate(18deg);
  pointer-events: none;
}
.cell .piece { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.cell .piece .sprite { width: 82%; height: 82%; }
.cell .heart-piece .sprite {
  filter: drop-shadow(0 0 6px rgba(255, 140, 66, 0.7));
  animation: ember 2.6s ease-in-out infinite;
}
.cell.has-lantern .piece .sprite {
  filter: drop-shadow(0 0 5px rgba(255, 200, 80, 0.7));
  animation: ember 2.4s ease-in-out infinite;
}
@keyframes ember {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(255, 180, 60, 0.45)); }
  50% { filter: drop-shadow(0 0 8px rgba(255, 210, 90, 0.9)); }
}
.cell.has-wall .piece .sprite { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5)); }

.creature-token {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: transform 0.25s ease;
}
.creature-token .sprite { width: 78%; height: 78%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)); }
.creature-token .sprite[data-mod="dusk"] {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)) drop-shadow(0 0 4px rgba(80, 50, 140, 0.55));
}
.creature-token .sprite[data-mod="breaker"] {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)) drop-shadow(0 1px 0 rgba(210, 200, 170, 0.35));
}
.creature-token b {
  position: absolute;
  right: -3px;
  top: -4px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  font: 700 10px/15px var(--sans);
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.cell > .creature-token ~ .creature-token { transform: translate(18%, 18%) scale(0.85); }
.cell > .creature-token ~ .creature-token ~ .creature-token { transform: translate(-18%, 18%) scale(0.85); }
.cell > .creature-token ~ .creature-token ~ .creature-token ~ .creature-token { transform: translate(0, -16%) scale(0.8); }
.creature-token.focus { z-index: 4; }
.creature-token.focus .sprite {
  filter: drop-shadow(0 0 6px var(--amber)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.creature-token.focus b { box-shadow: 0 0 0 2px var(--ink), 0 0 0 3px var(--amber); }
.creature-token.dazed { opacity: 0.7; }
.creature-token.dazed .sprite {
  filter: grayscale(0.5) brightness(0.72) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}
.creature-token.dazed b {
  border-radius: 3px;
  background: var(--muted);
  color: var(--ink);
}
.creature-token.dazed::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 1.5px dashed rgba(233, 236, 245, 0.5);
  border-radius: 50%;
  pointer-events: none;
}
.cell .coord {
  position: absolute;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0.7;
}
.cell .coord.row { left: 2px; top: 1px; }
.cell .coord.col { right: 3px; bottom: 0; }

.turnbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  max-width: 560px;
  margin: 10px auto 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(20, 26, 44, 0.94);
  font-size: 14px;
}
.turnbar .turn { color: var(--amber-2); font-variant-numeric: tabular-nums; }
.turnbar .turn b { font-family: var(--font); font-size: 18px; }
.turnbar .log { flex: 1 1 160px; min-width: 0; color: var(--muted); }

.tools { display: grid; gap: 12px; min-width: 0; }
.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 24, 40, 0.94);
  box-shadow: var(--shadow);
}
.label {
  margin-bottom: 6px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .wide { grid-column: 1 / -1; }
.actions .btn { width: 100%; }
#hold {
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.03em;
  min-height: 48px;
}
.pieces { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.piece-btn {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 44px;
  min-width: 0;
  padding: 6px 2px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 11px;
  touch-action: manipulation;
}
.piece-btn .piece-art .sprite { width: 28px; height: 28px; }
.piece-btn .piece-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.piece-btn .count { color: var(--amber-2); font-weight: 700; font-variant-numeric: tabular-nums; }
.piece-btn.selected {
  border-color: var(--amber);
  background: rgba(232, 176, 74, 0.1);
  box-shadow: 0 0 0 1px var(--amber) inset, 0 0 12px rgba(232, 176, 74, 0.28);
}
.piece-btn.selected .piece-name { color: var(--amber-2); }
.piece-btn.empty { opacity: 0.45; border-style: dashed; }
.piece-btn.empty .count { color: var(--muted); }
.piece-btn:disabled { cursor: not-allowed; }
.message { min-height: 0; margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.message:empty { margin: 0; }
.message.bad { color: var(--red); padding-left: 8px; border-left: 3px solid var(--red); }
.message.ok { color: var(--green); padding-left: 8px; border-left: 3px solid var(--green); }

.creatures { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.creature {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: 10px;
  background: rgba(233, 236, 245, 0.03);
  cursor: pointer;
}
.creature.focus {
  background: rgba(232, 176, 74, 0.12);
  box-shadow: inset 0 0 0 1px rgba(232, 176, 74, 0.6);
}
.creature.out {
  opacity: 0.62;
  border-left-style: dashed;
  border-left-color: var(--line-strong);
}
.creature.out .creature-art { filter: grayscale(0.65); }
.creature.out .token { background: var(--muted); border-radius: 4px; }
.creature-head { display: flex; align-items: center; gap: 10px; }
.creature .token {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  font-weight: 800;
  font-size: 12px;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.creature-art .sprite { width: 34px; height: 34px; }
.creature-name { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.creature-name b { font-size: 17px; }
.creature-name .meta { color: var(--muted); font-size: 12px; }
.creature .fate {
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.creature .rule {
  margin: 8px 0 0;
  color: var(--text);
  font-family: var(--font);
  font-size: 15.5px;
  font-style: italic;
  line-height: 1.4;
}
.coach { border-left: 3px solid var(--amber); }
.coach p { margin: 0 0 10px; font-size: 15px; }
.notebook summary {
  display: flex;
  align-items: center;
  min-height: 32px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}
.notebook summary::marker { color: var(--amber); }
.notebook[open] { border-color: var(--line-strong); }
.legend { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.legend b { color: var(--text); }

/* Actions pin to the bottom of the screen until the two-column desk takes over. */
.tools > .panel:has(> .actions) {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 35;
  margin: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border: 0;
  border-top: 1px solid rgba(232, 176, 74, 0.38);
  border-radius: 16px 16px 0 0;
  background: rgba(8, 11, 20, 0.96);
  box-shadow: 0 -14px 36px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}
body:has(.watch) footer { padding-bottom: calc(172px + env(safe-area-inset-bottom)); }
@media (max-width: 1099px) {
  html:has(.watch) { scroll-padding-bottom: 180px; }
  .topnav { flex-basis: 100%; }
}

/* ---------- the end of a run ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 38%, rgba(48, 34, 70, 0.45), rgba(3, 4, 10, 0.92) 72%);
  animation: fade 0.22s ease;
  overflow: auto;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.closed {
  position: relative;
  width: min(540px, 100%);
  padding: 28px 22px 22px;
  border: 1px solid rgba(232, 176, 74, 0.42);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(232, 176, 74, 0.06), transparent 28%),
    linear-gradient(180deg, #1c2338, #101628);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.65);
  overflow: visible;
}
.closed .stamp {
  display: inline-block;
  margin: 4px 0 14px;
  padding: 8px 13px 6px;
  border: 3px double var(--red-ink);
  border-radius: 4px;
  background:
    repeating-linear-gradient(-18deg, rgba(142, 47, 42, 0.07) 0 2px, transparent 2px 5px),
    #f3e6d2;
  color: var(--red-ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
  transform: rotate(-6deg);
  box-shadow: 2px 3px 0 rgba(142, 47, 42, 0.22);
}
.closed h2 { margin: 2px 0 6px; font-size: clamp(26px, 5vw, 32px); }
.closed .legend { color: var(--text); }
.closed .facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.closed .fact {
  padding: 10px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 15, 28, 0.55);
  text-align: center;
}
.closed .fact b { display: block; font-size: 22px; color: var(--amber-2); }
.closed .fact span { color: var(--muted); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
.closed pre {
  margin: 0 0 12px;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b0f1c;
  color: var(--text);
  font: 13px/1.55 var(--mono);
  white-space: pre-wrap;
}
.closed .close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
}
.closed .close:hover { background: rgba(233, 236, 245, 0.06); color: var(--text); }

/* ---------- record and prose ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 20px; }
.stat {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 30px; line-height: 1.1; color: var(--amber-2); }
.stat span { color: var(--muted); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
table.tiers-table { width: 100%; max-width: 560px; border-collapse: collapse; }
table.tiers-table td, table.tiers-table th { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.tiers-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
table.tiers-table tbody tr:hover { background: rgba(232, 176, 74, 0.06); }
.prose { max-width: 68ch; }
.prose h1 {
  margin: 8px 0 12px;
  font-size: clamp(32px, 6vw, 52px);
  letter-spacing: -0.02em;
  line-height: 1.08;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.4);
}
.prose h2 { margin: 28px 0 8px; font-size: 26px; }
.prose p, .prose li { color: #dde1ee; }
.prose li::marker { color: var(--amber); }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose a { text-underline-offset: 3px; }
footer {
  border-top: 1px solid var(--line);
  padding: 18px 16px 28px;
  color: var(--muted);
  font-size: 14px;
  background: rgba(0, 0, 0, 0.18);
}
footer .inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
  max-width: var(--max);
  margin: 0 auto;
}
footer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-right: 8px;
  color: var(--muted);
  text-decoration: none;
}
footer a:hover { color: var(--text); text-decoration: underline; }

/* ---------- breakpoints ---------- */
@media (min-width: 720px) {
  main { padding: 22px 20px 48px; }
  .topbar { padding-right: 18px; padding-left: 18px; }
  .board { padding: 8px; gap: 4px; }
  .piece-btn { font-size: 12px; }
  .piece-btn .piece-art .sprite { width: 34px; height: 34px; }
}
@media (min-width: 1100px) {
  .topnav { flex: 0 1 auto; margin-left: auto; flex-wrap: nowrap; }
  .topnav .up {
    margin-left: 4px;
    padding-left: 14px;
    border-left: 1px solid var(--line);
    border-radius: 0;
  }
  .yard { grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; }
  .tools {
    position: sticky;
    top: 78px;
    max-height: calc(100vh - 90px);
    overflow: auto;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
  }
  .tools > .panel:has(> .actions) {
    position: static;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(18, 24, 40, 0.94);
    box-shadow: var(--shadow);
    backdrop-filter: none;
  }
  body:has(.watch) footer { padding-bottom: 28px; }
}
@media (max-width: 719px) {
  body { background-attachment: scroll; }
  .topbar {
    flex-wrap: nowrap;
    gap: 8px;
    padding: 4px 0 4px 10px;
    padding-top: calc(4px + env(safe-area-inset-top));
  }
  .brand { flex: 0 0 auto; min-height: 40px; padding-left: 16px; font-size: 16px; letter-spacing: 0.16em; }
  .brand::before { top: 12px; width: 9px; height: 9px; }
  .brand small { display: none; }
  .topnav {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    min-width: 0;
    padding-right: 20px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav a, .topnav button {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 8px;
    font-size: 13px;
    white-space: nowrap;
  }
  html { scroll-padding-top: 58px; }
  .creature .rule { font-size: 14.5px; }
  .cell .coord { display: none; }
  .hero { padding-top: 16px; }
  .closed .stamp { font-size: 15px; letter-spacing: 0.12em; }
}
@media (max-width: 400px) {
  .closed .fact b { font-size: 20px; }
  .closed .stamp { padding: 7px 10px 5px; }
}
@media (hover: hover) and (pointer: fine) {
  .mode, .btn, .piece-btn { transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease; }
  .mode:hover { transform: translateY(-2px); border-color: var(--amber); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after { animation: none !important; transition: none !important; }

/* Compact dock on phones and tablets: the bank and the actions share the pinned bar without covering the board. */
@media (max-width: 1099px) {
  .dock .label { display: none; }
  .dock .pieces { gap: 6px; margin-bottom: 8px; }
  .dock .piece-btn {
    grid-auto-flow: column;
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 4px 6px;
  }
  .dock .piece-btn .piece-name { display: none; }
  .dock .piece-btn .piece-art { display: grid; place-items: center; }
  .dock .piece-btn .piece-art .sprite { width: 26px; height: 26px; }
  .dock .piece-btn .count { font-size: 14px; }
  .dock .actions { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .dock .actions .wide { grid-column: 1 / -1; }
  .dock .actions .btn { min-height: 42px; padding: 8px 6px; font-size: 14px; }
  .dock #hold { min-height: 46px; }
  .dock .message { font-size: 13px; }
  body:has(.watch) footer { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }
  html:has(.watch) { scroll-padding-bottom: 200px; }
}

/* Static description under the app: readable without JavaScript, out of the way with it. */
.about-game { max-width: 68ch; margin: 36px auto 24px; padding: 0 16px; }
.about-game h2 { font-size: clamp(24px, 4vw, 34px); margin: 6px 0 10px; }
.about-game h3 { font-size: 18px; margin: 20px 0 6px; }
