:root {
  color-scheme: dark;
  --hud-height: 60px;
  --bg: #171512;
  --panel: rgba(28, 25, 21, 0.92);
  --panel-strong: #242019;
  --ink: #f6efe0;
  --muted: #c6bca6;
  --line: rgba(255, 238, 201, 0.16);
  --gold: #d6a94f;
  --green: #6aa66a;
  --blue: #5c91b8;
  --red: #bb5e50;
  --stone: #8f8b80;
  --wood: #9b6d42;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 12%, rgba(214, 169, 79, 0.12), transparent 28rem),
    linear-gradient(135deg, #10120f 0%, #221b14 45%, #13191a 100%);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(13, 13, 11, 0.72);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 45%, rgba(255, 255, 255, 0.24) 46% 54%, transparent 55%),
    linear-gradient(135deg, var(--gold), #7f4d29);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28);
  flex: 0 0 auto;
}

.brand-lockup h1,
.menu-copy h2,
.section-heading h2,
.game-hud h2,
.vote-panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand-lockup h1 {
  font-size: 1.25rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 800;
}

.input-status {
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  white-space: nowrap;
  font-size: 0.9rem;
}

.icon-button,
.primary-button,
.secondary-button,
.mode-card {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  font-size: 2rem;
  line-height: 1;
}

.icon-button[hidden] {
  visibility: hidden;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(135deg, #c88d2f, #81512a);
  border-color: rgba(255, 220, 150, 0.36);
  color: #fff7e8;
}

.secondary-button:hover,
.icon-button:hover,
.mode-card:hover,
.primary-button:hover {
  filter: brightness(1.08);
}

.screen-root {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
  flex: 1;
}

.main-menu {
  min-height: calc(100vh - 144px);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.78fr);
  align-items: end;
  gap: 28px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(20px, 4vw, 54px);
  box-shadow: var(--shadow);
  background: #1d1710;
}

.menu-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.72;
}

.main-menu::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(14, 14, 12, 0.82), rgba(14, 14, 12, 0.42) 50%, rgba(14, 14, 12, 0.82)),
    linear-gradient(0deg, rgba(14, 14, 12, 0.72), transparent 55%);
}

.menu-copy,
.mode-grid {
  position: relative;
  z-index: 1;
}

.menu-copy {
  max-width: 680px;
  align-self: center;
}

.menu-copy h2 {
  font-size: clamp(2.4rem, 6vw, 5.8rem);
  line-height: 0.96;
  max-width: 760px;
}

.menu-copy p:last-child {
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
  max-width: 620px;
}

.mode-grid {
  display: grid;
  gap: 12px;
  align-self: center;
}

.mode-card {
  min-height: 98px;
  border-radius: 8px;
  padding: 20px;
  text-align: left;
  background: rgba(22, 22, 18, 0.82);
}

