:root {
  --ink: #0b0a09;
  --ink-2: #161311;
  --ink-3: #221c17;
  --paper: #f3ebe0;
  --muted: #a89a88;
  --gold: #d4a574;
  --gold-bright: #e8c49a;
  --cinnabar: #c23b22;
  --line: rgba(212, 165, 116, 0.22);
  --ok: #7cb389;
  --warn: #d4a574;
  --fail: #c23b22;
  --radius: 14px;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "Figtree", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--paper);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(194, 59, 34, 0.18), transparent 55%),
    radial-gradient(900px 600px at 90% 10%, rgba(212, 165, 116, 0.12), transparent 50%),
    linear-gradient(165deg, #070605 0%, var(--ink) 40%, #12100e 100%);
  line-height: 1.5;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.07;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.glow {
  pointer-events: none;
  position: fixed;
  width: 40vw;
  height: 40vw;
  right: -10vw;
  bottom: -10vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212, 165, 116, 0.09), transparent 70%);
  animation: drift 14s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes drift {
  from { transform: translate(0, 0); }
  to { transform: translate(-4vw, -3vh); }
}

.hero,
.layout,
.planner-stage,
.foot {
  position: relative;
  z-index: 1;
}

.planner-stage {
  max-width: 1100px;
  margin: 0 auto 1.5rem;
  padding: 0 clamp(1.25rem, 4vw, 3rem);
}

.stage-head h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2rem;
}

.stage-head-produce {
  grid-column: 1 / -1;
}

.planner-stage iframe {
  display: block;
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f1117;
}

.hero {
  padding: clamp(2.5rem, 8vw, 5rem) clamp(1.25rem, 4vw, 3rem) 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 0.4rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--gold);
  font-weight: 600;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(3.8rem, 14vw, 7rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: var(--paper);
  animation: brandIn 0.9s ease both;
}

.brand::after {
  content: "";
  display: block;
  width: 4.5rem;
  height: 2px;
  margin-top: 0.85rem;
  background: linear-gradient(90deg, var(--cinnabar), var(--gold));
}

.tagline {
  margin: 1rem 0 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 1.05rem;
}

@keyframes brandIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.layout {
  display: grid;
  gap: 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 4vw, 3rem) 3rem;
}

.layout-chat {
  max-width: 1180px;
}

@media (min-width: 960px) {
  .layout-chat {
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr);
    align-items: start;
  }

  .layout-chat .draft-panel,
  .layout-chat .workspace {
    grid-column: 1 / -1;
  }
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.series-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.series-head h2 {
  margin: 0;
}

.series-head .btn.ghost {
  width: auto;
  margin: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.series-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 220px;
  overflow: auto;
}

.series-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(243, 235, 224, 0.1);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.16);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  font: inherit;
  color: inherit;
}

.series-item:hover {
  border-color: rgba(243, 235, 224, 0.22);
}

.series-item.active {
  border-color: rgba(212, 165, 116, 0.55);
  background: rgba(212, 165, 116, 0.08);
}

.series-item-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--paper);
  line-height: 1.35;
}

.series-item-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: rgba(168, 154, 136, 0.95);
  line-height: 1.4;
}

.series-item-status {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid rgba(243, 235, 224, 0.12);
  color: var(--muted);
}

.series-empty {
  font-size: 0.82rem;
  color: rgba(168, 154, 136, 0.85);
  font-style: italic;
  margin: 0.35rem 0 0;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.chat-head h2 {
  margin: 0;
}

.chat-log {
  height: min(52vh, 520px);
  overflow: auto;
  padding: 0.85rem;
  border-radius: 12px;
  background: #0a0908;
  border: 1px solid rgba(243, 235, 224, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bubble {
  max-width: 92%;
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 0.95rem;
  animation: bubbleIn 0.35s ease both;
}

.bubble.user {
  align-self: flex-end;
  background: rgba(194, 59, 34, 0.22);
  border: 1px solid rgba(194, 59, 34, 0.35);
}

.bubble.assistant {
  align-self: flex-start;
  background: rgba(212, 165, 116, 0.1);
  border: 1px solid rgba(212, 165, 116, 0.22);
}

.bubble .who {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-weight: 700;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  margin-top: 0.85rem;
  align-items: end;
}

.chat-form textarea {
  min-height: 3.2rem;
  margin: 0;
}

.chat-form .btn.primary {
  width: auto;
  margin: 0;
  min-width: 5.5rem;
}

.chat-upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.75rem;
  margin-top: 0.65rem;
}

.chat-upload-row .btn.ghost {
  width: auto;
  margin: 0;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
}

.upload-file-name {
  font-size: 0.75rem;
  color: var(--paper);
  opacity: 0.85;
}

.hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: rgba(168, 154, 136, 0.85);
}

.brief-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.brief-list li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(243, 235, 224, 0.06);
  font-size: 0.88rem;
}

