/* Kill Team Battle Simulator — original UI design.
   No Games Workshop artwork, layouts, or typography are reproduced here. */

:root {
  --bg: #10131a;
  --bg-panel: #171b25;
  --bg-raised: #1e2432;
  --bg-input: #0d1017;
  --line: #2b3242;
  --line-soft: #222836;
  --text: #e6eaf2;
  --text-dim: #9aa4b8;
  --text-faint: #6b7488;
  --accent: #59a5f5;
  --accent-dim: #2f5f92;
  --p1: #4a7fb5;
  --p2: #c98a2e;
  --good: #5fbf8f;
  --warn: #e0a83c;
  --bad: #d9614f;
  --board: #171a20;
  --board-grid: #232833;
  --terrain: #39414f;
  --terrain-edge: #4d586a;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* High-contrast mode: never rely on colour alone (§32). */
body.high-contrast {
  --bg: #000; --bg-panel: #0a0a0a; --bg-raised: #141414; --bg-input: #000;
  --line: #6a6a6a; --line-soft: #4a4a4a;
  --text: #fff; --text-dim: #d8d8d8; --text-faint: #b0b0b0;
  --accent: #7fc4ff; --p1: #7fc4ff; --p2: #ffc04d;
  --board: #000; --board-grid: #333; --terrain: #4a4a4a; --terrain-edge: #9a9a9a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

button, select, input {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}

button {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
button:hover:not(:disabled) { background: #262d3d; border-color: #3b455a; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent-dim); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #3a72ad; }
button.active { background: var(--accent-dim); border-color: var(--accent); }

select, input[type="text"], input[type="number"], textarea {
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- */
/* App shell                                                         */
/* ---------------------------------------------------------------- */

#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.topbar .brand {
  font-weight: 700;
  letter-spacing: .3px;
  margin-right: 6px;
  white-space: nowrap;
}
.topbar .brand small {
  display: block;
  font-weight: 400;
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: .5px;
  text-transform: uppercase;
}
.topbar .spacer { flex: 1; }
.field { display: flex; align-items: center; gap: 6px; }
.field label { color: var(--text-dim); font-size: 12px; white-space: nowrap; }

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 260px;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
}
.panel:last-child { border-right: none; border-left: 1px solid var(--line); }

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--board);
  display: flex;
}
#board { width: 100%; height: 100%; display: block; touch-action: none; }

.logbar {
  flex: 0 0 auto;
  height: 168px;
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- */
/* Team panels                                                       */
/* ---------------------------------------------------------------- */

.team-head { margin-bottom: 8px; }
.team-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.team-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.35);
}
.team-sub { color: var(--text-faint); font-size: 11px; margin-top: 2px; }