.mode-card span {
  display: block;
  font-size: 1.12rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.mode-card small {
  color: var(--muted);
}

.learning-panel {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 8px;
  background: rgba(22, 22, 18, 0.84);
  color: var(--ink);
  padding: 14px;
}

.learning-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.learning-panel-header span {
  display: block;
  font-weight: 900;
  font-size: 0.98rem;
}

.learning-panel-header small,
.learning-status {
  color: var(--muted);
  font-size: 0.72rem;
}

.learning-toggle {
  min-height: 34px;
  border: 1px solid rgba(255, 238, 201, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-weight: 900;
  padding: 0 10px;
}

.learning-toggle.active {
  background: rgba(78, 168, 112, 0.24);
  border-color: rgba(135, 226, 161, 0.44);
}

.learning-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.learning-stats span {
  display: grid;
  gap: 3px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.24);
  padding: 7px 6px;
}

.learning-stats b {
  font-size: 0.92rem;
  line-height: 1;
}

.learning-stats small {
  color: rgba(255, 247, 232, 0.64);
  font-size: 0.61rem;
  line-height: 1;
}

.learning-status {
  margin: 0;
  line-height: 1.35;
}

.setup-screen,
.map-vote-screen,
.game-screen {
  display: grid;
  gap: 20px;
}

.section-heading {
  display: grid;
  gap: 6px;
}

.section-heading h2 {
  font-size: clamp(1.8rem, 3vw, 3.1rem);
}

.section-heading p:not(.eyebrow) {
  margin: 0;
  max-width: 850px;
  color: var(--muted);
  line-height: 1.55;
}

.setup-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.control-tile,
.player-card,
.vote-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.control-tile {
  padding: 14px;
}

.control-tile label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.control-tile select,
.control-tile input {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #15130f;
  color: var(--ink);
  padding: 0 10px;
}

.replay-setup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.secondary-button.compact {
  min-height: 40px;
  padding: 0 12px;
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.player-card {
  min-height: 188px;
  padding: 14px;
  display: grid;
  gap: 10px;
  border-left: 4px solid var(--player-color, rgba(255, 255, 255, 0.32));
}

.player-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-name {
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.player-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: var(--player-color, #fff7e8);
  box-shadow: 0 0 0 2px rgba(255, 247, 232, 0.18);
}

.team-badge,
.type-badge,
.resource-pill,
.age-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.team-badge.team-1 {
  color: #e8f5ff;
  background: rgba(92, 145, 184, 0.28);
}

.team-badge.team-2 {
  color: #ffece6;
  background: rgba(187, 94, 80, 0.3);
}

.type-badge {
  color: #fff2cf;
  background: rgba(214, 169, 79, 0.2);
}

.player-card select {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #15130f;
  color: var(--ink);
  padding: 0 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
}

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

.civ-summary {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.88rem;
}

.footer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.map-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  min-height: 420px;
  background: #201a10;
  box-shadow: var(--shadow);
}

#arabiaCanvas,
#gameMapCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.vote-panel {
  padding: 18px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.vote-panel h3 {
  font-size: 1.65rem;
}

.vote-panel p {
  color: var(--muted);
  line-height: 1.45;
}

.vote-list {
  display: grid;
  gap: 8px;
}

.vote-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.game-hud {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
}

.game-hud h2 {
  font-size: 2.4rem;
}

.hud-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.22);
}

.battlefield {
  position: relative;
  min-height: 470px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #1f1a12;
  box-shadow: var(--shadow);
}

.strategy-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: end;
  pointer-events: none;
}

