:root {
  --bg: #f7f5ef;
  --ink: #1d2329;
  --muted: #65717c;
  --line: #ddd8cd;
  --panel: #fffdf8;
  --teal: #166b68;
  --teal-dark: #0f4d4b;
  --coral: #bd4f3f;
  --gold: #b68b2f;
  --blue: #314f7d;
  --soft-teal: #e7f1ef;
  --soft-coral: #fae8e3;
  --soft-gold: #f6edda;
  --shadow: 0 18px 45px rgba(29, 35, 41, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: #20262b;
  color: #fffaf1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 250, 241, 0.25);
  background: #2c363b;
  color: #f3c76e;
  font-weight: 800;
  border-radius: 8px;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.section-heading h3,
.section-heading p,
.panel h4,
.status-panel h2 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  margin-top: 4px;
  color: #c8d1d2;
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #e9eeec;
  background: transparent;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  border-color: rgba(243, 199, 110, 0.4);
  background: rgba(243, 199, 110, 0.12);
}

.status-panel {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 250, 241, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.05);
}

.status-panel h2 {
  font-size: 13px;
  color: #f3c76e;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  color: #dfe7e4;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.progress-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #a6cbbf;
  border-radius: 8px;
  background: var(--soft-teal);
  box-shadow: var(--shadow);
}

.progress-copy {
  display: grid;
  gap: 3px;
}

.progress-copy strong {
  color: var(--teal-dark);
}

.progress-copy span,
.progress-meta {
  color: var(--muted);
  font-size: 13px;
}

.progress-meta {
  display: flex;
  gap: 12px;
  font-weight: 900;
}

.progress-track {
  grid-column: 1 / -1;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #cfdfdc;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 220ms ease;
}

.topbar h2 {
  font-size: 28px;
}

.eyebrow {
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.section-heading,
.panel-header,
.field-row,
.blend-row,
.action-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-heading h3 {
  font-size: 23px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.setup-grid,
.export-grid,
.vault-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.form-panel {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfc8ba;
  border-radius: 7px;
  background: #fffefa;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  min-height: 360px;
  resize: vertical;
  line-height: 1.55;
}

.compact-textarea {
  min-height: 92px;
}

.form-section {
  display: grid;
  gap: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-section h4 {
  margin: 0;
  font-size: 16px;
}

.subsection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.field-row > label,
.blend-row > label {
  flex: 1;
}

.primary-action,
.icon-button,
.segment {
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 800;
}

.primary-action {
  min-height: 42px;
  padding: 10px 15px;
  background: var(--teal);
  color: white;
}

.primary-action:hover {
  background: var(--teal-dark);
}

.primary-action.secondary {
  background: var(--blue);
}

.primary-action.secondary:hover {
  background: #263f66;
}

.full-width {
  width: 100%;
}

.icon-button {
  min-height: 38px;
  padding: 9px 12px;
  background: #263139;
  color: white;
}

.icon-button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.api-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fffefa;
  font-size: 12px;
  font-weight: 900;
}

.api-pill.ready {
  border-color: #a6cbbf;
  color: var(--teal-dark);
  background: var(--soft-teal);
}

.api-pill.offline {
  border-color: #e7b7ac;
  color: #84382f;
  background: var(--soft-coral);
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 156px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segment {
  min-height: 36px;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  border-radius: 0;
}

.segment.active {
  background: var(--blue);
  color: white;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.style-summary {
  margin-top: 14px;
  padding: 14px;
  border-left: 4px solid var(--gold);
  background: var(--soft-gold);
  border-radius: 6px;
  line-height: 1.55;
  color: #493818;
  font-size: 14px;
}

.generation-policy {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.generation-policy h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.generation-policy p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.api-setup-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.api-setup-panel h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.api-setup-panel p,
.api-setup-panel li {
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.api-setup-panel ol {
  margin: 8px 0 12px;
  padding-left: 22px;
}

.api-setup-panel pre {
  overflow-x: auto;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #20262b;
  color: #fffaf1;
  line-height: 1.45;
  font-size: 13px;
}

.hidden {
  display: none;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.meta-card {
  padding: 12px;
  border-radius: 8px;
  background: var(--soft-teal);
}

.meta-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-card strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
}

.outline-list,
.chapter-list {
  display: grid;
  gap: 12px;
}

.outline-item,
.scene-card,
.chapter-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.outline-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 180px;
  gap: 14px;
  padding: 14px;
}

.outline-index {
  color: var(--teal);
  font-weight: 900;
}

.outline-item h4,
.scene-card h4,
.chapter-item h4 {
  margin: 0 0 8px;
  font-size: 16px;
}

.outline-item p,
.scene-card p,
.chapter-item p,
.chapter-preview p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.beat-pill {
  align-self: start;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--soft-coral);
  color: #7c342b;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.beat-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f5f8f4;
}

.beat-list p {
  margin: 0;
  font-size: 13px;
}

.scene-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.scene-card {
  padding: 15px;
}

.scene-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--soft-teal);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.chapter-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.chapter-panel {
  min-height: 560px;
}

.chapter-item {
  padding: 12px;
}

.chapter-item.active {
  border-color: var(--teal);
  background: var(--soft-teal);
}

.chapter-preview {
  line-height: 1.7;
}

.generation-progress {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #a6cbbf;
  border-radius: 8px;
  background: var(--soft-teal);
  color: var(--teal-dark);
  font-weight: 900;
}

.chapter-preview h4 {
  margin: 0 0 14px;
  font-size: 22px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-list {
  margin: 10px 0 0;
  padding-left: 20px;
  line-height: 1.8;
  color: var(--muted);
}

.diagnostics {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.diagnostic-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.diagnostic-row strong {
  color: var(--ink);
  text-align: right;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 8px;
  background: #20262b;
  color: #fffaf1;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.startup-error {
  margin: 12px;
  padding: 14px 16px;
  border: 1px solid #e7b7ac;
  border-radius: 8px;
  background: var(--soft-coral);
  color: #84382f;
  line-height: 1.5;
}

.startup-error strong {
  color: #5f211b;
}

.startup-error span {
  display: block;
  margin-top: 4px;
  color: #7c4a43;
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .setup-grid,
  .export-grid,
  .vault-grid,
  .chapter-layout {
    grid-template-columns: 1fr;
  }

  .scene-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .section-heading,
  .field-row,
  .blend-row,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-list,
  .scene-board,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .outline-item {
    grid-template-columns: 1fr;
  }
}
