/* Top bar ---------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--line);
  background: rgb(20 26 34 / 0.92);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgb(216 178 113 / 0.4);
  background: rgb(216 178 113 / 0.12);
  color: var(--accent);
  font-size: var(--text-lg);
}

.brand-sub {
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Page layout ------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  align-items: start;
  gap: var(--space-4);
  width: 100%;
  max-width: 1640px;
  margin: 0 auto;
  padding: var(--space-4);
}

.sidebar {
  display: grid;
  gap: var(--space-3);
  align-content: start;
  min-width: 0;
}

/* Map panel -------------------------------------------------------------- */

.map-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
}

.map-tools {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.viewport {
  position: relative;
  height: clamp(340px, calc(100dvh - 300px), 800px);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: grab;
  background-color: var(--surface-sunken);
  background-image: radial-gradient(#263140 1px, transparent 1px);
  background-size: 24px 24px;
}

.viewport.is-dragging {
  cursor: grabbing;
}

.viewport:focus-visible {
  outline-offset: -3px;
}

.world {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: 0 0;
  will-change: transform;
}

/* Tiles ------------------------------------------------------------------ */

.cell {
  position: absolute;
  display: block;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 1px solid #0a0f14;
  border-radius: 3px;
  overflow: hidden;
  background: var(--surface-sunken);
  color: var(--ink);
  cursor: default;
  box-shadow: var(--shadow-sm);
}

.cell.is-spawn,
.cell.cell-place,
.cell.is-target {
  cursor: pointer;
}

.cell.is-spawn {
  box-shadow: inset 0 0 0 3px var(--accent), 0 4px 14px rgb(0 0 0 / 0.5);
}

.cell.is-spawn:hover {
  filter: brightness(1.12);
}

.cell.is-target {
  box-shadow: inset 0 0 0 3px var(--danger), 0 4px 14px rgb(0 0 0 / 0.5);
}

.cell.is-target:hover {
  filter: brightness(1.15);
}

.cell.cell-place {
  opacity: 0.45;
  border-style: dashed;
  border-color: rgb(216 178 113 / 0.7);
}

.cell.cell-place:hover {
  opacity: 1;
}

.cell.has-owner::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--owner);
  opacity: 0.4;
  pointer-events: none;
  z-index: 1;
}

.tile-art {
  display: block;
  width: 100%;
  height: 100%;
}

.tile-icon {
  fill: #fff0cc;
  font-size: 22px;
  text-anchor: middle;
}

.edge-glyph {
  fill: #fff7e7;
  stroke: #101818;
  stroke-width: 2.4px;
  paint-order: stroke;
  font-size: 10px;
  font-weight: 900;
  text-anchor: middle;
}

.coord {
  position: absolute;
  top: 2px;
  left: 4px;
  z-index: 2;
  padding: 0 3px;
  border-radius: 3px;
  background: rgb(16 22 29 / 0.72);
  color: var(--ink-muted);
  font-size: 9px;
  line-height: 1.4;
  pointer-events: none;
}

.city {
  position: absolute;
  top: 2px;
  right: 4px;
  z-index: 2;
  color: var(--accent);
  font-size: var(--text-xs);
  line-height: 1.3;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

.tokens {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 3px;
  pointer-events: none;
}

.token {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid #0c1116;
  border-radius: 50%;
  background: var(--owner);
  color: #111820;
  font-size: var(--text-xs);
  font-weight: 700;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.5);
}

.token.is-wounded {
  outline: 2px dashed var(--danger);
  outline-offset: 1px;
}

.token.is-ready {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.token-traits {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 2px;
  border-radius: 3px;
  background: rgb(8 12 16 / 0.82);
  color: #f2ecdf;
  font-size: 7px;
  line-height: 1.35;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.cell-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.5);
}

.cell.is-target .cell-badge {
  background: var(--danger);
  color: #1b0f0d;
}

/* Legend ----------------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--line);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--ink-soft);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend-glyph {
  color: var(--accent);
  font-size: var(--text-sm);
}

/* Phase steps ------------------------------------------------------------ */

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: 0;
  list-style: none;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 var(--space-2) 0 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--ink-muted);
  font-size: 12px;
  white-space: nowrap;
}

.step-index {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-raised);
  font-size: 10px;
}

.step.is-done {
  color: var(--ink-soft);
}

.step.is-done .step-index {
  color: var(--ok);
}

.step.is-current {
  border-color: var(--accent);
  background: rgb(216 178 113 / 0.12);
  color: var(--ink);
}

.step.is-current .step-index {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* Turn panel ------------------------------------------------------------- */

.turn {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
}

.turn-head {
  display: grid;
  gap: var(--space-1);
}

.turn-round {
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.turn-role {
  font-size: var(--text-xs);
  color: var(--accent);
}

.turn-role.is-blocked {
  color: var(--danger);
}

.turn-instruction {
  font-size: var(--text-sm);
  color: var(--ink-soft);
}

.turn-controls {
  display: grid;
  gap: var(--space-3);
}

.turn-hint {
  font-size: var(--text-xs);
  color: var(--warn);
}

/* Scoreboard ------------------------------------------------------------- */

.scores {
  display: grid;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-4);
}

.score {
  display: grid;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--owner);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.score.is-active {
  background: var(--surface-raised);
  border-color: var(--line-strong);
  border-left-color: var(--owner);
}

.score-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.score-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
}

.score-crown {
  color: var(--accent);
}

.score-value {
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.score-meta {
  font-size: 11px;
  color: var(--ink-muted);
}

/* Event log -------------------------------------------------------------- */

.panel-log {
  display: flex;
  flex-direction: column;
}

.log {
  display: grid;
  gap: 0;
  max-height: 220px;
  margin: 0;
  padding: 0 var(--space-4) var(--space-4);
  overflow-y: auto;
  font-size: var(--text-xs);
}

.log-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: var(--space-2);
  padding: 5px 0;
  border-top: 1px solid rgb(255 255 255 / 0.05);
  color: var(--ink-soft);
  line-height: 1.4;
}

.log-round {
  color: var(--ink-muted);
  font-size: 10px;
  padding-top: 1px;
}

.log-combat {
  color: #eab2a8;
}

.log-score {
  color: var(--ok);
}

.log-role {
  color: var(--ink);
}

/* Responsive ------------------------------------------------------------- */

[hidden] {
  display: none !important;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar .turn {
    grid-column: 1 / -1;
  }

  .viewport {
    height: clamp(320px, 52dvh, 560px);
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: var(--space-2) var(--space-3);
  }

  .brand h1 {
    font-size: var(--text-lg);
  }

  .brand-sub {
    display: none;
  }

  .layout {
    padding: var(--space-2);
    gap: var(--space-2);
  }

  .sidebar {
    grid-template-columns: minmax(0, 1fr);
  }

  .viewport {
    height: clamp(260px, 44dvh, 420px);
  }

  .step span:last-child {
    display: none;
  }

  .step.is-current span:last-child {
    display: inline;
  }

  .step {
    padding-right: 4px;
  }

  .dialog-body {
    padding: var(--space-4);
  }

  .legend {
    font-size: 11px;
  }

  .table th,
  .table td {
    padding: 5px 4px;
  }
}
