/* Refined Cartographic Frosted-Glass Theme (Light default + Dark toggle) */
:root,
[data-theme="light"] {
  color-scheme: light;
  --ocean: #dae4ec;
  --land-ctx: #ecebe6;
  --land-ctx-stroke: #c6cfd6;
  --land-unreported: #dfe4e8;
  --county-stroke: rgba(255, 255, 255, 0.78);
  --country-border: rgba(22, 32, 44, 0.65);
  --country-border-active: #0f172a;
  --label-fill: #0f172a;
  --label-halo: rgba(255, 255, 255, 0.88);
  --sublabel-fill: #334155;

  --hud-bg: rgba(255, 255, 255, 0.92);
  --hud-border: rgba(15, 23, 42, 0.11);
  --hud-hairline: rgba(15, 23, 42, 0.08);
  --hud-shadow: 0 8px 26px rgba(15, 23, 42, 0.09), 0 1px 2px rgba(15, 23, 42, 0.06);
  --surface-subtle: rgba(15, 23, 42, 0.045);
  --surface-hover: rgba(15, 23, 42, 0.08);
  --select-bg: #ffffff;

  --text: #0f172a;
  --muted: #556578;
  --ink-bg: #111827;
  --ink-text: #ffffff;
  --ink-hover: #1f2937;
  --accent-bg: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --accent-ring: rgba(37, 99, 235, 0.35);
  --dot-empty: #cbd5e1;
  --live: #dc2626;
  --paused: #d97706;
  --up: #059669;
  --down: #dc2626;
}

[data-theme="dark"] {
  color-scheme: dark;
  --ocean: #0c1219;
  --land-ctx: #182029;
  --land-ctx-stroke: #26313e;
  --land-unreported: #212b36;
  --county-stroke: rgba(10, 15, 22, 0.72);
  --country-border: rgba(235, 241, 248, 0.55);
  --country-border-active: #ffffff;
  --label-fill: #f1f5f9;
  --label-halo: rgba(10, 15, 22, 0.88);
  --sublabel-fill: #cbd5e1;

  --hud-bg: rgba(18, 23, 30, 0.90);
  --hud-border: rgba(255, 255, 255, 0.11);
  --hud-hairline: rgba(255, 255, 255, 0.08);
  --hud-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  --surface-subtle: rgba(255, 255, 255, 0.05);
  --surface-hover: rgba(255, 255, 255, 0.10);
  --select-bg: #161d26;

  --text: #f1f5f9;
  --muted: #94a3b8;
  --ink-bg: #f1f5f9;
  --ink-text: #0f172a;
  --ink-hover: #ffffff;
  --accent-bg: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-text: #ffffff;
  --accent-ring: rgba(96, 165, 250, 0.45);
  --dot-empty: #334155;
  --live: #ef4444;
  --paused: #fbbf24;
  --up: #34d399;
  --down: #f87171;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ocean);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Fullscreen Map Canvas */
#map-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#map-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

#map-canvas.dragging {
  cursor: grabbing;
}

#map-canvas.hovering {
  cursor: pointer;
}

/* Refined Frosted Glass HUD */
.hud {
  position: absolute;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: var(--hud-shadow);
  contain: layout style;
  z-index: 10;
}

/* Top-Left Command Strip */
.hud-top-left {
  top: 14px;
  left: 14px;
  width: min(535px, calc(100vw - 28px));
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}

.brand > div {
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: var(--ink-bg);
  color: var(--ink-text);
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.04em;
  border-radius: 6px;
}

.brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.subtitle {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.scenario-select {
  margin-top: 3px;
  width: 100%;
  max-width: 245px;
  background: var(--select-bg);
  color: var(--text);
  border: 1px solid var(--hud-border);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 5px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 1px solid var(--hud-border);
  background: var(--surface-subtle);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.status-live .status-dot {
  background: var(--live);
  animation: pulseDot 1.1s infinite;
}

.status-paused .status-dot {
  background: var(--paused);
}

.status-done .status-dot {
  background: var(--up);
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.btn {
  border: 1px solid var(--hud-border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease;
}

.btn:hover {
  background: var(--surface-hover);
}

.btn:disabled {
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
}

.btn-icon {
  padding: 5px 8px;
}

#btn-run {
  min-width: 84px;
  text-align: center;
}

.btn-ink {
  background: var(--ink-bg);
  border-color: var(--ink-bg);
  color: var(--ink-text);
}

.btn-ink:hover {
  background: var(--ink-hover);
}

.btn-accent {
  background: var(--accent-bg);
  border-color: var(--accent-bg);
  color: var(--accent-text);
  box-shadow: 0 2px 8px var(--accent-ring);
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-accent.is-custom {
  box-shadow: 0 0 0 2px var(--hud-bg), 0 0 0 4px var(--accent-bg);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-subtle);
}

.seg-btn,
.cm-btn,
.htab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
  padding: 4px 7px;
  cursor: pointer;
  border-right: 1px solid var(--hud-hairline);
}

.seg-btn:last-child,
.cm-btn:last-child,
.htab-btn:last-child { border-right: none; }

.seg-btn:hover,
.cm-btn:hover,
.htab-btn:hover { color: var(--text); }

.seg-btn.active,
.cm-btn.active,
.htab-btn.active {
  background: var(--ink-bg);
  color: var(--ink-text);
  font-weight: 700;
}

.sim-clock {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--surface-subtle);
  border: 1px solid var(--hud-hairline);
}

.country-select {
  background: var(--select-bg);
  color: var(--text);
  border: 1px solid var(--hud-border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
}

select option {
  background: var(--select-bg);
  color: var(--text);
}

.hemi-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.coalition-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--hud-hairline);
}

.coalition-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--hud-hairline);
  cursor: pointer;
  font-size: 11px;
  transition: background 120ms ease, border-color 120ms ease;
}

.coalition-row:hover,
.coalition-row.active {
  background: var(--surface-hover);
  border-color: var(--ink-bg);
}

.coalition-partners {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  font-weight: 700;
}

.coalition-partner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.coalition-meta {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.mini-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  padding: 3px 6px;
}

.mini-field input[type="number"] {
  width: 48px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
}

.mini-field input[type="range"] {
  width: 58px;
  accent-color: var(--ink-bg);
}

.mini-field output {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text);
  min-width: 28px;
}

.mini-field select {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 5px;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--hud-hairline);
  padding-top: 7px;
}

.focus-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.focus-btn {
  border: 1px solid var(--hud-border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
}

.focus-btn:hover { color: var(--text); background: var(--surface-subtle); }
.focus-btn.active {
  background: var(--ink-bg);
  color: var(--ink-text);
  border-color: var(--ink-bg);
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}

.progress-bar {
  width: 92px;
  height: 4px;
  background: var(--surface-hover);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--ink-bg);
  transition: width 120ms linear;
}

/* Right Rail: Overlay Switcher stacked cleanly above Slide-In Inspector */
.right-rail {
  position: absolute;
  top: 14px;
  right: 14px;
  bottom: 120px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 15;
  max-width: calc(100vw - 28px);
}

.hud-top-right {
  position: static;
  pointer-events: auto;
  flex-shrink: 0;
  padding: 9px 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 300px;
  max-width: 100%;
}

.overlay-bar {
  display: flex;
  gap: 3px;
}

