/* Ironhold — fantasy chrome around the WebGL board.
   Parchment, dark wood and brass: the art is sliced from two CC0 packs
   (see assets/ui/CREDITS.md) and stretched with border-image. Nothing here
   touches the simulation; the board itself is still drawn on canvas. */

:root {
  --bg-0: #0a0806;
  --bg-1: #15100b;
  --wood-2: #4a2d16;
  --wood-3: #6b4826;
  --brass: #c9a45c;
  --brass-hi: #f2d99c;
  --brass-lo: #7d5c2c;
  --parchment: #e9d7ae;
  --ink: #33200e;
  --ink-soft: #5d3f22;
  --ink-faint: #87673f;
  --gold: #f3c558;
  --life: #e4694f;
  --life-hi: #ff9d86;
  --good: #5f9c4a;
  --arrow: #7dd3fc;
  --cannon: #fbbf24;
  --frost: #a5b4fc;
  --tesla: #c084fc;
  --panel-w: 340px;
  --font-display: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Songti SC", "Hiragino Mincho ProN", "Noto Serif CJK JP", serif;
  --font-ui: "Avenir Next", "Segoe UI", system-ui, -apple-system, "PingFang SC", "Hiragino Sans", "Malgun Gothic", "Noto Sans CJK JP", sans-serif;
  --font-num: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* `hidden` is only a UA stylesheet rule, so any author rule that sets
   `display` keeps the element painted while `el.hidden` reads true. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background:
    radial-gradient(1100px 620px at 18% -12%, rgba(96, 70, 42, 0.35) 0%, transparent 62%),
    radial-gradient(900px 520px at 112% 112%, rgba(74, 45, 22, 0.38) 0%, transparent 58%),
    repeating-linear-gradient(104deg, rgba(255, 236, 200, 0.016) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(14deg, rgba(0, 0, 0, 0.16) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--parchment);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button, select { font-family: inherit; }

::selection { background: rgba(201, 164, 92, 0.45); color: #fff6df; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- top bar ---------------------------------------------------------- */

.topbar {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 10px 12px 0;
  padding: 8px 16px;
  border: 12px solid transparent;
  border-image: url("../assets/ui/plaque-dark.png") 34 / 12px stretch;
  background:
    linear-gradient(180deg, rgba(255, 226, 166, 0.16), transparent 38%),
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.16) 0 2px, rgba(255, 232, 190, 0.014) 2px 4px, transparent 4px 9px),
    linear-gradient(180deg, #503219, #2d1a0c 56%, #1c0f07);
  background-clip: padding-box;
  box-shadow: inset 0 1px 0 rgba(255, 232, 180, 0.22), inset 0 -10px 20px rgba(0, 0, 0, 0.35);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.55));
}

.topbar::after {
  content: "";
  position: absolute;
  left: 26px;
  right: 26px;
  bottom: -10px;
  height: 3px;
  border-radius: 2px;
  background:
    radial-gradient(closest-side, var(--brass-hi) 0 28%, transparent 30%) center / 9px 9px no-repeat,
    linear-gradient(90deg, transparent, var(--brass-lo) 12%, var(--brass) 50%, var(--brass-lo) 88%, transparent);
  opacity: 0.85;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  min-height: 50px;
  padding: 0 4px;
  border: 13px solid transparent;
  border-width: 13px 46px 12px 46px;
  border-image: url("../assets/ui/ribbon.png") 24 190 22 190 fill / 13px 46px 12px 46px stretch;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}

.brand-mark {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border-radius: 3px;
  transform: rotate(45deg);
  background:
    linear-gradient(145deg, #fff0bd, var(--brass) 45%, #8a6322 75%);
  box-shadow: 0 0 10px rgba(243, 197, 88, 0.65), inset 0 0 0 1px rgba(74, 45, 22, 0.65);
}

.brand-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.brand-text {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.14em;
  color: #43260e;
  text-shadow: 0 1px 0 rgba(255, 236, 190, 0.55);
}

.brand-tag {
  font-size: 8.5px;
  line-height: 1.15;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6d421c;
  white-space: nowrap;
}

.stats {
  flex: 0 1 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  margin: 0 auto;
}

.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 96px;
  height: 50px;
  padding: 0 7px 0 2px;
  border: 12px solid transparent;
  border-width: 12px 9px 12px 30px;
  border-style: solid;
  border-color: transparent;
  border-image: url("../assets/ui/stat-pill.png") 30 34 30 112 fill / 12px 9px 12px 30px stretch;
  color: #f6e8c8;
  transition: transform 140ms ease, filter 200ms ease;
}

