:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #111820;
  --panel-2: #151e28;
  --line: #283342;
  --text: #e9eef5;
  --muted: #96a4b5;
  --accent: #6aa8ff;
  --accent-2: #8bc5ff;
  --danger: #e36d6d;
  --ok: #63c986;
  --warn: #e1b55e;
  --plain: #90ee90;
  --water: #87cefa;
  --forest: #228b22;
  --hill: #a0522d;
  --mountain: #8b4513;
  --urban: #a9a9a9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-width: 1100px;
}
button, input { font: inherit; }
button {
  color: var(--text);
  background: #18212b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
}
button:hover { border-color: #42546a; background: #1d2935; }
button.active, button.primary { background: #214b7b; border-color: #3c7fc3; }
button.danger { background: #682e36; border-color: #9a4852; }
button:disabled { opacity: .45; cursor: not-allowed; }
input {
  color: var(--text);
  background: #0e141b;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 8px;
  width: 100%;
}
code { color: #c9dcff; }

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #0e141b;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 29px; color: #ffd86b; }
.brand h1 { margin: 0; font-size: 19px; }
.brand h1 span { color: var(--accent-2); font-size: 13px; font-weight: 600; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(620px, 1fr) 290px;
  min-height: calc(100vh - 76px);
}
.sidebar {
  background: var(--panel);
  padding: 14px;
  overflow-y: auto;
}
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.sidebar section { padding: 9px 0 18px; border-bottom: 1px solid #202a36; }
.sidebar section:last-child { border-bottom: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: #c7d2df; margin: 5px 0 12px; }
label { display: block; color: var(--muted); font-size: 12px; margin: 9px 0; }
label input { margin-top: 5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.wide { width: 100%; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.45; margin: 9px 0 0; }

.palette { display: grid; gap: 7px; }
.palette button { display: flex; align-items: center; gap: 9px; text-align: left; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); flex: 0 0 18px; }
.formation-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.formation-buttons button { display: flex; align-items: center; justify-content: center; gap: 7px; }
.dot { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }
.dot.wei { background: #4f79ff; }
.dot.shu { background: #ff5f5f; }
.dot.wu { background: #46c878; }

.workspace { display: flex; flex-direction: column; min-width: 0; }
.workspace-toolbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.segmented { display: flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 7px 0 0 7px; }
.segmented button:last-child { border-radius: 0 7px 7px 0; }
.inline-check { display: flex; align-items: center; gap: 5px; margin: 0; white-space: nowrap; }
.inline-check input { width: auto; margin: 0; }
.cursor-info { margin-left: auto; color: var(--muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.map-viewport {
  position: relative;
  flex: 1;
  min-height: 620px;
  overflow: auto;
  background:
    radial-gradient(circle at 50% 40%, rgba(88,114,144,.12), transparent 45%),
    #0a0f15;
}
#mapSvg { width: 100%; height: 100%; min-height: 620px; display: block; touch-action: none; }
.hex-cell { cursor: crosshair; transition: filter .08s ease; }
.hex-cell:hover { filter: brightness(1.15); }
.hex-outline { stroke: #17202a; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.no-grid .hex-outline { stroke: transparent; }
.hex-coordinate { pointer-events: none; font-size: 8px; font-weight: 700; fill: rgba(0,0,0,.65); text-anchor: middle; dominant-baseline: middle; }
.formation-marker { pointer-events: none; stroke: rgba(255,255,255,.9); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.formation-label { pointer-events: none; fill: white; font-size: 8px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; }
.preview-mode .hex-coordinate { display: none; }
.preview-mode .hex-outline { stroke: rgba(0,0,0,.26); }
.reference-image { pointer-events: none; }
.legend-bar { height: 34px; flex: 0 0 34px; display: flex; gap: 20px; align-items: center; padding: 0 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; background: var(--panel-2); }

.image-controls.disabled { opacity: .45; pointer-events: none; }
.validation-summary { font-size: 12px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.validation-list { display: grid; gap: 6px; margin-bottom: 10px; }
.validation-item { font-size: 11px; line-height: 1.35; padding: 7px 8px; border-radius: 7px; background: #0e141b; }
.validation-item.ok { border-left: 3px solid var(--ok); }
.validation-item.warn { border-left: 3px solid var(--warn); }
.validation-item.error { border-left: 3px solid var(--danger); }
.stats-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 9px; font-size: 11px; color: var(--muted); }
.stats-grid strong { color: var(--text); font-weight: 600; }

dialog { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 420px; }
dialog::backdrop { background: rgba(0,0,0,.62); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 1250px) {
  .app-shell { grid-template-columns: 220px minmax(560px, 1fr) 260px; }
  .workspace-toolbar { gap: 8px; }
}