.strategy-card {
  pointer-events: auto;
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 8px;
  background: rgba(17, 15, 12, 0.92);
  backdrop-filter: blur(10px);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.strategy-card.locked {
  border-color: rgba(106, 166, 106, 0.58);
}

.strategy-options {
  display: grid;
  gap: 8px;
}

.strategy-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.strategy-option.active {
  border-color: var(--gold);
  background: rgba(214, 169, 79, 0.18);
}

.strategy-option strong,
.strategy-card strong {
  display: block;
}

.strategy-option small,
.strategy-card small {
  color: var(--muted);
  line-height: 1.4;
}

.game-panels {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.panel {
  padding: 14px;
  min-height: 220px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-heading h3 {
  margin: 0;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.score-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 4px solid var(--player-color, rgba(255, 255, 255, 0.4));
}

.score-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.score-row-top strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  min-width: 0;
}

.strategy-status {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.strategy-status.locked {
  color: #dff7df;
  background: rgba(106, 166, 106, 0.22);
}

.strategy-status.pending {
  color: #ffe5b2;
  background: rgba(214, 169, 79, 0.16);
}

.resource-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.resource-pill {
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(0, 0, 0, 0.2);
  gap: 5px;
}

.resource-pill small {
  color: var(--muted);
  font-size: 0.68rem;
}

.resource-pill.food {
  color: #eecb8a;
}

.resource-pill.wood {
  color: #d29a65;
}

.resource-pill.gold {
  color: #ffe087;
}

.resource-pill.stone {
  color: #d5d1c8;
}

.event-log {
  max-height: 252px;
  overflow: auto;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.event-log p {
  margin: 0;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

@media (max-width: 1080px) {
  .main-menu,
  .map-layout,
  .game-panels {
    grid-template-columns: 1fr;
  }

  .setup-controls,
  .player-grid,
  .strategy-overlay {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .vote-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 42px 1fr;
  }

  .input-status {
    grid-column: 1 / -1;
    justify-self: start;
    white-space: normal;
  }

  .screen-root {
    padding: 12px;
  }

  .main-menu {
    min-height: calc(100vh - 158px);
    padding: 18px;
  }

  .menu-copy h2 {
    font-size: 2.45rem;
  }

  .setup-controls,
  .player-grid,
  .strategy-overlay,
  .scoreboard,
  .vote-panel,
  .game-hud {
    grid-template-columns: 1fr;
  }

  .battlefield {
    min-height: 560px;
  }

  .strategy-overlay {
    align-content: start;
    overflow: auto;
  }
}

body.game-active {
  overflow: hidden;
}

body.game-active .topbar {
  display: none;
}

body.game-active .screen-root {
  width: 100%;
  max-width: none;
  height: 100vh;
  padding: 0;
}

.immersive-game {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: var(--hud-height) minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
  background: #15120d;
}

.immersive-game #gameMapCanvas {
  position: relative;
  grid-row: 2;
  display: block;
  min-height: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: 16 / 9;
}

.hud-layer {
  z-index: 3;
  border: 1px solid rgba(255, 238, 201, 0.14);
  border-radius: 8px;
  background: rgba(17, 15, 12, 0.62);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
}

.top-left,
.top-right,
.bottom-left,
.bottom-right {
  position: absolute;
}

.top-left {
  left: 16px;
  top: 16px;
  padding: 12px 14px;
  min-width: 152px;
}

.top-left h2 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0;
}

.top-left span,
.top-right {
  color: var(--muted);
  font-size: 0.88rem;
}

.top-right {
  right: 16px;
  top: 16px;
  padding: 12px 14px;
  max-width: min(420px, calc(100vw - 210px));
}

.top-hud-row {
  position: relative;
  grid-row: 1;
  left: auto;
  right: auto;
  top: auto;
  height: var(--hud-height);
  min-height: 0;
  padding: 4px 8px;
  display: grid;
  grid-template-columns: 92px 142px 66px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  background: rgba(17, 15, 12, 0.82);
  backdrop-filter: blur(8px);
  box-shadow: none;
}

.hud-clock-block h2 {
  margin: 0;
  font-size: 1.24rem;
  letter-spacing: 0;
  line-height: 1;
}

.hud-clock-block span,
.hud-match-block {
  color: var(--muted);
  font-size: 0.72rem;
}

.hud-clock-block {
  display: grid;
  align-content: center;
  gap: 1px;
  min-width: 0;
}

.hud-clock-block .eyebrow {
  margin: 0;
  font-size: 0.54rem;
  line-height: 1;
}

.hud-clock-block span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-match-block {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 6px;
  align-items: center;
}

.hud-progress-strip {
  display: none;
}

.hud-progress-tile {
  --hud-progress: 0%;
  position: relative;
  flex: 0 0 38px;
  height: 44px;
  display: grid;
  grid-template-rows: 22px 14px;
  place-items: center;
  border: 1px solid rgba(255, 238, 201, 0.16);
  border-left: 3px solid var(--player-color);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.hud-progress-tile::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--hud-progress);
  background: rgba(255, 238, 201, 0.18);
}

.hud-progress-tile strong,
.hud-progress-tile small {
  position: relative;
  z-index: 1;
  line-height: 1;
}

.hud-progress-tile strong {
  color: #fff7e8;
  font-size: 0.62rem;
  font-weight: 900;
}

.hud-progress-tile small {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
}

#strategyCountdown {
  grid-column: 1 / -1;
}

.bottom-left {
  left: 16px;
  bottom: 16px;
  width: min(620px, calc(100vw - 32px));
  max-height: 35vh;
  padding: 12px;
  overflow: hidden;
}

.bottom-right {
  right: 16px;
  bottom: 16px;
  width: min(380px, calc(100vw - 32px));
  max-height: 34vh;
  padding: 12px;
  overflow: hidden;
}

.bottom-right.log-collapsed {
  width: auto;
  max-height: none;
  padding: 6px;
}

.top-log-panel {
  align-self: stretch;
  min-width: 0;
  border: 1px solid rgba(255, 238, 201, 0.14);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: none;
  box-shadow: none;
  overflow: hidden;
}

.top-hud-row .top-log-panel.bottom-right {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  width: auto;
  max-height: none;
  padding: 0;
}

.top-hud-row .top-log-panel.bottom-right.log-collapsed {
  width: auto;
  padding: 0;
}

.top-log-panel .panel-heading {
  height: 100%;
  margin: 0;
  justify-content: center;
}

.top-log-panel h3 {
  display: none;
}

.top-log-panel .event-log {
  display: none;
}

.top-hud-row .top-log-panel:not(.log-collapsed) {
  position: absolute;
  top: calc(var(--hud-height) + 6px);
  right: 10px;
  width: min(380px, calc(100vw - 32px));
  max-height: 34vh;
  padding: 12px;
  border: 1px solid rgba(255, 238, 201, 0.14);
  border-radius: 8px;
  background: rgba(17, 15, 12, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
}

.top-hud-row .top-log-panel:not(.log-collapsed) .panel-heading {
  height: auto;
  margin-bottom: 10px;
  justify-content: space-between;
}

.top-hud-row .top-log-panel:not(.log-collapsed) h3 {
  display: block;
}

.top-hud-row .top-log-panel:not(.log-collapsed) .event-log {
  display: grid;
}

.top-hud-row .top-log-panel:not(.log-collapsed) .log-toggle-button {
  width: auto;
  height: auto;
  min-height: 26px;
  border: 1px solid rgba(255, 238, 201, 0.2);
  padding: 0 9px;
}

.top-log-panel .log-toggle-button {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 6px;
  padding: 0 6px;
  font-size: 0.72rem;
}

.bottom-right.log-collapsed .panel-heading {
  margin-bottom: 0;
}

.bottom-right.log-collapsed h3,
.bottom-right.log-collapsed .event-log {
  display: none;
}

.log-toggle-button {
  min-height: 26px;
  border: 1px solid rgba(255, 238, 201, 0.2);
  border-radius: 6px;
  background: rgba(255, 238, 201, 0.1);
  color: var(--ink);
  padding: 0 9px;
  font-size: 0.72rem;
  font-weight: 900;
}

.log-toggle-button:hover {
  background: rgba(255, 238, 201, 0.18);
}

.scoreboard.compact {
  display: flex;
  align-items: stretch;
  align-self: center;
  gap: 6px;
  height: 48px;
  max-height: none;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0;
}

.scoreboard.compact .score-row {
  height: 48px;
  padding: 3px 6px;
  gap: 2px;
  min-width: 222px;
  border-radius: 6px;
  border-left-width: 3px;
  font-size: 0.86rem;
  overflow: hidden;
}

.scoreboard.compact .score-row.focus-player {
  min-width: 246px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 17px 18px;
  align-content: center;
  column-gap: 0;
  row-gap: 2px;
}

.scoreboard.compact .score-row-top {
  gap: 5px;
  min-height: 18px;
  line-height: 1;
}

.scoreboard.compact .score-row-top strong {
  gap: 5px;
  line-height: 1;
}

.scoreboard.compact .score-meta {
  gap: 3px;
  min-width: 0;
}

.scoreboard.compact .score-row-top:nth-of-type(2) {
  display: none;
}

.scoreboard.compact .strategy-status {
  padding: 1px 5px;
  font-size: 0.68rem;
  line-height: 1;
  white-space: nowrap;
}

.scoreboard.compact .team-badge,
.scoreboard.compact .age-badge,
.scoreboard.compact .villager-badge {
  min-height: 15px;
  padding: 0 5px;
  font-size: 0.68rem;
  line-height: 1;
  white-space: nowrap;
}

.scoreboard.compact .villager-badge {
  color: #fff7e8;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  font-weight: 900;
}

.scoreboard.compact .age-badge {
  color: #15120d;
  background: rgba(255, 238, 201, 0.88);
}

.scoreboard.compact .army-line {
  display: none;
}

.scoreboard.compact .resource-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  overflow: hidden;
  min-width: 0;
}

.scoreboard.compact .score-row.focus-player .resource-grid {
  grid-row: 2;
  align-self: center;
}

.scoreboard.compact .resource-pill,
.scoreboard.compact .mini-chip {
  min-width: 0;
  min-height: 17px;
  padding: 0 4px;
  font-size: 0.74rem;
  gap: 2px;
  line-height: 1;
  justify-content: center;
  white-space: nowrap;
}

.scoreboard.compact .resource-pill small {
  font-size: 0.67rem;
}

.event-log.compact {
  max-height: 25vh;
}

.event-log .bot-learning-line {
  color: #dff7df;
  border-left: 3px solid rgba(106, 166, 106, 0.76);
  padding-left: 7px;
  background: rgba(106, 166, 106, 0.1);
}

.bot-debug-overlay {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 3;
  display: grid;
  gap: 5px;
  width: min(520px, calc(100vw - 20px));
  pointer-events: none;
}

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

.diagnostic-overlay {
  position: absolute;
  left: 10px;
  top: calc(var(--hud-height) + 8px);
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 280px));
  gap: 6px;
  max-width: min(580px, calc(100vw - 20px));
  max-height: min(46vh, 390px);
  overflow: auto;
  pointer-events: none;
}

