:root {
  --bg: #0b0d16;
  --bg-panel: #141827;
  --bg-panel-2: #1a2033;
  --line: #2a3350;
  --text: #e8ecf8;
  --muted: #9aa6c4;
  --accent: #7ad7ff;
  --accent-2: #b58bff;
  --danger: #ff6b7a;
  --ok: #6ee7a8;
  --wood: #6fd08c;
  --fire: #ff8551;
  --earth: #d8b26a;
  --metal: #b9c6e8;
  --water: #63c7ff;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(122, 215, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(181, 139, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 48px) 8px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--muted);
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3.4vw, 38px);
  letter-spacing: 0.14em;
  font-weight: 700;
}

h1 span {
  color: var(--accent);
}

h2 {
  margin: 0;
  font-size: 16px;
}

h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--muted);
  white-space: nowrap;
}

main {
  padding: 8px clamp(12px, 4vw, 48px) 32px;
}

.button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--bg-panel-2);
  color: var(--text);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) {
  border-color: var(--accent);
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button.primary {
  background: linear-gradient(140deg, rgba(122, 215, 255, 0.24), rgba(181, 139, 255, 0.24));
  border-color: rgba(122, 215, 255, 0.5);
}

.button.secondary {
  background: transparent;
}

.button.full {
  width: 100%;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.72);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.player-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-stat.align-right {
  text-align: right;
  align-items: flex-end;
}

.label {
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.player-stat strong {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.center-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 140px;
}

.turn-owner {
  font-size: 13px;
  color: var(--accent);
}

.timer {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 10px;
  min-width: 74px;
  text-align: center;
}

.timer.danger {
  color: var(--danger);
  border-color: rgba(255, 107, 122, 0.6);
  box-shadow: 0 0 14px rgba(255, 107, 122, 0.25);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(230px, 300px) 1fr;
  gap: 16px;
  align-items: start;
}

.side-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.85);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.panel-heading span {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.flux-track {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.flux-orb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #0d1120;
}

.flux-orb.active {
  background: radial-gradient(circle at 35% 30%, #d6f4ff, var(--accent) 55%, #2d7fa8);
  border-color: rgba(122, 215, 255, 0.7);
}

.muted {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
  line-height: 1.45;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

.selected-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #101525;
  min-height: 108px;
  font-size: 13px;
  line-height: 1.5;
}

.selected-card.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.selected-card h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.selected-card p {
  margin: 4px 0;
}

.preview {
  color: var(--accent);
  font-size: 12px;
}

.message {
  min-height: 52px;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #cfd8ef;
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.counters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.counters div {
  background: #101525;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.counters dt {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}

.counters dd {
  margin: 2px 0 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.board-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.nexus {
  width: min(100%, 640px);
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(16, 21, 37, 0.8);
  color: var(--muted);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font: inherit;
}

.nexus.enemy {
  border-color: rgba(255, 107, 122, 0.45);
}

.nexus.enemy.ready {
  border-style: solid;
  border-color: var(--danger);
  box-shadow: 0 0 18px rgba(255, 107, 122, 0.25);
  color: var(--text);
}

.nexus-label {
  font-size: 11px;
  letter-spacing: 0.18em;
}

.nexus-hint {
  font-size: 10px;
  color: var(--muted);
}

.board {
  width: min(100%, 640px);
  display: grid;
  /* --grid is written by main.js from BOARD_SIZE, so the tiles and the rules
     can never disagree about how many columns the arena has. */
  grid-template-columns: repeat(var(--grid, 5), 1fr);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(160deg, #0e1322, #131a2c);
  padding: 8px;
}

/* ---------------------------- card art ---------------------------- */

/* Generated SVG illustration sitting behind the card's own text. */
.card-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 46%;
  opacity: 0.92;
  pointer-events: none;
  z-index: 0;
  -webkit-user-drag: none;
}

/* Text stays readable over any scene: a bottom-weighted scrim, then content. */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    rgba(6, 9, 16, 0.86) 0%,
    rgba(6, 9, 16, 0.58) 46%,
    rgba(6, 9, 16, 0.16) 100%
  );
}

.card > *:not(.card-art) {
  position: relative;
  z-index: 1;
}

.card h3,
.card .card-effect,
.card .card-role,
.card .card-stats,
.card .card-tags {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 10px rgba(0, 0, 0, 0.65);
}

.inspector-art {
  display: block;
  width: 100%;
  aspect-ratio: 20 / 13;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 8px;
  object-fit: cover;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid #222b45;
  border-radius: 8px;
  background: #0f1524;
  color: var(--muted);
  padding: 2px;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 120ms ease, background 120ms ease;
}

.cell:hover {
  border-color: #3a4a78;
}

.cell .coord {
  position: absolute;
  left: 4px;
  bottom: 2px;
  font-size: 9px;
  color: #39446a;
}

.cell.legal {
  border-color: rgba(110, 231, 168, 0.8);
  background: rgba(110, 231, 168, 0.12);
}

.cell.move {
  border-color: rgba(122, 215, 255, 0.75);
  background: rgba(122, 215, 255, 0.12);
}

.cell.attack {
  border-color: rgba(255, 107, 122, 0.9);
  background: rgba(255, 107, 122, 0.16);
}

.cell.selected {
  border-color: var(--accent-2);
  box-shadow: inset 0 0 0 2px rgba(181, 139, 255, 0.55);
}

.unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto 3px;
  column-gap: 2px;
  height: 100%;
  padding: 0;
  text-align: left;
  /* The Vessel stands on the terrain; only its nameplate is a panel. */
  background: none;
}

.element-badge {
  align-self: flex-start;
  font-size: 8px;
  letter-spacing: 0.08em;
  border-radius: 4px;
  padding: 0 3px;
  border: 1px solid currentColor;
  color: var(--muted);
}

.element-badge.wood { color: var(--wood); }
.element-badge.fire { color: var(--fire); }
.element-badge.earth { color: var(--earth); }
.element-badge.metal { color: var(--metal); }
.element-badge.water { color: var(--water); }

.unit-name {
  font-size: 10px;
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.unit-stats {
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  color: #cfd8ef;
  margin-top: auto;
}

.unit-flag {
  font-size: 8px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  border: 1px solid var(--line);
  display: inline-block;
}

.legend-dot.friendly { background: var(--accent); }
.legend-dot.enemy { background: var(--danger); }
.legend-dot.legal { background: rgba(110, 231, 168, 0.6); }
.legend-dot.move { background: rgba(122, 215, 255, 0.6); }
.legend-dot.attack { background: rgba(255, 107, 122, 0.6); }

.hand-section {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.7);
  padding: 14px 16px;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.deck-count {
  font-size: 12px;
  color: var(--muted);
}

.hand {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.card {
  min-width: 132px;
  max-width: 150px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(170deg, #1a2136, #0f1424);
  color: var(--text);
  padding: 10px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.card:hover:not(:disabled) {
  border-color: var(--accent);
}

.card.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(181, 139, 255, 0.35);
}

.card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card .cost {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: rgba(122, 215, 255, 0.18);
  border: 1px solid rgba(122, 215, 255, 0.5);
}

.card .cost.unaffordable {
  background: rgba(255, 107, 122, 0.16);
  border-color: rgba(255, 107, 122, 0.45);
}

.card-element {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.card h3 {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  /* Sixty Vessels include long names; wrap them instead of clipping. */
  overflow-wrap: anywhere;
}

.card-role {
  margin: 0;
  font-size: 10px;
  color: var(--muted);
  text-transform: capitalize;
}

.card-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  font-size: 10px;
  color: #cfd8ef;
}

.card-flavor {
  margin: 0;
  font-size: 10px;
  line-height: 1.35;
  color: #8d99b8;
  font-style: italic;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #5f6b8c;
  text-transform: uppercase;
}

.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 13, 0.78);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.result-overlay[hidden] {
  display: none;
}

.result-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #131a2b;
  padding: 28px 32px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.result-panel h2 {
  font-size: 26px;
  margin: 6px 0 8px;
}

.result-panel .button {
  margin-top: 16px;
}

@media (max-width: 880px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .status-strip {
    grid-template-columns: 1fr auto;
  }

  .center-stat {
    order: -1;
    grid-column: 1 / -1;
    flex-direction: row;
    gap: 12px;
    align-items: center;
    justify-content: center;
  }
}

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

/* ------------------------------------------------------------------ *
 * M2-003: navigation, AI opponent, profile and log
 * ------------------------------------------------------------------ */

.brand { min-width: 0; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 13, 23, 0.6);
}

.tab {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 8px 14px;
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: linear-gradient(140deg, rgba(122, 215, 255, 0.22), rgba(181, 139, 255, 0.22));
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(122, 215, 255, 0.35);
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  max-width: 220px;
}

.profile-chip:hover { border-color: var(--accent); }

.profile-chip-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
  min-width: 0;
}

.profile-chip-text strong {
  font-size: 12px;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chip-text small {
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: #121627;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.avatar-sm { width: 32px; height: 32px; }
.avatar-lg { width: 96px; height: 96px; border-radius: 18px; }

.avatar.thinking {
  border-color: var(--accent);
  animation: pulse-ring 1.1s ease-in-out infinite;
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122, 215, 255, 0.0); }
  50% { box-shadow: 0 0 0 5px rgba(122, 215, 255, 0.18); }
}

.opponent-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 14px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(120deg, rgba(255, 107, 122, 0.08), rgba(20, 24, 39, 0.7));
}

.opponent-text { flex: 1; min-width: 0; }
.opponent-text h2 { margin: 0; font-size: 15px; }
.opponent-text .muted { margin: 2px 0 0; font-size: 11px; }

.opponent-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.thinking {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.view[hidden] { display: none; }

.log-section {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.55);
  padding: 14px 16px;
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 190px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: #cbd5ee;
}

.log-list li {
  display: flex;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(42, 51, 80, 0.6);
}

.log-time {
  flex: 0 0 auto;
  font-size: 10px;
  color: #6c789c;
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}

.button.danger {
  border-color: rgba(255, 107, 122, 0.45);
  color: #ffb7bf;
}

.button.danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: rgba(255, 107, 122, 0.12);
}

.button.small { padding: 6px 10px; font-size: 11px; }

/* -------------------------- profile view -------------------------- */

.profile-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.75);
  padding: 18px 20px;
}