.stat::before {
  content: attr(data-icon);
  position: absolute;
  left: -30px;
  top: 50%;
  width: 30px;
  transform: translateY(-50%);
  text-align: center;
  font-size: 15px;
  line-height: 1;
  color: var(--brass-hi);
  text-shadow: 0 0 7px rgba(242, 217, 156, 0.8), 0 1px 1px #000;
  pointer-events: none;
}

.stat-k {
  font-size: 8px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #c8a570;
  white-space: nowrap;
}

.stat-v {
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: #ffefc9;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 1px #000, 0 0 8px rgba(255, 225, 160, 0.2);
  white-space: nowrap;
}

.stat-v .dim { font-size: 11px; font-weight: 600; color: #b8955f; }

#stat-lives .stat::before, #stat-lives::before {
  color: var(--life-hi);
  text-shadow: 0 0 8px color-mix(in srgb, var(--life) 80%, transparent);
}
#stat-lives .stat-v { color: #ffc6b4; }
#stat-gold .stat-v { color: var(--gold); }
#stat-score .stat-v { color: #e9f1f7; }
#stat-best .stat-v { color: #d8c7ea; }

.stat.bump { animation: stat-bump 260ms ease; }
@keyframes stat-bump {
  45% { transform: scale(1.07); filter: brightness(1.3); }
}

.stat.warn {
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--life) 65%, transparent));
  animation: stat-warn 1.5s ease-in-out infinite;
}
@keyframes stat-warn {
  50% { filter: drop-shadow(0 0 12px rgba(255, 120, 90, 0.9)); }
}

.top-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 10px solid transparent;
  border-image: url("../assets/ui/btn-square-wood.png") 52 fill / 10px stretch;
  background: none;
  color: var(--brass-hi);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  text-shadow: 0 1px 1px #000, 0 0 8px rgba(242, 217, 156, 0.5);
  transition: filter 140ms ease, transform 100ms ease;
}
.icon-btn:hover { filter: brightness(1.25); transform: translateY(-1px); }
.icon-btn.is-off { color: #8c7a5e; filter: grayscale(0.7) brightness(0.8); }

.lang-field {
  display: flex;
  width: 106px;
  height: 38px;
  border: 10px solid transparent;
  border-image: url("../assets/ui/btn-square-wood.png") 52 fill / 10px stretch;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

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

#lang {
  width: 100%;
  height: 100%;
  padding: 0 18px 0 4px;
  border: 0;
  border-radius: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23f2d99c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 1px center / 10px 7px no-repeat;
  color: #f6e8c8;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.85);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.lang-field:hover { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45)) brightness(1.18); }
#lang:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 3px; }
#lang option { background: #23140a; color: #f2e3c2; }

/* ---- layout ----------------------------------------------------------- */

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  gap: 16px;
  padding: 16px;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 5% 4%;
  border-radius: 46px;
  background: radial-gradient(closest-side, rgba(201, 164, 92, 0.14), transparent 72%);
  filter: blur(22px);
  pointer-events: none;
}

/* Two stacked canvases: WebGL for the world, a transparent 2D canvas above
   it for health bars, particles and the wave banner. The wooden band and
   brass line are shadows / a pseudo-element so the measured board is not
   charged for the frame. */
.board-stack {
  position: relative;
  line-height: 0;
  background: #0c1116;
  border-radius: 3px;
  box-shadow:
    0 0 0 1px #140c05,
    0 0 0 5px #2f1c0d,
    0 0 0 12px #64401f,
    0 0 0 14px #2a180b,
    0 24px 55px rgba(0, 0, 0, 0.72);
}

.board-stack::after {
  content: "";
  position: absolute;
  inset: -14px;
  border: 14px solid transparent;
  border-image: url("../assets/ui/frame-brass.png") 30 / 14px stretch;
  opacity: 0.92;
  pointer-events: none;
}

#board {
  display: block;
  background: #0c1116;
  border-radius: 3px;
  touch-action: none;
  cursor: crosshair;
}
#board.is-orbiting { cursor: grabbing; }

#board-overlay {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  pointer-events: none;
}

.stage-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(70% 60% at 50% 45%, rgba(0, 0, 0, 0.34), rgba(5, 3, 1, 0.8));
  backdrop-filter: blur(3px);
  z-index: 40;
}