.diagnostic-card {
  display: grid;
  gap: 5px;
  border-left: 4px solid var(--player-color, rgba(255, 238, 201, 0.58));
  border-radius: 7px;
  padding: 7px 8px;
  background: rgba(22, 17, 12, 0.82);
  color: #fff7e8;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(9px);
}

.diagnostic-card strong {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 0.78rem;
  color: #ffe6a9;
}

.diagnostic-card strong span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--player-color, #ffe6a9);
}

.diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
}

.diagnostic-grid span {
  min-width: 0;
  border-radius: 4px;
  padding: 2px 4px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.68rem;
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diagnostic-card small {
  color: rgba(255, 247, 232, 0.78);
  font-size: 0.66rem;
  line-height: 1.2;
}

.diagnostic-issues {
  grid-column: 1 / -1;
  border-left-color: #e25c5c;
}

.entity-inspector[hidden],
.lab-overlay[hidden] {
  display: none;
}

.entity-inspector {
  position: absolute;
  left: 10px;
  top: calc(var(--hud-height) + 8px);
  z-index: 8;
  width: min(280px, calc(100vw - 20px));
  display: grid;
  gap: 5px;
  padding: 8px 9px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-left: 4px solid var(--player-color, #ffe6a9);
  border-radius: 7px;
  color: #fff7e8;
  background: rgba(17, 13, 10, 0.86);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(9px);
  pointer-events: none;
}

.entity-inspector strong {
  color: #ffe6a9;
  font-size: 0.82rem;
}

.entity-inspector small {
  color: rgba(255, 247, 232, 0.78);
  font-size: 0.68rem;
  line-height: 1.2;
}

.lab-overlay {
  position: absolute;
  right: 10px;
  top: calc(var(--hud-height) + 8px);
  z-index: 8;
  width: min(360px, calc(100vw - 20px));
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 7px;
  color: #fff7e8;
  background: rgba(17, 13, 10, 0.86);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(9px);
  pointer-events: auto;
}

.lab-overlay strong {
  color: #ffe6a9;
  font-size: 0.85rem;
}

.lab-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.lab-actions button {
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff7e8;
  font: 900 0.68rem/1 system-ui;
  padding: 7px 8px;
}

.lab-overlay small {
  color: rgba(255, 247, 232, 0.72);
  font-size: 0.68rem;
  line-height: 1.22;
}

.bot-debug-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 7px;
  border: 1px solid rgba(255, 238, 201, 0.2);
  border-left: 3px solid var(--player-color, #fff);
  border-radius: 6px;
  color: #fff7df;
  background: rgba(20, 15, 10, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  font-size: 0.74rem;
}

.bot-debug-card strong,
.bot-debug-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-debug-card strong {
  color: #ffe6a9;
  font-size: 0.78rem;
}

.bot-debug-card .debug-economy {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  min-width: 0;
}

.bot-debug-card .debug-replay {
  grid-column: 1 / -1;
  color: rgba(255, 247, 223, 0.78);
  font-size: 0.69rem;
}

.bot-debug-card .debug-economy span {
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  text-align: center;
}

.debug-layer-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 7;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  max-width: min(520px, calc(100vw - 20px));
  pointer-events: auto;
}

.debug-layer-controls button,
.online-status-pill {
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 6px;
  background: rgba(31, 24, 17, 0.74);
  color: rgba(255, 247, 232, 0.78);
  font: 800 0.62rem/1 system-ui;
  padding: 6px 7px;
}

.debug-layer-controls button.active {
  background: rgba(255, 206, 101, 0.18);
  color: #fff4ce;
  border-color: rgba(255, 220, 132, 0.55);
}

.online-status-pill {
  color: rgba(142, 255, 198, 0.86);
}

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

.replay-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 28px);
  background: rgba(9, 7, 5, 0.52);
  pointer-events: auto;
}

