:root {
  --bg: #fffdf5;
  --ink: #000000;
  --panel: #ffffff;
  --accent: #ff6b6b;
  --secondary: #ffd93d;
  --muted: #c4b5fd;
  --stroke: 4px;
  --shadow-sm: 4px 4px 0 0 #000;
  --shadow-md: 8px 8px 0 0 #000;
  --shadow-lg: 12px 12px 0 0 #000;
  --image-aspect-ratio: 3 / 4;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Space Grotesk", "PingFang SC", system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(#000 1.5px, transparent 1.5px),
    linear-gradient(90deg, rgba(0,0,0,0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(0,0,0,0.05) 1px, transparent 1px);
  background-size: 22px 22px, 44px 44px, 44px 44px;
  color: var(--ink);
}
a { color: inherit; text-decoration: none; font-weight: 700; }

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 32px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  background: var(--secondary);
  border: var(--stroke) solid var(--ink);
  box-shadow: var(--shadow-md);
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: var(--stroke) solid var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.title {
  margin: 0;
  font-weight: 900;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: -0.02em;
}
.subtitle { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }

.nav-links { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.nav-links a {
  padding: 12px 16px;
  border: var(--stroke) solid var(--ink);
  background: var(--panel);
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.nav-links a:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); }
.nav-links a.active {
  background: var(--accent);
  color: #fff;
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
}

.main {
  padding: 28px;
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: var(--stroke) solid var(--ink);
  padding: 22px;
  box-shadow: var(--shadow-lg);
}

.outputs-header,
.panel-header,
.queue-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h2 {
  margin: 6px 0 0 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.muted { color: var(--ink); opacity: 0.7; font-size: 14px; }
.error { color: var(--accent); font-weight: 900; }

.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-top: 18px; }
.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: var(--stroke) solid var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow-md);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.stat-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-weight: 900;
  border: var(--stroke) solid var(--ink);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.stat-icon.blue { background: var(--accent); }
