:root {
  color-scheme: dark;
  --bg: #12171b;
  --surface: #1a2024;
  --surface-2: #1e252a;
  --border: #2e3a42;
  --border-soft: #243038;
  --text: #e8e9ec;
  --text-dim: #9aa0ac;
  --text-faint: #6b7680;
  --accent: #d99a2b;
  --accent-ink: #1a1305;
  --win: #4fae74;
  --loss: #d1544a;
}

* { box-sizing: border-box; }
/* The browser's default [hidden]{display:none} loses to any later rule that sets display
   explicitly (e.g. .sanctuary-form{display:flex}) at the same specificity — so toggling the
   hidden attribute on an element with its own display rule silently does nothing without this. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

/* ---- login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  padding: 2rem; width: 20rem; display: flex; flex-direction: column; gap: 0.9rem;
}
.login-box h1 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.login-box label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-dim); }
.login-box input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; padding: 0.5rem; font-size: 0.9rem;
}
.login-box button {
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 3px;
  padding: 0.6rem; font-weight: 700; cursor: pointer;
}
.login-error { color: var(--loss); font-size: 0.85rem; margin: 0; }

/* ---- layout ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.8rem 1.25rem; border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 0.8rem; }
.topbar-right form { margin: 0; }
.conn-status { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--loss); }
.conn-status.live { color: var(--win); }
.n { color: var(--text-dim); font-size: 0.85rem; }

main { display: flex; gap: 1rem; padding: 1rem; align-items: flex-start; flex-wrap: wrap; }
.panel { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 3px; padding: 0.9rem; }
.editor-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; flex-wrap: wrap; }
.editor-head h3 { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.settings-row { display: flex; gap: 0.5rem; align-items: center; font-size: 0.8rem; color: var(--text-dim); }
.settings-row input { width: 4rem; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 3px; padding: 0.3rem; }

.board-panel { flex: 1 1 600px; min-width: 0; }
.coverage-panel { flex: 0 1 300px; max-height: 70vh; overflow-y: auto; }
.roster-panel { flex: 0 1 240px; max-height: 70vh; overflow-y: auto; }

.roster-import { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.8rem; }
.roster-import textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; padding: 0.4rem 0.5rem; font-size: 0.78rem; font-family: inherit; resize: vertical;
}
.roster-list { display: flex; flex-direction: column; gap: 0.4rem; }
.roster-empty { color: var(--text-faint); font-size: 0.8rem; font-style: italic; }
.roster-chip {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 3px;
  padding: 0.4rem 0.6rem; font-size: 0.8rem; cursor: grab; user-select: none; touch-action: none;
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
}
.roster-chip:hover { border-color: var(--accent); }
.roster-chip.dragging { opacity: 0.5; }
.roster-chip .rc-level { color: var(--text-dim); font-size: 0.72rem; white-space: nowrap; }
.roster-chip .rc-remove {
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 0.85rem;
  padding: 0 0.2rem; line-height: 1;
}
.roster-chip .rc-remove:hover { color: var(--loss); }

/* A roster chip being dragged over the board gets a ghost tile preview showing exactly where
   it would land, same visual language as a real placed tile. */
.drop-preview {
  position: absolute; border: 2px dashed var(--accent); border-radius: 3px;
  background: rgba(217, 154, 43, 0.12); pointer-events: none;
}
.drop-preview.collision { border-color: var(--loss); background: rgba(209, 84, 74, 0.15); }

.coverage-section { margin-bottom: 1rem; }
.coverage-section:last-child { margin-bottom: 0; }
.coverage-section-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); margin: 0 0 0.4rem;
}
.coverage-empty { color: var(--text-faint); font-size: 0.8rem; font-style: italic; }
.coverage-card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 3px;
  padding: 0.5rem 0.6rem; margin-bottom: 0.4rem; font-size: 0.8rem;
}
.coverage-card.warn { border-color: var(--loss); }
.coverage-card.move { border-color: var(--accent); }
.coverage-card .cc-title { font-weight: 700; display: flex; justify-content: space-between; gap: 0.5rem; }
.coverage-card .cc-sub { color: var(--text-dim); font-size: 0.72rem; margin-top: 0.15rem; }
.coverage-card ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.coverage-card li { color: var(--text-dim); }
.coverage-card li.near { color: var(--accent); }

