:root {
  color-scheme: light;
  --ink: #29231e;
  --muted: #786d62;
  --paper: #e9e1d3;
  --panel: #f8f3e9;
  --sheet: #fbf6eb;
  --line: #cbbfaf;
  --accent: #8f342f;
  --accent-dark: #712824;
  --accent-soft: #ead8d1;
  --warning: #8b581d;
  --shadow: 0 12px 34px rgba(55, 42, 31, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,.16)),
    repeating-linear-gradient(0deg, transparent 0, transparent 3px, rgba(92,68,43,.018) 4px),
    var(--paper);
  color: var(--ink);
  font-family: "Source Han Serif SC", "Noto Serif SC", "Songti SC", SimSun, serif;
}

button, input, select { font: inherit; }
button, .drop-zone { cursor: pointer; }
.hidden { display: none !important; }

.site-header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 243, 233, .94);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
}

.logo svg {
  width: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand strong {
  display: block;
  font: 500 21px/1 Georgia, "Times New Roman", serif;
  letter-spacing: .06em;
}

.brand small, .privacy, .eyebrow, button, input, select, .form-note, .preview-footer {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.brand small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .12em;
}

.privacy { color: var(--muted); font-size: 12px; }
main { min-height: calc(100vh - 72px); }

.upload-view {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(420px, 620px) minmax(360px, 500px);
  align-items: center;
  justify-content: center;
  gap: clamp(45px, 8vw, 120px);
  padding: 70px 6vw;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .2em;
}

.intro h1, .ready-view h1 {
  margin: 0;
  font-size: clamp(44px, 5vw, 72px);
  font-weight: 500;
  line-height: 1.28;
  letter-spacing: .02em;
}

.intro > p:last-child {
  max-width: 540px;
  margin: 30px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.9;
}

.upload-card {
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.drop-zone {
  min-height: 310px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
  border: 1px dashed #a99a87;
  background: rgba(255,255,255,.22);
  text-align: center;
}

.drop-zone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone strong { font-size: 21px; font-weight: 500; }
.drop-zone > span:last-child { color: var(--muted); font: 12px Inter, sans-serif; }

.seal {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 20px;
}

.seal.working { animation: breathe 1.5s ease-in-out infinite; }
@keyframes breathe { 50% { background: var(--accent); color: white; } }

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 0;
  background: var(--accent);
  color: white;
  font-weight: 650;
  text-decoration: none;
}
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: .55; cursor: wait; }
.upload-card > .primary { width: 100%; margin-top: 14px; }
.form-note { margin: 14px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.progress-view, .ready-view {
  min-height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}

.progress-view h1 { margin: 24px 0 10px; font-size: 36px; font-weight: 500; }
.progress-view p, .ready-view > p { color: var(--muted); }
.progress-line { width: 340px; height: 2px; margin-top: 25px; overflow: hidden; background: var(--line); }
.progress-line span { display: block; width: 35%; height: 100%; background: var(--accent); animation: progress 1.3s infinite ease-in-out; }
@keyframes progress { from { transform: translateX(-100%); } to { transform: translateX(390%); } }

.editor-view {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 270px minmax(500px, 1fr) 315px;
  gap: 1px;
  background: var(--line);
}

.chapters-panel, .preview-panel, .settings-panel { min-height: 0; background: var(--panel); }
.chapters-panel, .settings-panel { overflow: auto; }
.preview-panel { display: grid; grid-template-rows: 70px 1fr 44px; }

.panel-heading, .preview-toolbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2, .preview-toolbar h2 { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: .08em; }
.panel-heading .eyebrow, .preview-toolbar .eyebrow { margin-bottom: 6px; }

.text-button, .quiet-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
}