.modal {
  width: min(440px, 94%);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  padding: 12px 18px 18px;
  border: 18px solid transparent;
  border-image: url("../assets/ui/panel-card.png") 64 / 18px stretch;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 250, 224, 0.55), transparent 58%),
    linear-gradient(180deg, #f0dfb9, #ddc28a);
  background-clip: padding-box;
  color: var(--ink);
  filter: sepia(0.12) saturate(0.96) brightness(0.96) drop-shadow(0 22px 30px rgba(0, 0, 0, 0.65));
}

.modal h2 {
  margin: 0 0 11px;
  padding: 6px 12px;
  border: 10px solid transparent;
  border-image: url("../assets/ui/plaque-dark.png") 34 / 10px stretch;
  background:
    linear-gradient(180deg, rgba(255, 226, 166, 0.18), transparent 44%),
    linear-gradient(180deg, #4c2e17, #291709);
  background-clip: padding-box;
  color: #fbf0d5;
  font-family: var(--font-display);
  font-size: clamp(19px, 4.6vh, 26px);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px #000;
  box-shadow: inset 0 1px 0 rgba(255, 232, 180, 0.18);
}

.modal p {
  margin: 0 0 16px;
  color: #5e3f21;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---- side panel ------------------------------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 3px 14px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--wood-3) transparent;
}
.panel::-webkit-scrollbar { width: 9px; }
.panel::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--wood-3), var(--wood-2));
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 6px;
}
.panel::-webkit-scrollbar-track { background: transparent; }

.card {
  position: relative;
  flex: 0 0 auto;
  padding: 1px 7px 8px;
  border: 16px solid transparent;
  border-image: url("../assets/ui/panel-card.png") 64 / 16px stretch;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 250, 224, 0.55), transparent 55%),
    repeating-linear-gradient(92deg, rgba(93, 63, 34, 0.045) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #eeddb7, #ddc28a);
  background-clip: padding-box;
  color: var(--ink);
  filter: sepia(0.12) saturate(0.96) brightness(0.96) drop-shadow(0 7px 10px rgba(0, 0, 0, 0.42));
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 1px 9px;
  padding: 5px 11px 6px;
  border: 9px solid transparent;
  border-image: url("../assets/ui/plaque-dark.png") 34 / 9px stretch;
  background:
    linear-gradient(180deg, rgba(255, 226, 166, 0.18), transparent 44%),
    linear-gradient(180deg, #4c2e17, #291709);
  background-clip: padding-box;
  color: #f4e6c6;
  box-shadow: inset 0 1px 0 rgba(255, 232, 180, 0.18);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.card-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #fbf0d5;
  text-shadow: 0 1px 1px #000;
  white-space: nowrap;
}

.hint {
  color: #cbb183;
  font-size: 10px;
  font-style: italic;
  line-height: 1.2;
  text-align: right;
  text-shadow: 0 1px 1px #000;
}

/* shop */

.shop { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.tower-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 92px;
  padding: 5px 6px 6px 8px;
  border: 12px solid transparent;
  border-image: url("../assets/ui/btn-wood.png") 52 fill / 12px stretch;
  background: none;
  color: #f4e6c8;
  font-family: var(--font-ui);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.85);
  transition: filter 150ms ease, transform 90ms ease;
}

.tower-btn:hover:not(:disabled) {
  filter: brightness(1.18) drop-shadow(0 0 6px var(--t-color));
  transform: translateY(-1px);
}

.tower-btn.is-on {
  border-image-source: url("../assets/ui/btn-primary.png");
  filter: drop-shadow(0 0 9px var(--t-color)) brightness(1.05);
}

.tower-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.72) brightness(0.72);
  opacity: 0.72;
}

.tower-btn:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.x:focus-visible {
  outline: 2px solid var(--brass-hi);
  outline-offset: 2px;
}

.tower-row { display: flex; align-items: center; gap: 6px; min-width: 0; }

.tower-ico {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
}
.tower-ico svg { display: block; width: 100%; height: 100%; }

.tower-name {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff1d2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tower-key {
  position: absolute;
  top: 3px;
  right: 4px;
  min-width: 13px;
  padding: 0 3px;
  border: 1px solid rgba(201, 164, 92, 0.55);
  border-radius: 3px;
  background: rgba(15, 8, 3, 0.55);
  color: var(--brass-hi);
  font-family: var(--font-num);
  font-size: 8.5px;
  line-height: 13px;
  text-align: center;
}

.tower-cost {
  font-family: var(--font-num);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--brass-hi);
  text-shadow: 0 1px 1px #000, 0 0 7px rgba(243, 197, 88, 0.35);
}