.panel h2 { margin: 2px 0 14px; }

.avatar-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.avatar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.avatar-actions p { flex-basis: 100%; margin: 0; }

.field {
  display: block;
  margin-bottom: 10px;
}

.field span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0e1322;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

input[type="text"]:focus,
select:focus {
  outline: 2px solid rgba(122, 215, 255, 0.5);
  outline-offset: 1px;
}

input[readonly] { color: var(--muted); }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: #cdd6ee;
  margin-bottom: 10px;
}

.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.small { font-size: 11px; }
.mono { font-family: "Cascadia Mono", "Consolas", monospace; font-size: 11px; }

.inline-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.inline-row.center { justify-content: center; margin-top: 16px; }

.counters.stats { grid-template-columns: repeat(3, 1fr); }

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

.result-stats {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
}

.result-stats strong { color: var(--text); }

[data-state="synced"] { color: var(--ok); }
[data-state="saving"] { color: var(--accent); }
[data-state="offline"] { color: #ffcf8b; }

@media (max-width: 880px) {
  .topbar { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .opponent-card { flex-wrap: wrap; }
  .counters.stats { grid-template-columns: repeat(2, 1fr); }
}

body.reduce-motion * {
  transition: none !important;
  animation: none !important;
}

/* ------------------------------------------------------------------ *
 * Actions, Relics and voxel combat presentation
 * ------------------------------------------------------------------ */

.legend-dot.target { background: rgba(181, 139, 255, 0.7); }

.relic-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.relic-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(181, 139, 255, 0.08);
}

.relic-list li strong { font-weight: 600; }
.relic-list li span { color: var(--muted); }
.relic-list li.relic-empty {
  border-style: dashed;
  background: none;
  color: var(--muted);
}

.card .card-kind {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.card.relic .card-kind { color: var(--ok); }

.card .card-effect {
  margin: 3px 0 0;
  font-size: 11px;
  line-height: 1.25;
  color: #d7def2;
}

.code-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px dashed rgba(122, 215, 255, 0.45);
  border-radius: 10px;
  background: rgba(122, 215, 255, 0.07);
}

.code-box .eyebrow { width: 100%; margin: 0; }

.code-box code {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 15px;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- voxel unit marker ---- */

.cell .voxel {
  --vox-size: 18px;
  position: absolute;
  top: 4px;
  right: 4px;
  width: var(--vox-size);
  height: var(--vox-size);
  transform-style: preserve-3d;
  transform: rotateX(-24deg) rotateY(-38deg);
  pointer-events: none;
  z-index: 2;
}

.cell .voxel i {
  position: absolute;
  inset: 0;
  display: block;
  background: var(--vox);
  border: 1px solid rgba(6, 9, 18, 0.55);
  backface-visibility: hidden;
}

.cell .voxel i.v-front { transform: translateZ(calc(var(--vox-size) / 2)); }
.cell .voxel i.v-back { transform: rotateY(180deg) translateZ(calc(var(--vox-size) / 2)); filter: brightness(0.5); }
.cell .voxel i.v-right { transform: rotateY(90deg) translateZ(calc(var(--vox-size) / 2)); filter: brightness(0.72); }
.cell .voxel i.v-left { transform: rotateY(-90deg) translateZ(calc(var(--vox-size) / 2)); filter: brightness(0.62); }
.cell .voxel i.v-top { transform: rotateX(90deg) translateZ(calc(var(--vox-size) / 2)); filter: brightness(1.25); }
.cell .voxel i.v-bottom { transform: rotateX(-90deg) translateZ(calc(var(--vox-size) / 2)); filter: brightness(0.45); }

.cell .voxel[data-element="wood"] { --vox: var(--wood); }
.cell .voxel[data-element="fire"] { --vox: var(--fire); }
.cell .voxel[data-element="earth"] { --vox: var(--earth); }
.cell .voxel[data-element="metal"] { --vox: var(--metal); }
.cell .voxel[data-element="water"] { --vox: var(--water); }

.unit-name { padding-right: 20px; }

/* ---- action targets ---- */

.cell.target {
  border-color: rgba(181, 139, 255, 0.95);
  background: rgba(181, 139, 255, 0.16);
}

.cell.target::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(181, 139, 255, 0.6);
  animation: target-pulse 1.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes target-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.9; }
}

/* ---- combat feedback ---- */

.dmg-float {
  position: absolute;
  left: 50%;
  top: 26%;
  transform: translate(-50%, 0);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #ffd7dc;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  z-index: 6;
  animation: fx-float 820ms ease-out forwards;
}

.dmg-float.advantage { color: #ffb347; font-size: 17px; }
.dmg-float.retaliation { color: #ff9aa4; font-size: 12px; }
.dmg-float.heal { color: #7dffb0; }
.dmg-float.nexus { position: static; font-size: 22px; color: #ff8a95; animation: none; }

@keyframes fx-float {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -2px) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -26px) scale(1); }
}

@keyframes fx-lunge {
  0% { transform: translate(0, 0); }
  38% { transform: translate(var(--fx-dx, 0px), var(--fx-dy, 0px)) scale(1.06); }
  100% { transform: translate(0, 0); }
}

.cell.fx-lunge { overflow: visible; z-index: 5; }
.cell.fx-lunge .unit { animation: fx-lunge 380ms cubic-bezier(0.32, 0.9, 0.3, 1); }

@keyframes fx-hit-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-3px); }
  38% { transform: translateX(3px); }
  62% { transform: translateX(-2px); }
  80% { transform: translateX(1px); }
}

