* { box-sizing: border-box; }

/* Warcraft II-flavoured: carved stone panels with gold trim and rivets, serif gold lettering,
   icon cards for units, and a soft mud battlefield. */
:root {
  --page: #0e0a06;
  --panel-hi: #3d3226;
  --panel-lo: #241c13;
  --inset: #150f09;
  --stone-hi: #74624a;
  --stone-lo: #42362a;
  --edge: #0f0a05;
  --gold: #e3b94f;
  --gold-hi: #ffe08a;
  --gold-lo: #8c6522;
  --parch: #eadfc4;
  --muted: #b4a27e;
  --dim: #7b6b52;
  --ember: #ff5b3d;
  --moss: #4fe35f;
  --sky: #29adff;
  --wall: #4a3121;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: 'Alegreya', Georgia, 'Times New Roman', serif;
  --sym: 'Segoe UI Symbol', 'Noto Sans Symbols 2', 'Apple Symbols', 'DejaVu Sans', serif;
  --bevel: inset 2px 2px 0 rgba(255, 236, 190, 0.28), inset -2px -2px 0 rgba(0, 0, 0, 0.45);
  --rivet: radial-gradient(circle, var(--gold-hi) 0 1.5px, var(--gold-lo) 2.5px, transparent 3.5px);
  --outline: -2px 0 #000, 2px 0 #000, 0 -2px #000, 0 2px #000;
}

html { background: var(--page); }

body {
  margin: 0;
  padding: 0 12px 40px;
  min-height: 100vh;
  color: var(--parch);
  font-family: var(--body);
  font-size: 18px;
  font-variant-numeric: lining-nums; /* Alegreya's old-style 0 reads as an "o" */
  background-color: var(--page);
  background-image:
    radial-gradient(rgba(255, 214, 140, 0.035) 1px, transparent 1.6px),
    radial-gradient(ellipse at 50% -10%, #2b2116 0%, var(--page) 65%);
  background-size: 7px 7px, 100% 100%;
  background-attachment: fixed;
}
/* a soft vignette, like the edge of the fog of war */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  background: radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.5) 100%);
}

