:root {
  --bg: #151b24;
  --panel: rgba(18, 24, 33, 0.9);
  --card: #1b2330;
  --text: #e7ecf3;
  --muted: #93a0b4;
  --line: rgba(255, 255, 255, 0.09);
  --azure: #7fb0ff;
  --ember: #ff9a80;
  --button: #2a3546;
  --button-hover: #34445a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

#board { position: fixed; inset: 0; }
#board canvas { display: block; }

#hud, #panel, #log {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(6px);
}

#hud {
  top: 12px; left: 12px; right: 12px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 12px;
}
#hud .spacer { flex: 1; }
.cred { font-variant-numeric: tabular-nums; }
.cred::before {
  content: ""; display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; margin-right: 6px; background: currentColor;
}

#panel {
  top: 72px; right: 12px; width: 280px;
  max-height: calc(100% - 96px); overflow: auto;
  padding: 12px;
}
#panel h3 { margin: 0 0 6px; font-size: 15px; }
#panel h4 { margin: 12px 0 2px; font-size: 13px; }
/* Low fuel or ammo: a blinking tag by the number, and a note under the stats. */
.supply-tag {
  display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px;
  font-size: 11px; font-weight: 700; color: #14181f; background: #ffc04d;
  animation: supply-blink 1s ease-in-out infinite;
}
.supply-tag.empty { background: #ff5a4a; color: #fff; animation-duration: 0.5s; }
.supply-warn {
  margin: 8px 0 0; padding: 6px 8px; border-radius: 6px; font-size: 12px;
  border-left: 3px solid #ffc04d; background: rgba(255, 192, 77, 0.1);
}
.supply-warn.empty { border-left-color: #ff5a4a; background: rgba(255, 90, 74, 0.12); }
@keyframes supply-blink { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .supply-tag { animation: none; } }
#hex-panel:not(:empty) { border-top: 1px solid var(--line); margin-top: 10px; }

#log {
  left: 12px; bottom: 12px;
  width: min(440px, calc(100% - 24px)); max-height: 30vh; overflow: auto;
  padding: 8px 12px; font-size: 12.5px;
}
#log .turn { color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; font-weight: 600; }
#log .dim { color: var(--muted); }
#log .bad { color: #ffb08f; }
#log .good { color: #9be7a8; }
#log .win { color: #ffd23f; font-weight: 700; }

.side0 { color: var(--azure); }
.side1 { color: var(--ember); }
.dim { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); margin: 6px 0; }

button, select, input {
  font: inherit; color: var(--text);
  background: var(--button); border: 1px solid #3a4a61; border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--button-hover); }
button:disabled { opacity: 0.45; cursor: default; }
input { width: 9em; margin-left: 6px; }
#map { margin-left: 6px; }
#map-blurb { margin: 4px 0 10px; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.build { display: grid; gap: 4px; margin-top: 8px; }
.build button { display: flex; justify-content: space-between; }

/* The unit panel's header: the crew portrait (src/portraits.js) beside the unit's name. */
.unit-head { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; }
#panel .unit-head h3 { margin: 0; }
#hex-panel .unit-head { margin-top: 10px; }
.unit-portrait {
  flex: none; width: 64px; height: 64px; image-rendering: pixelated;
  border: 2px solid currentColor; border-radius: 6px; background: #0d1117;
}
dl.stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 6px 0; }
dl.stats dt { color: var(--muted); }
dl.stats dd { margin: 0; }