.cell.fx-hit { background: rgba(255, 107, 122, 0.3); border-color: rgba(255, 107, 122, 0.9); }
.cell.fx-hit .unit { animation: fx-hit-shake 320ms ease-in-out; }

.cell.fx-cast-hit { border-color: var(--accent-2); background: rgba(181, 139, 255, 0.2); }
.cell.fx-cast-hit .unit { animation: fx-hit-shake 340ms ease-in-out; }

.cell.fx-heal { border-color: rgba(110, 231, 168, 0.9); background: rgba(110, 231, 168, 0.14); }
.cell.fx-buff { border-color: rgba(255, 209, 102, 0.95); background: rgba(255, 209, 102, 0.14); }
.cell.fx-step { border-color: var(--accent); background: rgba(122, 215, 255, 0.12); }

@keyframes fx-spawn-in {
  from { opacity: 0; transform: translateY(9px) scale(0.82); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cell.fx-spawn { border-color: rgba(122, 215, 255, 0.9); }
.cell.fx-spawn .unit { animation: fx-spawn-in 300ms ease-out; }

@keyframes fx-crumble {
  0% { opacity: 0.95; transform: none; filter: grayscale(0); }
  100% { opacity: 0; transform: rotate(16deg) scale(0.5) translateY(8px); filter: grayscale(1); }
}

.cell .unit.fx-ghost {
  position: absolute;
  inset: 2px;
  z-index: 4;
  background: linear-gradient(170deg, rgba(255, 107, 122, 0.45), rgba(12, 16, 28, 0.9));
  animation: fx-crumble 500ms ease-in forwards;
  pointer-events: none;
}

@keyframes fx-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-2px, 2px); }
  80% { transform: translate(2px, -2px); }
}

.board.fx-shake { animation: fx-shake 420ms ease-in-out; }

.nexus.fx-nexus-hit {
  border-style: solid;
  border-color: var(--danger);
  box-shadow: 0 0 26px rgba(255, 107, 122, 0.55);
}

@media (max-width: 640px) {
  .cell .voxel { --vox-size: 11px; top: 2px; right: 2px; }
  .dmg-float { font-size: 12px; }

  /* A phone cell is too narrow for a name plus four stat labels: the tile
     becomes a voxel plus the two numbers that matter, and the full name and
     rules stay available in the selection panel and the cell's aria-label. */
  .unit { padding: 2px; }
  .unit-name,
  .unit-flag { display: none; }
  .unit-name { padding-right: 0; }
  .unit-stats {
    font-size: 8px;
    line-height: 1.15;
    letter-spacing: 0.01em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell.target::after { animation: none; }
}

/* ==================================================================
   Main menu
   ================================================================== */

.brand-button {
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.brand-word {
  display: block;
  font-size: clamp(22px, 3vw, 34px);
  letter-spacing: 0.14em;
  font-weight: 700;
}

.brand-word span { color: var(--accent); }

.view[hidden] { display: none; }

.menu-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: clamp(20px, 4vw, 56px);
  align-items: center;
  padding: clamp(18px, 4vw, 48px) 0;
}

.menu-title {
  margin: 6px 0 12px;
  font-size: clamp(30px, 5vw, 58px);
  line-height: 1.02;
  letter-spacing: -0.01em;
  background: linear-gradient(120deg, #e8ecf8 25%, var(--accent) 70%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.menu-lede {
  max-width: 56ch;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 22px 0 10px;
}

.button.large { padding: 14px 22px; font-size: 14px; }

.button.accent {
  background: linear-gradient(140deg, rgba(110, 231, 168, 0.22), rgba(122, 215, 255, 0.22));
  border-color: rgba(110, 231, 168, 0.5);
}

.menu-secondary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.menu-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.62);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.menu-link:hover {
  border-color: var(--accent);
  background: rgba(26, 32, 51, 0.85);
  transform: translateY(-2px);
}

.menu-link span { font-size: 12px; color: var(--muted); }

.menu-unavailable {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px dashed rgba(42, 51, 80, 0.8);
}

.menu-stage {
  position: relative;
  min-height: clamp(220px, 25vw, 320px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    radial-gradient(60% 50% at 50% 78%, rgba(122, 215, 255, 0.16), transparent 70%),
    linear-gradient(180deg, #0e1322, #0a0e1a 70%);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px 16px 34px;
  perspective: 900px;
}

.menu-models {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(10px, 3vw, 34px);
  width: 100%;
  transform-style: preserve-3d;
}

.menu-model {
  --u-base: clamp(5.4px, 1.1vw, 8.6px);
  width: calc(var(--u-base) * 15);
  position: relative;
  display: grid;
  align-items: end;
  justify-items: center;
  padding-bottom: 6px;
}

.menu-model::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 62%;
  height: 9px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), transparent);
}

.menu-model:nth-child(2) { --u-base: clamp(6.6px, 1.4vw, 11px); }
.menu-model:nth-child(3) { --u-base: clamp(5px, 1vw, 8px); }
.menu-model:nth-child(4) { --u-base: clamp(5px, 1.05vw, 8.4px); }
.menu-model .vox-model { animation: vox-breathe 4.4s ease-in-out infinite; }
.menu-model:nth-child(2) .vox-model { animation-delay: -1.2s; }
.menu-model:nth-child(3) .vox-model { animation-delay: -2.1s; }
.menu-model:nth-child(4) .vox-model { animation-delay: -0.6s; }

.menu-stage-floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34%;
  background:
    repeating-linear-gradient(90deg, rgba(122, 215, 255, 0.11) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(180deg, rgba(122, 215, 255, 0.11) 0 1px, transparent 1px 26px),
    linear-gradient(180deg, transparent, rgba(10, 14, 26, 0.9));
  pointer-events: none;
}

/* ==================================================================
   Voxel models (CSS 3D)
   ================================================================== */

.model-stage {
  --u-base: 3.9px;
  /* Board Vessels are miniatures on the table: without this they rendered at
     roster-thumbnail scale (27px tall) and read as scenery. */
  --board-u: clamp(6.2px, 1.05vw, 9.6px);
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  align-items: end;
  justify-items: center;
  perspective: 340px;
  transform-style: preserve-3d;
}

.cell .model-stage { --u-base: var(--board-u); }

/* Board models stand upright in the world: the tile is tilted, a miniature on
   it is not. Counter-rotating by the arena tilt keeps Vessels vertical. */
.cell .vox-model {
  transform: rotateX(calc(var(--tilt, 24deg) * 1)) rotateX(-13deg) rotateY(var(--spin, -32deg));
  transform-origin: 50% 100%;
}

.vox-model {
  --u: calc(var(--u-base, 2.4px) * var(--scale, 1));
  --spin: -32deg;
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  /* Three-quarter camera. Roster models can override --spin by dragging. */
  transform: rotateX(-13deg) rotateY(var(--spin));
  pointer-events: none;
}

/* Perspective keys and rounded forms are forbidden: this is a voxel pipeline.
   Faces are shaded per material in JS, so no CSS filter pass is required. */
