:root {
  color-scheme: dark;
  --bg-0: #05070a;
  --bg-1: #0b0f14;
  --bg-2: #121820;
  --bg-3: #1a222c;
  --line: #2a3440;
  --line-strong: #3b4754;
  --text: #edf3f8;
  --text-muted: #9aa8b6;
  --text-dim: #748291;
  --accent: #56b4ff;
  --accent-hover: #80c7ff;
  --accent-soft: rgb(86 180 255 / 16%);
  --ok: #3dd68c;
  --ok-soft: rgb(61 214 140 / 16%);
  --warn: #ffd400;
  --warn-soft: rgb(255 212 0 / 14%);
  --error: #ff5d5d;
  --stage-1: #56b4ff;
  --stage-2: #3dd68c;
  --stage-3: #ff9f0a;
  --stage-4: #bf5af2;
  --region-a: #56b4ff;
  --region-b: #3dd68c;
  --region-c: #ff9f0a;
  --region-d: #ff5d8f;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  --shadow: 0 18px 50px rgb(0 0 0 / 45%);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg-0);
}

body {
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
}

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--accent);
  color: #061018;
  border-radius: 8px;
}

.skip-link:focus { top: 12px; }

.claw-shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  background:
    radial-gradient(ellipse 70% 40% at 10% -10%, rgb(86 180 255 / 10%), transparent 60%),
    radial-gradient(ellipse 50% 36% at 90% 0%, rgb(61 214 140 / 8%), transparent 55%),
    var(--bg-0);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 52px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand strong { font-size: 15px; letter-spacing: -0.02em; }
.brand em {
  font-style: normal;
  color: var(--accent);
  font-weight: 650;
}

.brand-sub {
  color: var(--text-muted);
  font-size: 12px;
}

.topbar-spacer { flex: 1; }

.seed-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.seed-field input {
  width: 88px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text);
  padding: 0 8px;
  font-family: var(--font-mono);
}

.tool-button,
.accent-button {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.accent-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #061018;
}

.tool-button:disabled,
.accent-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.prompt-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 16px 4px;
}

.prompt-box {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

.prompt-tools {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
}

.examples button {
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text-muted);
  cursor: pointer;
}

.examples button:hover,
.examples button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px 12px;
}

.stage-card {
  min-height: 112px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-1);
  box-shadow: var(--shadow);
}

.stage-card[data-status="done"],
.stage-card[data-status="ready"] { border-color: rgb(61 214 140 / 40%); }
.stage-card[data-status="review"] { border-color: rgb(255 212 0 / 40%); }
.stage-card[data-status="idle"] { opacity: 0.72; }

.stage-kicker {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stage-card[data-stage="intent"] .stage-kicker { color: var(--stage-1); }
.stage-card[data-stage="global"] .stage-kicker { color: var(--stage-2); }
.stage-card[data-stage="regional"] .stage-kicker { color: var(--stage-3); }
.stage-card[data-stage="place"] .stage-kicker { color: var(--stage-4); }

.stage-card h2 {
  margin: 6px 0 8px;
  font-size: 14px;
}

.stage-card ul {
  margin: 0;
  padding-left: 16px;
  color: var(--text-muted);
}

.stage {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(240px, 320px);
  gap: 12px;
  min-height: 0;
  padding: 0 16px 16px;
}

.stage-center {
  display: grid;
  grid-template-rows: minmax(240px, 1fr) auto auto auto;
  gap: 10px;
  min-height: 0;
}

.viewport-frame {
  position: relative;
  height: 100%;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #070b10;
  overflow: hidden;
  box-shadow: var(--shadow);
}

#worldclaw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 280px;
  touch-action: none;
  cursor: grab;
}

#worldclaw-canvas:active { cursor: grabbing; }

.viewport-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
}

.viewport-hint[hidden] { display: none; }

.view-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.view-rail button {
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 600;
}

.view-rail button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}

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

.look-card {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  color: inherit;
  padding: 8px 10px;
  cursor: pointer;
}

.look-card[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.look-card .hash {
  margin-top: 4px;
}

.lookbook .empty-state {
  grid-column: 1 / -1;
  min-height: 48px;
  padding: 8px;
}

.panel {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-1);
  padding: 12px;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
}

.fact-list {
  display: grid;
  gap: 8px;
}

.fact-list div {
  display: grid;
  gap: 2px;
}

.fact-list dt,
.kicker {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#status.kicker {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  max-width: 16rem;
}

.maps {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  grid-template-rows: auto auto;
  gap: 10px;
}

.map-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  padding: 8px;
  min-height: 180px;
}

.map-card h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.map-card svg,
.map-card canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: #0a1016;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
}

.region-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.region-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  color: inherit;
  padding: 8px 10px;
  cursor: pointer;
}

.region-card[aria-current="true"] { border-color: var(--accent); }
.region-card[data-region="a"] { box-shadow: inset 3px 0 0 var(--region-a); }
.region-card[data-region="b"] { box-shadow: inset 3px 0 0 var(--region-b); }
.region-card[data-region="c"] { box-shadow: inset 3px 0 0 var(--region-c); }
.region-card[data-region="d"] { box-shadow: inset 3px 0 0 var(--region-d); }

.issue {
  margin: 0 0 6px;
  color: var(--text-muted);
}

.issue[data-level="error"] { color: var(--error); }
.issue[data-level="warning"],
.issue[data-level="warn"] { color: var(--warn); }

.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.status-error { color: var(--error); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.hash {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  word-break: break-all;
}

.busy .stage-card[data-status="idle"] {
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .busy .stage-card { animation: none; }
}

@media (max-width: 1100px) {
  .pipeline,
  .stage,
  .maps,
  .lookbook {
    grid-template-columns: 1fr 1fr;
  }
  .stage {
    grid-template-rows: auto auto auto;
  }
  .stage-center {
    grid-template-rows: minmax(220px, 360px) auto auto auto;
  }
}

@media (max-width: 760px) {
  .prompt-bar,
  .pipeline,
  .stage,
  .maps,
  .lookbook {
    grid-template-columns: 1fr;
  }
  .topbar { flex-wrap: wrap; }
}