.ov-btn {
  flex: 1;
  border: 1px solid var(--hud-border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.ov-btn:hover { color: var(--text); background: var(--surface-subtle); }
.ov-btn.active {
  background: var(--ink-bg);
  border-color: var(--ink-bg);
  color: var(--ink-text);
}

.sub-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sub-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.sub-control-row select {
  flex: 1;
  background: var(--select-bg);
  color: var(--text);
  border: 1px solid var(--hud-border);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
}

.legend {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-bar {
  height: 6px;
  border-radius: 3px;
  width: 100%;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* Zoom Controls — placed beside bottom-left parliament HUD so inspector never covers them */
.zoom-controls {
  left: 404px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
}

.zoom-btn {
  width: 32px;
  height: 30px;
  border: none;
  border-bottom: 1px solid var(--hud-hairline);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.zoom-btn:last-child { border-bottom: none; font-size: 14px; }
.zoom-btn:hover { background: var(--surface-hover); }

/* Bottom-Left Hemicycle HUD */
.hud-bottom-left {
  bottom: 14px;
  left: 14px;
  width: 380px;
  max-width: calc(100vw - 28px);
  padding: 10px 12px;
  border-radius: 10px;
}

.hud-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.hud-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-sub {
  font-size: 11px;
  color: var(--text);
  margin-top: 2px;
}

.hemicycle-body {
  margin-top: 6px;
}

#hemicycle-svg {
  width: 100%;
  height: auto;
  display: block;
}

.seat-dot {
  transition: fill 200ms ease;
}

.seat-ledger {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--hud-hairline);
}

.ledger-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ledger-top {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.ledger-nums {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding-left: 13px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

.ledger-seats {
  font-size: 13px;
  font-weight: 700;
}

.ledger-delta {
  font-size: 10px;
  font-weight: 600;
}

.delta-up { color: var(--up); }
.delta-down { color: var(--down); }
.delta-flat { color: var(--muted); }

/* Bottom-Right Ticker + Attribution */
.bottom-right-stack {
  position: absolute;
  bottom: 12px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 10;
  pointer-events: none;
}

.ticker {
  position: static;
  pointer-events: auto;
  width: 315px;
  max-width: calc(100vw - 28px);
  padding: 7px 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ticker:empty {
  display: none;
}

.ticker-row {
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  padding: 3px 5px;
  border-radius: 5px;
  cursor: pointer;
}

button.coalition-row {
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
}

.ticker-row:hover {
  background: var(--surface-hover);
}

.ticker-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ticker-right {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.attribution {
  font-size: 10px;
  color: var(--muted);
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  padding: 2px 7px;
  border-radius: 4px;
  pointer-events: auto;
}

.attribution:empty {
  display: none;
}

/* Right Slide-In Inspector (flex-stacked inside .right-rail below .hud-top-right) */
.inspector {
  position: static;
  pointer-events: auto;
  flex: 0 1 auto;
  min-height: 0;
  width: 315px;
  max-width: 100%;
  overflow-y: auto;
  padding: 12px;
  border-radius: 10px;
}

.inspector-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hud-hairline);
}

.inspector-head h2 {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.inspector-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 10px 0;
}

.stat-box {
  background: var(--surface-subtle);
  border: 1px solid var(--hud-hairline);
  border-radius: 6px;
  padding: 6px 7px;
}

.stat-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-value {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}

.inspector-actions {
  margin-bottom: 10px;
  display: flex;
  gap: 6px;
}

.inspector-bars {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.bar-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.bar-party {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.group-tag {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--surface-subtle);
  color: var(--muted);
}

.bar-track {
  height: 5px;
  background: var(--surface-hover);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 180ms ease;
}

/* Hover Tooltip */
.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 11px;
  z-index: 30;
  box-shadow: var(--hud-shadow);
  max-width: 240px;
  will-change: transform;
}

.tooltip-title {
  font-weight: 700;
  margin-bottom: 2px;
}

.tooltip-sub {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
}

#hemicycle-svg.bar-mode {
  height: 92px;
}

.district-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

.district-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-subtle);
  border: 1px solid var(--hud-hairline);
}

/* Responsive layout for laptops & smaller viewports */
@media (max-width: 1040px) {
  .hud-top-left {
    width: auto;
    max-width: calc(100vw - 340px);
  }
  .hud-bottom-left {
    width: 320px;
  }
  .zoom-controls {
    left: 344px;
  }
}

@media (max-width: 820px) {
  .hud-top-left {
    left: 10px;
    top: 10px;
    right: 10px;
    max-width: none;
  }
  .right-rail {
    top: 168px;
    bottom: auto;
    right: 10px;
    max-height: calc(100vh - 240px);
  }
  .hud-top-right {
    min-width: 0;
    width: min(320px, calc(100vw - 20px));
  }
  .hud-bottom-left {
    left: 10px;
    bottom: 10px;
    width: min(300px, calc(100vw - 62px));
  }
  .zoom-controls {
    left: auto;
    top: auto;
    right: 10px;
    bottom: 10px;
  }
  .bottom-right-stack {
    display: none;
  }
}

@media (max-height: 740px) and (min-width: 821px) {
  .hud-bottom-left {
    width: 340px;
    padding: 8px 10px;
  }
  .zoom-controls {
    left: 364px;
  }
  .right-rail {
    bottom: 96px;
  }
}

/* Scenario editor modal */
.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 12px;
}

.editor-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.editor-dialog {
  position: relative;
  width: min(920px, calc(100vw - 24px));
  max-height: min(90vh, 860px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hud-hairline);
}

.editor-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.editor-name-input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--hud-border);
  border-radius: 7px;
  padding: 5px 9px;
}