.replay-panel {
  width: min(980px, 96vw);
  max-height: min(760px, 88vh);
  overflow: auto;
  border: 1px solid rgba(255, 238, 201, 0.22);
  border-radius: 8px;
  background: rgba(25, 20, 15, 0.96);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.46);
  color: #fff7e8;
  padding: 14px;
}

.replay-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.replay-panel h3 {
  margin: 0;
  font-size: 1.05rem;
}

.replay-close,
.replay-actions button,
.replay-card-actions button {
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff7e8;
  font: 800 0.72rem/1 system-ui;
  padding: 8px 10px;
}

.replay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.replay-actions button:disabled {
  opacity: 0.45;
}

.replay-list {
  display: grid;
  gap: 8px;
}

.replay-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(255, 238, 201, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  padding: 10px;
}

.replay-card strong,
.replay-player-row strong {
  display: block;
  font-size: 0.9rem;
}

.replay-card small,
.replay-player-row small,
.replay-empty {
  color: rgba(255, 247, 232, 0.68);
  font-size: 0.72rem;
}

.replay-card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.replay-viewer-grid {
  display: grid;
  grid-template-columns: minmax(340px, 1.35fr) minmax(260px, 0.9fr);
  gap: 12px;
}

.replay-map {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(255, 238, 201, 0.14);
  border-radius: 8px;
  background: #c89555;
}