.board-scroll { overflow: auto; border: 1px solid var(--border-soft); background: var(--bg); max-height: 70vh; }
.board-grid {
  position: relative;
  /* width/height set inline by JS (boardCols/boardRows * CELL) — the field is resizable, see
     the resize-row controls and POST /api/board/resize. */
  /* 180deg ("to bottom") and 90deg ("to right") both anchor their repeat pattern to the
     top-left corner, matching the tiles' top/left-anchored grid coordinates exactly. The
     original used 0deg ("to top") for the horizontal lines, which anchors to the BOTTOM edge
     instead — since the board's pixel size isn't always a multiple of 28, that put every
     horizontal line off from where a gridY*28-positioned tile expects it (horizontal was
     already fine because 90deg anchors left, matching gridX*28). */
  background-image:
    repeating-linear-gradient(180deg, var(--border-soft) 0, transparent 1px, transparent 28px, var(--border-soft) 28px),
    repeating-linear-gradient(90deg, var(--border-soft) 0, transparent 1px, transparent 28px, var(--border-soft) 28px);
}
#boardTiles { position: absolute; inset: 0; }
.defend-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.defend-line { stroke: var(--accent); stroke-width: 1.5; }
.defend-line.dotted { stroke-dasharray: 4 4; opacity: 0.6; }
.defend-line.solid { opacity: 0.9; }

.sanctuary {
  position: absolute;
  border-radius: 3px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 0.6rem; text-align: center; overflow: hidden; cursor: grab;
  user-select: none; touch-action: none;
}
.sanctuary::before {
  content: ""; position: absolute; width: 28px; height: 28px;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  border: 1px dashed rgba(217, 154, 43, 0.4); pointer-events: none;
}
.sanctuary.strong { border-color: var(--win); }
.sanctuary.weak { border-color: var(--loss); }
.sanctuary.inactive { opacity: 0.35; }
.sanctuary.ready { box-shadow: 0 0 0 2px var(--accent) inset; }
.sanctuary.uncovered { box-shadow: 0 0 0 2px var(--loss), 0 0 8px 1px rgba(209, 84, 74, 0.6); }
.sanctuary.defended::after {
  content: "\2713"; position: absolute; top: -7px; right: -7px; width: 15px; height: 15px;
  border-radius: 50%; background: var(--win); color: #06210f;
  font-size: 10px; font-weight: 700; line-height: 15px; text-align: center;
}
.sanctuary-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 95%; }
.sanctuary-level { color: var(--text-dim); }

button.tiny {
  font-size: 0.72rem; padding: 0.3rem 0.6rem; background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border-soft); border-radius: 3px; cursor: pointer;
}
button.tiny:hover { color: var(--text); border-color: var(--accent); }
button.tiny.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.tiny.primary:hover { color: var(--accent-ink); filter: brightness(1.1); }
button.tiny.danger { color: var(--loss); border-color: var(--loss); }
button.tiny.danger:hover { background: var(--loss); color: var(--bg); }

.board-actions { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }

.resize-row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.7rem; font-size: 0.78rem; }
.resize-label { color: var(--text-dim); }
.resize-group { display: inline-flex; gap: 0.2rem; }
.resize-group button { padding: 0.25rem 0.45rem; }
.resize-size { color: var(--text-faint); margin-left: auto; }

.sanctuary-form {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 3px;
  padding: 0.6rem; margin-bottom: 0.7rem; font-size: 0.8rem; color: var(--text-dim);
}
.sanctuary-form input[type="text"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; padding: 0.35rem 0.5rem; font-size: 0.85rem; flex: 1 1 10rem; min-width: 8rem;
}
.sanctuary-form input[type="number"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; padding: 0.35rem 0.5rem; font-size: 0.85rem; width: 4.5rem;
}
.sanctuary-form select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; padding: 0.35rem 0.4rem; font-size: 0.85rem;
}
.sanctuary-form label { display: flex; align-items: center; gap: 0.3rem; white-space: nowrap; }

.sanctuary.dragging { cursor: grabbing; z-index: 10; box-shadow: 0 0 0 2px var(--accent); }
.sanctuary.collision { border-color: var(--loss) !important; box-shadow: 0 0 0 2px var(--loss); }
