:root {
  --bg: #f5f1e9;
  --surface: #fffdf8;
  --surface-strong: #f8f6f0;
  --ink: #26231f;
  --muted: #706a60;
  --soft: #9a9285;
  --line: #d8d0c3;
  --line-strong: #bfb4a4;
  --teal: #147c78;
  --teal-weak: #dcefed;
  --rust: #a9572a;
  --rust-weak: #f5e1d5;
  --blue: #3b6f95;
  --blue-weak: #dce9f2;
  --green: #577a43;
  --green-weak: #e5eedf;
  --red: #aa463e;
  --red-weak: #f2dcd9;
  --shadow: 0 18px 44px rgba(38, 35, 31, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(20, 124, 120, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(169, 87, 42, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px;
  color: var(--ink);
}

button,
select,
textarea,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

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

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(12px);
  z-index: 3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 188px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--ink);
  color: #fffdf8;
  font-weight: 800;
}

.brand-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-copy strong,
.brand-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy strong {
  font-size: 15px;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.project-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 260px;
  min-width: 190px;
  padding: 0 10px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.project-switcher svg {
  width: 18px;
  color: var(--teal);
  flex: 0 0 auto;
}

.project-switcher select {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.top-metrics {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.top-metrics span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  white-space: nowrap;
}

.top-metrics b {
  color: var(--ink);
}

.top-metrics .risk b {
  color: var(--rust);
}

.top-actions,
.editor-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button,
.rail-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button:hover,
.rail-button:hover {
  border-color: var(--line-strong);
  background: #fff;
}

.icon-button svg,
.rail-button svg,
.command-button svg {
  width: 18px;
  height: 18px;
}

.icon-button.small {
  width: 32px;
  height: 32px;
}

.icon-button.small svg {
  width: 16px;
  height: 16px;
}

.command-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.command-button.primary {
  background: var(--teal);
  color: #fff;
}

.command-button.secondary {
  border-color: var(--line);
  background: var(--surface);
}

.command-button.dark {
  background: var(--ink);
  color: #fff;
}

.rail {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  background: rgba(248, 246, 240, 0.92);
}

.rail-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.rail-button.active {
  background: var(--teal-weak);
  color: var(--teal);
  border-color: #b9d8d5;
}

.rail-bottom {
  margin-top: auto;
}

.project-panel,
.inspector {
  min-width: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.74);
}

.project-panel {
  grid-row: 2;
  padding: 18px 16px;
}

.panel-block {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.panel-block:first-child {
  padding-top: 0;
}

.section-heading,
.inspector-header,
.work-header,
.editor-toolbar,
.editor-footer,
.prompt-dock,
.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.section-heading h2,
.inspector-header h2 {
  margin: 0;
  font-size: 15px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.good {
  background: var(--green-weak);
  color: var(--green);
}

.status-pill.neutral {
  background: var(--blue-weak);
  color: var(--blue);
}

.logline {
  margin: 12px 0 16px;
  color: var(--muted);
  line-height: 1.55;
}

.progress-wrap {
  display: grid;
  gap: 8px;
}

.progress-label {
  color: var(--muted);
  font-size: 12px;
}

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

.progress-track {
  height: 8px;
  border-radius: 8px;
  background: #ebe5da;
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  background: var(--teal);
  min-width: 8px;
}

.blueprint-list,
.chapter-list,
.check-list,
.foreshadow-stack,
.fact-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.blueprint-item,
.chapter-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

.blueprint-item span,
.chapter-row span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.blueprint-item b,
.chapter-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.blueprint-item em,
.chapter-row em {
  font-size: 12px;
  color: var(--soft);
  font-style: normal;
  white-space: nowrap;
}

.blueprint-item.done span,
.chapter-row.complete span {
  background: var(--green-weak);
  color: var(--green);
}

.blueprint-item.active,
.chapter-row.active {
  border-color: #9ac9c6;
  background: var(--teal-weak);
}

.blueprint-item.active span,
.chapter-row.active span {
  background: var(--teal);
  color: #fff;
}

.pulse-line {
  display: flex;
  align-items: end;
  gap: 9px;
  height: 80px;
  margin-top: 12px;
  padding: 0 4px 8px;
  border-bottom: 1px solid var(--line);
}

.pulse-node {
  width: 16px;
  border-radius: 5px 5px 0 0;
  background: var(--blue);
}

.pulse-node.low { height: 22px; background: var(--green); }
.pulse-node.mid { height: 40px; background: var(--blue); }
.pulse-node.high { height: 56px; background: var(--teal); }
.pulse-node.peak { height: 70px; background: var(--rust); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.teal { background: var(--teal); }
.dot.rust { background: var(--rust); }
.dot.blue { background: var(--blue); }

.workspace {
  grid-row: 2;
  min-width: 0;
  overflow: auto;
  padding: 20px;
}

.work-header {
  align-items: flex-start;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.work-header h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
}

.header-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 430px;
}

.header-tags span {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.generation-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.strip-item {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.item-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.strip-item strong {
  display: block;
  line-height: 1.5;
}

.editor-surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-toolbar {
  min-height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.segmented-control,
.inspector-tabs {
  display: inline-flex;
  min-width: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee8dc;
}

.segment,
.inspector-tab {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active,
.inspector-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(38, 35, 31, 0.09);
}

.tab-panel,
.inspector-panel {
  display: none;
}

.tab-panel.active,
.inspector-panel.active {
  display: block;
}

#draftText {
  display: block;
  width: 100%;
  min-height: 508px;
  resize: vertical;
  padding: 28px 36px;
  border: 0;
  outline: 0;
  background: #fffdf8;
  color: var(--ink);
  font-size: 18px;
  line-height: 2;
}

.editor-footer {
  min-height: 42px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.note-card,
.thread-card,
.fact-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.note-card {
  min-height: 150px;
  padding: 16px;
}

.note-card span,
.thread-card span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border-radius: 8px;
  background: var(--blue-weak);
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.note-card h3,
.thread-card h3,
.fact-item h3,
.ledger-box h3,
.blacklist h3 {
  margin: 12px 0 8px;
  font-size: 15px;
}

.note-card p,
.thread-card p,
.fact-item p,
.prompt-source p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.timeline {
  padding: 20px;
}

.timeline-item {
  position: relative;
  padding: 0 0 18px 22px;
  border-left: 1px solid var(--line);
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
}

.timeline-item time {
  display: block;
  color: var(--soft);
  font-size: 12px;
  margin-bottom: 6px;
}

.timeline-item p {
  margin: 0;
  line-height: 1.55;
}

.prompt-dock {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.prompt-source {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 4px;
  min-width: 230px;
}

.prompt-source span {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--rust-weak);
  color: var(--rust);
  font-weight: 800;
}

.prompt-source strong,
.prompt-source p {
  min-width: 0;
}

.prompt-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
}

.prompt-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.inspector {
  grid-row: 2;
  border-right: 0;
  border-left: 1px solid var(--line);
  padding: 18px 16px;
}

.inspector-header {
  align-items: flex-start;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  margin: 16px 0;
}

.inspector-tab {
  padding: 0 6px;
}

.check-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.check-summary strong,
.check-summary span {
  display: grid;
  place-items: center;
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.check-summary strong {
  background: var(--green-weak);
  color: var(--green);
}

.check-summary span {
  background: var(--rust-weak);
  color: var(--rust);
  font-weight: 800;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.45;
}

.check-item.pass {
  border-color: #c9d8bd;
}

.check-item.warn {
  border-color: #e6c5af;
}

.ledger-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.ledger-box dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.ledger-box div {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
}

.ledger-box dt {
  color: var(--ink);
  font-weight: 800;
}

.ledger-box dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.thread-card {
  padding: 14px;
}

.thread-card.active {
  border-color: #9ac9c6;
  background: var(--teal-weak);
}

.style-meter {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.style-meter div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

.style-meter b {
  color: var(--ink);
}

meter {
  width: 100%;
  height: 10px;
}

.blacklist {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.token {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 0 6px 8px 0;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.token.hit {
  border-color: #dfb0aa;
  background: var(--red-weak);
  color: var(--red);
}

.fact-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
}

.fact-item svg {
  width: 22px;
  height: 22px;
  margin-top: 2px;
}

.fact-item.pass svg {
  color: var(--green);
}

.fact-item.warn svg {
  color: var(--rust);
}

.fact-item h3 {
  margin-top: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
  z-index: 5;
}

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

@media (max-width: 1280px) {
  .app-shell {
    grid-template-columns: 60px 280px minmax(460px, 1fr);
    grid-template-rows: 64px minmax(0, 1fr) auto;
  }

  .inspector {
    grid-column: 2 / -1;
    grid-row: 3;
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .top-metrics span:nth-child(3) {
    display: none;
  }
}

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

  .project-panel {
    grid-column: 1 / -1;
    grid-row: 3;
    border-top: 1px solid var(--line);
  }

  .workspace {
    grid-column: 2;
  }

  .inspector {
    grid-column: 1 / -1;
    grid-row: 4;
  }

  .topbar {
    flex-wrap: wrap;
    min-height: 120px;
    align-content: center;
  }

  .top-actions {
    margin-left: auto;
  }

  .generation-strip,
  .card-grid {
    grid-template-columns: 1fr;
  }

  .prompt-dock,
  .work-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-tags {
    justify-content: flex-start;
    max-width: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .topbar,
  .rail,
  .project-panel,
  .workspace,
  .inspector {
    width: 100%;
  }

  .topbar {
    order: 1;
  }

  .rail {
    order: 2;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    order: 3;
    max-width: 100%;
    overflow-x: hidden;
  }

  .editor-surface,
  .generation-strip,
  .prompt-dock {
    max-width: calc(100vw - 28px);
  }

  .inspector {
    order: 4;
  }

  .project-panel {
    order: 5;
  }

  .project-switcher,
  .top-metrics,
  .top-actions {
    width: 100%;
  }

  .top-actions {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .workspace {
    padding: 14px;
  }

  #draftText {
    min-height: 420px;
    padding: 20px;
    font-size: 16px;
  }

  .editor-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented-control {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    max-width: 336px;
  }

  .segment {
    padding: 0 2px;
    min-width: 0;
    overflow: hidden;
    font-size: 13px;
    white-space: nowrap;
  }
}