.replay-snapshot-summary {
  display: grid;
  gap: 8px;
}

.replay-player-row {
  display: grid;
  gap: 5px;
  border-left: 4px solid var(--player-color);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  padding: 8px 10px;
}

.replay-system-row {
  --player-color: rgba(120, 255, 160, 0.72);
  background: rgba(120, 255, 160, 0.08);
}

.replay-player-row strong {
  display: flex;
  align-items: center;
  gap: 6px;
}

.replay-player-row strong span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--player-color);
}

.replay-resource-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.replay-resource-grid span {
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  color: #ffefbe;
  padding: 4px 5px;
  text-align: center;
  font: 900 0.68rem/1 system-ui;
}

.replay-timeline {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  border-top: 1px solid rgba(255, 238, 201, 0.12);
  padding-top: 10px;
}

.replay-timeline-title {
  color: #ffe6a9;
  font-size: 0.86rem;
}

.replay-timeline-row {
  display: grid;
  grid-template-columns: 52px 72px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border-radius: 5px;
  padding: 5px 7px;
  background: rgba(255, 255, 255, 0.06);
}

.replay-timeline-row span,
.replay-timeline-row b,
.replay-timeline-row small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.7rem;
}

.replay-timeline-row.validator {
  background: rgba(226, 92, 92, 0.14);
}

