:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: rgba(23, 29, 43, 0.94);
  --panel2: rgba(31, 39, 57, 0.96);
  --text: #f3ead8;
  --muted: #b9af9e;
  --gold: #d7b56d;
  --gold2: #f2d48a;
  --danger: #e05a4f;
  --line: rgba(242, 212, 138, 0.18);
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.45);
  --serif: Georgia, "Times New Roman", serif;
  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;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 16%, rgba(122, 42, 55, 0.24), transparent 30%),
    linear-gradient(135deg, #070a10 0%, #101722 58%, #16131b 100%);
}

button,
select,
input {
  font-family: inherit;
}

button,
.file-label {
  min-height: 34px;
  border: 1px solid rgba(242, 212, 138, 0.36);
  border-radius: 10px;
  padding: 8px 11px;
  color: var(--text);
  background: rgba(215, 181, 109, 0.12);
  font-weight: 850;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

button:hover:not(:disabled),
.file-label:hover {
  transform: translateY(-1px);
  border-color: rgba(242, 212, 138, 0.75);
  background: rgba(215, 181, 109, 0.22);
}

button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(180deg, rgba(215, 181, 109, 0.42), rgba(116, 61, 47, 0.8));
  border-color: rgba(242, 212, 138, 0.72);
}

button.danger {
  border-color: rgba(224, 90, 79, 0.7);
  background: rgba(224, 90, 79, 0.18);
}

input,
select {
  min-height: 34px;
  border: 1px solid rgba(242, 212, 138, 0.2);
  border-radius: 10px;
  padding: 7px 9px;
  color: var(--text);
  background: rgba(5, 8, 13, 0.84);
}

.file-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(600px, 1fr) 365px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top top top"
    "left board right";
  gap: 14px;
  padding: 14px;
}

.topbar,
.left,
.right,
.board-shell {
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 244, 216, 0.045), rgba(255, 255, 255, 0)),
    var(--panel);
  box-shadow: var(--shadow);
}

.topbar {
  grid-area: top;
  min-height: 82px;
  display: grid;
  grid-template-columns: 270px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 42px;
  line-height: 1;
  letter-spacing: 0;
  color: var(--gold2);
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  border: 1px solid rgba(242, 212, 138, 0.16);
  border-radius: 999px;
  padding: 0 9px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
  font-size: 12px;
  font-weight: 800;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.left {
  grid-area: left;
  padding: 13px;
  overflow: auto;
}

.right {
  grid-area: right;
  padding: 13px;
  overflow: auto;
}

.section-title {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 900;
}

.player-card {
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 11px;
  background: rgba(255, 255, 255, 0.048);
}

.player-card.active {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--pcolor), white 10%);
  background: rgba(255, 255, 255, 0.075);
}

.player-head,
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.player-name,
.vp {
  font-weight: 900;
}

.resources {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.res {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  border-radius: 9px;
  padding: 6px 8px;
  color: #fff6db;
  box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.22);
  font-size: 12px;
}

.res strong {
  font-size: 15px;
}

.res.flash-gain {
  animation: resourceGain 3s ease both;
}

.res.flash-loss {
  animation: resourceLoss 3s ease both;
}

.badge-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 8px;
}

.board-shell {
  grid-area: board;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.board-help {
  min-height: 42px;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(242, 212, 138, 0.12);
  color: var(--gold2);
  background: rgba(5, 8, 13, 0.62);
  font-weight: 850;
  font-size: 13px;
}

#board {
  width: 100%;
  height: 100%;
  min-height: 650px;
  background:
    radial-gradient(circle at 55% 42%, rgba(242, 212, 138, 0.07), transparent 28%),
    linear-gradient(160deg, rgba(9, 13, 20, 0.88), rgba(14, 19, 29, 0.98));
  touch-action: none;
}

.zoom-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  color: rgba(243, 234, 216, 0.55);
  font-size: 11px;
  pointer-events: none;
}

.dice-float {
  position: absolute;
  top: 58px;
  left: 14px;
  display: none;
  align-items: center;
  gap: 8px;
  transform: none;
  z-index: 4;
  padding: 8px 11px;
  border: 1px solid rgba(242, 212, 138, 0.34);
  border-radius: 999px;
  background: rgba(10, 13, 20, 0.9);
  box-shadow: var(--shadow);
}

