:root {
  --bg: #e8e8ea;
  --panel: #f4f4f6;
  --panel-edge: #d0d0d4;
  --ink: #1a1a1c;
  --ink-dim: #6a6a70;
  --accent: #ff6a1f;
  --good: #2c8c4c;
  --bad: #c83030;
  --warn: #b8860b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  height: 100%;
}

.app {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 44px 1fr 180px;
  grid-template-areas:
    "header header"
    "stage  panel"
    "log    panel";
  height: 100vh;
  gap: 1px;
  background: var(--panel-edge);
}

header.bar {
  grid-area: header;
  background: #1a1a1c;
  color: #f0f0f2;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  border-bottom: 2px solid var(--accent);
}

header.bar .title {
  font-weight: 600;
  letter-spacing: 0.5px;
}

.mode-pill {
  color: #1a1a1c;
  background: #f4c430;
  border: 1px solid #f4c430;
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

header.bar .scene-select {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

header.bar select {
  background: #2a2a2c;
  color: #f0f0f2;
  border: 1px solid #3a3a3e;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 12px;
}

.phase2-controls {
  display: grid;
  gap: 8px;
}

.phase2-controls label,
.sample-panel label {
  display: grid;
  gap: 4px;
  color: var(--ink-dim);
  font-size: 11px;
}

.phase2-controls select,
.sample-panel select {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--panel-edge);
  padding: 5px 7px;
  font-family: var(--mono);
  font-size: 11px;
  max-width: 100%;
}

.phase2-note {
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.4;
}

.sample-panel {
  display: grid;
  gap: 8px;
  background: #fff8d9;
}

.sample-panel[hidden] {
  display: none;
}

.sample-note {
  color: #5a4700;
  font-size: 11px;
  line-height: 1.4;
}

.challenge-note {
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink);
}
.challenge-note b { color: var(--ink); }
.challenge-note i { color: var(--accent); font-style: normal; }
.challenge-section { border-left: 2px solid var(--accent); padding-left: 8px; }

.bundle-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
  font-size: 10px;
}
.bundle-links a {
  color: var(--accent);
  text-decoration: none;
}
.bundle-links a:hover { text-decoration: underline; }

.sample-note code {
  font-family: var(--mono);
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 4px;
}

.stage {
  grid-area: stage;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.stage .overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--panel-edge);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--ink-dim);
  pointer-events: none;
}

.panel {
  grid-area: panel;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel section {
  border-bottom: 1px solid var(--panel-edge);
  padding: 12px 14px;
}

.panel h3 {
  margin: 0 0 8px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-dim);
  font-weight: 600;
}

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

button {
  background: #1a1a1c;
  color: #f0f0f2;
  border: 1px solid #1a1a1c;
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}

button:hover { background: #2a2a2c; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: #e85a10; }

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

.upload input[type=file] {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--ink-dim);
}
.upload input[type=file]::file-selector-button,
.upload input[type=file]::-webkit-file-upload-button {
  background: #1a1a1c;
  color: #f0f0f2;
  border: 1px solid #1a1a1c;
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  margin-right: 8px;
}
.upload input[type=file]::file-selector-button:hover,
.upload input[type=file]::-webkit-file-upload-button:hover {
  background: #2a2a2c;
}

.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.speed input { flex: 1; }
.speed .val { width: 40px; text-align: right; color: var(--ink-dim); font-size: 11px; }

.speed input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 16px;
  cursor: pointer;
  padding: 0;
}
.speed input[type=range]:focus { outline: none; }

.speed input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(to right,
    #1a1a1c 0%,
    #1a1a1c var(--fill, 0%),
    #ffffff var(--fill, 0%),
    #ffffff 100%);
  border: 1px solid #1a1a1c;
  border-radius: 2px;
}
.speed input[type=range]::-moz-range-track {
  height: 4px;
  background: #ffffff;
  border: 1px solid #1a1a1c;
  border-radius: 2px;
}
.speed input[type=range]::-moz-range-progress {
  height: 4px;
  background: #1a1a1c;
  border: 1px solid #1a1a1c;
  border-radius: 2px;
}

.speed input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid #1a1a1c;
  cursor: pointer;
}
.speed input[type=range]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid #1a1a1c;
  cursor: pointer;
}

.result {
  font-size: 12px;
  line-height: 1.6;
}

.result .row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted var(--panel-edge);
  padding: 2px 0;
}

.result .row .k { color: var(--ink-dim); }
.result .row .v { font-weight: 600; }
.result .status-pass { color: var(--good); }
.result .status-fail { color: var(--bad); }
.result .status-pending { color: var(--ink-dim); }

.bottom-panel {
  grid-area: log;
  background: #0e0e10;
  color: #d0d0d4;
  font-size: 11px;
  border-top: 1px solid #2a2a2c;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.bottom-tabs {
  display: flex;
  gap: 1px;
  background: #2a2a2c;
  border-bottom: 1px solid #2a2a2c;
}

.bottom-tabs .tab-btn {
  background: #151518;
  border: 0;
  border-right: 1px solid #2a2a2c;
  color: #8e8e96;
  padding: 6px 12px;
  font-size: 11px;
}

.bottom-tabs .tab-btn.active {
  background: #0e0e10;
  color: #f0f0f2;
  box-shadow: inset 0 2px 0 var(--accent);
}

.tab-body {
  display: none;
  overflow: auto;
  padding: 8px 12px;
  min-height: 0;
}

.tab-body.active { display: block; }

.log {
  flex: 1;
}