.vox-body {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.vox-model[data-idle="breathe"] .vox-body { animation: vox-breathe 4.2s ease-in-out infinite; }
.vox-model[data-idle="heavy"] .vox-body { animation: vox-breathe 6.4s ease-in-out infinite; }
.vox-model[data-idle="hover"] .vox-body { animation: vox-hover 5.4s ease-in-out infinite; }
.vox-model[data-idle="sway"] .vox-body { animation: vox-sway 5.8s ease-in-out infinite; }
.vox-model[data-idle="none"] .vox-body { animation: none; }

/* Rotating a group rotates every box around that group's authored pivot: a
   shoulder, wrist, hip, tail root or neck. */
.vox-group {
  position: absolute;
  transform-style: preserve-3d;
  transform-origin: var(--ox, 0) var(--oy, 0) var(--oz, 0);
}

.vox-box {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: var(--h);
  transform-style: preserve-3d;
  transform: var(--t) translate(-50%, -50%) var(--r, rotateZ(0deg));
}

.vox-face {
  position: absolute;
  display: block;
  background: var(--c);
  /* No per-face border: at 2-3 px per voxel a border eats the fill and turns
     the model into noise. Depth comes from the material face tones. */
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.045);
  backface-visibility: hidden;
}

.vox-front {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: var(--c);
  transform: translateZ(calc(var(--d) / 2));
}

.vox-right {
  width: var(--d);
  height: 100%;
  left: calc((var(--w) - var(--d)) / 2);
  top: 0;
  background: var(--cs);
  transform: translateX(calc(var(--w) / 2)) rotateY(90deg);
}

/* The top face carries the bevel highlight: that single bright edge is what
   makes a stack of cubes read as a sculpted miniature. */
.vox-top {
  width: 100%;
  height: var(--d);
  left: 0;
  top: calc((var(--h) - var(--d)) / 2);
  background: var(--ct);
  border-top: 1px solid var(--ce);
  transform: translateY(calc(var(--h) / -2)) rotateX(90deg);
}

.vox-box.is-emissive .vox-front { box-shadow: 0 0 7px var(--c), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
.vox-box.is-emissive .vox-top { box-shadow: 0 0 6px var(--c); }

/* Metal and stone read through sharper stiping, not brighter colour alone. */
.vox-box[data-material="metal"] .vox-top { border-top-color: rgba(255, 255, 255, 0.35); }
.vox-box[data-material="crystal"] .vox-front,
.vox-box[data-material="glass"] .vox-front { opacity: 0.94; }

.model-shadow {
  position: absolute;
  bottom: -1px;
  left: 50%;
  width: 52%;
  height: 6px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), transparent);
  pointer-events: none;
}

@keyframes vox-breathe {
  0%, 100% { transform: translateY(0) rotateZ(0deg); }
  50% { transform: translateY(calc(var(--u) * -0.5)) rotateZ(calc(var(--sway) * 0.5deg)); }
}

@keyframes vox-hover {
  0%, 100% { transform: translateY(calc(var(--u) * -0.4)) rotateZ(0deg); }
  50% { transform: translateY(calc(var(--u) * -1.2)) rotateZ(calc(var(--sway) * -0.8deg)); }
}

@keyframes vox-sway {
  0%, 100% { transform: translateY(0) rotateZ(calc(var(--sway) * -1deg)); }
  50% { transform: translateY(calc(var(--u) * -0.35)) rotateZ(calc(var(--sway) * 1deg)); }
}

@keyframes vox-attack {
  0% { transform: translateY(0) rotateZ(0deg); }
  26% { transform: translateY(calc(var(--u) * -1.5)) rotateZ(-7deg); }
  58% { transform: translateY(calc(var(--u) * 0.5)) rotateZ(5deg); }
  100% { transform: translateY(0) rotateZ(0deg); }
}

/* Weapon, arm and head pivots give each attack a readable arc instead of
   sliding the whole model forward. */
@keyframes vox-swing {
  0% { transform: rotateZ(0deg); }
  32% { transform: rotateZ(-26deg); }
  62% { transform: rotateZ(78deg); }
  100% { transform: rotateZ(0deg); }
}
@keyframes vox-thrust {
  0% { transform: translateZ(0); }
  38% { transform: translateZ(calc(var(--u) * 3)); }
  100% { transform: translateZ(0); }
}
@keyframes vox-arm {
  0% { transform: rotateZ(0deg); }
  40% { transform: rotateZ(-38deg); }
  100% { transform: rotateZ(0deg); }
}

.cell.fx-lunge .vox-body { animation: vox-attack 380ms cubic-bezier(0.3, 0.9, 0.3, 1); }
.cell.fx-lunge .vox-group[data-group="weapon"] { animation: vox-swing 420ms cubic-bezier(0.2, 0.8, 0.3, 1); }
.cell.fx-lunge .vox-group[data-group="armR"] { animation: vox-arm 420ms cubic-bezier(0.2, 0.8, 0.3, 1); }
.cell.fx-lunge .vox-group[data-group="head"] { animation: vox-arm 380ms ease-out; }
.cell.fx-lunge .vox-group[data-group="tail"] { animation: vox-arm 400ms ease-out reverse; }
.cell.fx-hit .vox-body { animation: vox-flinch 320ms ease-in-out; }
.cell.fx-hit .vox-group[data-group="head"] { animation: vox-flinch-head 320ms ease-in-out; }

@keyframes vox-flinch {
  0%, 100% { transform: translateY(0) rotateZ(0deg); }
  25% { transform: translateY(calc(var(--u) * 0.8)) rotateZ(6deg); }
  60% { transform: translateY(calc(var(--u) * 0.4)) rotateZ(-4deg); }
}
@keyframes vox-flinch-head {
  0%, 100% { transform: rotateZ(0deg); }
  30% { transform: rotateZ(16deg); }
  65% { transform: rotateZ(-8deg); }
}

.cell.fx-spawn .vox-body { animation: vox-summon 340ms ease-out; }

@keyframes vox-summon {
  0% { opacity: 0; transform: translateY(calc(var(--u) * 4)) scale(0.6); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* The unit tile keeps its numbers readable underneath the model. */
.unit {
  position: relative;
  z-index: 3;
  /* Everything in the unit sits just above its own tile face; otherwise the
     raised ground plane sorts in front of the model and hides it. The unit
     itself stays flat: a nested preserve-3d context painted a dark backdrop
     over the tile instead of compositing the ground behind the model. */
  transform: translateZ(calc(var(--lift, 0px) + 1.5px));
  transform-style: flat;
}

/* The model owns the tile; the nameplate is a narrow strip at its feet. */
.unit .model-stage {
  grid-column: 1 / -1;
  grid-row: 1;
  align-self: stretch;
}

.unit::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 34%;
  z-index: 1;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(180deg, transparent, rgba(7, 11, 19, 0.42));
  pointer-events: none;
}

.unit-name {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  z-index: 2;
  display: block;
  min-width: 0;
  padding: 1px 3px;
  border-radius: 3px 0 0 0;
  background: rgba(8, 12, 20, 0.74);
  font-size: 8.5px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-stats {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  z-index: 2;
  display: flex;
  gap: 4px;
  padding: 1px 3px;
  border-radius: 0 3px 0 0;
  background: rgba(8, 12, 20, 0.74);
  font-size: 8.5px;
  line-height: 1.25;
  white-space: nowrap;
}

.unit-stats .stat.atk::before { content: "ATK "; color: var(--muted); }
.unit-stats .stat.gd::before { content: "GD "; color: var(--muted); }
.unit-stats .stat { font-variant-numeric: tabular-nums; }

/* Element and readiness become corner markers so the model gets the centre. */
.unit .element-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  z-index: 3;
  background: rgba(10, 14, 26, 0.72);
}

.unit-flag {
  position: absolute;
  top: 3px;
  right: 3px;
  z-index: 3;
  padding: 1px 3px;
  border-radius: 4px;
  font-size: 7px;
  letter-spacing: 0.06em;
  background: rgba(10, 14, 26, 0.72);
}

/* Only your own unready Vessels are dimmed; enemy units are unready by
   definition while it is your turn, so dimming them would be noise. */
.unit.friendly.unready .model-stage { opacity: 0.6; }
.unit.friendly.unready .unit-name { color: var(--muted); }

.legend-dot.unready { background: #6c789c; }

.guard-bar {
  grid-column: 1 / -1;
  grid-row: 3;
  position: relative;
  z-index: 2;
  display: block;
  height: 3px;
  border-radius: 0 0 2px 2px;
  background: rgba(10, 14, 26, 0.85);
  overflow: hidden;
}

.guard-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--ok), var(--accent));
  transition: width 260ms ease;
}

