:root {
  color-scheme: dark;
  --bg: #150d0a;
  --panel: rgb(33 22 17 / 0.94);
  --panel-edge: #6b4a2e;
  --ink: #f4e7d1;
  --muted: #c3ab8a;
  --gold: #e8b64c;
  --ember: #e0673a;
  --hp: #c9423a;
  --heal: #6ccf7f;
  --block: #6cb4ee;
  --poison: #b07cff;
  --energy: #f2a93b;
  --card-w: 128px;
  --card-h: 184px;
  --hand-h: 214px;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, "Iowan Old Style", Georgia, serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#table {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
}

/* --- Top bar ---------------------------------------------------------------- */

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: linear-gradient(rgb(12 7 5 / 0.92), rgb(12 7 5 / 0.6));
  border-bottom: 1px solid rgb(232 182 76 / 0.2);
  min-height: 48px;
}

#topbar .home {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.2rem;
  padding: 2px 6px;
  border-radius: 6px;
}

#topbar .home:hover { color: var(--ink); background: rgb(255 255 255 / 0.08); }
.brand { font-weight: 800; letter-spacing: 0.04em; color: var(--gold); }
.stat { white-space: nowrap; font-variant-numeric: tabular-nums; }
.floor { color: var(--muted); }
.spacer { flex: 1; }
body:not(.in-run) .run-only { display: none; }

.relics { display: flex; gap: 2px; flex-wrap: wrap; }
.relic {
  font: 20px/1 var(--emoji);
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(232 182 76 / 0.25);
  border-radius: 8px;
  padding: 3px 4px;
}

.icon {
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: 8px;
  padding: 4px 9px;
  min-width: 36px;
  min-height: 32px;
}

.icon:hover { background: rgb(255 255 255 / 0.14); }

/* --- Combat HUD ---------------------------------------------------------------- */

.hud {
  position: fixed;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.4);
}

/* The enemy's plaque and intents follow its painting (placed from main.js). */
#enemy-hud, #intent-panel {
  top: 0;
  left: 0;
  visibility: hidden;
}

#enemy-hud.placed, #intent-panel.placed { visibility: visible; }

#enemy-hud {
  padding: 3px 10px 6px;
  border: 1px solid #c89a44;
  border-radius: 4px 4px 12px 12px;
  background: linear-gradient(#2c180d, #150b06);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.6), 0 6px 18px rgb(0 0 0 / 0.55);
  transform: translate(-50%, -50%);
}

#enemy-hud .bar { height: 15px; }
#enemy-hud .bar span { font-size: 0.72rem; line-height: 13px; }
#enemy-hud .chip { margin-top: 0; padding: 0 6px; font-size: 0.7rem; }

.hud-title {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
  margin-bottom: 3px;
  font: 800 0.88rem/1.3 var(--serif);
  color: #f3dca4;
}

#intent-panel {
  padding: 5px 8px 6px;
  max-width: 190px;
  border-color: rgb(224 103 58 / 0.55);
}

#intent-panel:has(.intents:empty) { display: none; }

.intent-title {
  margin: 0 0 3px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.affix {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ember);
  cursor: help;
}

.bar {
  position: relative;
  height: 18px;
  border-radius: 9px;
  background: rgb(0 0 0 / 0.45);
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.12);
}

.bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: linear-gradient(#e0584d, #9e2a24);
  transition: width 0.3s ease;
}

.bar span {
  position: relative;
  display: block;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 16px;
  text-shadow: 0 1px 2px #000;
  font-variant-numeric: tabular-nums;
}

.statuses {
  display: flex;
  gap: 6px;
  justify-content: center;
  min-height: 0;
  flex-wrap: wrap;
}

.statuses:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 5px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: rgb(255 255 255 / 0.08);
  border: 1px solid rgb(255 255 255 / 0.14);
  white-space: nowrap;
}

