:root {
  --bg: #f0efe9;
  --panel: #fcfbf7;
  --ink: #1f1c15;
  --muted: #6e675a;
  --accent: #bf3d1e;
  --accent-2: #184f83;
  --line: #d6d1c6;
  --good: #1b7f4b;
  --bad: #a83232;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(24, 79, 131, 0.16), transparent 28%),
    radial-gradient(circle at 90% 5%, rgba(191, 61, 30, 0.18), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.shell {
  width: min(1400px, 100% - 2rem);
  margin: 1rem auto 2rem auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
}

.pill {
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 700;
}

.pill.offline {
  background: #f2d7d7;
  color: var(--bad);
}

.pill.online {
  background: #d9f0e3;
  color: var(--good);
}

.alerts {
  min-height: 1.6rem;
  margin-bottom: 0.8rem;
}

.alert {
  padding: 0.5rem 0.7rem;
  border-radius: 0.5rem;
  background: #fbe6e3;
  color: #7d2515;
  border: 1px solid #e6b6ad;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.9rem;
  box-shadow: 0 7px 30px rgba(42, 39, 31, 0.06);
}

.hidden {
  display: none !important;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
}

.row.split {
  flex-direction: row;
  align-items: center;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 0.52rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: #fff;
}

button {
  border: 1px solid var(--line);
  background: #efe9da;
  color: var(--ink);
  border-radius: 0.6rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

button.primary {
  background: linear-gradient(135deg, var(--accent), #cb5a35);
  border: none;
  color: #fff;
  font-weight: 700;
}

button.danger {
  background: linear-gradient(135deg, #7f1111, #be2323);
  border: none;
  color: #fff;
  font-weight: 700;
}

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

.button-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.divider {
  text-align: center;
  color: var(--muted);
  margin: 0.5rem 0;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.room-code {
  font-size: 1rem;
  color: var(--accent-2);
  font-weight: 700;
}

.player-list {
  margin: 0.9rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
}

.player-card {
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.6rem;
  background: #fff;
}

.game-info {
  display: grid;
  gap: 0.35rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 0.8rem;
}

.game-info-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.layout {
  display: grid;
  grid-template-columns: 1.3fr 1.2fr 1fr;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.column h3 {
  margin: 0 0 0.65rem 0;
}

.player-stats {
  display: grid;
  gap: 0.45rem;
}

.player-row {
  display: grid;
  gap: 0.3rem;
  grid-template-columns: 1.2fr repeat(4, 0.8fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.45rem 0.5rem;
  background: #fff;
}

.player-row.current {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(24, 79, 131, 0.23);
}

.player-row.you {
  background: #f6f2e8;
}

.player-name {
  font-weight: 700;
}

.player-elim {
  color: var(--bad);
}

.actions-content {
  display: grid;
  gap: 0.7rem;
}

.action-block {
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.7rem;
  background: #fff;
}

.action-block h4 {
  margin: 0 0 0.55rem 0;
}

.inline {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

#event-log {
  min-height: 4.5rem;
  padding: 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid var(--line);
  background: #fff;
  line-height: 1.3;
}

.board-panel {
  margin-bottom: 0.8rem;
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.board-header h3 {
  margin: 0;
}

.board-status {
  font-size: 0.86rem;
  color: var(--muted);
}

.board-wrap {
  overflow: auto;
  border-radius: 0.7rem;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 10% 12%, rgba(32, 118, 179, 0.1), transparent 28%),
    radial-gradient(circle at 85% 18%, rgba(217, 95, 2, 0.12), transparent 32%),
    #f8f6ef;
}

#board-map {
  width: 100%;
  min-width: 980px;
  display: block;
}

.board-territory-label {
  font-size: 20px;
  font-weight: 700;
  opacity: 0.78;
  pointer-events: none;
}

.board-state {
  stroke: rgba(255, 255, 255, 0.9);
  transition: fill-opacity 0.2s ease;
}

.board-state:hover {
  fill-opacity: 0.45;
}

.board-state-source {
  stroke: #154f8b !important;
  stroke-width: 2.8 !important;
  fill-opacity: 0.45 !important;
}

.board-state-battle {
  stroke: #d62728;
  stroke-width: 3.2 !important;
  stroke-dasharray: 11 8;
  animation: battlePulse 1s linear infinite;
}

.board-edge {
  stroke: #8f8a7f;
  stroke-opacity: 0.35;
  stroke-width: 2;
}

.board-edge.battle {
  stroke: #d62728;
  stroke-opacity: 0.92;
  stroke-width: 4;
  stroke-dasharray: 12 10;
  animation: battlePulse 1s linear infinite;
}

.board-node-ring {
  stroke-width: 3;
}

.board-node-owner {
  stroke: #ffffff;
  stroke-width: 2;
}

.board-node-label {
  font-size: 9px;
  font-weight: 700;
  fill: #1f1c15;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.board-node-armies {
  font-size: 10px;
  font-weight: 700;
  fill: #1f1c15;
  text-anchor: middle;
  pointer-events: none;
}

.board-node-flag {
  stroke: #ffffff;
  stroke-width: 0.9;
}

.board-battle-node .board-node-ring {
  stroke: #d62728 !important;
  stroke-width: 5;
  stroke-dasharray: 10 7;
  animation: battlePulse 1s linear infinite;
}

.board-source-node .board-node-ring {
  stroke: #154f8b !important;
  stroke-width: 5;
}

.board-legend {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.legend-chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

@keyframes battlePulse {
  0% {
    stroke-dashoffset: 0;
  }
  100% {
    stroke-dashoffset: -24;
  }
}

.table-wrap {
  overflow: auto;
  max-height: 430px;
}

#states-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

#states-table th,
#states-table td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.45rem 0.5rem;
  font-size: 0.92rem;
  vertical-align: top;
}

#states-table th {
  position: sticky;
  top: 0;
  background: #f5f1e6;
}

.state-owner-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 0.17rem 0.5rem;
  background: #ece7dc;
  font-size: 0.8rem;
}

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

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

  .player-row {
    grid-template-columns: 1fr 1fr 1fr;
  }

  #board-map {
    min-width: 760px;
  }
}