.brief-list .k {
  color: var(--muted);
  font-weight: 600;
}

.brief-list .v {
  color: var(--paper);
}

.brief-list .v.empty {
  color: rgba(168, 154, 136, 0.55);
  font-style: italic;
}

.ready-badge {
  display: inline-flex;
  margin: -0.35rem 0 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  color: var(--muted);
}

.ready-badge.on {
  color: #1a120c;
  background: var(--gold);
  border-color: var(--gold);
}

.actions.stacked {
  flex-direction: column;
}

.actions.stacked .btn.primary,
.actions.stacked .btn.secondary {
  width: 100%;
}

.draft-panel {
  animation: workspaceIn 0.55s ease both;
}

@media (min-width: 920px) {
  .layout:not(.layout-chat) {
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.15fr);
    align-items: start;
  }
}

.panel {
  background: linear-gradient(180deg, rgba(34, 28, 23, 0.92), rgba(17, 14, 12, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem 1.5rem;
  backdrop-filter: blur(8px);
}

.panel h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 400;
}

.panel h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

input,
textarea,
select {
  font: inherit;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid rgba(243, 235, 224, 0.12);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(212, 165, 116, 0.55);
  box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.12);
}

textarea {
  resize: vertical;
  min-height: 6rem;
}

.grid-2 {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 520px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.platforms {
  border: 1px solid rgba(243, 235, 224, 0.1);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin: 0 0 0.9rem;
}

.platforms legend {
  padding: 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
  font-weight: 500;
  color: var(--paper);
  cursor: pointer;
}

.check input {
  width: auto;
  accent-color: var(--cinnabar);
}

.tone-picker {
  border: 1px solid rgba(243, 235, 224, 0.1);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin: 0 0 0.9rem;
  display: grid;
  gap: 0.45rem;
}

.tone-picker legend {
  padding: 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.tone-option {
  display: block;
  margin: 0;
  cursor: pointer;
  font-weight: 500;
}

.tone-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tone-card {
  display: block;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(243, 235, 224, 0.1);
  background: rgba(0, 0, 0, 0.18);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.tone-option input:checked + .tone-card {
  border-color: rgba(212, 165, 116, 0.55);
  background: rgba(212, 165, 116, 0.08);
  box-shadow: 0 0 0 2px rgba(212, 165, 116, 0.12);
}

.tone-option:hover .tone-card {
  border-color: rgba(243, 235, 224, 0.22);
}

.tone-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--paper);
  line-height: 1.35;
}

.tone-blurb {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: rgba(168, 154, 136, 0.95);
  line-height: 1.4;
}

.tone-picker > .hint {
  margin-top: 0.25rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, opacity 0.2s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.btn.primary {
  width: 100%;
  margin-top: 0.35rem;
  background: linear-gradient(135deg, var(--cinnabar), #9a2e1a);
  color: #fff7f2;
}

.btn.primary:not(:disabled):hover {
  background: linear-gradient(135deg, #d2472d, var(--cinnabar));
}

.btn.secondary {
  background: transparent;
  border-color: var(--gold);
  color: var(--gold-bright);
}

.btn.ghost {
  background: transparent;
  border-color: rgba(243, 235, 224, 0.15);
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
}

.btn.ghost.active {
  color: var(--paper);
  border-color: var(--gold);
  background: rgba(212, 165, 116, 0.1);
}

.error {
  color: #f0a090;
  font-size: 0.88rem;
  margin: 0.75rem 0 0;
}

.note {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  min-height: 1.2em;
}

/* Workspace */
.workspace {
  opacity: 0;
  transform: translateY(10px);
}

.workspace.visible {
  animation: workspaceIn 0.55s ease forwards;
}

.workspace.awaiting {
  border-color: rgba(212, 165, 116, 0.55);
  box-shadow: 0 0 0 1px rgba(212, 165, 116, 0.15), 0 18px 50px rgba(0, 0, 0, 0.35);
}

@keyframes workspaceIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.workspace-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.project-id {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.project-id code {
  color: var(--gold-bright);
  font-size: 0.8rem;
}

.status-chip {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--gold);
  background: rgba(212, 165, 116, 0.08);
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.status-chip.awaiting_approval {
  color: #1a120c;
  background: var(--gold);
  border-color: var(--gold);
  animation: pulseChip 1.6s ease infinite;
}

.status-chip.completed {
  color: #0f1a12;
  background: var(--ok);
  border-color: var(--ok);
}

.status-chip.failed {
  color: #fff;
  background: var(--fail);
  border-color: var(--fail);
}

@keyframes pulseChip {
  0%, 100% { box-shadow: 0 0 0 0 rgba(212, 165, 116, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(212, 165, 116, 0); }
}

.progress-wrap {
  margin-bottom: 1.25rem;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.45rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#progress-label {
  color: var(--gold-bright);
  font-weight: 700;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(243, 235, 224, 0.08);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cinnabar), var(--gold));
  transition: width 0.45s ease;
}

.screenplay-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.toolbar-actions {
  display: flex;
  gap: 0.4rem;
}

.readable-view {
  max-height: 52vh;
  overflow: auto;
  padding: 1rem;
  border-radius: 12px;
  background: #0a0908;
  border: 1px solid rgba(243, 235, 224, 0.08);
  font-size: 0.92rem;
}

.readable-view .ep {
  margin-bottom: 1.4rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid rgba(212, 165, 116, 0.15);
}

.readable-view .ep:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.readable-view h4 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--gold-bright);
}

.readable-view .hook,
.readable-view .cliff {
  color: var(--muted);
  font-style: italic;
  margin: 0.35rem 0 0.75rem;
}

.readable-view .scene {
  margin: 0.85rem 0;
}

.readable-view .scene-meta {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cinnabar);
  margin-bottom: 0.25rem;
}

.readable-view .dialogue {
  margin: 0.25rem 0 0.25rem 0.75rem;
}

.readable-view .char {
  color: var(--gold);
  font-weight: 600;
}

.bible-block {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(212, 165, 116, 0.2);
}

.bible-block p {
  margin: 0.35rem 0;
  color: var(--muted);
}

.json-editor {
  width: 100%;
  min-height: 52vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

.actions .btn.primary {
  width: auto;
  flex: 1;
  min-width: 12rem;
}

.storyboard-area {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.storyboard-grid {
  display: grid;
  gap: 1.25rem;
}

.sb-ep h4 {
  margin: 0 0 0.75rem;
}

.sb-panels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.sb-panel {
  border: 1px solid rgba(243, 235, 224, 0.12);
  border-radius: 12px;
  overflow: hidden;
  background: #12100e;
}

.sb-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #1a1714;
}

.sb-body {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
}

.sb-body .muted {
  color: var(--muted);
  font-size: 0.78rem;
}

.sb-body label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.sb-body textarea {
  width: 100%;
  min-height: 3.2rem;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid rgba(243, 235, 224, 0.12);
  background: #0a0908;
  color: var(--ink);
  padding: 0.45rem 0.55rem;
  font: inherit;
}

.sb-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.sb-actions a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.sb-upload-label {
  cursor: pointer;
  margin: 0;
}

.sb-actions .chk {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.character-lock-area {
  margin: 0 0 1.25rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 9, 8, 0.45);
}

.character-lock-area h4 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.character-lock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.85rem;
  margin-top: 0.85rem;
}

.char-card {
  border: 1px solid rgba(243, 235, 224, 0.1);
  border-radius: 10px;
  overflow: hidden;
  background: #12100e;
}

.char-card img,
.sheet-placeholder {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #1a1714;
}

.sheet-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.char-card-body {
  display: grid;
  gap: 0.35rem;
  padding: 0.65rem;
}

.char-card-body strong {
  font-size: 0.9rem;
}

.char-card-body .badge {
  font-size: 0.72rem;
  color: var(--gold);
}

.char-card-body .btn {
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
}

.output-area {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.output-area pre {
  margin: 0.6rem 0 0;
  padding: 0.85rem;
  overflow: auto;
  border-radius: 10px;
  background: #0a0908;
  border: 1px solid rgba(243, 235, 224, 0.08);
  font-size: 0.78rem;
  color: var(--muted);
}

.foot {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  padding: 0 1rem 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.foot a {
  color: var(--gold);
  text-decoration: none;
}

.foot a:hover {
  color: var(--gold-bright);
  text-decoration: underline;
}

[hidden] {
  display: none !important;
}
