:root {
  --paper: #f7f5ef;
  --surface: #ffffff;
  --surface-soft: #fbfaf6;
  --line: #ded9ce;
  --line-strong: #c8c0b3;
  --ink: #20211f;
  --muted: #68665f;
  --subtle: #8b877c;
  --teal: #177c78;
  --teal-soft: #e4f3ef;
  --wine: #8f3846;
  --wine-soft: #f7e8eb;
  --amber: #b66b18;
  --amber-soft: #fff1db;
  --sage: #687a46;
  --sage-soft: #edf3df;
  --blue: #356d91;
  --blue-soft: #e5f0f6;
  --danger: #a33b2f;
  --danger-soft: #fae8e5;
  --shadow: 0 16px 42px rgba(41, 36, 27, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

textarea {
  resize: vertical;
}

.app {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 239, 0.95);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 210px;
  color: var(--ink);
  font-weight: 760;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid #2f7972;
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(23, 124, 120, 0.18), rgba(143, 56, 70, 0.12)),
    #fff;
  color: var(--teal);
  font-size: 15px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav a {
  min-width: 72px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav a:hover {
  background: var(--surface);
  color: var(--ink);
}

.nav a.active {
  background: var(--ink);
  color: #fff;
}

.topbar-right {
  display: flex;
  min-width: 210px;
  justify-content: flex-end;
}

.save-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.save-pill::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sage);
  content: "";
}

.page {
  width: min(1180px, calc(100vw - 40px));
  margin: 26px auto 48px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 28px;
  line-height: 1.18;
}

h2 {
  margin-bottom: 14px;
  font-size: 19px;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.field,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.field,
.select {
  padding: 0 12px;
}

.textarea {
  padding: 10px 12px;
  line-height: 1.55;
}

.field:focus,
.select:focus,
.textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 124, 120, 0.13);
}

.search {
  flex: 1;
}

.select {
  max-width: 160px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-weight: 680;
  white-space: nowrap;
}

.btn.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 14px;
}

.story-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.card {
  padding: 16px;
}

.story-card {
  display: grid;
  min-height: 190px;
  gap: 14px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-size: 17px;
}

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

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}

.badge.teal {
  border-color: #b7dcd6;
  background: var(--teal-soft);
  color: #126762;
}

.badge.wine {
  border-color: #e0b9c0;
  background: var(--wine-soft);
  color: var(--wine);
}

.badge.amber {
  border-color: #edca97;
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.sage {
  border-color: #ccd9aa;
  background: var(--sage-soft);
  color: var(--sage);
}

.progress-line {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe5d8;
}

.progress-line span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--sage));
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.empty {
  display: grid;
  min-height: 360px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
  text-align: center;
}

.empty-inner {
  width: min(420px, 90%);
}

.empty-mark {
  display: grid;
  width: 62px;
  height: 62px;
  margin: 0 auto 18px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(23, 124, 120, 0.12), rgba(182, 107, 24, 0.14)),
    #fff;
  color: var(--teal);
  font-size: 24px;
}

.split-page {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  gap: 16px;
  align-items: start;
}

.form-panel {
  padding: 18px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 680;
}

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

.genre-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.genre-options.two-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.genre-option {
  display: grid;
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  text-align: left;
}

.genre-option.active {
  border-color: var(--teal);
  background: var(--teal-soft);
  box-shadow: inset 0 0 0 1px rgba(23, 124, 120, 0.22);
}

.genre-option strong {
  font-size: 15px;
}

.genre-option small {
  color: var(--muted);
  line-height: 1.45;
}

