:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
  --night: #2d3e50;
  --night-deep: #1c2b38;
  --forest: #5d8a52;
  --forest-deep: #3f6738;
  --fox: #e67e22;
  --sun: #f5c04d;
  --cream: #f5f2e9;
  --paper: #fffdf8;
  --ink: #26323a;
  --muted: #69757b;
  --line: #dce2dc;
  --shadow: 0 14px 34px rgba(35, 52, 48, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 6%, rgba(245, 192, 77, 0.16), transparent 24rem),
    linear-gradient(180deg, #eef2eb 0, #f8f7f2 30rem);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(18rem, 1fr) auto;
  align-items: center;
  gap: 1rem;
  min-height: 92px;
  padding: 1rem clamp(1rem, 4vw, 3.5rem);
  color: white;
  background: linear-gradient(120deg, var(--night-deep), var(--night));
  border-bottom: 4px solid var(--sun);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  aspect-ratio: 1;
  border-radius: 16px 5px 16px 5px;
  color: var(--night-deep);
  background: var(--sun);
  font-weight: 900;
  letter-spacing: -0.08em;
}

h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 3vw, 2rem); }
h2 { margin-bottom: 0; max-width: 42rem; font-size: clamp(1.5rem, 3vw, 2.25rem); line-height: 1.12; }
h3 { margin-bottom: 0; font-size: 1.25rem; }
h4 { margin-bottom: 0.45rem; font-size: 1.05rem; }