.unit.enemy .guard-bar i { background: linear-gradient(90deg, #ff9aa4, var(--danger)); }

/* ==================================================================
   Board zones
   ================================================================== */

.board-wrap {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
  width: min(100%, 680px);
}

.board-wrap .board { width: 100%; }

.board-gutter { position: relative; }

.gutter-label {
  position: absolute;
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 9px;
  letter-spacing: 0.24em;
  color: #55628c;
  text-align: center;
}

.gutter-label.enemy { color: rgba(255, 138, 149, 0.75); }
.gutter-label.friendly { color: rgba(122, 215, 255, 0.8); }

/* Zone tints use :where() so the interaction colours below always win. */
:where(.cell).zone-opponent {
  background: linear-gradient(180deg, rgba(255, 107, 122, 0.10), rgba(15, 21, 36, 0.95));
  border-color: #38263a;
}

:where(.cell).zone-contested {
  background:
    repeating-linear-gradient(45deg, rgba(255, 209, 102, 0.07) 0 5px, rgba(15, 21, 36, 0.95) 5px 10px);
  border-color: #3a3626;
}

:where(.cell).zone-home {
  background: linear-gradient(180deg, rgba(122, 215, 255, 0.09), rgba(15, 21, 36, 0.95));
  border-color: #24384f;
}

:where(.cell).deploy-blocked {
  border-style: dashed;
  border-color: rgba(122, 215, 255, 0.4);
  opacity: 0.62;
}

.cell.legal {
  border-style: solid;
  box-shadow: inset 0 0 0 1px rgba(110, 231, 168, 0.5), 0 0 12px rgba(110, 231, 168, 0.18);
}

/* ==================================================================
   Battlefield diorama
   A raised stone table, layered ground blocks, props and a key light.
   All of it is decoration painted under the interactive grid: the 7x7
   hit targets, coordinates and legal-tile rings stay exactly where the
   rules engine puts them.
   ================================================================== */

.board-stage {
  position: relative;
  width: min(100%, 600px);
  margin: 14px auto 20px;
  isolation: isolate;
}

/* Plinth: the arena is an object sitting on a dark table, not a rectangle. */
.board-stage::before {
  content: "";
  position: absolute;
  inset: -12px -9px -18px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, #333d52 0%, #232b3c 42%, #141a28 72%, #0b0f18 100%);
  box-shadow:
    0 26px 44px rgba(0, 0, 0, 0.62),
    0 6px 0 #0a0e16,
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -14px 22px rgba(0, 0, 0, 0.5);
  z-index: -1;
}

/* Key light from the upper left, vignette at the table edge. */
.board-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background:
    radial-gradient(120% 80% at 26% -10%, rgba(255, 238, 205, 0.07), transparent 58%),
    radial-gradient(100% 100% at 50% 54%, transparent 52%, rgba(5, 8, 14, 0.45));
  pointer-events: none;
  z-index: 5;
}

.board {
  --tilt: 24deg;
  --slab: 32px;
  position: relative;
  z-index: 2;
  /* A tabletop camera: steep enough that the ground blocks have visible sides,
     shallow enough that tile coordinates and stat text stay crisp. */
  transform: perspective(1450px) rotateX(var(--tilt));
  transform-origin: 50% 46%;
  transform-style: preserve-3d;
  padding: 13px;
  gap: 3px;
  border: 1px solid #4a4534;
  border-radius: 8px;
  /* The rim is packed earth and moss, so the lawns sit inside a place. */
  background:
    radial-gradient(120% 60% at 30% 0%, rgba(214, 220, 178, 0.18), transparent 60%),
    linear-gradient(168deg, #7c8460 0%, #666f4e 34%, #4f5740 68%, #3a4030 100%),
    #5d6547;
  box-shadow:
    inset 0 2px 0 rgba(255, 252, 240, 0.55),
    inset 0 -6px 14px rgba(60, 52, 38, 0.45),
    inset 0 0 0 4px rgba(226, 219, 200, 0.22);
}

/* The slab the diorama sits on: two visible sides and a cast shadow. */
.board::before,
.board::after {
  content: "";
  position: absolute;
  pointer-events: none;
  background-repeat: repeat;
}

/* Front face: layered soil under the paving edge. */
.board::before {
  left: 0;
  right: 0;
  top: 100%;
  height: var(--slab);
  transform-origin: 50% 0;
  transform: rotateX(-90deg);
  background-image:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 22px),
    linear-gradient(180deg, #8d8574 0 26%, #6a5b45 26% 62%, #493d2d 62%);
  box-shadow: inset 0 2px 0 rgba(255, 250, 235, 0.28);
}

/* Right face, in shade. */
.board::after {
  top: 0;
  bottom: 0;
  left: 100%;
  width: var(--slab);
  transform-origin: 0 50%;
  transform: rotateY(90deg);
  background-image:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 20px),
    linear-gradient(90deg, #6a5b45 0 40%, #453a2b 100%);
}

.board-post {
  position: absolute;
  width: 24px;
  height: 30px;
  z-index: 4;
  border-radius: 4px;
  background:
    linear-gradient(90deg, #2b3448 0 62%, #1a2233 62% 100%),
    #232c3e;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.14),
    inset 0 -6px 0 rgba(0, 0, 0, 0.45),
    0 10px 16px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.board-post::before {
  content: "";
  position: absolute;
  inset: -5px -3px auto;
  height: 7px;
  border-radius: 3px;
  background: linear-gradient(180deg, #4d5a75, #333e54);
}

.board-post.tl { left: -19px; top: -17px; }
.board-post.tr { right: -19px; top: -17px; }
.board-post.bl { left: -19px; bottom: -22px; }
.board-post.br { right: -19px; bottom: -22px; }

.arena-caption {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 -2px;
  text-align: center;
}

.arena-name {
  font-size: 11px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: #d8c9a6;
}

.arena-caption em {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---- ground blocks ------------------------------------------------- */

.cell {
  --lift: 0px;
  --block: 17px;
  /* Transparent: the gaps between tiles are soil and slab, not a dark card. */
  border-color: transparent;
  background: transparent;
  overflow: visible;
  transform-style: preserve-3d;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}


/* A tile is a block of ground, not a painted square: the top face is the
   material, the two front-facing sides are soil. Neighbouring gaps expose the
   sides, which is what makes the board read as a physical diorama. */
.cell-ground {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  z-index: 0;
  pointer-events: none;
  transform: translateZ(var(--lift));
  transform-style: preserve-3d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.cell-ground::before,
.cell-ground::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

/* Front wall of the block.
  
the tile face is the ground plane. A side wall has to contain the world-down
   direction, which for a board tilted by `--tilt` is the element rotated by the
   *negative* of that angle: rotateX(-90deg) would only make a horizontal slab
   and read as a painted square. */
.cell-ground::before {
  left: 0;
  right: 0;
  top: 100%;
  height: var(--block);
  transform-origin: 50% 0;
  transform: rotateX(calc(var(--tilt) * -1));
  background-image:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.14) 0 2px, transparent 2px 13px),
    linear-gradient(180deg, var(--soil-1) 0 30%, var(--soil-2) 30% 64%, var(--soil-3) 64%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

/* A darker lip on the wall's foot, so the block meets the earth behind it. */
.cell-ground::after {
  left: 0;
  right: 0;
  top: 100%;
  height: var(--block);
  transform-origin: 50% 0;
  transform: rotateX(calc(var(--tilt) * -1));
  background-image: linear-gradient(180deg, transparent 78%, rgba(0, 0, 0, 0.34));
}

/* Voxel grain plus directional light on the tile face: eight-pixel blocks of
   texture, a lit top-left and a shaded near edge. */
.cell-grain {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 2px;
  pointer-events: none;
  transform: translateZ(calc(var(--lift, 0px) + 0.5px));
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 8px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 8px),
    radial-gradient(120% 90% at 26% 10%, rgba(255, 250, 220, 0.16), transparent 64%),
    radial-gradient(110% 100% at 76% 98%, rgba(0, 0, 0, 0.26), transparent 68%);
  box-shadow: inset 0 -5px 9px rgba(0, 0, 0, 0.14);
}

/* ---- materials ------------------------------------------------------ *
 * Five surfaces, each defined by colour *and* texture: a mown lawn has clumps
 * and clover, paving has joints and chips, sand has pebbles, water has swell
 * lines and foam. Soil colours drive the block sides below every tile.
 */

.cell[data-terrain="grass"] {
  --soil-1: #6b8f45;
  --soil-2: #4d6634;
  --soil-3: #3a4a27;
}

.cell[data-terrain="grass"] .cell-ground {
  background:
    radial-gradient(38% 34% at 26% 22%, rgba(198, 236, 132, 0.5), transparent 68%),
    radial-gradient(30% 26% at 74% 62%, rgba(126, 176, 86, 0.55), transparent 70%),
    radial-gradient(circle at 18% 70%, rgba(58, 92, 42, 0.55) 0 3px, transparent 3px),
    radial-gradient(circle at 62% 30%, rgba(58, 92, 42, 0.45) 0 2px, transparent 2px),
    radial-gradient(circle at 82% 78%, rgba(168, 214, 120, 0.5) 0 2px, transparent 2px),
    linear-gradient(158deg, #86b657 0%, #6ca044 46%, #578c3c 100%);
}

.cell[data-terrain="moss"] {
  --soil-1: #4f7a3a;
  --soil-2: #3c5c2c;
  --soil-3: #2c4522;
}

.cell[data-terrain="moss"] .cell-ground {
  background:
    radial-gradient(46% 40% at 30% 26%, rgba(166, 220, 122, 0.42), transparent 70%),
    radial-gradient(circle at 30% 66%, rgba(96, 148, 62, 0.6) 0 3px, transparent 3px),
    radial-gradient(circle at 70% 40%, rgba(96, 148, 62, 0.5) 0 2px, transparent 2px),
    radial-gradient(circle at 54% 82%, rgba(196, 234, 140, 0.45) 0 2px, transparent 2px),
    linear-gradient(158deg, #6f9f48 0%, #578b3c 48%, #446f30 100%);
}

.cell[data-terrain="stone"] {
  --soil-1: #9a9484;
  --soil-2: #7b7462;
  --soil-3: #5d5749;
}

.cell[data-terrain="stone"] .cell-ground {
  background:
    linear-gradient(90deg, transparent 0 47%, rgba(70, 64, 52, 0.5) 47% 53%, transparent 53%),
    linear-gradient(0deg, transparent 0 47%, rgba(70, 64, 52, 0.45) 47% 53%, transparent 53%),
    radial-gradient(60% 50% at 30% 26%, rgba(255, 250, 232, 0.35), transparent 72%),
    radial-gradient(circle at 76% 74%, rgba(90, 84, 70, 0.4) 0 2px, transparent 2px),
    linear-gradient(158deg, #cfc8b4 0%, #b3ab95 52%, #948c78 100%);
  box-shadow:
    inset 0 0 0 1px rgba(96, 90, 74, 0.45),
    inset 0 2px 0 rgba(255, 253, 242, 0.4);
}

.cell[data-terrain="sand"] {
  --soil-1: #c9ab74;
  --soil-2: #a98b58;
  --soil-3: #83683e;
}

.cell[data-terrain="sand"] .cell-ground {
  background:
    radial-gradient(42% 36% at 32% 24%, rgba(255, 244, 206, 0.55), transparent 70%),
    radial-gradient(circle at 24% 62%, rgba(132, 106, 62, 0.5) 0 2px, transparent 2px),
    radial-gradient(circle at 68% 36%, rgba(132, 106, 62, 0.42) 0 2px, transparent 2px),
    radial-gradient(circle at 58% 78%, rgba(255, 246, 214, 0.5) 0 2px, transparent 2px),
    linear-gradient(158deg, #e2c893 0%, #cfb27a 52%, #b4945f 100%);
}

.cell[data-terrain="water"] {
  --soil-1: #2f7f8c;
  --soil-2: #23636f;
  --soil-3: #184b55;
}

.cell[data-terrain="water"] .cell-ground {
  /* Foam along the bank edge, a soft swell and a darker centre, rather than
     evenly spaced stripes across the whole tile. */
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62) 0 2px, rgba(255, 255, 255, 0.12) 2px 5px, transparent 5px),
    radial-gradient(46% 34% at 30% 62%, rgba(255, 255, 255, 0.18), transparent 72%),
    radial-gradient(40% 30% at 72% 36%, rgba(226, 252, 255, 0.22), transparent 74%),
    radial-gradient(130% 100% at 50% 30%, rgba(6, 54, 68, 0.34), transparent 70%),
    linear-gradient(158deg, #6fd0d6 0%, #46b0bf 42%, #2c8398 100%);
  box-shadow:
    inset 0 0 0 1px rgba(206, 248, 255, 0.4),
    inset 0 -8px 14px rgba(8, 44, 56, 0.45);
}

.cell[data-terrain="crystal"] {
  --soil-1: #9fb6b4;
  --soil-2: #7d938f;
  --soil-3: #5e6f6d;
}

.cell[data-terrain="crystal"] .cell-ground {
  background:
    radial-gradient(46% 44% at 50% 46%, rgba(154, 239, 255, 0.55), transparent 70%),
    repeating-linear-gradient(58deg, rgba(70, 150, 168, 0.28) 0 2px, transparent 2px 12px),
    repeating-linear-gradient(-58deg, rgba(70, 150, 168, 0.22) 0 2px, transparent 2px 14px),
    linear-gradient(158deg, #d8e6e2 0%, #b7cdc9 48%, #93aeab 100%);
  box-shadow:
    inset 0 0 0 1px rgba(126, 214, 232, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

/* Keep legal-tile feedback above the ground and props. */
.cell.legal .cell-ground { box-shadow: inset 0 0 0 2px rgba(110, 231, 168, 0.65), 0 0 14px rgba(110, 231, 168, 0.22); }
.cell.move .cell-ground { box-shadow: inset 0 0 0 2px rgba(122, 215, 255, 0.55), 0 0 12px rgba(122, 215, 255, 0.18); }
.cell.attack .cell-ground { box-shadow: inset 0 0 0 2px rgba(255, 107, 122, 0.6), 0 0 12px rgba(255, 107, 122, 0.2); }
.cell.selected .cell-ground { box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.8), 0 0 16px rgba(255, 209, 102, 0.24); }

/* ---- props --------------------------------------------------------- */

.cell-prop {
  position: absolute;
  left: 50%;
  bottom: 58%;
  z-index: 1;
  /* Scenery stands on the raised tile face, not under it: with preserve-3d the
     ground is sorted by real depth, so scenery must share its elevation. */
  transform: translateX(-50%) translateZ(var(--lift, 0px));
  pointer-events: none;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.42));
}

.cell-prop.is-flipped { transform: translateX(-50%) translateZ(var(--lift, 0px)) scaleX(-1); }

/* Scenery is authored at Vessel scale, so a tree stands taller than a unit. */
.cell-prop-model {
  --u-base: clamp(10px, 1.9vw, 15.5px);
}

/* Scenery sits in the world: every prop drops a soft contact shadow. */  .cell-prop::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 26px;
  height: 8px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.42), transparent);
  pointer-events: none;
}

.cell-prop .vox-body { animation: none; }

@media (max-width: 640px) {
  /* Mobile tiles are ~57px: scenery has to shrink with them or it buries the
     tile, and the board model follows the same rule. */
  .cell-prop-model { --u-base: 4.4px; }
  .cell-prop { bottom: 56%; }
  .cell .model-stage { --u-base: 4.8px; }
  .cell .vox-model { transform: rotateX(calc(var(--tilt, 24deg) * 1)) rotateX(-9deg) rotateY(var(--spin, -32deg)); }
  .board-post { width: 16px; height: 20px; }
  .board-post.tl, .board-post.bl { left: -11px; }
  .board-post.tr, .board-post.br { right: -11px; }
  .board-post.tl, .board-post.tr { top: -11px; }
  .board-post.bl, .board-post.br { bottom: -14px; }
  .arena-caption em { display: none; }
}

/* ==================================================================
   Back row, prompt bar, tutorial
   ================================================================== */

.back-row {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(181, 139, 255, 0.07), rgba(20, 24, 39, 0.6));
  padding: 14px 16px;
}

.back-row-slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.relic-slot {
  border: 1px dashed rgba(122, 215, 255, 0.35);
  border-radius: 10px;
  min-height: 84px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
  background: rgba(12, 16, 28, 0.6);
}

.relic-slot.filled {
  border-style: solid;
  border-color: var(--accent-2);
  background: linear-gradient(150deg, rgba(181, 139, 255, 0.18), rgba(12, 16, 28, 0.85));
  box-shadow: 0 0 18px rgba(181, 139, 255, 0.15);
}

.slot-index {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: #6c789c;
}

.slot-body { display: flex; flex-direction: column; gap: 2px; }
.slot-body strong { font-size: 14px; }
.slot-element { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.slot-effect { font-size: 11px; color: var(--muted); }
.slot-empty { margin: 0; font-size: 12px; color: #5b678c; }

.turn-bar {
  position: sticky;
  bottom: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(11, 13, 22, 0.94);
  backdrop-filter: blur(6px);
}

.message {
  flex: 1;
  margin: 0;
  font-size: 13px;
  color: #d5ddf3;
}

.message::before {
  display: inline-block;
  margin-right: 10px;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 9px;
  letter-spacing: 0.16em;
  vertical-align: 1px;
  border: 1px solid currentColor;
  color: var(--muted);
}

.message[data-state="idle"]::before { content: "READY"; }
.message[data-state="deploy"]::before { content: "DEPLOY"; color: var(--ok); }
.message[data-state="target"]::before { content: "TARGET"; color: var(--accent-2); }
.message[data-state="command"]::before { content: "MOVE / ATTACK"; color: var(--accent); }
.message[data-state="waiting"]::before { content: "OPPONENT"; color: var(--danger); }
.message[data-state="over"]::before { content: "FINISHED"; color: var(--danger); }

.tutorial-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
  padding: 12px 16px;
  border: 1px solid rgba(110, 231, 168, 0.45);
  border-radius: var(--radius);
  background: linear-gradient(120deg, rgba(110, 231, 168, 0.12), rgba(20, 24, 39, 0.75));
}

.tutorial-panel[hidden] { display: none; }
.tutorial-copy { flex: 1; min-width: 0; }
.tutorial-copy h3 { margin: 0 0 4px; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); }
.tutorial-actions { display: flex; gap: 8px; }

/* ==================================================================
   How to Play and Roster
   ================================================================== */

.guide-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: clamp(14px, 3vw, 34px) 0 18px;
}

.guide-head h2 { font-size: clamp(20px, 3vw, 30px); }

.guide-steps {
  list-style: none;
  counter-reset: step;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.guide-steps li {
  counter-increment: step;
  position: relative;
  padding: 16px 18px 16px 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.68);
}

.guide-steps li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 16px;
  top: 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.guide-steps h3 {
  margin: 0 0 6px;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

.guide-steps p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--muted); }

.guide-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 20px 0 8px;
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 14px;
  padding-bottom: 30px;
}

.roster-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 24, 39, 0.7);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.roster-stage {
  --u-base: 10px;
  height: 200px;
  background-size: cover;
  background-position: 50% 60%;
  display: grid;
  align-items: end;
  justify-items: center;
  padding-bottom: 14px;
  perspective: 700px;
  cursor: grab;
  touch-action: pan-y;
  background: radial-gradient(60% 46% at 50% 82%, rgba(122, 215, 255, 0.16), transparent 72%), linear-gradient(180deg, #0d1220, #0a0e1a);
}

.roster-stage::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 34%;
  background: radial-gradient(50% 60% at 50% 100%, rgba(0, 0, 0, 0.55), transparent 75%);
  pointer-events: none;
}

.roster-stage { position: relative; }
.roster-stage .vox-model { z-index: 1; transition: transform 90ms linear; }
.roster-stage.is-spinning { cursor: grabbing; }
.roster-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.roster-flavor {
  margin: 10px 0 0 !important;
  font-size: 11px;
  line-height: 1.5;
  color: #9aa6c4;
  font-style: italic;
}

.roster-ability {
  margin: 6px 0 0 !important;
  font-size: 11px;
  line-height: 1.45;
}

.roster-card.fire .roster-stage { background: radial-gradient(60% 46% at 50% 82%, rgba(255, 133, 81, 0.2), transparent 72%), linear-gradient(180deg, #150e12, #0a0e1a); }
.roster-card.water .roster-stage { background: radial-gradient(60% 46% at 50% 82%, rgba(99, 199, 255, 0.2), transparent 72%), linear-gradient(180deg, #0c1420, #0a0e1a); }
.roster-card.earth .roster-stage { background: radial-gradient(60% 46% at 50% 82%, rgba(216, 178, 106, 0.2), transparent 72%), linear-gradient(180deg, #14110c, #0a0e1a); }
.roster-card.metal .roster-stage { background: radial-gradient(60% 46% at 50% 82%, rgba(185, 198, 232, 0.2), transparent 72%), linear-gradient(180deg, #101420, #0a0e1a); }
.roster-card.wood .roster-stage { background: radial-gradient(60% 46% at 50% 82%, rgba(111, 208, 140, 0.2), transparent 72%), linear-gradient(180deg, #0d150f, #0a0e1a); }

.roster-meta { padding: 12px 14px 16px; border-top: 1px solid var(--line); }
.roster-meta h3 { margin: 8px 0 4px; font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); }
.roster-meta p { margin: 0 0 10px; }

.roster-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.roster-stats strong { color: var(--text); font-size: 13px; }

.tab:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 900px) {
  .menu-hero { grid-template-columns: minmax(0, 1fr); }
  .menu-stage { order: -1; min-height: 220px; }
}

@media (max-width: 640px) {
  .board-gutter { display: none; }
  .board-wrap { grid-template-columns: minmax(0, 1fr); }
  /* Phone tiles are ~43 px: let the model grow upward past the stage box so it
     still reads, since the space above it only holds a corner badge. */
  .model-stage { --u-base: 2.6px; overflow: visible; }
  .unit-stats { font-size: 8px; gap: 2px; }
  .unit-stats .stat.atk::before { content: "A"; }
  .unit-stats .stat.gd::before { content: "G"; }
  .unit-flag { display: none; }
  .unit .element-badge { font-size: 7px; padding: 0 2px; }
  .menu-model { --u-base: 6px; }
  .menu-model:nth-child(2) { --u-base: 7.4px; }
  .menu-model:nth-child(3) { --u-base: 5.6px; }
  .menu-model:nth-child(4) { --u-base: 5.8px; }
  .roster-stage { --u-base: 6.4px; height: 150px; }
  .back-row-slots { grid-template-columns: minmax(0, 1fr); }
  .unit .guard-bar { height: 2px; }
}

/* ------------------------------ card library ------------------------------ */

.library-filters {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  appearance: none;
  border: 1px solid rgba(150, 178, 220, 0.28);
  background: rgba(18, 24, 38, 0.72);
  color: #cfdaf0;
  border-radius: 999px;
  padding: 7px 15px;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.chip:hover { border-color: rgba(170, 205, 255, 0.55); color: #f2f7ff; }

.chip.active {
  background: linear-gradient(180deg, rgba(120, 176, 255, 0.28), rgba(60, 96, 150, 0.28));
  border-color: rgba(180, 216, 255, 0.7);
  color: #ffffff;
}

.chip.wood { border-color: rgba(127, 224, 106, 0.4); }
.chip.fire { border-color: rgba(255, 106, 42, 0.42); }
.chip.earth { border-color: rgba(216, 178, 116, 0.42); }
.chip.metal { border-color: rgba(138, 216, 240, 0.42); }
.chip.water { border-color: rgba(95, 208, 240, 0.42); }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 20px;
  padding-bottom: 40px;
}

.library-tile {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  display: grid;
  gap: 8px;
  border-radius: 12px;
  transition: transform 160ms ease, filter 160ms ease;
  filter: drop-shadow(0 14px 26px rgba(0, 0, 0, 0.55));
}

.library-tile img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
}

.library-tile:hover,
.library-tile:focus-visible {
  transform: translateY(-4px);
  filter: drop-shadow(0 20px 34px rgba(0, 0, 0, 0.65)) brightness(1.06);
  outline: none;
}

.library-tile-name {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9dabca;
}

.roster-print { margin-top: 10px; justify-self: start; }

/* Full-size card viewer */

body.card-modal-open { overflow: hidden; }

.card-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 32px);
}

.card-modal[hidden] { display: none; }

.card-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, 0.86);
  backdrop-filter: blur(6px);
}

.card-modal-body {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(180px, 260px);
  gap: clamp(16px, 2.5vw, 32px);
  align-items: center;
  max-height: 100%;
}

.card-modal-image {
  display: block;
  height: min(86vh, 1000px);
  width: auto;
  border-radius: 14px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.7);
}

.card-modal-meta h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(20px, 2.2vw, 28px);
  margin: 0 0 8px;
}

.card-modal-close {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(190, 214, 250, 0.4);
  background: rgba(16, 22, 34, 0.9);
  color: #e8f0ff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.card-modal-close:hover { background: rgba(40, 56, 82, 0.95); }

@media (max-width: 760px) {
  .card-modal-body {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    overflow-y: auto;
  }
  .card-modal-image { height: auto; width: min(88vw, 460px); }
  .card-modal-meta { text-align: center; }
  .card-modal-close { top: 4px; right: 4px; }
}

#card-modal-file {
  display: inline-block;
  margin-top: 12px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
}

@media (max-width: 640px) {
  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }
  .library-tile-name { font-size: 10px; }
  .library-filters { gap: 8px; }
  .chip { padding: 6px 12px; font-size: 12px; }
}

/* ---- 2026-10-29: approved-frame cards, systems views, 3D arena ---- */
.arena-3d { width: 100%; min-height: 320px; }
.arena-3d canvas { display: block; width: 100%; border-radius: 12px; }
.arena-3d-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.sys-head { max-width: 900px; margin-bottom: 16px; }
.sys-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.sys-balance { font-size: 20px; font-weight: 700; }
.sys-status { background: rgba(127, 208, 138, 0.14); border: 1px solid rgba(127, 208, 138, 0.4); padding: 10px 12px; border-radius: 8px; }
.sys-warning { background: rgba(255, 193, 7, 0.12); border: 1px solid rgba(255, 193, 7, 0.45); padding: 10px 12px; border-radius: 8px; }
.sys-errors { color: #ffb3a8; }
.sys-deck { border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 12px; padding: 12px; margin: 12px 0; }
.sys-deck-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.pill.ok { background: rgba(127, 208, 138, 0.2); }
.pill.bad { background: rgba(224, 90, 74, 0.25); }
.sys-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.sys-card { border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 10px; padding: 8px; }
.sys-card-name { display: block; font-weight: 700; font-size: 13px; margin-top: 6px; }
.sys-card-meta, .sys-card-owned { display: block; font-size: 11px; opacity: 0.8; }
.sys-seat { border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 10px; padding: 10px; margin: 10px 0; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sys-opening { border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 12px; padding: 12px; margin: 12px 0; }
.discard-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; max-height: 60vh; overflow: auto; }
.sys-discard-row { border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 10px; padding: 8px; }
.discard-modal-body { max-width: 900px; }

/* Approved frame card: 214:300 geometry from CardFrames/frame-manifest.json. */
.approved-card { position: relative; width: 100%; aspect-ratio: 214 / 300; container-type: inline-size; overflow: hidden; border-radius: 6px; background: #1a2233; }
.approved-card.relic-pending { border: 2px solid #c9a86f; }
.approved-art { position: absolute; object-fit: cover; z-index: 1; }
.approved-art-full { inset: 0; width: 100%; height: 100%; }
.approved-overlay { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.approved-name { position: absolute; z-index: 3; left: 9%; top: 3.5%; width: 66%; font-family: Georgia, serif; font-weight: 700; font-size: 9cqw; line-height: 1.1; color: #1c2416; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.approved-cost { position: absolute; z-index: 3; right: 4%; top: 2.5%; width: 14%; text-align: center; font-family: Georgia, serif; font-weight: 700; font-size: 11cqw; color: #fff; text-shadow: 0 1px 3px #000; }
.approved-mid { position: absolute; z-index: 3; left: 0; right: 0; top: 65.5%; text-align: center; font-size: 7cqw; font-weight: 700; color: #1c2416; letter-spacing: 0.04em; }
.approved-text { position: absolute; z-index: 3; left: 10%; right: 10%; top: 72%; font-size: 6.5cqw; line-height: 1.25; color: #1c2416; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.approved-card.relic-pending .approved-name { color: #f5eeda; top: 4%; }
.approved-card.relic-pending .approved-text { color: #f5eeda; }
@media (max-width: 640px) {
  .sys-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .arena-3d { min-height: 240px; }
}

/* 2026-10-29 fix: `.arena-core .board-wrap { display: block }` beat the UA
   [hidden] rule, so in 3D mode the classic board rendered underneath the
   canvas as a second battlefield. The toggle sets `hidden`; honour it. */
.board-wrap[hidden],
.arena-3d[hidden] { display: none !important; }

/* 2026-10-29 mobile fix: nine tabs in one non-wrapping pill measured 518 px
   on a 390 px phone, widening the whole layout viewport (horizontal page
   scroll, zoomed-out page). Wrap the tabs instead. */
@media (max-width: 640px) {
  .tabs { flex-wrap: wrap; justify-content: center; gap: 4px; border-radius: 16px; max-width: 100%; min-width: 0; }
  .tab { white-space: nowrap; padding: 7px 10px; }
}