/* ---------- Sticky top bar (logo, tabs, HUD, controls) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  margin: 0 -12px;
  padding: 12px 12px 18px;
  background: linear-gradient(var(--page) 88%, rgba(14, 10, 6, 0));
}
.hud { padding-top: 14px; padding-bottom: 14px; }
.hud .playhead { margin-bottom: 12px; }
.hud .controls { margin-bottom: 0; gap: 4px; }
.hud .controls .btn { padding-left: 10px; padding-right: 10px; }

/* ---------- Header ---------- */
header {
  max-width: 1180px;
  margin: 0 auto 12px;
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px;
}
.logo {
  margin: 0;
  font-family: var(--display);
  font-size: 40px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 8px;
  color: var(--gold);
  background: linear-gradient(180deg, #fff4c2 0%, var(--gold) 46%, #8a5d18 54%, #f2cc66 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(2px 3px 0 var(--edge));
}
.tagline {
  margin-top: 6px;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
}
.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
nav { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Buttons: carved stone, gold lettering ---------- */
.btn,
.tab,
.palette button,
.pool-row button {
  margin: 2px;
  padding: 8px 12px;
  border: 2px solid var(--edge);
  border-radius: 3px;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--gold-hi);
  text-shadow: 1px 1px 0 var(--edge);
  background: linear-gradient(var(--stone-hi), var(--stone-lo));
  cursor: pointer;
  box-shadow: var(--bevel), 0 2px 0 rgba(0, 0, 0, 0.5);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover, .tab:hover, .palette button:hover, .pool-row button:hover { filter: brightness(1.15); }
.btn:active:not(:disabled), .tab:active, .palette button:active, .pool-row button:active {
  transform: translateY(1px);
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.45), inset -1px -1px 0 rgba(255, 236, 190, 0.15);
}
.btn.primary { background: linear-gradient(#94722c, #5a4216); color: #fff3c4; }
.btn.accent { background: linear-gradient(#a8742a, #6a4412); color: #fff3c4; }
.btn.blue { background: linear-gradient(#3d6cb4, #22427a); color: #fff; }
.btn.red { background: linear-gradient(#b8352a, #6e1810); color: #fff; }
.btn.ghost { background: linear-gradient(#55483a, #2f271e); color: var(--muted); }
.btn:disabled {
  background: linear-gradient(#3a332b, #262019);
  color: #6b5f4e;
  text-shadow: none;
  cursor: default;
  filter: none;
  box-shadow: none;
}
.tab { background: linear-gradient(#4b3f31, #2e261d); color: var(--muted); }
.tab.active {
  background: linear-gradient(#9a7a34, #5e4515);
  color: #fff3c4;
  box-shadow: var(--bevel), 0 0 10px rgba(227, 185, 79, 0.45);
}
.btn.on {
  outline: 2px solid var(--gold-hi);
  outline-offset: 3px;
  box-shadow: var(--bevel), 0 0 14px rgba(255, 224, 138, 0.55);
}

/* ---------- Panels: stone slab, gold trim, corner rivets ---------- */
.card {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 22px;
  border: 2px solid var(--edge);
  border-radius: 4px;
  background:
    var(--rivet) top 5px left 5px / 10px 10px no-repeat,
    var(--rivet) top 5px right 5px / 10px 10px no-repeat,
    var(--rivet) bottom 5px left 5px / 10px 10px no-repeat,
    var(--rivet) bottom 5px right 5px / 10px 10px no-repeat,
    repeating-linear-gradient(115deg, rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 6px),
    radial-gradient(ellipse at 30% 0%, rgba(255, 230, 180, 0.06), transparent 60%),
    linear-gradient(var(--panel-hi), var(--panel-lo));
  box-shadow:
    inset 0 0 0 2px var(--gold-lo), inset 0 0 0 3px var(--gold), inset 0 0 0 5px var(--edge),
    0 8px 24px rgba(0, 0, 0, 0.65);
}
.hidden { display: none !important; }

/* sunken inner panels (army, legend, coming up, scores) */
.army, .legend, .nextpanel, .leaderboard, .powers {
  background: var(--inset);
  border: 1px solid var(--gold-lo);
  border-radius: 3px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.75), 0 0 0 1px var(--edge);
}

.playhead {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gold-lo);
  box-shadow: 0 1px 0 var(--edge);
}
#puzzleName {
  margin: 0;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.4;
  color: var(--gold-hi);
  text-shadow: 1px 2px 0 var(--edge);
}

/* resource bar */
.stats { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; }
.stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 62px;
  padding: 4px 10px 5px;
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--inset);
  border: 1px solid var(--gold-lo);
  border-radius: 3px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}
.stat b {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold-hi);
  text-shadow: 1px 1px 0 var(--edge);
  font-variant-numeric: tabular-nums;
}
/* this round's spend: the number to watch */
.stat-round {
  flex-direction: row; gap: 10px;
  padding: 4px 14px;
  border: 2px solid var(--gold);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6), 0 0 10px rgba(227, 185, 79, 0.35);
}
.stat-round .lbl { line-height: 1.2; text-align: right; }
.stat-round b { min-width: 1.4em; font-size: 28px; text-align: center; }
.stat-round em { font-style: normal; font-size: 13px; color: var(--ember); }
.stat-round em:empty { display: none; }
.stat-round.over {
  border-color: var(--ember);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6), 0 0 12px rgba(255, 91, 61, 0.55);
}
.stat-round.over b { color: var(--ember); }

.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 16px;
}
select, input[type="text"] {
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--gold-lo);
  border-radius: 3px;
  font-family: var(--body);
  font-size: 17px;
  color: var(--parch);
  background: var(--inset);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}
select:focus, input[type="text"]:focus { outline: 2px solid var(--gold); outline-offset: 0; }
#editName { flex: 1 1 140px; min-width: 0; }

/* ---------- Streak runs (normal + hardcore) ---------- */
.runmode #prevBtn, .runmode #bestBtn, .runmode .level-list { display: none; }
.runmode.hardcore #playView {
  box-shadow:
    inset 0 0 0 2px #5a140e, inset 0 0 0 3px var(--ember), inset 0 0 0 5px var(--edge),
    0 8px 24px rgba(0, 0, 0, 0.65), 0 0 22px rgba(179, 38, 27, 0.35);
}

/* ---------- Layout: legend/coming-up | board | army ---------- */
.board-row {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 286px;
  grid-template-areas: "side board army";
  gap: 22px;
  align-items: start;
}
.side-col { grid-area: side; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.board-col {
  grid-area: board;
  container-type: inline-size;
  display: flex; flex-direction: column; align-items: center;
  min-width: 0;
}
.army-col { grid-area: army; display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.sideboard-wrap { margin-bottom: 16px; }
.sideboard-label, .lg-title, .lb-title, .army-title {
  margin-bottom: 10px;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 1px 1px 0 var(--edge);
}

/* ---------- Army panel: unit icon cards ---------- */
.army { padding: 12px 12px 10px; }
.army-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(140, 101, 34, 0.6);
}
.army-title { margin: 0; font-size: 13px; }
.army-val {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.army-val b { font-size: 24px; color: var(--gold-hi); text-shadow: 1px 1px 0 var(--edge); }
.sideboard {
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 16px 14px;
  min-height: 92px;
  padding: 6px 4px 10px 6px;
}
.army-empty { align-self: center; font-style: italic; color: var(--dim); }
.army-foot {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(140, 101, 34, 0.4);
  font-size: 15px;
  color: var(--muted);
}
.army-foot b { font-family: var(--display); color: var(--gold-hi); }
.army-foot.over b { color: var(--ember); }

.unit {
  position: relative;
  flex: none;
  width: 64px; height: 82px;
  cursor: grab;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.unit.spent { cursor: default; }
.u-layer, .u-face {
  position: absolute; inset: 0;
  border: 2px solid var(--edge);
  border-radius: 4px;
  background: linear-gradient(var(--stone-hi), var(--stone-lo));
}
/* 3+ common units fold into one card; the ones underneath peek out diagonally */
.u-layer { border-color: #1c130a; box-shadow: var(--bevel), 0 0 0 1px rgba(227, 185, 79, 0.35); }
.u-layer.l1 { transform: translate(6px, 6px); filter: brightness(0.85); }
.u-layer.l2 { transform: translate(12px, 12px); filter: brightness(0.7); }
.u-face {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 3px;
  box-shadow: var(--bevel), 0 3px 6px rgba(0, 0, 0, 0.6);
}
.u-key {
  position: absolute; top: 1px; left: 4px; z-index: 1;
  font-family: var(--display);
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  text-shadow: 1px 1px 0 #000;
}
.u-port {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 44px;
  background: radial-gradient(circle at 50% 40%, #2e2418, #0d0905);
  border: 1px solid var(--edge);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 190, 0.12), inset 0 2px 6px rgba(0, 0, 0, 0.8);
}
.u-port .pglyph {
  font-family: var(--sym);
  font-size: 30px;
  line-height: 1;
  color: var(--parch);
  text-shadow: 0 2px 0 #000;
  pointer-events: none;
}
.u-name {
  margin-top: 3px;
  font-family: var(--display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--parch);
  text-shadow: 1px 1px 0 #000;
}
/* point cost as pips under the portrait, like a health bar */
.u-pips { display: flex; gap: 1px; margin-top: 3px; }
.u-pips i { display: block; width: 5px; height: 4px; background: var(--moss); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7); }
.unit .pcount {
  position: absolute; top: -9px; right: -9px; z-index: 2;
  min-width: 24px;
  padding: 2px 5px;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: linear-gradient(#c0392b, #7a1a12);
  border: 2px solid var(--edge);
  border-radius: 10px;
  pointer-events: none;
}
.unit:not(.spent):hover .u-face { filter: brightness(1.15); }
/* selected: the green selection ring */
.unit.selected .u-face { outline: 2px solid var(--moss); outline-offset: 2px; }

/* elite (gold) and legendary (red) units glow so you feel it when you spend them */
.unit.tier-gold .u-face {
  background: linear-gradient(#b8913a, #6a4b14);
  border-color: #3a2806;
  box-shadow: var(--bevel), 0 0 0 1px var(--gold-hi), 0 0 12px 2px rgba(255, 205, 70, 0.55);
  animation: goldGlow 2.4s ease-in-out infinite;
}
.unit.tier-gold .pglyph { color: var(--gold-hi); text-shadow: 0 0 6px rgba(255, 210, 80, 0.9), 0 2px 0 #000; }
.unit.tier-gold .u-name { color: #fff3c4; }
.unit.tier-gold .u-pips i { background: var(--gold-hi); }
.unit.tier-red .u-face {
  background: linear-gradient(#a8321f, #4e0f08);
  border-color: #2a0603;
  box-shadow: var(--bevel), 0 0 0 1px var(--ember), 0 0 14px 3px rgba(255, 60, 30, 0.6);
  animation: emberGlow 1.8s ease-in-out infinite;
}
.unit.tier-red .pglyph { color: #ff8a6a; text-shadow: 0 0 8px rgba(255, 70, 40, 0.95), 0 2px 0 #000; }
.unit.tier-red .u-name { color: #ffd2c4; }
.unit.tier-red .u-pips i { background: var(--ember); }
@keyframes goldGlow {
  50% { box-shadow: var(--bevel), 0 0 0 1px var(--gold-hi), 0 0 20px 5px rgba(255, 205, 70, 0.8); }
}
@keyframes emberGlow {
  50% { box-shadow: var(--bevel), 0 0 0 1px var(--ember), 0 0 22px 6px rgba(255, 60, 30, 0.85); }
}
/* already deployed on this board */
.unit.spent { opacity: 0.55; }
.unit.spent .u-face, .unit.spent .u-layer {
  filter: grayscale(1) brightness(0.55);
  animation: none;
  box-shadow: var(--bevel);
}

.drag-ghost {
  position: fixed; z-index: 100;
  pointer-events: none;
  font-family: var(--sym);
  font-size: 40px;
  color: var(--parch);
  transform: translate(-50%, -60%);
  text-shadow: var(--outline), 5px 5px 0 rgba(0, 0, 0, 0.5);
}
.drag-ghost.tier-gold { color: var(--gold-hi); text-shadow: var(--outline), 0 0 14px rgba(255, 205, 70, 1); }
.drag-ghost.tier-red { color: #ff8a6a; text-shadow: var(--outline), 0 0 16px rgba(255, 60, 30, 1); }

/* ---------- Board: soft mud, no checkerboard ---------- */
.board {
  --cell: min(72px, calc((100vw - 64px) / var(--n, 5)));
  display: grid;
  grid-template-columns: repeat(var(--n, 5), var(--cell));
  width: fit-content;
  margin: 8px auto;
  border: 4px solid var(--edge);
  box-shadow: 0 0 0 3px var(--gold-lo), 0 0 0 4px var(--gold), 0 0 0 7px var(--edge),
    0 10px 24px rgba(0, 0, 0, 0.6);
  user-select: none; -webkit-user-select: none;
}
/* sized to the column and, on wide screens, to the window height under the sticky top bar */
.board-col .board, .edit-board-wrap .board {
  --cell: min(72px, calc((100cqi - 24px) / var(--n, 5)));
}
@media (min-width: 721px) {
  .board-col .board, .edit-board-wrap .board {
    --cell: max(40px, min(72px, calc((100cqi - 24px) / var(--n, 5)), calc((100vh - 290px) / var(--n, 5))));
  }
}
@media (min-width: 721px) and (max-height: 820px) {
  .tagline { display: none; }
  .logo { font-size: 30px; }
  .topbar { padding-top: 8px; padding-bottom: 12px; }
  header { margin-bottom: 8px; }
  .hud { padding-top: 10px; padding-bottom: 10px; }
  .hud .playhead { margin-bottom: 8px; padding-bottom: 8px; }
}
.edit-board-wrap { container-type: inline-size; }
.cell {
  position: relative;
  width: var(--cell); height: var(--cell);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell) * 0.64);
  cursor: pointer;
  touch-action: none;
  /* --tone (0-4, set per square) nudges the mud a shade lighter or redder */
  background-color: hsl(calc(29 + var(--tone, 2) * 1.5) 27% calc(47% + var(--tone, 2) * 1.8%));
  box-shadow: inset 0 0 0 1px rgba(60, 38, 18, 0.22);
}
.cell.covered {
  background-color: hsl(calc(92 + var(--tone, 2) * 3) 30% calc(36% + var(--tone, 2) * 1.5%));
}
/* a tiled square reads as a finished block: solid green frame + bevel */
.cell.covered::before {
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  border: 3px solid var(--moss);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.22), inset -2px -2px 0 rgba(0, 0, 0, 0.25);
}
/* your elite / legendary units ring their square; the ring sits under the green "tiled"
   frame, so a tiled square reads green-then-gold and an untiled one plain gold */
.cell.t-gold { box-shadow: inset 0 0 0 6px var(--gold-hi), inset 0 0 18px 6px rgba(255, 205, 70, 0.55); }
.cell.t-red { box-shadow: inset 0 0 0 6px var(--ember), inset 0 0 20px 7px rgba(255, 60, 30, 0.6); }

/* barriers: darker brown, same brick markings */
.cell.wall, .sw-wall {
  background-color: var(--wall);
  background-image:
    linear-gradient(rgba(18, 10, 4, 0.85) 2px, transparent 2px),
    linear-gradient(90deg, rgba(18, 10, 4, 0.85) 2px, transparent 2px),
    linear-gradient(90deg, rgba(18, 10, 4, 0.85) 2px, transparent 2px);
  background-size: 100% 50%, 50% 50%, 50% 50%;
  background-position: 0 0, 0 0, calc(var(--cell) / 4) 100%;
  background-repeat: repeat, repeat-x, repeat-x;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.cell.wall { cursor: default; }

/* rubble: must be tiled, can't be built on; hatching leaves the build pads as the clean squares */
.cell.rubble, .sw-rubble, .np-board i.rubble {
  background-image: repeating-linear-gradient(45deg, rgba(50, 28, 10, 0.4) 0 3px, transparent 3px 8px);
}
.cell.rubble { cursor: not-allowed; }
.sw-rubble { background-color: hsl(32 27% 51%); }

/* helper suggestion: ghost pieces on dashed sky-blue squares */
.cell.hintcell { outline: 3px dashed var(--sky); outline-offset: -6px; }
.cell .hintg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--sym);
  font-size: calc(var(--cell) * 0.55);
  color: var(--sky);
  text-shadow: var(--outline);
  pointer-events: none;
  animation: blink 1.2s steps(1) infinite;
}
.cell .hintg.tier-gold { color: var(--gold-hi); text-shadow: var(--outline), 0 0 10px rgba(255, 205, 70, 1); }
.cell .hintg.tier-red { color: #ff8a6a; text-shadow: var(--outline), 0 0 12px rgba(255, 60, 30, 1); }

.cell.portal { background-color: var(--edge); cursor: default; }
.cell.portal .glyph {
  font-size: calc(var(--cell) * 0.55);
  animation: swirl 1.6s steps(8) infinite;
}
@keyframes swirl { to { transform: rotate(360deg); } }
.cell.portal.buddy { background-color: #2a2015; }

.cell.boat, .sw-water {
  background-color: var(--sky);
  background-image: repeating-linear-gradient(to bottom, transparent 0 6px, rgba(255, 241, 232, 0.6) 6px 8px);
  box-shadow: inset 0 0 0 3px var(--gold);
}
.cell.boat.on-wall { background-color: #22427a; }

.cell .glyph {
  display: inline-block;
  font-family: var(--sym);
  line-height: 1;
  pointer-events: none;
}
.cell .preplaced { color: #140d06; }
.cell .placed { color: #fff7e6; text-shadow: var(--outline); }
.cell .placed.best { color: #9fdcff; } /* gold and red stay reserved for value tiers */
.cell .placed.tier-gold { color: var(--gold-hi); text-shadow: var(--outline), 0 0 10px rgba(255, 205, 70, 1); }
.cell .placed.tier-red {
  color: #ff8a6a;
  text-shadow: var(--outline), 0 0 12px rgba(255, 60, 30, 1);
  animation: emberText 1.8s ease-in-out infinite;
}
@keyframes emberText {
  50% { text-shadow: var(--outline), 0 0 20px rgba(255, 60, 30, 1), 0 0 4px rgba(255, 200, 150, 1); }
}
.cell .glyph.dragging-origin { opacity: 0.3; }
.cell.drop-hover { outline: 4px solid var(--gold-hi); outline-offset: -4px; z-index: 1; }
/* hover/drag preview: the squares a piece would newly tile, outlined like the block they'd become */
.cell.preview::after,
.cell.foot::after {
  content: '';
  position: absolute; inset: 3px;
  pointer-events: none;
  border: 3px dashed var(--moss);
  background: rgba(79, 227, 95, 0.22);
}
/* hovering a placed piece traces everything it sees */
.cell.foot::after { border-color: var(--gold-hi); background: rgba(255, 224, 138, 0.16); }
.stackwrap {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  max-width: 100%;
  pointer-events: none;
}
.cell .glyph.mini { font-size: calc(var(--cell) * 0.3); }

/* ---------- Legend ---------- */
.legend { padding: 12px; }
.lg-note { margin: -2px 0 8px; font-size: 15px; line-height: 1.15; color: var(--muted); }
.lg-row { display: flex; align-items: center; gap: 10px; padding: 4px; border-radius: 2px; cursor: help; }
.lg-row:hover { background: rgba(227, 185, 79, 0.08); }
/* 7x7 pixel map of a piece's coverage shape, centred on the piece */
.pmap {
  flex: none;
  display: grid;
  grid-template-columns: repeat(7, 4px);
  grid-auto-rows: 4px;
  padding: 1px;
  background: #241a10;
  box-shadow: 0 0 0 1px var(--gold-lo);
}
.pmap i { display: block; }
.pmap i.on { background: var(--moss); }
.pmap i.me { background: var(--gold-hi); }
.lg-glyph {
  flex: none;
  width: 30px;
  text-align: center;
  font-family: var(--sym);
  font-size: 24px;
  line-height: 1;
  color: var(--parch);
}
.lg-glyph .tier-gold { color: var(--gold-hi); text-shadow: 0 0 8px rgba(255, 205, 70, 0.9); }
.lg-glyph .tier-red { color: #ff8a6a; text-shadow: 0 0 9px rgba(255, 60, 30, 0.95); }
.lg-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lg-text b {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gold-hi);
}
.lg-text small { font-size: 15px; line-height: 1.1; color: var(--muted); }
.lg-tier {
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 2px;
  font-style: normal;
  font-size: 9px;
  letter-spacing: 0.5px;
  color: #1a1006;
  background: var(--gold-hi);
}
.lg-tier.red { color: #fff; background: #c0321f; }
.lg-val { display: none; margin-left: 6px; color: var(--gold); }
.lg-row:hover .lg-val { display: inline; }
.sw { display: inline-block; width: 24px; height: 24px; vertical-align: middle; }
.sw-wall { --cell: 24px; }
.t-gold { color: var(--gold-hi); }
.t-red { color: var(--ember); }

/* ---------- Coming up (the minimap corner) ---------- */
.nextpanel { padding: 12px; }
.np-queue { display: flex; gap: 6px; justify-content: space-between; margin-bottom: 12px; }
.np-queue .np-board { --c: 7px; }
.np-item { margin: 0 0 10px; text-align: center; }
.np-item figcaption {
  margin-top: 4px;
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}
.np-item.boss figcaption { color: var(--ember); }
.np-item.boss .np-board { border-color: var(--ember); box-shadow: 0 0 10px rgba(255, 60, 30, 0.5); }
.np-board {
  --c: 13px;
  display: grid;
  grid-template-columns: repeat(var(--n), var(--c));
  grid-auto-rows: var(--c);
  gap: 1px;
  width: fit-content;
  margin: 0 auto;
  background: #5a4630;
  border: 2px solid var(--gold-lo);
}
.np-board i { display: block; background-color: hsl(32 27% 52%); }
.np-board i.wall { background: var(--wall); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6); }
.np-board i.portal { background: #ff77a8; }
.np-board i.free { background: #140d06; }
.np-note { font-size: 15px; line-height: 1.1; color: var(--muted); }

/* ---------- Commands (powers) ---------- */
.powers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.powers .lg-title { grid-column: 1 / -1; margin-bottom: 0; }
.btn.power {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin: 0;
  padding: 6px 4px;
  font-size: 10px;
  background: linear-gradient(#5d4a74, #33284a);
}
.btn.power .cmd-ic { font-family: var(--sym); font-size: 22px; line-height: 1; }
.btn.power .cmd-n { color: var(--gold-hi); }
.btn.power .cmd-n:empty { display: none; }
.btn.power.selected { background: linear-gradient(#9a7a34, #5e4515); outline: 2px solid var(--moss); outline-offset: 1px; }
.btn.power:disabled { background: linear-gradient(#3a332b, #262019); color: #6b5f4e; }
.btn.power.used .cmd-lb { text-decoration: line-through; }

/* ---------- Status / nav / scores ---------- */
.status {
  margin-top: 14px;
  min-height: 1.4em;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--parch);
  text-shadow: 1px 1px 0 #000;
}
.status.win { color: var(--gold-hi); animation: blink 0.4s steps(1) 6; }

.bottom-nav { display: flex; justify-content: center; gap: 14px; margin-top: 20px; }
.btn.big { flex: 1 1 0; max-width: 240px; padding: 12px 8px; font-size: 13px; }

.leaderboard {
  max-width: 400px;
  margin: 24px auto 0;
  padding: 12px 14px;
}
.lb-title { text-align: center; }
.lb-row {
  display: grid; grid-template-columns: 3em 4.5em 1fr 3em; gap: 6px;
  align-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  color: var(--muted);
}
.lb-row:nth-child(2) { color: var(--gold-hi); }
.lb-row:nth-child(3) { color: var(--parch); }
.lb-row:nth-child(4) { color: #d99a5b; }
.lb-row .lb-stars { letter-spacing: 2px; }
.lb-row .lb-by { text-align: right; }

.level-list {
  margin-top: 20px;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.level-list summary { cursor: pointer; list-style: none; }
.level-list summary::-webkit-details-marker { display: none; }
.level-list summary::before { content: '▶ '; }
.level-list[open] summary::before { content: '▼ '; }
.level-list select { width: 100%; margin-top: 8px; text-transform: none; }

.hint {
  margin: 22px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--gold-lo);
  font-size: 16px;
  line-height: 1.3;
  color: var(--muted);
}
.hint b { font-weight: 700; }
kbd {
  padding: 1px 5px;
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  color: var(--gold-hi);
  background: linear-gradient(var(--stone-hi), var(--stone-lo));
  border: 1px solid var(--edge);
  border-radius: 3px;
  box-shadow: var(--bevel);
}

/* ---------- Editor ---------- */
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.palette button.selected { background: linear-gradient(#9a7a34, #5e4515); color: #fff3c4; }
.pool-editor { display: flex; flex-wrap: wrap; gap: 10px; }
.pool-row {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 6px;
  background: var(--inset);
  border: 1px solid var(--gold-lo);
  border-radius: 3px;
}
.pool-row .pglyph { font-family: var(--sym); font-size: 22px; }
.pool-row .pglyph.tier-gold { color: var(--gold-hi); text-shadow: 0 0 8px rgba(255, 205, 70, 0.9); }
.pool-row .pglyph.tier-red { color: #ff8a6a; text-shadow: 0 0 9px rgba(255, 60, 30, 0.95); }
.pool-row button { padding: 3px 8px; }
.pool-row .pnum {
  min-width: 22px;
  text-align: center;
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-hi);
}

/* ---------- Narrower screens ---------- */
@media (max-width: 1080px) {
  .board-row {
    grid-template-columns: minmax(0, 1fr) 270px;
    grid-template-areas: "board army" "side side";
  }
  .side-col { flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
  .side-col > * { flex: 1 1 230px; }
}
@media (max-width: 720px) {
  /* phones: army above the board, commands and the side panels below it */
  .board-row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "army" "board" "cmds" "side";
    gap: 16px;
  }
  .army-col { display: contents; }
  .army { grid-area: army; }
  .powers { grid-area: cmds; grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 520px) {
  body { padding: 0 8px 28px; font-size: 17px; }
  .topbar { margin: 0 -8px; padding: 10px 8px 16px; }
  header { margin-bottom: 10px; align-items: center; }
  .tagline { display: none; }
  .logo { font-size: 26px; letter-spacing: 4px; }
  .tab { padding: 6px 7px; font-size: 10px; }
  .hud .playhead { margin-bottom: 8px; padding-bottom: 8px; }
  .hud .controls { flex-wrap: nowrap; overflow-x: auto; padding: 4px; }
  .hud .controls .btn { flex: none; }
  .card { padding: 14px 12px; }
  .hud { padding-top: 10px; padding-bottom: 10px; }
  .stats { gap: 4px; }
  .stat { min-width: 0; padding: 2px 6px; font-size: 8px; }
  .stat b { font-size: 14px; }
  .stat-round { padding: 2px 8px; gap: 6px; }
  .stat-round .lbl br { display: none; }
  .stat-round b { font-size: 20px; }
  .stat-round em { font-size: 10px; }
  #puzzleName { font-size: 14px; }
  .unit { width: 56px; height: 76px; }
  .u-port { height: 38px; }
  .u-port .pglyph { font-size: 26px; }
  .btn.big { padding: 11px 4px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