.creation-choice {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(0, 1.25fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
  padding: 16px;
}

.creation-choice h2 {
  margin-bottom: 6px;
}

.creation-choice-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.creation-card {
  display: grid;
  min-height: 118px;
  align-content: start;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.creation-card:hover {
  border-color: var(--teal);
  background: var(--teal-soft);
  transform: translateY(-1px);
}

.creation-card strong {
  font-size: 18px;
}

.creation-card span {
  color: var(--muted);
  line-height: 1.55;
}

.notice {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  line-height: 1.6;
}

.notice.warning {
  border-color: #edca97;
  background: var(--amber-soft);
  color: #7b4d12;
}

.selected-work-type {
  display: grid;
  gap: 5px;
}

.selected-work-type strong {
  color: var(--ink);
}

.selected-work-type span {
  color: var(--muted);
}

.notice.error {
  border-color: #e1afa8;
  background: var(--danger-soft);
  color: var(--danger);
}

.library-stat {
  display: grid;
  gap: 10px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat-number {
  font-size: 26px;
  font-weight: 780;
}

.workspace {
  display: grid;
  height: calc(100vh - 58px);
  min-height: 720px;
  grid-template-rows: auto 1fr auto;
}

.workspace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.workspace-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.workspace-title h1 {
  overflow: hidden;
  max-width: 360px;
  margin: 0;
  font-size: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.workspace-body {
  display: grid;
  min-height: 0;
  grid-template-columns: 270px minmax(0, 1fr) 330px;
}

.workspace-left,
.workspace-right {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: var(--surface-soft);
}

.workspace-left {
  border-right: 1px solid var(--line);
}

.workspace-right {
  border-left: 1px solid var(--line);
}

.workspace-main {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: #fcfbf8;
}

.workspace-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.rhythm {
  display: flex;
  overflow: hidden;
  width: min(520px, 45vw);
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.rhythm span {
  flex: 1;
}

.tone-pain {
  background: var(--wine-soft);
}

.tone-sat {
  background: var(--teal-soft);
}

.tone-flow {
  background: var(--blue-soft);
}

.tone-sweet {
  background: var(--sage-soft);
}

.side-section {
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.side-section h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.mini-item {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.mini-item.current {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 7px 7px 0 0;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 -2px 0 var(--teal);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin: 0;
}

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

.event-card,
.outline-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.event-head,
.outline-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.event-head h3,
.outline-head h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.event-fields,
.outline-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.field-chip {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.field-chip strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
  color: var(--muted);
}

.commercial-chip {
  border-color: #edca97;
  background: var(--amber-soft);
}

.commercial-chip strong {
  color: var(--amber);
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.editor {
  min-height: 420px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.9;
}

.editor p {
  margin-bottom: 16px;
}

.script-cn-heading {
  margin-top: 8px;
  font-weight: 780;
}

.script-cn-body,
.script-cn-dialogue {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  white-space: pre-wrap;
}

.script-cn-dialogue {
  margin-left: 22px;
}

.script-episode-title {
  text-align: center;
  font-weight: 780;
}

.script-meta-line {
  max-width: 520px;
  margin-right: auto;
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.script-scene-heading {
  margin-top: 24px;
  font-weight: 780;
}

.script-action {
  font-family: "Songti SC", "STSong", "SimSun", serif;
}

.script-card-point {
  color: var(--amber);
  font-weight: 760;
  white-space: pre-wrap;
}

.script-character,
.script-dialogue {
  max-width: 520px;
  margin-right: auto;
  margin-left: auto;
  text-align: center;
}

.script-character {
  margin-top: 18px;
  margin-bottom: 8px;
}

.script-dialogue {
  line-height: 1.8;
}

.annotated p {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.annotation {
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segmented button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(30, 26, 20, 0.09);
}

.library-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.import-panel {
  margin-bottom: 20px;
  padding: 18px;
}

.import-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.import-head h2 {
  margin-bottom: 6px;
}

.import-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.import-textarea {
  min-height: 188px;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.import-preview {
  min-height: 246px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.import-preview .section-title {
  margin-bottom: 10px;
}

.import-counts {
  margin-bottom: 10px;
}

.import-items {
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.library-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: start;
}

.filter-panel,
.detail-panel {
  position: sticky;
  top: 78px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-head h2 {
  margin-bottom: 0;
}

.detail-badges {
  margin-bottom: 12px;
}

.danger-text {
  color: var(--danger);
}

.compact-form {
  gap: 10px;
}

.library-list {
  display: grid;
  gap: 10px;
}

.library-item {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

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

.settings-wrap {
  display: grid;
  gap: 14px;
  max-width: 760px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-child {
  border-bottom: 0;
}

.number-pair {
  display: flex;
  align-items: center;
  gap: 8px;
}

.number-pair .field {
  width: 90px;
}

.toggle {
  position: relative;
  width: 50px;
  height: 28px;
  border-radius: 999px;
  background: #d7d0c4;
}

.toggle::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  content: "";
  transition: transform 0.15s ease;
}

.toggle.on {
  background: var(--teal);
}

.toggle.on::after {
  transform: translateX(22px);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .story-grid,
  .library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-page,
  .import-grid,
  .creation-choice,
  .library-layout {
    grid-template-columns: 1fr;
  }

  .filter-panel,
  .detail-panel {
    position: static;
  }

  .workspace {
    height: auto;
  }

  .workspace-body {
    grid-template-columns: 1fr;
  }

  .workspace-left,
  .workspace-right {
    border: 0;
  }
}

@media (max-width: 740px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
  }

  .brand,
  .topbar-right {
    min-width: 0;
  }

  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .nav a {
    min-width: auto;
  }

  .page {
    width: min(100vw - 24px, 1180px);
    margin-top: 18px;
  }

  .page-head,
  .toolbar,
  .import-head,
  .setting-row,
  .workspace-head,
  .workspace-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .story-grid,
  .genre-options,
  .creation-choice-grid,
  .library-grid,
  .event-fields,
  .outline-fields {
    grid-template-columns: 1fr;
  }

  .select {
    max-width: none;
  }

  .rhythm {
    width: 100%;
  }
}