.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(8, 11, 16, 0.72);
}
.overlay.opaque { background: var(--bg); }
#saves { z-index: 15; } /* above the menu, so a game can be loaded from it */
.slots { display: grid; gap: 8px; margin: 12px 0; }
.slot { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.slot .actions { margin-top: 6px; }
.slot button.armed { border-color: #ffc04d; color: #ffc04d; }
.hidden { display: none !important; }
/* The action menu floats beside the selected unit; main.js moves it with transform every frame. */
#unit-menu {
  position: fixed; left: 0; top: 0; z-index: 12;
  display: flex; flex-direction: column; gap: 4px; min-width: 130px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  backdrop-filter: blur(6px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
#unit-menu button { text-align: left; padding: 5px 10px; }
#unit-menu .menu-note { color: var(--muted); font-size: 12px; padding: 2px 6px; }
.check { display: block; margin-bottom: 10px; cursor: pointer; }
.check input { width: auto; margin: 0 6px 0 0; vertical-align: -2px; }

.card {
  width: min(460px, calc(100% - 32px));
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px;
}
.card h1, .card h2 { margin: 0 0 6px; }
.modes { display: grid; gap: 8px; margin: 18px 0; }
.modes button { padding: 10px; text-align: left; }
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--muted); }
details ul { padding-left: 18px; margin: 8px 0 0; }
details li { margin-bottom: 6px; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }

/* The music player sits above the menu and other overlays, so music can start from the menu. */
#music {
  position: fixed; right: 12px; bottom: 12px; z-index: 20;
  width: 360px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(6px);
  padding: 6px 8px; font-size: 12.5px;
}
.music-title {
  display: block; width: 100%; text-align: left;
  background: none; border: none; padding: 2px 4px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.music-buttons { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.music-buttons button { padding: 2px 8px; min-width: 30px; }
.music-buttons button.on, .music-list button.on { color: #6dffa8; border-color: #6dffa8; }
.music-volume { flex: 1; min-width: 0; width: auto; margin: 0; padding: 0; accent-color: var(--azure); }
.music-buttons .music-mute { min-width: 0; padding: 2px 4px; background: none; border-color: transparent; }
.sfx-label { flex: 0 0 auto; padding: 0 4px 0 4px; }
.music-level { width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }
.music-list {
  list-style: none; margin: 0 0 6px; padding: 0 0 6px;
  max-height: 40vh; overflow: auto; border-bottom: 1px solid var(--line);
}
.music-list button {
  display: block; width: 100%; text-align: left; margin: 2px 0; padding: 3px 8px;
  background: none; border: 1px solid transparent;
}

@media (max-width: 720px) {
  #panel { top: auto; bottom: 84px; left: 12px; right: 12px; width: auto; max-height: 30vh; }
  #log { display: none; }
  #music { left: 12px; width: auto; }
}

.ready { color: #6dffa8; }

/* End-of-game results */
.card.results { width: min(520px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto; }
.results-table { width: 100%; border-collapse: collapse; margin: 12px 0 16px; font-variant-numeric: tabular-nums; }
.results-table th, .results-table td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.results-table th:first-child, .results-table td:first-child { text-align: left; color: var(--muted); font-weight: normal; }
.results-table tr.won th.won-col::after { content: " \2605"; }
#show-results { padding: 1px 8px; font-size: 12px; margin-left: 4px; }
.chart-title { margin: 0 0 6px; font-size: 14px; }
.results-chart { display: block; width: 100%; height: 140px; margin-bottom: 16px; }
.results-chart .grid { stroke: var(--line); }
.results-chart .axis { fill: var(--muted); font-size: 10px; }
.results-chart .line0 { stroke: var(--azure); }
.results-chart .line1 { stroke: var(--ember); }
.results-chart polyline { fill: none; stroke-width: 2; stroke-linejoin: round; }

/* Combat duel: a timing bar over the board. The backdrop is light so the fight stays in view. */
/* It sits low on the screen, leaving the middle of the board (and usually the fight) in view. */
.overlay.duel {
  z-index: 14; background: rgba(8, 11, 16, 0.25); cursor: pointer; user-select: none;
  place-items: end center; padding-bottom: 9vh;
}
.duel-card { text-align: center; }
/* The VS banner: the player's crew, the two units face to face in 3D, the enemy's crew. */
.duel-vs {
  display: grid; grid-template-columns: 80px 1fr 80px; gap: 8px; align-items: start;
  margin: -6px 0 12px;
}
.duel-vs[hidden] { display: none; }
.duel-crew { margin: 0; min-width: 0; }
.duel-crew figcaption {
  margin-top: 3px; font-size: 11px; font-weight: 600; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.duel-portrait {
  display: block; width: 80px; height: 80px; image-rendering: pixelated;
  border: 2px solid currentColor; border-radius: 6px; background: #0d1117;
}
.duel-closeup {
  display: block; width: 100%; height: 80px; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: linear-gradient(#22324a, #151b24);
}
@media (max-width: 400px) {
  .duel-vs { grid-template-columns: 56px 1fr 56px; }
  .duel-portrait { width: 56px; height: 56px; }
  .duel-closeup { height: 56px; }
}
.duel-card h2 { font-size: 18px; }
.duel-bar {
  position: relative; height: 34px; margin: 16px 0 10px;
  background: #3a2428; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.duel[data-kind="defend"] .duel-bar { background: #26303f; }
.duel-zone { position: absolute; top: 0; bottom: 0; }
.duel-zone.good { background: #2f6b45; }
.duel-zone.best { background: #ffd166; }
.duel[data-kind="defend"] .duel-zone.good { background: #2f5a85; }
.duel-marker {
  position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px;
  background: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, 0.8); border-radius: 2px;
}
.duel-result { min-height: 1.45em; margin: 0 0 6px; font-weight: 600; font-size: 16px; }
.duel-result.perfect { color: #ffd166; }
.duel-result.good { color: #7ddc9a; }
.duel-result.weak { color: var(--ember); }
/* Lead the target: a canvas of sky in place of the bar. */
.duel-sky {
  display: block; width: 100%; aspect-ratio: 440 / 190; margin: 14px 0 10px;
  border: 1px solid var(--line); border-radius: 8px; cursor: none; touch-action: none;
}
.duel:not([data-game="timing"]) .duel-bar, .duel[data-game="timing"] .duel-sky { display: none; }
.duel[data-game="artillery"] .duel-sky { cursor: pointer; }