.dice-float.show {
  display: flex;
}

.die,
.battle-die {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(242, 212, 138, 0.5);
  background: #efe2c0;
  color: #17120c;
  font-weight: 950;
}

.battle-die.attack {
  background: #7a2d2a;
  color: white;
  border-color: #f2d48a;
}

.battle-die.defense {
  background: #efe2c0;
  color: #17120c;
}

.battle-die.artillery {
  background: #3a3f4d;
  color: #ffe08a;
  border-color: #ffe08a;
}

.battle-die {
  opacity: 0;
  transform: translateY(-4px) scale(0.92);
  animation: dieRollIn 0.82s ease forwards;
}

.toast {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  max-width: min(360px, calc(100% - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(242, 212, 138, 0.4);
  border-radius: 12px;
  color: var(--text);
  background: rgba(10, 13, 20, 0.92);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.16s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.panel-card,
.collapsible {
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.15);
}

.context-title,
.panel-card h2 {
  margin: 0 0 7px;
  color: var(--gold2);
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: 0;
}

.small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.multiline {
  white-space: pre-line;
}

.action-grid {
  display: grid;
  gap: 8px;
  margin-top: 9px;
}

.collapsible summary {
  cursor: pointer;
  color: var(--gold2);
  font-weight: 900;
}

.trade-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.cost-reference {
  display: grid;
  gap: 7px;
}

.cost-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
}

.cost-name {
  color: var(--gold2);
  font-weight: 900;
}

.cost-text {
  color: var(--text);
  opacity: 0.94;
  font-size: 12px;
  line-height: 1.32;
}

.event-list {
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.event {
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-size: 12px;
}

.progress-card {
  margin-top: 8px;
  border: 1px solid rgba(242, 212, 138, 0.22);
  border-radius: 12px;
  padding: 9px;
  background: rgba(215, 181, 109, 0.08);
}

.progress-card-title {
  color: var(--gold2);
  font-weight: 900;
}

.battle-dice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 8px;
}

.tile,
.angle-node,
.unit,
.structure,
.vertex-target,
.edge-target,
.port-marker {
  cursor: pointer;
}

.tile-resource {
  fill: rgba(255, 245, 222, 0.95);
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 900;
  pointer-events: none;
}

.tile-number {
  fill: #10151c;
  font-size: 21px;
  font-weight: 950;
  pointer-events: none;
}

.tile-number-token {
  fill: rgba(241, 224, 185, 0.94);
  stroke: rgba(244, 211, 123, 0.74);
  stroke-width: 2;
  pointer-events: none;
}

.tile-number-token.producing {
  filter: drop-shadow(0 0 13px rgba(255, 238, 168, 0.95)) drop-shadow(0 0 24px rgba(255, 238, 168, 0.55));
  stroke: #fff0a8;
  stroke-width: 3;
}

.edge-target.highlight,
.vertex-target.highlight,
.angle-node.valid-destination,
.unit.movable circle {
  filter: drop-shadow(0 0 10px rgba(244, 211, 123, 0.85));
}

.road-underlay {
  stroke: rgba(7, 10, 16, 0.36);
  stroke-width: 11;
  stroke-linecap: round;
  pointer-events: none;
}

.road {
  filter: drop-shadow(0 2px 7px rgba(0, 0, 0, 0.68));
}

.angle-node {
  opacity: 0.36;
}

body[data-phase^="SETUP"] .angle-node,
body[data-phase="MILITARY"] .angle-node,
.angle-node.valid-destination {
  opacity: 0.82;
}

.angle-node.battle-target,
.angle-node.bombard-target {
  fill: rgba(224, 90, 79, 0.82);
  stroke: #fff;
  filter: drop-shadow(0 0 9px rgba(224, 90, 79, 0.7));
}

.angle-node.stack-target {
  fill: rgba(104, 168, 255, 0.58);
}

.angle-node.support-target {
  fill: rgba(55, 58, 68, 0.92);
  stroke: #ffe08a;
  filter: drop-shadow(0 0 12px rgba(255, 224, 138, 0.7));
}

.angle-node.pending-destination {
  fill: #ffe08a;
  stroke: #fff;
  filter: drop-shadow(0 0 12px rgba(242, 212, 138, 0.9));
}

.angle-occupation {
  pointer-events: none;
}

.occupation-link {
  stroke-width: 5;
  stroke-dasharray: 6 4;
  stroke-linecap: round;
  pointer-events: none;
  opacity: 0.96;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.55));
}