.tower-desc {
  font-size: 9.5px;
  line-height: 1.35;
  color: #d9c4a0;
  text-shadow: none;
}

/* selection */

.sel-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  margin: 0 3px 10px;
}
.sel-stats div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 0;
  border-bottom: 1px dotted rgba(93, 63, 34, 0.28);
  font-size: 11px;
}
.sel-stats span { color: var(--ink-faint); }
.sel-stats b {
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.sel-stats .up { color: var(--good); font-size: 9.5px; }

.sel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 2px 8px;
}

#selection .btn-ghost { margin: 0 2px; width: calc(100% - 4px); }

.x {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: rgba(255, 230, 180, 0.08);
  color: #d9c19a;
  font-size: 16px;
  line-height: 18px;
  cursor: pointer;
}
.x:hover { color: #fff3d6; background: rgba(255, 230, 180, 0.18); }

/* buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 40px;
  padding: 3px 10px;
  border: 12px solid transparent;
  border-image: url("../assets/ui/btn-secondary.png") 52 fill / 12px stretch;
  background: none;
  color: #f7eacd;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
  cursor: pointer;
  transition: filter 140ms ease, transform 90ms ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.2); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); filter: brightness(0.95); }
.btn:disabled { cursor: not-allowed; filter: grayscale(0.65) brightness(0.7); opacity: 0.78; }
.btn b {
  font-family: var(--font-num);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--brass-hi);
  text-shadow: 0 1px 1px #000;
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  border-image-source: url("../assets/ui/btn-primary.png");
  color: #342006;
  text-shadow: 0 1px 0 rgba(255, 240, 195, 0.55);
  margin-bottom: 9px;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12) saturate(1.05); }
.btn-primary b { color: #4a2c06; text-shadow: none; }

.btn-up { border-image-source: url("../assets/ui/btn-upgrade.png"); }
.btn-sell { border-image-source: url("../assets/ui/btn-danger.png"); }
.btn-sell b { color: #ffd9cf; }

.btn-ghost {
  border-image-source: url("../assets/ui/btn-steel.png");
  color: #3b2a17;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.speed {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 6px;
  margin: 0 2px;
}
.speed .btn { min-height: 36px; padding: 1px 3px; font-size: 11.5px; }
.speed-btn.is-on {
  border-image-source: url("../assets/ui/btn-primary.png");
  color: #342006;
  text-shadow: 0 1px 0 rgba(255, 240, 195, 0.55);
  filter: drop-shadow(0 0 6px rgba(243, 197, 88, 0.45));
}

/* wave preview + legend */

.wave-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 22px;
  margin: 0 2px 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--wood-3);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 226, 170, 0.08), transparent 55%),
    linear-gradient(180deg, #3a2413, #20120a);
  color: #f2e2bd;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.35;
  text-shadow: 0 1px 1px #000;
  box-shadow: inset 0 1px 0 rgba(255, 228, 175, 0.16), 0 1px 2px rgba(0, 0, 0, 0.35);
}
.pill i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; box-shadow: 0 0 5px currentColor; }
.pill.boss {
  border-color: #a95a98;
  background: linear-gradient(180deg, #4a2344, #251020);
  box-shadow: 0 0 8px rgba(232, 121, 249, 0.4), inset 0 1px 0 rgba(255, 200, 250, 0.2);
}

.legend { list-style: none; margin: 0 3px; padding: 0; display: grid; gap: 4px; }
.legend li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  border-bottom: 1px dotted rgba(93, 63, 34, 0.22);
  font-size: 10.5px;
  color: var(--ink-soft);
}
.legend li:last-child { border-bottom: 0; }
.legend i { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 4px currentColor; }
.legend b { color: var(--ink); font-weight: 700; }
.legend .tag {
  margin-left: auto;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.keys { list-style: none; margin: 0 3px; padding: 0; display: grid; gap: 4px; font-size: 10px; line-height: 1.45; color: var(--ink-soft); }
.keys b { color: var(--ink); }
kbd {
  display: inline-block;
  min-width: 13px;
  padding: 0 3px;
  border: 1px solid #6d4c28;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: linear-gradient(180deg, #45301a, #2a1a0d);
  color: #f2e3c3;
  font-family: var(--font-num);
  font-size: 8.5px;
  line-height: 13px;
  text-align: center;
  text-shadow: 0 1px 1px #000;
  box-shadow: inset 0 1px 0 rgba(255, 230, 180, 0.2);
}

/* ---- CJK typography --------------------------------------------------- */

html:lang(zh) .stat-k,
html:lang(ja) .stat-k,
html:lang(ko) .stat-k,
html:lang(zh) .card-head h2,
html:lang(ja) .card-head h2,
html:lang(ko) .card-head h2 {
  letter-spacing: 0.04em;
}

html:lang(zh) .brand-tag,
html:lang(ja) .brand-tag,
html:lang(ko) .brand-tag { letter-spacing: 0.08em; }

html:lang(zh) .hint,
html:lang(ja) .hint,
html:lang(ko) .hint { font-style: normal; }

html:lang(zh) .btn,
html:lang(ja) .btn,
html:lang(ko) .btn { font-family: var(--font-ui); font-weight: 700; }

/* ---- narrow screens --------------------------------------------------- */

@media (max-width: 1180px) {
  .stat { min-width: 82px; }
  .brand { border-width: 13px 42px 12px 42px; border-image-width: 13px 42px 12px 42px; }
}

@media (max-width: 960px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; }
  .topbar { gap: 8px 8px; padding: 8px 10px; }
  .stats { gap: 5px; }
  .stat { flex: 1 1 0; min-width: 0; }
  .lang-field { width: 98px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .panel {
    width: min(100%, 720px);
    margin: 0 auto;
    overflow: visible;
    padding-bottom: 8px;
  }
  /* `container-type: size` means this cannot be sized by the board inside it,
     so fit() sets an explicit height for the stacked layout. */
  .stage { min-height: 0; }
  .card-help { display: none; }
  .shop { grid-template-columns: 1fr 1fr; }
  .board-stack::after { inset: -9px; border-width: 9px; }
  .board-stack {
    box-shadow:
      0 0 0 1px #120b05,
      0 0 0 3px #2a1809,
      0 0 0 7px #4a2d16,
      0 0 0 9px #24140a,
      0 18px 40px rgba(0, 0, 0, 0.65);
  }
}

@media (max-width: 620px) {
  .topbar {
    margin: 8px 8px 0;
    padding: 6px 10px;
    gap: 8px;
    border-width: 10px;
    border-image-width: 10px;
  }
  .topbar::after { left: 16px; right: 16px; bottom: -8px; }
  .brand {
    min-height: 40px;
    gap: 6px;
    border-width: 10px 30px 9px 30px;
    border-image-width: 10px 30px 9px 30px;
  }
  .brand-mark { width: 11px; height: 11px; }
  .brand-text { font-size: 11.5px; letter-spacing: 0.1em; }
  .brand-tag { font-size: 7px; letter-spacing: 0.1em; }
  .stats { order: 3; flex-basis: 100%; justify-content: space-between; gap: 4px; }
  .stat {
    flex: 1 1 0;
    min-width: 0;
    height: 46px;
    border-width: 11px 8px 11px 26px;
    border-image-width: 11px 8px 11px 26px;
  }
  .stat::before { left: -26px; width: 26px; font-size: 13px; }
  .stat-k { font-size: 7px; letter-spacing: 0.06em; }
  .stat-v { font-size: 14px; }
  .stat-v .dim { font-size: 9.5px; }
  .stat-best { display: none; }
  .top-actions { margin-left: auto; }
  .icon-btn { width: 34px; height: 34px; border-width: 9px; border-image-width: 9px; }
  .lang-field { width: 88px; height: 34px; border-width: 9px; border-image-width: 9px; }
  #lang { font-size: 11px; padding-right: 15px; background-size: 9px 6px; }
  .layout { padding: 12px 14px 16px; gap: 12px; }
  .modal { border-width: 15px; padding: 9px 12px 14px; }
  .modal h2 { font-size: 19px; padding: 5px 10px; border-width: 9px; border-image-width: 9px; }
  .modal p { font-size: 12px; }
  .tower-btn { min-height: 88px; }
  .tower-desc { font-size: 9px; }
}

@media (max-width: 360px) {
  .brand { border-width: 9px 26px 8px 26px; border-image-width: 9px 26px 8px 26px; }
  .brand-tag { display: none; }
  .tower-desc { display: none; }
  .tower-btn { min-height: 68px; }
}

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