:root {
  --bg: #403930;
  --panel: #574d41;
  --panel-edge: #7a6b59;
  --text: #f3ece0;
  --muted: #b8ab97;
  --accent: #e0a64a;
  --button: #877560;
  --button-hover: #9e8d76;
  --gap: 12px;
  --panel-width: 220px;
  --strip-height: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-width);
  grid-template-rows: minmax(0, 1fr) var(--strip-height);
  grid-template-areas:
    "board panel"
    "strip strip";
  gap: var(--gap);
  height: 100vh;
  padding: var(--gap);
}

.board-wrap {
  grid-area: board;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* Holds the board and what sits on it, sized to the board, so the corner score lands on the board
   and not in the margin the centring leaves beside it. */
.board-frame {
  position: relative;
  width: 100%;
  max-width: calc((100vh - var(--strip-height) - 3 * var(--gap)) * var(--board-w) / var(--board-h));
}

/* The board keeps its aspect and fills its frame, which sets the size. Its size comes from
   config.js: main.js sets --board-w and --board-h on its frame. */
#board {
  display: block;
  aspect-ratio: var(--board-w) / var(--board-h);
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  overflow-y: auto;
}

.stats { margin: 0; display: grid; gap: 4px; }
.stats div { display: flex; justify-content: space-between; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

button {
  font: inherit;
  color: var(--text);
  background: var(--button);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--button-hover); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; }

.send { font-weight: 600; }

.build, .selected { border-top: 1px solid var(--panel-edge); padding-top: var(--gap); }

.tower-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; }
/* Compact tiles: icon, cost, key. touch-action: none lets a finger drag a tile onto the board. */
.tower-buttons button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.tower-buttons button:active { cursor: grabbing; }
.tower-buttons .icon { display: block; background-repeat: no-repeat; pointer-events: none; }
.tower-buttons .cost { color: var(--accent); font-size: 12px; line-height: 1; }
.tower-buttons .key { position: absolute; top: 1px; left: 3px; color: var(--muted); font-size: 10px; line-height: 1; }

.selected h2 { margin: 0 0 4px; font-size: 14px; color: var(--muted); font-weight: 600; }
.selected p { margin: 0 0 8px; }
.selected-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.selected-stats { margin: 0 0 8px; font-size: 13px; }
.muted { color: var(--muted); }

.upcoming {
  grid-area: strip;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--gap);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  overflow: hidden;
  white-space: nowrap;
}
.upcoming-label { color: var(--muted); }
.upcoming-list { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; }
.upcoming-list li + li::before { content: "> "; color: var(--muted); }
.upcoming-list .routes { color: var(--accent); font-size: 12px; }
.upcoming-list li { display: inline-flex; align-items: center; gap: 4px; }
/* Size and frame come from config through main.js; this only keeps the sheet from tiling. */
.ant-icon { display: inline-block; flex: none; background-repeat: no-repeat; }

/* Narrow windows: stack the panel under the board rather than squeezing it. */
@media (max-width: 720px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto var(--strip-height);
    grid-template-areas: "board" "panel" "strip";
    height: auto;
  }
  .board-frame { max-width: 100%; }
}

/* The tower being placed. */
.tower-buttons button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.flow-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.flow-actions #sound { grid-column: 1 / -1; }
.flow-actions button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* The title, won and lost screens cover the board; paused is a banner that lets clicks through, since
   building goes on while paused. */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 16, 12, 0.62);
}
.screen[hidden] { display: none; }

/* The live score in the board's top left corner. Clicks pass through to the board under it. */
.live-score {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(20, 16, 12, 0.62);
  pointer-events: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.live-score[hidden] { display: none; }
.live-score-label { color: var(--muted); font-weight: 400; }
.screen-stats .total { border-top: 1px solid var(--panel-edge); padding-top: 4px; }
.screen-card {
  min-width: 240px;
  max-width: 360px;
  padding: 20px 24px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  text-align: center;
  display: grid;
  gap: var(--gap);
}
.screen-card h1 { margin: 0; font-size: 24px; color: var(--accent); }
.screen-card p { margin: 0; }
.screen-stats { text-align: left; }
.screen[data-kind="paused"] { background: none; align-items: flex-start; pointer-events: none; }
.screen[data-kind="paused"] .screen-card { margin-top: 12px; padding: 6px 16px; min-width: 0; }
.screen[data-kind="paused"] .screen-card h1 { font-size: 18px; }
.screen [hidden] { display: none; }
.modes { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.modes button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