@media (max-width: 780px) {
  .replay-viewer-grid {
    grid-template-columns: 1fr;
  }

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

.context-order-menu {
  position: absolute;
  z-index: 8;
  width: 280px;
  display: grid;
  gap: 8px;
  border: 1px solid rgba(255, 238, 201, 0.2);
  border-radius: 8px;
  background: rgba(31, 24, 17, 0.9);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.36);
  padding: 10px;
  color: #fff7e8;
}

.context-order-menu strong,
.context-order-menu b {
  font-size: 0.78rem;
}

.context-order-menu small {
  color: rgba(255, 247, 232, 0.66);
  font-size: 0.64rem;
}

.context-order-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.context-order-grid span {
  display: grid;
  place-items: center;
  min-height: 28px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 247, 232, 0.72);
  font: 900 0.68rem/1 system-ui;
}

.context-order-grid span.active {
  background: rgba(255, 203, 92, 0.24);
  color: #fff2c8;
  outline: 2px solid rgba(255, 230, 150, 0.42);
}

.private-layer {
  position: absolute;
  top: var(--hud-height);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  pointer-events: none;
}

.progress-layer {
  z-index: 5;
}

.private-layer .strategy-card,
.private-layer .build-menu,
.private-layer .resource-menu,
.private-layer .context-order-menu {
  pointer-events: auto;
}

.resource-menu {
  position: absolute;
  width: min(520px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-radius: 8px;
  background: rgba(17, 15, 12, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

.resource-menu-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
}

.resource-menu-title small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  white-space: nowrap;
}

.resource-menu-grid {
  display: grid;
  grid-template-columns: repeat(var(--resource-menu-cols, 4), minmax(0, 1fr));
  gap: 6px;
}

.resource-menu-item {
  display: grid;
  gap: 3px;
  min-width: 0;
  min-height: 58px;
  padding: 7px 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--muted);
}

.resource-menu-item.selected {
  color: var(--ink);
  border-color: rgba(255, 238, 201, 0.5);
  background: rgba(255, 238, 201, 0.12);
}

.resource-menu-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}

.resource-menu-item span {
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 900;
  line-height: 1;
}

.resource-menu-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.68rem;
}

.resource-menu-feedback {
  display: block;
  margin-top: 7px;
  color: #fff2c8;
  font-size: 0.76rem;
  font-weight: 900;
}

.food-assignment-panel {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 238, 201, 0.14);
}

.food-assignment-panel > strong {
  font-size: 0.86rem;
}

.food-assignment-panel > small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.construction-assignment-panel {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 238, 201, 0.14);
}

.construction-assignment-panel > strong {
  font-size: 0.88rem;
}

.construction-assignment-panel > small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.construction-assignment-list {
  display: grid;
  gap: 5px;
}

.construction-assignment-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding: 5px 7px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.construction-assignment-row.selected {
  border-color: rgba(255, 238, 201, 0.55);
  background: rgba(255, 238, 201, 0.12);
}

.construction-assignment-row.locked {
  opacity: 0.55;
}

.construction-assignment-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.construction-assignment-row strong {
  color: var(--ink);
  font-size: 0.82rem;
}

