:root {
  color-scheme: dark;
  --bg: #050710;
  --bg2: #07111a;
  --panel: rgba(9, 15, 31, 0.94);
  --panel2: rgba(12, 20, 42, 0.96);
  --line: rgba(120, 166, 230, 0.24);
  --line2: rgba(255, 255, 255, 0.10);
  --text: #edf4ff;
  --muted: #9ca9c6;
  --muted2: #74809d;
  --accent: #65d9f5;
  --accent2: #77f0c4;
  --good: #47f5a5;
  --warn: #ffd166;
  --bad: #ff6b8b;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.38);
  --radius: 7px;
  --gap: 8px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(101,217,245,0.10) 1px, transparent 1px),
    linear-gradient(0deg, rgba(101,217,245,0.06) 1px, transparent 1px),
    radial-gradient(circle at 10% 8%, rgba(101, 217, 245, 0.13), transparent 30%),
    radial-gradient(circle at 88% 0%, rgba(119, 240, 196, 0.10), transparent 28%),
    linear-gradient(140deg, var(--bg), var(--bg2) 55%, #060814);
  background-size: 42px 42px, 42px 42px, auto, auto, auto;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
small { color: var(--muted); }
code { color: #e4f8ff; }

.app-shell {
  height: 100vh;
  height: 100svh;
  width: 100vw;
  padding: var(--gap);
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  gap: var(--gap);
  overflow: hidden;
}

.topbar {
  min-height: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(4, 8, 18, 0.94);
  box-shadow: var(--shadow);
  overflow: visible;
}
.brand-block { min-width: 0; display: flex; align-items: center; gap: 10px; }
.brand-orb {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-weight: 950;
  color: #021017;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
h1 { font-size: clamp(1.06rem, 1.35vw, 1.55rem); letter-spacing: -0.04em; line-height: 1.05; white-space: nowrap; }
.topbar p { color: var(--muted); margin-top: 3px; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  transition: border-color .14s ease, background .14s ease, filter .14s ease;
}
.btn:hover { border-color: rgba(101,217,245,.58); background: rgba(255,255,255,.08); }
.btn.primary { color: #031219; border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent2)); font-weight: 850; }
.btn.secondary { border-color: rgba(101,217,245,.35); background: rgba(101,217,245,.09); }
.btn.ghost { background: rgba(255,255,255,.025); }
.btn.full { width: 100%; justify-content: center; margin-top: 8px; }
.menu-wrap { position: relative; }
.export-menu {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  min-width: 224px;
  padding: 5px;
  background: rgba(5, 9, 20, .98);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.export-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 0;
  border-radius: 4px;
  color: var(--text);
  background: transparent;
}
.export-menu button:hover { background: rgba(101,217,245,.12); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(292px, 22vw) minmax(520px, 1fr) minmax(284px, 20vw);
  gap: var(--gap);
  align-items: stretch;
  overflow: hidden;
}
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.control-panel, .info-panel {
  min-height: 0;
  height: 100%;
  padding: 10px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(101,217,245,.50) rgba(255,255,255,.04);
}
.panel-title { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-title.nested { margin-top: 12px; }
.panel-title.compact { margin: 0 0 6px; }
.panel-title span {
  min-width: 32px;
  height: 22px;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(101,217,245,.36);
  color: var(--accent);
  background: rgba(101,217,245,.08);
  font-size: .72rem;
  font-weight: 900;
}
.panel-title h2 { font-size: .92rem; letter-spacing: -0.02em; }
.drop-zone {
  display: grid;
  gap: 6px;
  border: 1px dashed rgba(101,217,245,.42);
  border-radius: 5px;
  padding: 10px;
  background: rgba(101,217,245,.055);
  color: var(--text);
}
.drop-zone input { display: none; }
.drop-zone small { line-height: 1.28; font-size: .76rem; }
.file-row { display: grid; gap: 6px; color: var(--muted); }
.file-row input { color: var(--muted); }
.mini-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 7px; }
.mini-grid label, .control-panel label { color: var(--muted); font-size: .78rem; }
input[type="text"], input[type="number"], select {
  width: 100%;
  margin-top: 4px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  background: rgba(2, 6, 16, .72);
  padding: 7px 9px;
  outline: none;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { border-color: rgba(101,217,245,.65); }
input[type="range"] { width: 100%; margin-top: 10px; accent-color: var(--accent); }

.stage-panel {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) 126px;
  gap: var(--gap);
  overflow: hidden;
}
.stage-toolbar {
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  overflow: hidden;
}
.stage-toolbar > div:first-child { min-width: 0; }
.stage-toolbar strong { display: block; margin-bottom: 2px; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-toolbar small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-pills { display: flex; flex-wrap: nowrap; gap: 5px; justify-content: flex-end; flex: 0 0 auto; }
.stat-pills span {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255,255,255,.045);
  color: var(--muted);
  font-size: .76rem;
  white-space: nowrap;
}
.canvas-wrap {
  min-height: 0;
  min-width: 0;
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #02050e;
  box-shadow: var(--shadow);
}
.canvas-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), inset 0 -72px 90px rgba(0,0,0,.34);
}
#previewCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  background: #030812;
}
.export-log-panel {
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}
#logOutput {
  margin: 0;
  height: 80px;
  overflow: auto;
  white-space: pre-wrap;
  color: #b9c7ed;
  font-size: .76rem;
  line-height: 1.32;
  background: rgba(0,0,0,.24);
  border: 1px solid var(--line2);
  border-radius: 5px;
  padding: 8px;
}
.check-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.check-list li { color: var(--muted); line-height: 1.28; border-bottom: 1px solid var(--line2); padding-bottom: 7px; font-size: .86rem; }
.check-list strong { color: var(--text); }
.warning-card, .summary-box {
  margin-top: 9px;
  border: 1px solid rgba(255, 209, 102, .28);
  border-radius: 5px;
  padding: 9px;
  background: rgba(255, 209, 102, .08);
  color: #ffe8a2;
}
.warning-card p { margin-top: 5px; font-size: .78rem; line-height: 1.32; color: #dec78b; }
.summary-box { border-color: var(--line); background: rgba(255,255,255,.04); color: var(--muted); font-size: .82rem; line-height: 1.38; overflow: auto; }
.summary-box strong { color: var(--text); }

.toast-stack {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 7px;
  width: min(360px, calc(100vw - 24px));
  z-index: 80;
  pointer-events: none;
}
.toast {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: rgba(7, 12, 26, .97);
  box-shadow: var(--shadow);
  border-radius: 5px;
  padding: 9px 10px;
  animation: toastIn .18s ease both;
  pointer-events: auto;
}
.toast.success { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--bad); }
.toast-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 5px; }
.toast strong { font-size: .86rem; }
.toast small { color: var(--muted2); }
.toast p { color: var(--muted); font-size: .78rem; line-height: 1.28; }
.toast .bar { height: 3px; border-radius: 99px; background: rgba(255,255,255,.08); margin-top: 7px; overflow: hidden; }
.toast .bar span { display: block; height: 100%; width: var(--p, 0%); background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateX(8px) translateY(5px); } to { opacity: 1; transform: translateX(0) translateY(0); } }