.eyebrow {
  margin-bottom: 0.2rem;
  color: var(--forest-deep);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar .eyebrow { color: #bdd7b5; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

label { font-size: 0.88rem; font-weight: 700; }

select, button {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 9px;
  padding: 0 0.85rem;
  font: inherit;
}

select { max-width: 23rem; color: white; background: rgba(255,255,255,0.1); }
select option { color: var(--ink); background: white; }
button { color: var(--night-deep); background: var(--sun); font-weight: 800; cursor: pointer; }
button:hover { background: #ffd66e; }
button:disabled { cursor: wait; opacity: 0.65; }

main {
  width: min(1480px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.view-tabs {
  display: flex;
  width: fit-content;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  padding: 0.35rem;
  background: rgba(255,253,248,0.82);
  border: 1px solid rgba(93,138,82,0.2);
  border-radius: 13px;
  box-shadow: 0 8px 22px rgba(35,52,48,0.06);
}

.view-tab {
  min-height: 38px;
  border: 0;
  padding: 0 1rem;
  color: var(--muted);
  background: transparent;
}

.view-tab:hover { color: var(--night-deep); background: #edf1e9; }
.view-tab.is-active { color: white; background: var(--night); }
.view-tab.is-active:hover { color: white; background: var(--night-deep); }

.book-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.4rem;
}

.book-heading .eyebrow { display: flex; align-items: center; gap: 0.7rem; }
.legacy-note { margin-bottom: 0; color: var(--muted); font-size: 0.9rem; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.summary, .panel {
  background: rgba(255,253,248,0.92);
  border: 1px solid rgba(93,138,82,0.19);
  box-shadow: var(--shadow);
}

.summary {
  display: flex;
  min-height: 128px;
  flex-direction: column;
  justify-content: center;
  padding: 1.15rem;
  border-radius: 16px;
}

.summary > strong { color: var(--night); font-size: 2rem; line-height: 1; }
.summary > span { margin-top: 0.55rem; font-weight: 750; }
.summary small { margin-top: 0.25rem; color: var(--muted); }

.progress-card { flex-direction: row; align-items: center; justify-content: flex-start; gap: 1rem; }
.progress-card > div:last-child { display: flex; flex-direction: column; }

.progress-ring {
  display: grid;
  flex: 0 0 82px;
  place-items: center;
  width: 82px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--paper) 55%, transparent 57%), conic-gradient(var(--forest) calc(var(--progress) * 1%), #dce5da 0);
}

.progress-ring strong { font-size: 1.2rem; }

.panel { margin-top: 1rem; padding: 1.25rem; border-radius: 18px; }
.panel-title { display: flex; align-items: start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel-title > span { color: var(--muted); font-size: 0.85rem; }

.phase-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.85rem; }
.phase { padding: 1rem; background: #f5f7f1; border: 1px solid var(--line); border-radius: 12px; }
.phase-line { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.phase p, .gate p, .task-list p { margin: 0.65rem 0 0; color: var(--muted); font-size: 0.88rem; line-height: 1.42; }

.bar { height: 7px; margin-top: 0.8rem; overflow: hidden; background: #dce5da; border-radius: 99px; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--forest), #86aa69); border-radius: inherit; }

.lower-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); gap: 1rem; }
.gate-list, .task-list { display: grid; gap: 0.65rem; margin: 0; padding: 0; list-style: none; }
.gate, .task-list li { display: grid; align-items: start; gap: 0.8rem; padding: 0.85rem; border: 1px solid var(--line); border-radius: 11px; }
.gate { grid-template-columns: auto 1fr auto; }
.task-list li { grid-template-columns: auto 1fr; }
.gate-id { display: grid; place-items: center; width: 40px; height: 40px; color: white; background: var(--night); border-radius: 10px; font-weight: 900; }

.status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: none;
}

.status-approved { color: #265323; background: #dcefd7; }
.status-in_progress { color: #78420d; background: #ffe2bd; }
.status-in_review { color: #314f78; background: #dce9fa; }
.status-blocked { color: #7d2424; background: #f8d4d4; }
.status-not_started { color: #596168; background: #e7e9e9; }

.priority { margin-top: 0.1rem; padding: 0.25rem 0.45rem; border-radius: 6px; color: white; font-size: 0.72rem; font-weight: 850; text-transform: uppercase; }
.priority-high { background: var(--fox); }
.priority-medium { background: var(--night); }
.priority-low { color: var(--ink); background: #d9dfdc; }

.story-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; }
.story-grid article { padding: 1rem; color: white; background: linear-gradient(145deg, var(--forest-deep), var(--forest)); border-radius: 13px; }
.story-grid article > span { color: #d8ebcf; font-size: 0.78rem; font-weight: 800; }
.story-grid article p { margin-bottom: 0.8rem; color: #edf6e8; }
.story-grid article div { display: flex; align-items: center; gap: 0.7rem; }
.story-grid small { color: #edf6e8; }

.artifact-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.artifact-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.9rem;
  min-height: 88px;
  padding: 0.9rem;
  color: inherit;
  background: #f5f7f1;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.artifact-card:hover { transform: translateY(-2px); border-color: var(--forest); box-shadow: 0 9px 20px rgba(35,52,48,0.08); }
.artifact-card.is-current { background: #eef6eb; border-color: rgba(63,103,56,0.42); }
.file-type { display: grid; place-items: center; width: 52px; height: 52px; color: white; background: var(--night); border-radius: 10px; font-size: 0.72rem; font-weight: 900; }
.artifact-card.is-current .file-type { background: var(--forest-deep); }
.artifact-copy { display: grid; gap: 0.2rem; min-width: 0; }
.artifact-copy strong { overflow-wrap: anywhere; }
.artifact-copy small { color: var(--forest-deep); font-weight: 800; }
.artifact-copy > span { color: var(--muted); font-size: 0.84rem; line-height: 1.35; }
.open-mark { color: var(--forest-deep); font-size: 1.25rem; font-weight: 900; }
.empty-inline { margin: 0; color: var(--muted); }

.text-summary .summary > strong { color: var(--forest-deep); }
.manuscript-story { overflow: hidden; }
.story-theme { margin: -0.35rem 0 1rem; color: var(--muted); }
.scene-list { display: grid; gap: 0.7rem; }
.text-scene { background: #f7f8f3; border: 1px solid var(--line); border-radius: 12px; }
.text-scene[open] { background: var(--paper); border-color: rgba(93, 138, 82, 0.42); }
.text-scene summary { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 0.8rem; padding: 0.9rem; cursor: pointer; list-style: none; }
.text-scene summary::-webkit-details-marker { display: none; }
.text-scene summary small { display: block; margin-top: 0.2rem; color: var(--muted); font-size: 0.78rem; }
.scene-number { display: grid; place-items: center; width: 34px; height: 34px; color: white; background: var(--forest-deep); border-radius: 9px; font-size: 0.78rem; font-weight: 900; }
.comment-indicator { padding: 0.25rem 0.5rem; color: #75450d; background: #ffe4bd; border-radius: 99px; font-size: 0.74rem; font-weight: 800; }
.scene-content { padding: 0 0.9rem 0.9rem; border-top: 1px solid var(--line); }
.scene-text { max-width: 54rem; margin: 1rem 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.08rem; line-height: 1.75; white-space: pre-wrap; }
.scene-feedback { padding: 0.9rem; background: #eef5e9; border: 1px solid #d6e3d0; border-radius: 10px; }
.scene-feedback label { display: block; margin-bottom: 0.45rem; color: var(--forest-deep); }
.scene-feedback textarea { display: block; width: 100%; resize: vertical; padding: 0.7rem; color: var(--ink); background: white; border: 1px solid #b7c9b0; border-radius: 8px; font: inherit; line-height: 1.45; }
.scene-feedback textarea:focus { outline: 3px solid rgba(245, 192, 77, 0.45); border-color: var(--forest); }
.feedback-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 0.65rem; }
.feedback-status { color: var(--muted); }
.feedback-actions button { min-height: 36px; border-color: var(--sun); }

.automation-goal {
  max-width: 58rem;
  margin: 0.8rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.idea-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.idea-card { padding: 1.1rem; background: #f5f7f1; border: 1px solid var(--line); border-radius: 13px; }
.idea-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; color: var(--forest-deep); font-size: 0.78rem; font-weight: 800; }
.idea-card h4 { margin-top: 0.8rem; font-size: 1.2rem; }
.idea-card dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin: 0.9rem 0; }
.idea-card dl div { padding: 0.65rem; background: var(--paper); border-radius: 9px; }
.idea-card dt { color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }
.idea-card dd { margin: 0.2rem 0 0; font-size: 0.9rem; font-weight: 700; }
.idea-card p { margin-bottom: 0; color: var(--muted); line-height: 1.5; }

.roadmap { display: grid; gap: 0.9rem; margin: 0; padding: 0; list-style: none; }
.roadmap-step { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 1rem; }
.roadmap-marker {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 92px;
  padding: 0.7rem;
  color: var(--muted);
  background: #e7e9e9;
  border-radius: 13px;
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.roadmap-marker strong { color: inherit; font-size: 1rem; }
.roadmap-approved .roadmap-marker { color: white; background: var(--forest-deep); }
.roadmap-in_progress .roadmap-marker { color: #653609; background: #ffd79d; }
.roadmap-in_review .roadmap-marker { color: #314f78; background: #dce9fa; }
.roadmap-blocked .roadmap-marker { color: #7d2424; background: #f8d4d4; }
.roadmap-body { padding: 1rem 1.1rem; background: #f8f8f4; border: 1px solid var(--line); border-radius: 13px; }
.roadmap-title { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.roadmap-title p { margin: 0.45rem 0 0; color: var(--muted); line-height: 1.45; }
.roadmap-details { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(15rem, 0.85fr); gap: 1rem; margin-top: 1rem; }
.roadmap-details h4 { font-size: 0.86rem; }
.roadmap-details ul { margin: 0; padding-left: 1.15rem; color: var(--muted); line-height: 1.5; }
.next-action { margin: 0; padding: 0.8rem; background: white; border-left: 4px solid var(--sun); border-radius: 0 9px 9px 0; line-height: 1.45; }
.optional-panel { border-style: dashed; }
.optional-task-list li { grid-template-columns: auto minmax(0, 1fr) auto; }

.loading, .error, .empty { padding: 3rem; background: white; border-radius: 16px; box-shadow: var(--shadow); }
.error { border-left: 5px solid #a63f3f; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem clamp(1rem, 4vw, 3.5rem);
  color: #d9e2df;
  background: var(--night-deep);
  font-size: 0.82rem;
}

@media (max-width: 1000px) {
  .topbar { grid-template-columns: auto 1fr; }
  .topbar-actions { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .phase-list { grid-template-columns: repeat(2, 1fr); }
  .lower-grid { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
  .topbar { align-items: start; padding: 1rem; }
  .brand-mark { width: 44px; }
  .topbar-actions { display: grid; grid-template-columns: 1fr auto; }
  .topbar-actions label { grid-column: 1 / -1; }
  select { width: 100%; }
  main { width: min(100% - 1rem, 1480px); padding-top: 1rem; }
  .book-heading { display: block; }
  .view-tabs { width: 100%; }
  .view-tab { flex: 1; padding: 0 0.55rem; }
  .legacy-note { margin-top: 0.7rem; }
  .summary-grid, .phase-list, .story-grid, .idea-grid { grid-template-columns: 1fr; }
  .artifact-grid { grid-template-columns: 1fr; }
  .gate { grid-template-columns: auto 1fr; }
  .gate .status { grid-column: 2; }
  .roadmap-step { grid-template-columns: 1fr; gap: 0.55rem; }
  .roadmap-marker { display: flex; min-height: auto; justify-content: space-between; }
  .roadmap-details { grid-template-columns: 1fr; }
  .roadmap-title { display: grid; }
  .optional-task-list li { grid-template-columns: auto 1fr; }
  .optional-task-list .status { grid-column: 2; }
  .text-scene summary { grid-template-columns: auto minmax(0, 1fr); }
  .comment-indicator { grid-column: 2; width: fit-content; }
  .feedback-actions { align-items: stretch; flex-direction: column; }
  footer { flex-direction: column; }
}