.tech-progress-card {
  position: absolute;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 32px;
  grid-template-rows: 24px;
  gap: 5px;
  align-items: center;
  padding: 4px 6px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  border-left: 3px solid var(--player-color);
  border-radius: 6px;
  background: rgba(28, 22, 15, 0.78);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.tech-progress-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 247, 232, 0.42);
  border-radius: 6px;
  color: #16100a;
  font-size: 0.62rem;
  font-weight: 900;
  background:
    linear-gradient(to top, rgba(255, 247, 232, 0.92) var(--tech-progress-percent), rgba(255, 247, 232, 0.22) 0);
}

.tech-progress-card strong,
.tech-progress-card small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tech-progress-card strong {
  font-size: 0.68rem;
}

.tech-progress-card small {
  text-align: right;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
}

.strategy-dock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(960px, calc(100vw - 36px));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.private-strategy-header {
  position: absolute;
  left: 50%;
  bottom: 210px;
  transform: translateX(-50%);
  width: min(960px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 238, 201, 0.16);
  background: rgba(17, 15, 12, 0.78);
  text-align: center;
}

.strategy-dock .strategy-option {
  min-height: 126px;
  color: var(--ink);
  text-align: left;
}

.strategy-dock .strategy-option.locked-choice {
  border-color: rgba(106, 166, 106, 0.72);
  background: rgba(106, 166, 106, 0.18);
}

.build-menu {
  position: absolute;
  width: 224px;
  display: grid;
  gap: 7px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  background: rgba(17, 15, 12, 0.78);
  backdrop-filter: blur(10px);
}

.build-menu-title {
  color: var(--gold);
  text-transform: uppercase;
  font-size: 0.76rem;
  font-weight: 900;
  padding: 0 2px 4px;
}

.build-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.9rem;
}

.build-menu-item.selected {
  border-color: var(--gold);
  background: rgba(214, 169, 79, 0.18);
}

.build-menu-item.locked {
  opacity: 0.46;
}

.build-menu-item.unaffordable,
.tech-row.unaffordable {
  border-color: rgba(230, 96, 76, 0.46);
  background: rgba(230, 96, 76, 0.12);
}

.build-menu-item.unaffordable small,
.tech-row.unaffordable small {
  color: #ffb3a8;
}

.build-menu-item small {
  color: var(--muted);
}

.build-menu-item.unaffordable small,
.tech-row.unaffordable small {
  color: #ffb3a8;
}

.build-tech-panel {
  position: absolute;
  width: 244px;
  display: grid;
  gap: 7px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 238, 201, 0.18);
  background: rgba(17, 15, 12, 0.78);
  backdrop-filter: blur(10px);
}

.build-tech-panel > strong {
  font-size: 0.95rem;
}

.build-tech-panel > small,
.tech-row small {
  color: var(--muted);
}

.tech-row.unaffordable small {
  color: #ffb3a8;
}

.tech-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 2px 8px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
}

.tech-row > span {
  grid-row: span 2;
  color: #15120d;
  background: #fff7e8;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 0.68rem;
  font-weight: 900;
  text-align: center;
}

.tech-row strong,
.tech-row small {
  min-width: 0;
}

.tech-row.disabled {
  opacity: 0.48;
}

.score-row .army-line {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-chip {
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  font-size: 0.72rem;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.mode-card.focus-ring {
  outline: 3px solid rgba(214, 169, 79, 0.88);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .bottom-right {
    display: none;
  }

  .top-hud-row {
    grid-template-columns: 96px minmax(0, 1fr);
    height: var(--hud-height);
    min-height: var(--hud-height);
    max-height: 36vh;
    overflow: auto;
  }

  .hud-match-block {
    grid-column: 2;
  }

  .hud-progress-strip {
    display: none;
    grid-column: 1 / -1;
    min-height: 0;
  }

  .scoreboard.compact {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .bottom-left {
    max-height: 30vh;
  }

  .strategy-dock {
    grid-template-columns: 1fr;
    bottom: 12px;
  }

  .private-strategy-header {
    bottom: 430px;
  }
}
