:root {
  color-scheme: dark;
  --bg: #11161d;
  --bg-deep: #0b1016;
  --panel: #19212b;
  --panel-raised: #202b37;
  --panel-soft: #16202a;
  --ink: #edf2f7;
  --muted: #aab5c2;
  --line: #3a4552;
  --line-soft: #2c3743;
  --even: #62a8ef;
  --odd: #ef7d74;
  --spine: #f1c84f;
  --duplicate: #aa8ae6;
  --u25: #42d3c0;
  --u54: #f38b68;
  --i91: #c28bea;
  --u106: #62b6d8;
  --anchor: #8a6700;
  --focus: #78b7ff;
  --danger: #ff938f;
  --sidebar-width: 382px;
  --header-height: 62px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button, input, select, output { font: inherit; }

button, input, select {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
}

button {
  cursor: pointer;
  min-height: 40px;
  font-weight: 700;
}

button:hover { background: var(--panel-raised); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
canvas:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 48%, transparent);
  outline-offset: 2px;
}

input[type="text"], input[type="search"], select {
  width: 100%;
  min-height: 40px;
  padding: 7px 9px;
}

input[type="checkbox"] { accent-color: var(--focus); }
input[type="range"] { width: 100%; accent-color: var(--focus); }

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) auto;
  height: var(--header-height);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 20px #0005;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-right: 1px solid var(--line);
  font-weight: 800;
  letter-spacing: -.015em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--focus);
  border-radius: 8px;
  color: var(--focus);
  font: 800 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.tabs {
  display: flex;
  align-items: stretch;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  position: relative;
  flex: 0 0 auto;
  min-width: 138px;
  padding: 0 18px;
  border: 0;
  border-right: 1px solid var(--line-soft);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.tab::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 0;
  left: 14px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
}

.tab.active { color: var(--ink); background: #23303d; }
.tab.active::after { background: var(--focus); }

.sidebar-toggle {
  display: none;
  margin: 9px;
  padding: 0 14px;
}

.app-shell {
  position: fixed;
  inset: var(--header-height) 0 0 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.sidebar {
  position: relative;
  z-index: 10;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 5px 0 22px #0004;
  scrollbar-width: thin;
}

.sidebar h1 {
  margin: 2px 0 4px;
  font-size: 1.42rem;
  letter-spacing: -.025em;
}

.sidebar h2 {
  margin: 0 0 9px;
  font-size: .88rem;
  letter-spacing: .015em;
}

.eyebrow,
.selected-kicker {
  color: var(--focus);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: .77rem;
  line-height: 1.5;
}

.muted.compact { margin-bottom: 8px; }

.gesture-tip {
  margin-top: 11px;
  padding: 9px 10px;
  border: 1px solid #365775;
  border-radius: 9px;
  background: #152a3d;
  color: #dbeafe;
  font-size: .76rem;
  line-height: 1.4;
}

.selected-card {
  margin-top: 12px;
  min-height: 166px;
  padding: 11px;
  border: 1px solid var(--focus);
  border-radius: 11px;
  background: #142433;
  box-shadow: inset 0 0 0 1px #78b7ff1f;
}

.selected-detail {
  margin-top: 7px;
  color: var(--ink);
  font: .72rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.control-section {
  margin-top: 17px;
  padding-top: 15px;
  border-top: 1px solid var(--line-soft);
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 7px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 7px;
}

.layer-grid,
.section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.layer-option,
.section-option {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  color: #d7e0e9;
  font-size: .72rem;
  line-height: 1.25;
}

.layer-option input,
.section-option input { flex: 0 0 auto; margin-top: 1px; }

.section-swatch {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  margin-top: 1px;
  border: 1px solid #ffffff33;
  border-radius: 3px;
}

.range-group {
  margin: 8px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-soft);
}

.range-group legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
}

.range-line {
  display: grid;
  grid-template-columns: 40px 1fr 26px;
  gap: 7px;
  align-items: center;
  margin: 4px 0;
  color: var(--muted);
  font-size: .7rem;
}

.range-line output {
  text-align: right;
  color: var(--ink);
  font: .7rem ui-monospace, SFMono-Regular, Consolas, monospace;
}

.repeat-key {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 11px;
  color: var(--muted);
  font-size: .66rem;
}

.repeat-key span { display: inline-flex; align-items: center; gap: 4px; }
.repeat-key i { width: 10px; height: 10px; border-radius: 3px; }
.repeat-1 { background: #1b5e20; }
.repeat-2 { background: var(--i91); }
.repeat-3 { background: var(--u54); }
.repeat-4 { background: var(--odd); }

.range-status,
.range-error {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  font: .66rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.range-error { border-color: #a74747; color: var(--danger); }

.search-results {
  max-height: 182px;
  overflow-y: auto;
  margin-top: 6px;
  border-radius: 8px;
}

.search-hit {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 6px 7px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  background: var(--panel-soft);
  text-align: left;
  font-size: .68rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.field-stack { display: grid; gap: 8px; }
.field-stack label { color: var(--muted); font-size: .69rem; font-weight: 700; }
.field-stack label span { display: block; margin-bottom: 4px; }

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}

.metric {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.metric b { display: block; font-size: .86rem; font-variant-numeric: tabular-nums; }
.metric span { color: var(--muted); font-size: .62rem; }

.evidence-warning {
  margin: 9px 0;
  padding: 9px;
  border: 1px solid #755a2b;
  border-radius: 8px;
  background: #2b2416;
  color: #f7dda4;
  font-size: .72rem;
  line-height: 1.45;
}

details { margin-top: 8px; color: var(--muted); font-size: .7rem; }
summary { cursor: pointer; color: var(--ink); font-weight: 700; }
.build-info { margin-top: 7px; font: .64rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #000;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.stage.dragging { cursor: grabbing; }

#atlasCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.surface-status,
.lod-status {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  border: 1px solid #ffffff1f;
  border-radius: 8px;
  background: #0b1119dc;
  color: #dbe5ef;
  font: .68rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
  backdrop-filter: blur(6px);
}

.surface-status { right: 12px; bottom: 11px; max-width: min(700px, 72%); padding: 7px 9px; }
.lod-status { top: 10px; right: 11px; padding: 5px 7px; color: var(--muted); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

@media (max-width: 900px) {
  :root { --sidebar-width: min(88vw, 382px); }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .brand-block { display: none; }
  .sidebar-toggle { display: block; }
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    transform: translateX(-102%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .tab { min-width: 124px; padding: 0 13px; }
}

@media (max-width: 480px) {
  :root { --header-height: 58px; }
  .sidebar { padding: 14px; }
  .layer-grid, .section-grid { grid-template-columns: 1fr; }
  .selected-card { min-height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
