:root {
  --bg: #101318;
  --panel: #1b2129;
  --panel-2: #222a35;
  --line: #394454;
  --text: #eef2f5;
  --muted: #a9b4c2;
  --gold: #e5b84b;
  --ally: #f3ead5;
  --enemy: #d94f4f;
  --blue: #4aa4ff;
  --amber: #ffbf52;
  --red: #ff5a5f;
  --yellow: #f4d44d;
  --purple: #a77cff;
  --green: #64d98b;
  --cell: min(9.2vh, 74px);
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 22%),
    radial-gradient(circle at 20% 10%, rgba(229, 184, 75, 0.08), transparent 28%),
    #101318;
  color: var(--text);
}

button {
  font: inherit;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(229, 184, 75, 0.55);
  background: #19150c;
  color: var(--gold);
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.05;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.meters {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 10px;
}

.meter {
  min-width: 94px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(27, 33, 41, 0.86);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.meter strong {
  display: block;
  margin-top: 2px;
  font-size: 24px;
}

.meter.danger strong {
  color: var(--gold);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(560px, 1fr) minmax(250px, 310px);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.panel {
  min-height: 500px;
  border: 1px solid var(--line);
  background: rgba(27, 33, 41, 0.92);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.22);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(57, 68, 84, 0.7);
}

.panel-head.compact {
  margin-top: 8px;
  border-top: 1px solid rgba(57, 68, 84, 0.7);
}

.panel h2 {
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-button,
.command-button,
.primary-button,
.choice-buttons button {
  border: 1px solid var(--line);
  background: #252e3a;
  color: var(--text);
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    transform 120ms ease;
}

.icon-button {
  width: 34px;
  height: 34px;
  font-weight: 800;
}

.command-button,
.primary-button,
.choice-buttons button {
  min-height: 40px;
  padding: 0 16px;
  font-weight: 800;
}

.icon-button:hover,
.command-button:hover,
.primary-button:hover,
.choice-buttons button:hover {
  border-color: var(--gold);
  background: #303b49;
}

.icon-button:active,
.command-button:active,
.primary-button:active,
.choice-buttons button:active {
  transform: translateY(1px);
}

.roster {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.roster-card {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}

.roster-card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(229, 184, 75, 0.45);
}

.roster-card.danger {
  border-color: var(--red);
}

.piece-token {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid rgba(243, 234, 213, 0.6);
  background: linear-gradient(145deg, #f4ead4, #c6ad72);
  color: #17130b;
  font-weight: 950;
  font-size: 22px;
}

.piece-token.enemy {
  border-color: rgba(255, 92, 95, 0.65);
  background: linear-gradient(145deg, #66252b, #2b1519);
  color: #ffd2d2;
}

.piece-meta strong {
  display: block;
  font-size: 15px;
}

.piece-meta span,
.roster-stat,
.selected-panel,
.summary-list,
.log {
  color: var(--muted);
  font-size: 13px;
}

.perk-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.perk-tag {
  padding: 2px 5px;
  border: 1px solid rgba(229, 184, 75, 0.45);
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
}

.selected-panel {
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid rgba(57, 68, 84, 0.8);
  background: rgba(16, 19, 24, 0.45);
  line-height: 1.42;
}

.selected-panel strong {
  color: var(--text);
}

.board-wrap {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.board-frame {
  position: relative;
  padding: 26px 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent),
    #181d24;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.28);
}

.front-label,
.convoy-label {
  position: absolute;
  left: 18px;
  right: 18px;
  height: 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.front-label {
  top: 5px;
}

.convoy-label {
  bottom: 4px;
  color: var(--gold);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  border: 2px solid #4d5968;
  background: #0d1015;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell);
  border: 1px solid rgba(11, 13, 17, 0.75);
  background: #242b35;
  overflow: hidden;
}

.cell:nth-child(16n + 1),
.cell:nth-child(16n + 3),
.cell:nth-child(16n + 5),
.cell:nth-child(16n + 7),
.cell:nth-child(16n + 10),
.cell:nth-child(16n + 12),
.cell:nth-child(16n + 14),
.cell:nth-child(16n + 16) {
  background: #1c232d;
}

.cell.edge {
  box-shadow: inset 0 -8px 0 rgba(229, 184, 75, 0.2);
}

.cell.front {
  box-shadow: inset 0 8px 0 rgba(74, 164, 255, 0.13);
}

.cell.move::after,
.cell.shot::after,
.cell.threat::after,
.cell.salvage::after,
.cell.command::after,
.cell.dragging::after {
  position: absolute;
  inset: 4px;
  content: "";
  pointer-events: none;
}

.cell.move::after {
  border: 2px solid var(--blue);
  background: rgba(74, 164, 255, 0.16);
}

.cell.shot::after {
  border: 2px solid var(--amber);
  background: rgba(255, 191, 82, 0.18);
}

.cell.threat::after {
  border: 2px solid var(--red);
  background: rgba(255, 90, 95, 0.18);
}

.cell.salvage::after {
  border: 2px solid var(--yellow);
  background: rgba(244, 212, 77, 0.18);
}

.cell.command::after {
  border: 2px dashed var(--purple);
}

.cell.dragging::after {
  border: 3px solid var(--gold);
}

.cell.selected-cell {
  outline: 3px solid var(--gold);
  outline-offset: -5px;
}

.unit {
  position: relative;
  z-index: 2;
  display: grid;
  width: calc(var(--cell) * 0.66);
  height: calc(var(--cell) * 0.66);
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 0;
  font-size: clamp(18px, calc(var(--cell) * 0.35), 30px);
  font-weight: 950;
  line-height: 1;
}

.unit.ally {
  background: linear-gradient(145deg, #f3ead5, #c5a96a);
  color: #17130b;
}

.unit.enemy {
  background: linear-gradient(145deg, #7d2d35, #281418);
  color: #ffdede;
}

.unit .hp-dot,
.unit .xp-dot {
  position: absolute;
  display: grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  padding: 0 4px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  background: rgba(16, 19, 24, 0.9);
  color: #fff;
  font-size: 10px;
}

.unit .hp-dot {
  right: -8px;
  top: -8px;
}

.unit .xp-dot {
  left: -8px;
  bottom: -8px;
}

.salvage-token {
  position: relative;
  z-index: 1;
  display: grid;
  width: calc(var(--cell) * 0.46);
  height: calc(var(--cell) * 0.46);
  place-items: center;
  border: 2px solid #fff1a8;
  background: #705c12;
  color: #fff4b8;
  font-weight: 950;
}

.float-label {
  position: absolute;
  z-index: 5;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.74);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  animation: floatUp 900ms ease forwards;
  pointer-events: none;
}

@keyframes floatUp {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -22px);
  }
}

.action-strip {
  display: flex;
  gap: 10px;
}

.summary-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.rule-note {
  margin: 14px 14px 0;
  padding: 10px;
  border: 1px solid rgba(229, 184, 75, 0.42);
  background: rgba(229, 184, 75, 0.08);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.summary-item {
  padding: 10px;
  border: 1px solid rgba(57, 68, 84, 0.8);
  background: rgba(16, 19, 24, 0.45);
  line-height: 1.35;
}

.summary-item strong {
  display: block;
  color: var(--text);
}

.log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 312px;
  overflow: auto;
  padding: 14px;
}

.log-entry {
  padding: 8px 10px;
  border-left: 3px solid var(--line);
  background: rgba(16, 19, 24, 0.44);
}

.log-entry.good {
  border-left-color: var(--green);
}

.log-entry.bad {
  border-left-color: var(--red);
}

.log-entry.gold {
  border-left-color: var(--gold);
}

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

.choice-overlay.hidden {
  display: none;
}

.choice-card {
  width: min(440px, calc(100vw - 40px));
  border: 1px solid var(--line);
  background: #1b2129;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.choice-card h2 {
  color: var(--text);
  font-size: 24px;
  text-transform: none;
}

.choice-card p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.choice-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.choice-buttons button {
  text-align: left;
  min-height: 58px;
}

.result-stats {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.result-stat {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(57, 68, 84, 0.55);
  padding-bottom: 8px;
}

.primary-button {
  width: 100%;
}

@media (max-width: 1120px) {
  :root {
    --cell: min(10.5vw, 64px);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100vw - 18px, 560px);
    padding: 10px 0;
  }

  .meters {
    grid-template-columns: repeat(2, 1fr);
  }

  h1 {
    font-size: 24px;
  }

  .board-frame {
    padding-left: 8px;
    padding-right: 8px;
  }

  .front-label,
  .convoy-label {
    left: 8px;
    right: 8px;
  }

  .choice-buttons {
    grid-template-columns: 1fr;
  }
}