.editor-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--hud-hairline);
  background: var(--surface-subtle);
}

.editor-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 6px 16px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--hud-hairline);
}

.editor-stats-bar strong {
  color: var(--text);
}

.editor-tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.editor-tab-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.editor-tab-btn.active {
  color: var(--ink-text);
  background: var(--ink-bg);
}

.editor-error {
  margin: 10px 16px 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

html[data-theme="dark"] .editor-error {
  color: #fca5a5;
}

.editor-body {
  flex: 1;
  min-height: 220px;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.editor-scope-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  width: 100%;
}

.editor-scope-label select,
.editor-search-input,
.editor-field input,
.editor-field select {
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--hud-border);
  border-radius: 7px;
  padding: 5px 8px;
}

.editor-scope-label select {
  flex: 1;
  min-width: 0;
}

.editor-search-input {
  width: 100%;
}

.editor-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-hint {
  font-size: 11px;
  color: var(--muted);
}

.editor-card {
  border: 1px solid var(--hud-hairline);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
}

.editor-muted {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-code {
  font-size: 10px;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--select-bg);
  border: 1px solid var(--hud-hairline);
}

.editor-color-input {
  width: 24px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--hud-border);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
}

.editor-party-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-slider-wrap {
  display: grid;
  grid-template-columns: 78px 1fr 48px;
  align-items: center;
  gap: 8px;
}

.editor-slider-wrap input[type="range"] {
  width: 100%;
}

.editor-mini-label {
  font-size: 11px;
  color: var(--muted);
}

.editor-val {
  font-size: 11px;
  text-align: right;
}

.editor-region-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 8px;
}

.editor-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}

.editor-json-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-json-textarea {
  flex: 1;
  min-height: 280px;
  width: 100%;
  resize: vertical;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--hud-border);
  border-radius: 8px;
  padding: 10px;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-top: 1px solid var(--hud-hairline);
  background: var(--surface-subtle);
}

.editor-footer-left,
.editor-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 680px) {
  .editor-slider-wrap {
    grid-template-columns: 78px 1fr 56px;
  }
  .editor-grid-2,
  .editor-grid-3 {
    grid-template-columns: 1fr;
  }
  .editor-footer {
    justify-content: flex-end;
  }
  .editor-footer-left {
    width: 100%;
  }
}

.editor-section {
  border: 1px solid var(--hud-hairline);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.editor-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.editor-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.editor-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
}

.editor-axes-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-axis-row,
.editor-slider-num-row {
  display: grid;
  grid-template-columns: 118px 1fr 68px;
  align-items: center;
  gap: 8px;
}