.occupation-halo {
  fill: transparent;
  stroke-width: 4;
  pointer-events: none;
  opacity: 0.95;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.55));
}

.unit.selected circle {
  stroke: #fff5cf;
  stroke-width: 4;
}

.unit.receded {
  opacity: 0.36;
}

.unit.target-battle circle {
  stroke: #ff6458;
  stroke-width: 4;
}

.unit.target-support circle {
  stroke: #2f313b;
  stroke-width: 4;
  filter: drop-shadow(0 0 9px rgba(255, 224, 138, 0.7));
}

.unit.target-stack circle {
  stroke: #a8d5ff;
  stroke-width: 4;
}

.unit-label,
.unit-stack-count,
.unit-selected-label,
.port-label {
  fill: #fff5cf;
  font-weight: 950;
  pointer-events: none;
}

.unit-label {
  font-size: 12px;
}

.unit-stack-count {
  font-size: 9px;
}

.unit-selected-dot,
.structure-muster-ring {
  fill: #fff5cf;
  stroke: #fff;
  stroke-width: 1.4;
  pointer-events: none;
}

.structure-muster-ring {
  fill: transparent;
  stroke: #f4d37b;
  stroke-width: 2;
  stroke-dasharray: 4 3;
  filter: drop-shadow(0 0 8px rgba(244, 211, 123, 0.75));
}

.structure-upgrade-ring {
  stroke-dasharray: 2 2;
}

.unit-selected-label {
  font-size: 7px;
  fill: #172331;
}

.port-line {
  stroke: rgba(214, 181, 103, 0.52);
  stroke-width: 2;
  stroke-dasharray: 4 5;
  pointer-events: none;
}

.port-label {
  font-size: 8px;
}

@keyframes resourceGain {
  0% { filter: brightness(1); box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.22); }
  8% { filter: brightness(1.8); box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.5), 0 0 18px rgba(255, 255, 255, 0.86); }
  86% { filter: brightness(1.22); box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.18), 0 0 10px rgba(255, 255, 255, 0.34); }
  100% { filter: brightness(1); box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.22); }
}

@keyframes resourceLoss {
  0% { filter: brightness(1); box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.22); }
  8% { filter: brightness(1.35); box-shadow: inset 0 0 0 999px rgba(224, 90, 79, 0.58), 0 0 18px rgba(224, 90, 79, 0.76); }
  86% { filter: brightness(1.08); box-shadow: inset 0 0 0 999px rgba(224, 90, 79, 0.2), 0 0 10px rgba(224, 90, 79, 0.28); }
  100% { filter: brightness(1); box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.22); }
}

@keyframes dieRollIn {
  0% { opacity: 0; transform: translateY(-6px) rotate(-8deg) scale(0.88); }
  70% { opacity: 1; transform: translateY(1px) rotate(2deg) scale(1.05); }
  100% { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
}

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

.modal {
  width: min(540px, calc(100vw - 30px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 24px;
  border: 1px solid rgba(242, 212, 138, 0.42);
  border-radius: 24px;
  background: #151c2a;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal h2 {
  margin: 0 0 10px;
  color: var(--gold2);
  font-family: var(--serif);
  font-size: 34px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.modal-panel {
  max-height: 330px;
  overflow: auto;
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.15);
  text-align: left;
}

.modal-row {
  display: grid;
  grid-template-columns: 1fr 90px 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.setup-grid {
  display: grid;
  gap: 10px;
}

.setup-player-row {
  display: grid;
  grid-template-columns: 1fr 70px;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

* {
  scrollbar-color: rgba(215, 181, 109, 0.46) rgba(8, 11, 18, 0.72);
  scrollbar-width: thin;
}

@media (max-width: 1120px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(560px, 1fr) auto;
    grid-template-areas:
      "top"
      "left"
      "board"
      "right";
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .status-strip,
  .top-actions {
    justify-content: flex-start;
  }

  .left {
    max-height: 360px;
  }
}