.stat-icon.cyan { background: var(--secondary); color: var(--ink); }
.stat-icon.purple { background: var(--muted); color: var(--ink); }
.stat-icon.teal { background: #000; }
.stat-title { margin: 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.stat-value { margin: 4px 0 0 0; font-size: 26px; font-weight: 900; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: var(--stroke) solid var(--ink);
  background: var(--secondary);
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: 0.1em;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.success { background: #000; color: #fff; }
.btn.ghost { background: var(--panel); }
.btn.link { background: transparent; border-color: transparent; box-shadow: none; color: var(--accent); padding: 10px 12px; }
.btn:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn.sm { padding: 9px 12px; font-size: 13px; }

.pill-group { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  padding: 9px 14px;
  border: var(--stroke) solid var(--ink);
  border-radius: 999px;
  background: var(--panel);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}
.pill:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); }
.pill.active { background: var(--accent); color: #fff; }

.series-list { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-top: 14px; }
.series-card {
  border: var(--stroke) solid var(--ink);
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.series-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.series-title { margin: 0; font-weight: 900; letter-spacing: -0.01em; text-transform: uppercase; }
.book-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.tag {
  padding: 10px 14px;
  border: var(--stroke) solid var(--ink);
  background: var(--secondary);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}
.tag.active { background: var(--accent); color: #fff; }
.tag i { margin-right: 6px; }

.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.sub-panel {
  border: var(--stroke) solid var(--ink);
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
}
.label { margin: 6px 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.input {
  width: 100%;
  border: var(--stroke) solid var(--ink);
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 700;
  background: var(--panel);
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.input:focus { outline: none; background: var(--secondary); box-shadow: var(--shadow-sm); }
.input.tall { min-height: 150px; resize: vertical; }
.actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.hint { color: var(--ink); opacity: 0.7; font-size: 13px; margin: 4px 0; }
.hint.error { color: var(--accent); opacity: 1; }

.book-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; margin-top: 12px; }
.nav-pane {
  border: var(--stroke) solid var(--ink);
  padding: 12px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
}
.nav-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: var(--stroke) solid var(--ink);
  background: var(--bg);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.nav-row:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-sm); }
.nav-row.active { background: var(--secondary); box-shadow: var(--shadow-md); }
.nav-title { margin: 0; font-weight: 900; }
.nav-sub { margin: 2px 0 0 0; font-size: 12px; opacity: 0.7; }
.nav-sub.ok { color: #0a8f55; opacity: 1; }
.nav-arrow { font-weight: 900; }

.content-pane {
  border: var(--stroke) solid var(--ink);
  padding: 16px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}
.controls .button-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.preview {
  border: var(--stroke) solid var(--ink);
  min-height: 320px;
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(135deg, var(--secondary) 0, var(--secondary) 14px, var(--bg) 14px, var(--bg) 28px);
  box-shadow: var(--shadow-md);
}
.preview img { max-width: 100%; max-height: 520px; border: var(--stroke) solid var(--ink); box-shadow: var(--shadow-lg); }

.preview-frame {
  position: relative;
  width: 100%;
  max-width: 900px;
  aspect-ratio: var(--image-aspect-ratio, 3 / 4);
  background: var(--panel);
  border: var(--stroke) solid var(--ink);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border: var(--stroke) solid var(--ink);
  box-shadow: var(--shadow-md);
}

.cover-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-top: 10px; }
.cover-card {
  border: var(--stroke) solid var(--ink);
  padding: 12px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-md);
}
.cover-thumb {
  width: 100%;
  aspect-ratio: var(--image-aspect-ratio, 3 / 4);
  object-fit: cover;
  background: var(--secondary);
  border: var(--stroke) solid var(--ink);
}
.cover-meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; opacity: 0.8; }
.cover-title { margin: 0; font-weight: 900; font-size: 15px; }
.cover-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.small-btn {
  padding: 8px 12px;
  border: var(--stroke) solid var(--ink);
  font-weight: 900;
  text-transform: uppercase;
  background: var(--muted);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.checked-mark { margin-left: 6px; }

.queue-panel {
  border: var(--stroke) solid var(--ink);
  padding: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}
.queue-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: var(--stroke) solid var(--ink);
  background: var(--bg);
}
.task-row.queued { background: var(--secondary); }
.task-row.running { background: var(--muted); }
.task-row.failed { background: var(--accent); color: #fff; }
.task-row.success { background: #000; color: #fff; }
.task-row.canceled { background: #fff; opacity: 0.7; }
.task-title { margin: 0; font-weight: 900; }
.task-sub { margin: 4px 0 0 0; font-size: 13px; opacity: 0.75; }
.chip {
  padding: 6px 10px;
  border: var(--stroke) solid var(--ink);
  font-weight: 900;
  font-size: 12px;
  text-transform: uppercase;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.chip.sm { font-size: 11px; padding: 5px 8px; }
.chip.neutral { background: var(--muted); }
.chip.queued { background: var(--secondary); }
.chip.running { background: var(--muted); }
.chip.failed { background: var(--accent); color: #fff; }
.chip.success { background: #000; color: #fff; }
.chip.canceled { background: #fff; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal-card {
  width: min(1100px, 96vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border: var(--stroke) solid var(--ink);
  box-shadow: var(--shadow-lg);
  padding: 16px 18px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.docstring { line-height: 1.6; }
.docstring h1, .docstring h2, .docstring h3, .docstring h4 { margin: 12px 0 8px; font-weight: 900; }
.docstring p { margin: 8px 0; }
.docstring ul, .docstring ol { padding-left: 20px; margin: 8px 0; }
.docstring blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: var(--stroke) solid var(--ink);
  background: var(--secondary);
}

.edit-layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; margin-top: 10px; align-items: flex-start; }
.edit-preview {
  position: relative;
  border: var(--stroke) solid var(--ink);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  display: inline-block;
  align-self: flex-start;
}
.edit-preview img { display: block; width: 100%; height: auto; }
.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  background: var(--accent);
  color: #fff;
  padding: 10px 12px;
  border: var(--stroke) solid var(--ink);
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.edit-form { display: flex; flex-direction: column; gap: 10px; }
.edit-form .pill { cursor: pointer; }

.attachment-pill {
  background: var(--panel);
  border: var(--stroke) solid var(--ink);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.attachment-pill.active { background: var(--secondary); }
.attachment-pill .chip.attach-on { background: var(--accent); color: #fff; }
.attachment-pill .chip.neutral { background: var(--muted); }

.viewer-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; margin-top: 12px; }
.viewer-only .nav-pane { max-height: 75vh; overflow: auto; }
.nav-thumb {
  width: 48px;
  height: 48px;
  margin-right: 10px;
  border: var(--stroke) solid var(--ink);
  background: var(--panel);
  flex-shrink: 0;
}
.nav-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-list { border: var(--stroke) solid var(--ink); padding: 10px; background: var(--panel); box-shadow: var(--shadow-sm); }
.viewer-pane { border: var(--stroke) solid var(--ink); padding: 12px; background: var(--panel); box-shadow: var(--shadow-md); }
.nav-list.horizontal { flex-direction: row; flex-wrap: wrap; gap: 10px; }
.nav-list.horizontal .nav-row { width: 180px; }
.nav-list.horizontal .nav-row .nav-arrow { display: none; }

@media (max-width: 960px) {
  .book-layout,
  .viewer-layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .main { padding: 22px; }
  .preview-frame { aspect-ratio: var(--image-aspect-ratio, 3 / 4); }
}

@media (max-width: 640px) {
  .main { padding: 16px; }
  .nav-links { flex-wrap: wrap; }
  .nav-list.horizontal .nav-row { width: 100%; }
  .viewer-pane { padding: 10px; }
  .pill-group { justify-content: flex-start; }
}

.script-review { align-items: flex-start; }
.scrollable { max-height: 720px; overflow-y: auto; }
.script-list { display: flex; flex-direction: column; gap: 12px; }
.script-group {
  border: var(--stroke) solid var(--ink);
  padding: 12px 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.script-group .series-title { margin: 0 0 8px; font-weight: 900; }
.script-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.script-tags .tag { cursor: pointer; }
.script-tags .tag.active { background: var(--accent); color: #fff; }
.script-detail { display: flex; flex-direction: column; gap: 12px; min-height: 520px; }
.script-meta textarea { min-height: 120px; }
.scene-card {
  border: var(--stroke) solid var(--ink);
  padding: 12px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.lint-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  border: var(--stroke) solid var(--ink);
  font-weight: 900;
  font-size: 12px;
  background: var(--secondary);
}
.lint-flag.warning { background: var(--muted); }
.lint-flag.error { background: var(--accent); color: #fff; }
.scene-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.scene-title { margin: 0; font-weight: 900; }
.scene-preview { margin: 4px 0 0 0; font-size: 13px; max-width: 540px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gap { gap: 12px; }
.scene-scroll { flex: 1; overflow-y: auto; padding-right: 4px; display: flex; flex-direction: column; gap: 12px; }
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  padding: 10px 0 6px;
  border-top: var(--stroke) solid var(--ink);
}
.docstring-card {
  border: var(--stroke) solid var(--ink);
  padding: 10px 12px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.docstring { margin: 6px 0 0 0; font-size: 13px; line-height: 1.55; }
.docstring ul { margin: 6px 0 6px 18px; padding: 0 0 0 8px; }
.docstring li { margin: 4px 0; }
.docstring blockquote {
  margin: 6px 0;
  padding: 8px 10px;
  border-left: var(--stroke) solid var(--ink);
  background: var(--secondary);
}
.detail-tabs { display: flex; gap: 8px; margin-bottom: 8px; }

.tab-bar { display: flex; gap: 10px; margin-bottom: 14px; }
.tab {
  padding: 10px 16px;
  border: var(--stroke) solid var(--ink);
  background: var(--panel);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}
.tab.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-md); }
.tab.sm { padding: 8px 12px; font-size: 13px; }

.style-scroll { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.style-column {
  min-width: 320px;
  max-width: 360px;
  flex: 0 0 auto;
  border: var(--stroke) solid var(--ink);
  padding: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
}
.cover-scroll { display: flex; flex-direction: column; gap: 12px; max-height: 520px; overflow-y: auto; padding-right: 4px; }
.style-column .cover-card { width: 100%; }

.empty-state {
  border: var(--stroke) solid var(--ink);
  padding: 16px;
  background: var(--panel);
  display: grid;
  gap: 6px;
  place-items: center;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.empty-state .emoji { font-size: 24px; }