@media (max-width: 1360px) {
  .workspace { grid-template-columns: minmax(270px, 28vw) minmax(460px, 1fr); }
  .info-panel { display: none; }
}
@media (max-width: 860px) {
  html, body { overflow: auto; }
  body { min-height: 100%; }
  .app-shell { height: auto; min-height: 100vh; min-height: 100svh; overflow: visible; grid-template-rows: auto auto; }
  .topbar { min-height: auto; flex-direction: column; align-items: stretch; }
  .brand-block { align-items: flex-start; }
  .topbar p, h1 { white-space: normal; }
  .top-actions { justify-content: space-between; }
  .workspace { grid-template-columns: 1fr; overflow: visible; }
  .control-panel, .info-panel { height: auto; max-height: none; display: block; }
  .stage-panel { grid-template-rows: auto minmax(280px, 58vh) 126px; }
  .stage-toolbar { min-height: 0; flex-direction: column; align-items: stretch; }
  .stat-pills { justify-content: flex-start; flex-wrap: wrap; }
  .mini-grid { grid-template-columns: 1fr; }
}

/* Phase 9 timeline/project + QA editor */
.stage-panel {
  grid-template-rows: 56px minmax(0, 1fr) 112px 112px;
}
.timeline-panel {
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}
.timeline-strip {
  height: 72px;
  overflow: auto hidden;
  border: 1px solid var(--line2);
  border-radius: 5px;
  background:
    linear-gradient(90deg, rgba(101,217,245,.12) 1px, transparent 1px),
    rgba(0,0,0,.22);
  background-size: 80px 100%;
  scrollbar-width: thin;
  scrollbar-color: rgba(101,217,245,.50) rgba(255,255,255,.04);
}
.timeline-content {
  position: relative;
  min-width: 100%;
  height: 72px;
}
.tl-note {
  position: absolute;
  height: 7px;
  min-width: 2px;
  border-radius: 2px;
  opacity: .88;
  box-shadow: 0 0 8px rgba(101,217,245,.22);
}
.tl-lane-label {
  position: absolute;
  left: 4px;
  color: rgba(237,244,255,.65);
  font-size: 10px;
  font-weight: 800;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
.tl-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 0 8px rgba(255,255,255,.45);
}
@media (max-width: 860px) {
  .stage-panel { grid-template-rows: auto minmax(280px, 52vh) 112px 126px; }
}


/* Phase 9 QA / failure detector matrix */
.qa-mini {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line2);
  border-radius: 5px;
  background: rgba(0,0,0,.20);
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.32;
}
.qa-box {
  max-height: 260px;
  padding: 8px;
}
.qa-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 7px;
  margin-bottom: 7px;
  border-bottom: 1px solid var(--line2);
}
.qa-summary small { font-size: .72rem; }
.qa-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  align-items: start;
  padding: 7px 0;
  border-bottom: 1px solid var(--line2);
}
.qa-row b {
  min-width: 0;
  color: var(--text);
  font-size: .78rem;
  overflow-wrap: anywhere;
}
.qa-row span {
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .66rem;
  font-weight: 900;
}
.qa-row small {
  grid-column: 1 / -1;
  font-size: .74rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.qa-row.pass span { color: var(--good); }
.qa-row.warn span { color: var(--warn); }
.qa-row.fail span { color: var(--bad); }