.scoreline {
  display: flex; gap: 6px; margin: 8px 0;
}
.stat-chip {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 5px 7px;
  text-align: center;
}
.stat-chip .k { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; }
.stat-chip .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.op-card {
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  display: block;
}
.op-card:hover { border-color: var(--accent-dim); }
.op-card.selected { border-color: var(--accent); background: #202942; }
.op-card.down { opacity: .42; }
.op-card.down .op-name { text-decoration: line-through; }
.op-card.active-now { box-shadow: 0 0 0 1px var(--accent) inset; }

.op-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.op-name { font-weight: 600; font-size: 12.5px; }
.op-meta { font-size: 10px; color: var(--text-faint); display: flex; gap: 6px; margin-top: 3px; }
.badge {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .4px;
  padding: 1px 5px; border-radius: 3px; border: 1px solid var(--line);
  color: var(--text-dim); white-space: nowrap;
}
.badge.engage { color: #ffb4a2; border-color: #7a4034; }
.badge.conceal { color: #9ecbff; border-color: #2f4f74; }
.badge.down { color: var(--bad); border-color: #6d2f26; }

.wound-track { height: 4px; background: #0b0e14; border-radius: 2px; margin-top: 5px; overflow: hidden; }
.wound-fill { height: 100%; background: var(--good); transition: width 200ms; }
.wound-fill.hurt { background: var(--warn); }
.wound-fill.critical { background: var(--bad); }

.section-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); margin: 12px 0 6px;
  border-bottom: 1px solid var(--line-soft); padding-bottom: 4px;
}

/* ---------------------------------------------------------------- */
/* Battle log                                                        */
/* ---------------------------------------------------------------- */

.log-head {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; border-bottom: 1px solid var(--line-soft);
}
.log-head .title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); }
.log-body { flex: 1; overflow-y: auto; padding: 6px 10px; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; }
.log-line { display: flex; gap: 8px; padding: 1px 0; }
.log-line .tp { color: var(--text-faint); flex: 0 0 34px; }
.log-line .msg { flex: 1; color: var(--text-dim); }
.log-line.p1 .msg { color: #a8ccf0; }
.log-line.p2 .msg { color: #f0d3a0; }
.log-line.hit .msg { color: #ffd9d0; }
.log-line.kill .msg { color: var(--bad); font-weight: 600; }
.log-line.score .msg { color: var(--good); }
.log-line.turn .msg { color: var(--text); font-weight: 700; border-top: 1px solid var(--line-soft); padding-top: 4px; margin-top: 3px; }
.log-line.warn .msg { color: var(--warn); }
.log-line.rule .msg { color: #cbb8e8; font-style: italic; }
.log-line.plan .msg { color: var(--text-faint); font-style: italic; }

/* ---------------------------------------------------------------- */
/* Modals                                                            */
/* ---------------------------------------------------------------- */

.overlay {
  position: fixed; inset: 0; background: rgba(6,8,12,.78);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.overlay[hidden] { display: none !important; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 860px; width: 100%;
  max-height: 88vh; overflow-y: auto;
  padding: 18px 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal h3 { font-size: 13px; margin: 16px 0 6px; color: var(--text-dim); }
.modal p { color: var(--text-dim); line-height: 1.6; }
.modal .close-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.setup-col { background: var(--bg-raised); border: 1px solid var(--line-soft); border-radius: 8px; padding: 12px; }
.setup-col h3 { margin-top: 0; }
.setup-col select { width: 100%; margin-bottom: 8px; }

.support-badge {
  display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--text-dim); margin-top: 4px;
}
.support-badge.full { border-color: #2f6f4f; color: var(--good); }
.support-badge.partial { border-color: #6d5a26; color: var(--warn); }
.support-badge.experimental { border-color: #6d3a26; color: #f0a58c; }

.roster-preview { margin-top: 8px; font-size: 11.5px; color: var(--text-dim); }
.roster-preview li { margin: 2px 0; }

.notice {
  background: #1b1710; border: 1px solid #4a3c1c; color: var(--warn);
  border-radius: var(--radius); padding: 8px 10px; font-size: 12px; margin-top: 10px;
}
.notice.error { background: #1d1210; border-color: #5a2a20; color: #f0a58c; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

textarea.import-box {
  width: 100%; min-height: 120px; font-family: var(--mono); font-size: 11px; resize: vertical;
}

table.stats { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
table.stats th, table.stats td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line-soft); }
table.stats th { color: var(--text-faint); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; }
table.stats td.num { font-variant-numeric: tabular-nums; }

.result-head { text-align: center; padding: 10px 0 4px; }
.result-head .winner { font-size: 22px; font-weight: 700; }
.result-head .score { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0; }
.vp-table { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 14px; margin-top: 10px; font-size: 12.5px; }
.vp-table .hdr { color: var(--text-faint); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; }

.muted { color: var(--text-faint); font-size: 11px; }
.mono { font-family: var(--mono); }
.footer-note { padding: 4px 14px; font-size: 10.5px; color: var(--text-faint); background: var(--bg-panel); border-top: 1px solid var(--line-soft); }
.footer-note a { color: var(--text-dim); }

/* Reduced motion (§32) */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
body.no-motion * { transition: none !important; animation: none !important; }

/* Responsive: battlefield first, panels become drawers (§24) */
@media (max-width: 980px) {
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(0,1fr) auto; }
  .panel { display: none; }
  body.show-rosters .panel { display: block; max-height: 32vh; border: none; border-top: 1px solid var(--line); }
  .logbar { height: 130px; }
}