.quiet-button { padding: 7px 9px; border: 1px solid var(--line); background: #fbf7ef; color: var(--ink); }
.quiet-button:disabled { opacity: .4; cursor: not-allowed; }
.toolbar-actions { display: flex; gap: 7px; }

.chapter-list { padding: 8px 0 20px; }
.chapter-item {
  width: 100%;
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
  padding: 12px 15px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.chapter-item:hover { background: #eee6d9; }
.chapter-item.active { background: #eee2d8; color: #702a27; box-shadow: inset 3px 0 var(--accent); }
.chapter-number { color: var(--muted); font: 10px Inter, sans-serif; }
.chapter-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

.paper-stage {
  min-height: 0;
  overflow: auto;
  padding: 30px;
  background:
    repeating-linear-gradient(0deg, transparent 0, transparent 5px, rgba(92,68,43,.022) 6px),
    #ded4c5;
}

.book-preview {
  width: min(680px, 100%);
  min-height: 760px;
  margin: 0 auto;
  padding: 66px 76px;
  border-top: 3px solid #332b25;
  background: var(--sheet);
  box-shadow: 0 12px 35px rgba(55,42,31,.15);
  font-size: 17px;
  line-height: 1.85;
}
.book-preview h1 { margin: 0 0 2.2em; text-align: center; font-size: 1.45em; font-weight: 500; }
.book-preview h2, .book-preview h3 { margin: 1.5em 0 .8em; font-weight: 500; }
.book-preview p { margin: 0; text-indent: 2em; text-align: justify; }
.book-preview .byline { margin: 0 0 1.2em; text-align: left; text-indent: 0; font-size: 1.08em; }
.book-preview .contributor-alias { margin: -.7em 0 1.2em; text-align: left; text-indent: 0; font-style: italic; }
.book-preview p.selected { outline: 1px solid var(--accent); background: var(--accent-soft); }
.book-preview .scene-break { margin: 1em 0; text-align: center; text-indent: 0; letter-spacing: .8em; }

.preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

.settings { padding: 18px; }
fieldset { margin: 0 0 20px; padding: 0 0 18px; border: 0; border-bottom: 1px solid var(--line); }
legend { margin-bottom: 13px; color: var(--muted); font-size: 11px; letter-spacing: .14em; }
label { display: block; margin-bottom: 12px; color: var(--muted); font: 11px Inter, "Microsoft YaHei", sans-serif; }
input, select {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fcf8f0;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.profile-option {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px dotted var(--line);
}
.profile-option input { width: 14px; margin: 3px 0 0; accent-color: var(--accent); }
.profile-option strong { display: block; color: var(--ink); font: 500 12px "Noto Serif SC", serif; }
.profile-option small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.notice { padding: 10px; border-left: 3px solid #a66b28; background: #f3e6cc; color: var(--warning); font-size: 11px; line-height: 1.55; }
.settings > .primary { width: 100%; margin-top: 12px; }

.ready-view .seal { margin-bottom: 24px; }
.ready-view h1 { font-size: clamp(38px, 4vw, 58px); }
.download { min-width: 210px; margin: 20px 0 16px; }

.error-banner {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 13px 16px;
  border-left: 4px solid var(--accent);
  background: #fff8f0;
  box-shadow: var(--shadow);
  color: var(--accent-dark);
  font: 13px Inter, "Microsoft YaHei", sans-serif;
}

@media (max-width: 1050px) {
  .editor-view { grid-template-columns: 220px 1fr; }
  .settings-panel { position: fixed; right: 0; top: 72px; bottom: 0; width: 315px; z-index: 5; box-shadow: var(--shadow); }
  .upload-view { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .site-header { padding: 0 16px; }
  .privacy { display: none; }
  .upload-view { padding: 45px 20px; }
  .intro h1 { font-size: 40px; }
  .editor-view { height: auto; min-height: calc(100vh - 72px); display: block; }
  .chapters-panel { max-height: 260px; }
  .preview-panel { min-height: 760px; }
  .settings-panel { position: static; width: auto; }
  .book-preview { padding: 45px 28px; }
  .toolbar-actions { display: none; }
}