.editor-slider-num-row input[type="range"],
.editor-axis-row input[type="range"] {
  width: 100%;
}

.editor-num-input {
  width: 68px;
  font: inherit;
  font-size: 11px;
  text-align: right;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  padding: 3px 6px;
}

.editor-details {
  border: 1px solid var(--hud-hairline);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--select-bg);
}

.editor-details summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}

.editor-details[open] summary {
  margin-bottom: 8px;
  color: var(--text);
}

.editor-inline-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.editor-inline-grow {
  flex: 1;
  min-width: 110px;
}

.editor-check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.editor-btn-sm {
  font-size: 11px;
  padding: 3px 8px;
}

.editor-btn-danger {
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--down);
}

.editor-btn-danger:hover {
  background: rgba(220, 38, 38, 0.12);
}

.editor-tilt-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.editor-tilt-row {
  display: grid;
  grid-template-columns: 1fr 1fr 82px auto;
  gap: 6px;
  align-items: center;
}

.editor-control-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.editor-help {
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

.editor-textarea {
  width: 100%;
  resize: vertical;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--select-bg);
  border: 1px solid var(--hud-border);
  border-radius: 7px;
  padding: 6px 8px;
}

.scenario-note {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.forecast-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--ink-bg);
  color: var(--ink-text);
}

.ledger-item-forecast {
  padding: 4px 0;
  gap: 3px;
}

.ledger-odds-pill {
  margin-left: auto;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-hover);
  color: var(--text);
}

.ledger-range-text {
  font-size: 10px;
  color: var(--muted);
}

.ledger-range-track {
  position: relative;
  height: 4px;
  margin-left: 13px;
  border-radius: 999px;
  background: var(--surface-hover);
  overflow: hidden;
}

.ledger-range-band {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
  opacity: 0.72;
}

.ledger-range-median {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: var(--text);
}

.meta-pills {
  display: flex;
  align-items: center;
  gap: 5px;
}

.version-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--hud-border);
  background: var(--hud-bg);
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
}

.version-pill:hover {
  color: var(--text);
  border-color: var(--text);
}

.forecast-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--hud-hairline);
}

.forecast-odds-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.forecast-odds-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  align-items: center;
}

.forecast-odds-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.forecast-odds-bar {
  display: flex;
  height: 7px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-hover);
}

.forecast-odds-seg {
  height: 100%;
}

.forecast-hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}

.forecast-hist-title {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.forecast-hist-hint {
  font-size: 10px;
  color: var(--muted);
}

.forecast-hist-svg {
  width: 100%;
  height: auto;
  display: block;
}

.ledger-item-forecast[role="button"] {
  cursor: pointer;
  padding: 4px 5px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.ledger-item-forecast[role="button"]:hover {
  background: var(--surface-subtle);
}

.ledger-item-forecast.is-selected {
  background: var(--surface-hover);
  border-color: var(--hud-border);
}

.battlegrounds {
  padding: 9px 12px;
  width: 315px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.battlegrounds-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 210px;
  overflow-y: auto;
}

.bg-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--hud-hairline);
  background: var(--surface-subtle);
  color: var(--text);
  font: inherit;
  border-radius: 7px;
  padding: 5px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bg-row:hover {
  background: var(--surface-hover);
}

.bg-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.bg-row-odds {
  font-size: 10px;
  color: var(--muted);
}

.bg-bar {
  display: flex;
  height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-hover);
}

.bg-bar-seg {
  height: 100%;
}

.changelog-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(80vh, 640px);
}

.changelog-footer {
  justify-content: flex-end;
}

.changelog-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.changelog-ver-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-hover);
  border: 1px solid var(--hud-border);
}

.changelog-entry {
  border: 1px solid var(--hud-hairline);
  background: var(--surface-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.changelog-entry-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}

.changelog-notes {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