.chip.block { color: #cfe7ff; border-color: var(--block); background: rgb(108 180 238 / 0.18); }
.chip.poison { color: #e3d0ff; border-color: var(--poison); background: rgb(176 124 255 / 0.18); }

.intents {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.intent {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 8px;
  background: rgb(224 103 58 / 0.16);
  border: 1px solid rgb(224 103 58 / 0.5);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: help;
  transition: transform 0.2s, background 0.2s;
}

.intent.now { transform: scale(1.06); background: rgb(224 103 58 / 0.55); }
.intent.done { opacity: 0.4; }

#player-hud {
  left: max(12px, env(safe-area-inset-left));
  bottom: calc(var(--hand-h) + 8px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  width: 270px;
}

.player-stats { flex: 1; min-width: 0; }
.player-stats .statuses { justify-content: flex-start; }
.bar.player .fill { background: linear-gradient(#e36b52, #a8321f); }

.energy {
  flex: none;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe3a0, var(--energy) 45%, #a4521a);
  border: 3px solid #5a3212;
  box-shadow: 0 0 18px rgb(242 169 59 / 0.5);
  color: #3b1d05;
  font-size: 1.25rem;
  font-weight: 900;
  cursor: help;
}

.energy.empty { filter: grayscale(0.8) brightness(0.7); box-shadow: none; }

.incoming {
  margin-top: 4px;
  padding: 3px 0;
  border: 0;
  background: none;
  text-align: left;
  font-size: 0.78rem;
  color: #ffb9a6;
}

.incoming:empty { display: none; }
.incoming:hover:not(:disabled) { text-decoration: underline; }
.incoming.danger { color: #ff8270; font-weight: 800; }
.incoming.safe { color: var(--heal); }
.forecast-lanes { list-style: none; padding: 0; color: var(--muted); }
.forecast-lanes li { margin: 4px 0; }

.warbands { border: 0; padding: 0; margin: 16px 0 8px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: left; }
.warbands legend { text-align: center; margin-bottom: 8px; color: var(--gold); }
.warband { display: flex; align-items: flex-start; gap: 6px; padding: 10px; border: 1px solid var(--panel-edge); border-radius: 10px; cursor: pointer; background: rgb(0 0 0 / 0.15); }
.warband:has(input:checked) { border-color: var(--gold); background: rgb(232 182 76 / 0.12); }
.warband input { flex: none; accent-color: var(--gold); margin: 4px 0 0; }
.warband b { display: block; color: var(--ink); }
.warband span span { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8rem; }
.starter-preview { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; color: var(--muted); font-size: 0.8rem; }
.starter-preview span { cursor: help; }
@media (max-width: 600px) {
  .warbands { grid-template-columns: 1fr; }
  .warband { padding: 7px 10px; }
  .warband span span { margin-top: 1px; }
}

.pile {
  position: fixed;
  z-index: 10;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 54px;
  padding: 6px 0;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  font-size: 1.2rem;
}

.pile b { font-size: 0.85rem; }
#pile-draw { left: max(12px, env(safe-area-inset-left)); }
#pile-discard { right: max(12px, env(safe-area-inset-right)); }

#end-turn {
  position: fixed;
  z-index: 10;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(var(--hand-h) + 8px);
  padding: 12px 22px;
  border-radius: 12px;
  border: 2px solid #8a5a1f;
  background: linear-gradient(#f0b54d, #c77a23);
  color: #2a1604;
  font-weight: 900;
  font-size: 1.05rem;
  box-shadow: 0 4px 0 #6d3f10, 0 8px 24px rgb(0 0 0 / 0.4);
}

#end-turn:hover:not(:disabled) { filter: brightness(1.08); }
#end-turn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #6d3f10; }
#end-turn:disabled { filter: grayscale(0.7) brightness(0.6); cursor: default; }
#end-turn.nudge { animation: nudge 1.4s ease-in-out infinite; }

@keyframes nudge {
  50% { box-shadow: 0 4px 0 #6d3f10, 0 0 26px 6px rgb(242 169 59 / 0.7); }
}

#hint {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(var(--hand-h) + 12px);
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.6);
  font-size: 0.85rem;
  color: var(--ink);
  pointer-events: none;
  white-space: nowrap;
}

#hint:empty { display: none; }

/* --- Cards ---------------------------------------------------------------------- */

#hand {
  position: fixed;
  z-index: 11;
  left: 76px;
  right: 76px;
  bottom: 0;
  height: var(--hand-h);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 30px;
  pointer-events: none;
}

.card {
  --frame: linear-gradient(150deg, #6b4a1f, #e8c67c 28%, #8a6028 52%, #f1d690 76%, #5e3f16);
  --plate: linear-gradient(#f6e8c6, #d5ba84);
  --box: linear-gradient(#f7eed8, #e6d3aa);
  --ink: #2c1c0c;
  --gem: #cfc6b4;
  position: relative;
  flex: none;
  width: var(--card-w);
  height: var(--card-h);
  padding: 5px 5px 6px;
  border: 0;
  border-radius: 10px;
  background: var(--frame);
  color: var(--ink);
  font-family: var(--serif);
  text-align: center;
  box-shadow: inset 0 0 0 1px rgb(255 240 200 / 0.45), inset 0 0 0 3px rgb(38 22 6 / 0.55), 0 6px 16px rgb(0 0 0 / 0.5);
  display: flex;
  flex-direction: column;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.card.spell {
  --frame: linear-gradient(150deg, #241a48, #9c8ad8 28%, #3a2a6a 52%, #b4a4ea 76%, #1e1640);
  --plate: linear-gradient(#ece6f8, #c9bde8);
  --box: linear-gradient(#f3eefa, #dcd2f0);
  --ink: #221a38;
}

.card.curse {
  --frame: linear-gradient(150deg, #1a181c, #5a5560 30%, #242128 55%, #6a6470 80%, #141216);
  --plate: linear-gradient(#5a5560, #3a3640);
  --box: linear-gradient(#3e3a44, #2a272e);
  --ink: #e6e0ea;
}

.card.starter { --gem: #a8916a; }
.card.uncommon { --gem: #5aa0e6; }
.card.rare {
  --gem: #f0b43c;
  box-shadow: inset 0 0 0 1px rgb(255 240 200 / 0.45), inset 0 0 0 3px rgb(38 22 6 / 0.55), 0 0 16px rgb(240 180 60 / 0.55), 0 6px 16px rgb(0 0 0 / 0.5);
}

.card .name {
  flex: none;
  height: 20px;
  margin: 0 0 0 14px;
  padding: 0 6px 0 12px;
  border-radius: 3px 10px 10px 3px;
  background: var(--plate);
  box-shadow: inset 0 0 0 1px rgb(40 24 8 / 0.5), 0 1px 2px rgb(0 0 0 / 0.4);
  font-weight: 700;
  font-size: 0.72rem;
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card.upgraded .name { color: #1f6a2a; }
.card.curse.upgraded .name, .card.spell.upgraded .name { color: #1f6a2a; }

.card .art {
  flex: none;
  aspect-ratio: 3 / 2;
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: #1a120c center / cover no-repeat;
  box-shadow: 0 0 0 1px rgb(255 232 170 / 0.6), inset 0 0 0 1px rgb(0 0 0 / 0.6), inset 0 0 14px rgb(0 0 0 / 0.55);
  font: 36px/1 var(--emoji);
}

.card .type {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 15px;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--plate);
  box-shadow: inset 0 0 0 1px rgb(40 24 8 / 0.45);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.card .gem {
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  background: var(--gem);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.55), 0 0 4px var(--gem);
}

.card .text {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--box);
  box-shadow: inset 0 0 0 1px rgb(40 24 8 / 0.35), inset 0 0 10px rgb(90 60 20 / 0.18);
  font-size: 0.64rem;
  line-height: 1.2;
  overflow: hidden;
}

.card.unit .text { padding: 2px 16px 6px; }
.card .text b { font-weight: 800; }

.card .cost, .card .atk, .card .hp {
  position: absolute;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: #fff;
  font: 900 1rem/1 system-ui, sans-serif;
  text-shadow: 0 0 2px #000, 0 1px 0 #000, 0 0 4px #000;
  box-shadow: 0 0 0 2px #2a1706, 0 0 0 3px rgb(255 236 190 / 0.6), 0 2px 5px rgb(0 0 0 / 0.6);
  z-index: 1;
}

.card .cost {
  top: -6px;
  left: -6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff1c4, var(--energy) 45%, #8a3c0e);
}

.card .atk {
  bottom: -6px;
  left: -6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff0b0, #e3a52c 55%, #7a4808);
}

.card .hp {
  bottom: -6px;
  right: -6px;
  border-radius: 50% 50% 50% 50% / 42% 42% 58% 58%;
  background: radial-gradient(circle at 35% 35%, #ffb0a0, #d4382a 55%, #5e0d08);
}

.priced {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.price { font-weight: 800; color: var(--gold); }

.card .affix-tag {
  position: absolute;
  top: 30px;
  right: 9px;
  padding: 1px 3px;
  border-radius: 6px;
  background: rgb(20 10 4 / 0.75);
  font: 0.7rem/1 var(--emoji);
}

/* Each card sits in a slot that keeps the card's resting place and owns the
   hover, so a raised card never slides out from under the pointer. */
#hand .hand-slot {
  position: relative;
  flex: none;
  pointer-events: auto;
  margin: 0 calc(var(--overlap, -18px) / 2);
  transform: translateY(calc(var(--lift, 0px) + var(--peek, 0px))) rotate(var(--rot, 0deg));
  transform-origin: 50% 120%;
  animation: deal 0.3s ease-out backwards;
  animation-delay: calc(var(--i) * 50ms);
}

#hand .hand-slot:hover, #hand .hand-slot:has(.selected) { z-index: 5; }

#hand .card {
  transform-origin: 50% 100%;
  transition: transform 0.15s ease, box-shadow 0.15s, filter 0.15s;
  cursor: grab;
}

@keyframes deal {
  from { transform: translate(-40vw, 60px) rotate(-30deg); opacity: 0; }
}

#hand .card.unplayable { filter: saturate(0.4) brightness(0.72); cursor: not-allowed; }
#hand .card.playable { box-shadow: 0 0 0 2px rgb(255 214 110 / 0.8), 0 0 16px rgb(255 190 80 / 0.55), 0 6px 16px rgb(0 0 0 / 0.45); }

/* On roomy desktop screens the hand rests partly below the edge, like
   Hearthstone, and rises when you point at it. */
@media (hover: hover) and (min-width: 900px) and (min-height: 600px) {
  :root { --hand-h: 136px; }
  #hand { padding-bottom: 0; }
  #hand .hand-slot { --peek: 58px; }
}

/* Raised cards stand upright with their bottom just above the screen edge. */
@media (hover: hover) {
  #hand .hand-slot:hover .card {
    transform: translateY(calc(-1 * (var(--peek, 0px) + var(--lift, 0px)) - 12px)) rotate(calc(-1 * var(--rot, 0deg))) scale(1.35);
  }
}

#hand .card.selected, #hand .hand-slot:hover .card.selected {
  transform: translateY(calc(-1 * (var(--peek, 0px) + var(--lift, 0px)) - 18px)) rotate(calc(-1 * var(--rot, 0deg))) scale(1.2);
  box-shadow: 0 0 0 3px #fff2b0, 0 0 26px rgb(255 214 110 / 0.9);
}

#hand .card.dragging {
  position: fixed;
  z-index: 50;
  margin: 0;
  transition: none;
  animation: none;
  pointer-events: none;
  opacity: 0.92;
}

#hand .card.gone { visibility: hidden; }

/* --- Banner, floaters, flash ------------------------------------------------------ */

#banner {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  top: 42%;
  text-align: center;
  font-size: clamp(1.8rem, 6vw, 3.4rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #ffe2a6;
  text-shadow: 0 0 24px rgb(255 140 50 / 0.8), 0 3px 0 #5a2a0c;
  pointer-events: none;
  opacity: 0;
}

#banner.show { animation: banner 1.1s ease-out; }

@keyframes banner {
  0% { opacity: 0; transform: scale(1.4); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px); }
}

#flash {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  box-shadow: inset 0 0 120px 30px rgb(200 20 20 / 0.7);
  opacity: 0;
}

#flash.show { animation: flash 0.5s ease-out; }
@keyframes flash { 20% { opacity: 1; } }

#fx { position: fixed; inset: 0; z-index: 26; pointer-events: none; }

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 1.6rem;
  white-space: nowrap;
  text-shadow: 0 2px 0 #000, 0 0 10px rgb(0 0 0 / 0.8);
  animation: float 1s ease-out forwards;
}

.float.dmg { color: #ff6b57; }
.float.big { font-size: 2.3rem; }
.float.heal { color: var(--heal); }
.float.block { color: var(--block); }
.float.poison { color: var(--poison); }
.float.buff { color: #ffd35a; font-size: 1.2rem; }
.float.info { color: #fff; font-size: 1rem; }

@keyframes float {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}

/* --- Screens ------------------------------------------------------------------------ */

#screen {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 60px 12px 12px;
  background: radial-gradient(rgb(20 12 9 / 0.55), rgb(10 6 4 / 0.88));
  overflow-y: auto;
}

#screen[hidden] { display: none; }

.panel {
  width: min(880px, 100%);
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.6);
  text-align: center;
  animation: rise 0.3s ease-out;
}

@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

.panel h1, .panel h2 { margin: 0 0 6px; }
.panel h2 { font-size: 1.6rem; color: var(--gold); }
.panel p { margin: 6px 0; color: var(--muted); }
.panel .lead { color: var(--ink); }
.big-art { font: 64px/1.1 var(--emoji); margin: 4px 0; }

.showcase {
  display: flex;
  justify-content: center;
  margin: 4px 0 10px;
  pointer-events: none;
}

.showcase .card { margin: 0 -14px; transform-origin: 50% 110%; }
.showcase .card:nth-child(1) { transform: rotate(-9deg) translateY(10px); }
.showcase .card:nth-child(2) { transform: translateY(-6px); z-index: 1; }
.showcase .card:nth-child(3) { transform: rotate(9deg) translateY(10px); }

.logo {
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  margin: 0;
  background: linear-gradient(#ffe7a8, #f0a13c 55%, #c2502a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #4a200a);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 14px 0;
}

.btn {
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgb(255 255 255 / 0.06);
  font-weight: 700;
}

.btn:hover:not(:disabled) { background: rgb(255 255 255 / 0.14); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(#f0b54d, #c77a23);
  border-color: #8a5a1f;
  color: #2a1604;
}

.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(460px, 100%);
  margin: 8px auto;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: rgb(255 255 255 / 0.05);
  text-align: left;
}

.choice:hover:not(:disabled) { background: rgb(255 255 255 / 0.12); border-color: var(--gold); }
.choice:disabled { opacity: 0.45; cursor: not-allowed; }
.choice .emoji { font: 30px/1 var(--emoji); flex: none; }
.choice b { display: block; }
.choice small { color: var(--muted); }
.choice.taken { opacity: 0.4; text-decoration: line-through; }

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin: 12px 0;
}

.card-row .card { transition: transform 0.15s, opacity 0.2s; }
.card-row .card:hover:not([aria-disabled="true"]) { transform: translateY(-6px) scale(1.06); }
.card-row .card[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }
.card-row .card.picked { outline: 3px solid var(--gold); }

.seed {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.seed input {
  width: 180px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-edge);
  background: rgb(0 0 0 / 0.35);
  color: var(--ink);
  font: inherit;
}

details.how {
  max-width: 620px;
  margin: 10px auto 0;
  text-align: left;
  color: var(--muted);
}

details.how summary { cursor: pointer; color: var(--ink); text-align: center; }
details.how li { margin: 4px 0; }

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats b { color: var(--ink); }

/* --- Map scroll and card spread ----------------------------------------------------- */

/* The map itself is a scroll on the 3D table. These are the bits around it. */
.map-choices {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 12;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  transform: translateX(-50%);
}

/* Only there for keyboards and screen readers until one of its buttons has focus. */
.map-choices:not(:focus-within) {
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#map-hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 12;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgb(20 12 8 / 0.8);
  color: var(--muted);
  font-size: 0.85rem;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

/* While the map is unrolled for a look, the fight's HUD and any screen step aside. */
#combat, #screen { transition: opacity 0.25s; }
body.map-peek #combat, body.map-peek #screen { opacity: 0; pointer-events: none; }
body.map-peek #map-hint { opacity: 1; transition-delay: 0.6s; }

/* Cards dealt out of their stack on the table, hovering over the board. */
#cards-view {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 64px 16px 32px;
  background: radial-gradient(ellipse at 50% 55%, rgb(12 7 4 / 0.35), rgb(8 5 3 / 0.8));
  animation: fade-in 0.25s ease-out;
}

#cards-view[hidden] { display: none; }
#cards-view.closing { opacity: 0; transition: opacity 0.3s 0.1s; pointer-events: none; }

@keyframes fade-in { from { opacity: 0; } }

.cards-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 4px 14px;
  /* Auto margins centre the spread over the board, and still let a big deck scroll. */
  margin: auto auto 14px;
  text-shadow: 0 2px 8px rgb(0 0 0 / 0.8);
}

.cards-head h2 { margin: 0; font: 800 1.6rem var(--serif); color: var(--gold); }
.cards-head p { margin: 0; color: var(--muted); }

.cards-spread {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  max-width: 1180px;
  margin: 0 auto auto;
  /* Tipped back a little, as if the cards were hovering over the table. */
  transform: perspective(1600px) rotateX(9deg);
  transform-origin: 50% 100%;
}

.cards-spread .card { box-shadow: 0 14px 28px rgb(0 0 0 / 0.55); }
.cards-spread .empty { color: var(--muted); }

/* --- Modal and tooltip ------------------------------------------------------------------ */

#modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgb(0 0 0 / 0.65);
}

#modal[hidden] { display: none; }

.modal-card {
  position: relative;
  width: min(900px, 100%);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  text-align: center;
}

.modal-card h2 { margin: 0 0 4px; color: var(--gold); }
.modal-card .close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  background: none;
  font-size: 1.2rem;
  color: var(--muted);
}

#tooltip {
  position: fixed;
  z-index: 60;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgb(14 9 7 / 0.96);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.5);
  font-size: 0.85rem;
  pointer-events: none;
}

#tooltip b { color: var(--gold); }
#tooltip p { margin: 4px 0 0; color: var(--ink); }
#tooltip .kw { color: var(--muted); font-size: 0.8rem; }

.noscript { position: fixed; inset: 40% 0 auto; text-align: center; }

/* --- Small screens ------------------------------------------------------------------------ */

@media (max-width: 700px), (max-height: 560px) {
  :root { --card-w: 90px; --card-h: 132px; --hand-h: 164px; }
  .card { padding: 3px 3px 4px; gap: 2px; border-radius: 8px; }
  .card .name { height: 15px; line-height: 15px; font-size: 0.58rem; margin-left: 10px; padding-left: 9px; }
  .card .type { display: none; }
  .card .art { font-size: 26px; }
  .card .text { font-size: 0.52rem; padding: 1px 4px; }
  .card.unit .text { padding: 1px 10px 5px; }
  .card .cost, .card .atk, .card .hp { width: 22px; height: 22px; font-size: 0.78rem; }
  .card .affix-tag { top: 22px; right: 6px; }
  #hand { left: 4px; right: 4px; }
  .pile { width: 42px; padding: 3px 0; font-size: 0.9rem; bottom: calc(var(--hand-h) + 66px); }
  #player-hud { width: auto; max-width: calc(100vw - 150px); padding: 5px 8px 5px 5px; gap: 6px; }
  .energy { width: 42px; height: 42px; font-size: 1rem; }
  #end-turn { padding: 9px 14px; font-size: 0.95rem; }
  .hud-title { font-size: 0.74rem; }
  #intent-panel { max-width: 150px; padding: 4px 6px; }
  .brand { display: none; }
  #topbar { gap: 8px; font-size: 0.9rem; }
  .relics { display: none; }
  .intent { font-size: 0.78rem; padding: 2px 8px; }
  .float { font-size: 1.3rem; }
}

@media (max-width: 420px) {
  #topbar .floor { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #hand .hand-slot, .panel, #cards-view, #end-turn.nudge { animation: none; }
  #hand .card, .card-row .card { transition: none; }
}

/* --- Coach: tutorial steps and first-time tips -------------------------------- */

#coach {
  position: fixed;
  z-index: 35;
  left: 0;
  top: 0;
  width: min(330px, calc(100vw - 24px));
  padding: 12px 14px 10px;
  border-radius: 14px;
  background: linear-gradient(rgb(52 33 22 / 0.98), rgb(33 22 17 / 0.98));
  border: 2px solid var(--gold);
  box-shadow: 0 10px 32px rgb(0 0 0 / 0.55), 0 0 22px rgb(232 182 76 / 0.25);
  font-size: 0.92rem;
  transition: opacity 0.2s;
}

#coach[hidden] { display: none; }
#coach p { margin: 0 0 8px; color: var(--ink); }
#coach b { color: var(--gold); }
#coach.shake { animation: coach-shake 0.4s; }

.coach-row { display: flex; align-items: center; gap: 10px; }
.coach-row .btn { padding: 6px 14px; margin-left: auto; }
.coach-row .btn[hidden] { display: none; }
#coach-count { color: var(--muted); font-size: 0.78rem; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: underline;
}

.link:hover { color: var(--ink); }
.link[hidden] { display: none; }

#coach-ring {
  position: fixed;
  z-index: 34;
  border: 3px solid var(--gold);
  border-radius: 14px;
  box-shadow: 0 0 0 4px rgb(232 182 76 / 0.25), 0 0 24px rgb(232 182 76 / 0.6);
  pointer-events: none;
  animation: coach-pulse 1.3s ease-in-out infinite;
}

#coach-ring[hidden] { display: none; }

#hand .card.coach-pick { animation: coach-card 1.1s ease-in-out infinite; }

@keyframes coach-pulse { 50% { transform: scale(1.06); opacity: 0.75; } }
@keyframes coach-card { 50% { box-shadow: 0 0 0 3px var(--gold), 0 0 26px rgb(255 200 90 / 0.9); } }
@keyframes coach-shake { 25% { translate: -6px 0; } 75% { translate: 6px 0; } }

/* The tutorial is a single fight: hide what only matters in a run. */
body.tutorial #btn-deck, body.tutorial #btn-map, body.tutorial #top-floor,
body.tutorial .gold, body.tutorial #relics { display: none; }

.kindling {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.kindling .btn { padding: 2px 12px; }
.kindling b { color: var(--ember); min-width: 1.5em; }
.kindling-rules { margin: 4px auto 0; max-width: 460px; padding-left: 18px; text-align: left; font-size: 0.82rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  #coach-ring, #hand .card.coach-pick { animation: none; }
}