.log .line { white-space: pre-wrap; }
.log .line.err { color: #ff8a6a; }
.log .line.ok { color: #6ade94; }
.log .line.warn { color: #f4c430; }
.log .line .ts { color: #5a5a60; margin-right: 8px; }

.routine-view {
  flex: 1;
  font-family: var(--mono);
  color: #d0d0d4;
}

.routine-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: #8e8e96;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #2a2a2c;
}

.routine-empty { color: #8e8e96; }

.routine-step {
  display: grid;
  grid-template-columns: 42px 110px 1fr;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: pre-wrap;
}

.routine-step .idx { color: #5a5a60; text-align: right; }
.routine-step .type { color: #f0f0f2; }
.routine-step.active {
  color: #fff3df;
  background: rgba(255, 106, 31, 0.20);
  border-left: 2px solid var(--accent);
  padding-left: 6px;
}
.routine-step.active .idx,
.routine-step.active .type {
  color: #fff3df;
}
.routine-step.violation {
  color: #ffb09c;
  background: rgba(255, 106, 31, 0.12);
}

.kbd {
  display: inline-block;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  background: #2a2a2c;
  color: #d0d0d4;
}

.notes-view {
  flex: 1;
  font-family: var(--mono);
  color: #d0d0d4;
  line-height: 1.55;
  padding: 14px 18px;
}
.notes-view .notes-header {
  color: #8e8e96;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #2a2a2c;
}
.notes-view .notes-empty { color: #8e8e96; }
.notes-view h1, .notes-view h2, .notes-view h3 { color: #f0f0f2; margin: 16px 0 6px; font-weight: 600; }
.notes-view h1 { font-size: 16px; }
.notes-view h2 { font-size: 14px; color: var(--accent); }
.notes-view h3 { font-size: 12px; }
.notes-view p { margin: 6px 0; }
.notes-view code { background: #1a1a1c; padding: 1px 5px; border-radius: 3px; font-size: 11px; }
.notes-view pre { background: #151518; padding: 10px 12px; border-radius: 4px; overflow-x: auto; border: 1px solid #2a2a2c; }
.notes-view pre code { background: transparent; padding: 0; font-size: 11px; line-height: 1.5; }
.notes-view ul, .notes-view ol { margin: 6px 0 6px 22px; }
.notes-view li { margin: 2px 0; }
.notes-view blockquote { border-left: 3px solid var(--accent); padding: 4px 12px; margin: 10px 0; color: #a0a0a8; }
.notes-view hr { border: 0; border-top: 1px solid #2a2a2c; margin: 14px 0; }
.notes-view table { border-collapse: collapse; margin: 8px 0; font-size: 11px; }
.notes-view th, .notes-view td { padding: 4px 10px; border: 1px solid #2a2a2c; text-align: left; }
.notes-view th { background: #1a1a1c; color: #f0f0f2; }
.notes-view a { color: var(--accent); text-decoration: underline; }
.notes-view strong { color: #f0f0f2; }

.mode-pill {
  background: var(--accent);
  color: #1a1a1c;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mode-pill .mode-pill-exit {
  font-weight: 500;
  opacity: 0.7;
  border-left: 1px solid rgba(26, 26, 28, 0.3);
  padding-left: 6px;
}
.mode-pill:hover { background: #e85a10; }
.mode-pill:hover .mode-pill-exit { opacity: 1; }

/* scene navigator (header) */
.scene-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #2a2a2c;
  border: 1px solid #3a3a3e;
  border-radius: 4px;
  padding: 2px 2px;
}
.scene-nav-btn {
  background: transparent;
  border: 0;
  color: #d0d0d4;
  padding: 4px 10px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 3px;
}
.scene-nav-btn:hover { background: rgba(255, 106, 31, 0.2); color: var(--accent); }
.scene-nav-btn:focus { outline: 1px solid var(--accent); }
.scene-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 120px;
  padding: 0 4px;
}
.scene-label .scene-idx {
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
}
.scene-label .scene-name {
  color: #f0f0f2;
  font-size: 12px;
  letter-spacing: 0.3px;
}

/* overlay with metrics */
.overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--panel-edge);
  padding: 6px 8px;
  font-size: 11px;
  color: var(--ink-dim);
  pointer-events: none;
  max-width: 320px;
}
.overlay .overlay-scene {
  margin: 0 0 4px 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
  white-space: pre;
}
.overlay-metrics {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-top: 4px;
  border-top: 1px dotted var(--panel-edge);
}
.spark-row {
  display: grid;
  grid-template-columns: 28px 56px 122px 78px;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--ink-dim);
}
.spark-row .spark-label { color: var(--ink); font-weight: 600; }
.spark-row .spark-value { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.spark-row .spark-canvas { background: rgba(10, 10, 12, 0.08); border-radius: 2px; }
.spark-row .spark-range { color: #9a9a9e; font-size: 9px; font-variant-numeric: tabular-nums; }

/* run-next overlay button */
.canvas-overlay-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--accent);
  color: #1a1a1c;
  border: 1px solid var(--accent);
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  z-index: 10;
}
.canvas-overlay-btn:hover { background: #e85a10; }
.canvas-overlay-btn:focus { outline: 2px solid #1a1a1c; outline-offset: 1px; }

.header-subtitle {
  color: #888;
  font-size: 11px;
}
.header-link {
  color: var(--accent);
  font-size: 11px;
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid rgba(255, 106, 31, 0.3);
  border-radius: 3px;
  transition: background 0.12s ease;
}
.header-link:hover {
  background: rgba(255, 106, 31, 0.18);
  border-color: var(--accent);
}
.header-link:focus { outline: 1px solid var(--accent); }

.sample-note a {
  color: var(--accent);
  text-decoration: underline;
}
.sample-note a:hover { color: #e85a10; }
