:root {
  --ink: #142238;
  --ink-soft: #566275;
  --paper: #f6f4ef;
  --paper-bright: #fcfbf8;
  --line: #d9d7d0;
  --blue: #2e638d;
  --blue-dark: #1d4669;
  --blue-soft: #dce8f1;
  --warm: #a96844;
  --shadow: 0 24px 70px rgba(20, 34, 56, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  color: var(--ink);
  background: #e9edf0;
  font-family: "SF Pro Display", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  height: 76px;
  padding: 0 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(20, 34, 56, 0.12);
  background: rgba(237, 240, 242, 0.94);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--ink);
  border-radius: 10px;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 22px;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 17px; letter-spacing: .08em; }
.brand div > span { margin-top: 2px; color: var(--ink-soft); font-size: 11px; letter-spacing: .12em; }

.model-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}
.model-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8693a0;
}
.model-status.is-ready::before { background: #4c896a; }
.topbar-actions, .header-actions { display: flex; align-items: center; gap: 18px; }
.review-link, .quiet-link {
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: none;
  transition: color 150ms ease;
}
.review-link:hover, .quiet-link:hover { color: var(--ink); }

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

.stage-rail {
  padding: 42px 28px 30px 36px;
  border-right: 1px solid rgba(20, 34, 56, 0.12);
  display: flex;
  flex-direction: column;
  background: #edf0f2;
}

.eyebrow {
  margin: 0 0 16px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.stage-rail nav { display: grid; gap: 4px; }
.stage-link {
  position: relative;
  width: 100%;
  padding: 16px 8px 16px 42px;
  border: 0;
  text-align: left;
  background: transparent;
  cursor: pointer;
  opacity: .58;
  transition: opacity 180ms ease, transform 180ms ease;
}
.stage-link:disabled { cursor: default; }
.stage-link:not(:disabled):hover { opacity: 1; transform: translateX(2px); }
.stage-link.is-active { opacity: 1; }
.stage-link > span {
  position: absolute;
  left: 7px;
  top: 17px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
}
.stage-link b, .stage-link small { display: block; }
.stage-link b { font-size: 14px; }
.stage-link small { margin-top: 5px; color: var(--ink-soft); font-size: 12px; }
.stage-link.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  width: 2px;
  height: 38px;
  background: var(--blue);
}

.rail-note {
  margin-top: auto;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.rail-note span { color: var(--ink-soft); font-size: 11px; letter-spacing: .12em; }
.rail-note p { margin: 9px 0 0; font-family: "Songti SC", serif; font-size: 13px; line-height: 1.75; }

.workspace {
  min-width: 0;
  padding: 54px clamp(40px, 6vw, 96px);
  background: var(--paper);
}

.stage { display: none; max-width: 1080px; margin: 0 auto; }
.stage.is-visible { display: block; animation: stage-in 320ms ease both; }
@keyframes stage-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.stage-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 34px;
  margin-bottom: 32px;
}
.stage-header.compact { align-items: center; }
.stage-header h1 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: clamp(34px, 4vw, 54px);
  font-weight: 600;
  letter-spacing: -.04em;
}
.stage-header.compact h1 { font-size: clamp(30px, 3vw, 42px); }
.stage-header p:last-child { max-width: 620px; margin: 13px 0 0; color: var(--ink-soft); font-size: 14px; line-height: 1.7; }

.mode-switch {
  flex: 0 0 auto;
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,255,255,.42);
}
.mode-button {
  padding: 9px 12px;
  border: 0;
  border-radius: 6px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}
.mode-button.is-active { color: #fff; background: var(--ink); }
.mode-button:disabled { cursor: not-allowed; opacity: .45; }

.source-meta {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}
.source-meta label span { display: block; margin-bottom: 5px; color: var(--ink-soft); font-size: 11px; }
.source-meta input {
  min-width: 280px;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-family: "Songti SC", serif;
  font-size: 18px;
}
.source-state { color: var(--blue); font-size: 12px; }

.text-editor { display: block; border-block: 1px solid var(--line); background: var(--paper-bright); }
.text-editor textarea {
  display: block;
  width: 100%;
  height: min(49vh, 500px);
  padding: 30px 34px;
  resize: none;
  border: 0;
  outline: 0;
  color: #27354a;
  background: transparent;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 17px;
  line-height: 2;
}
.text-editor textarea:read-only { color: #4b586a; }

.stage-actions {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink-soft);
  font-size: 12px;
}

.primary-button, .secondary-button, .quiet-button {
  border-radius: 8px;
  cursor: pointer;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease;
}
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.primary-button { padding: 13px 20px; border: 1px solid var(--ink); color: #fff; background: var(--ink); }
.secondary-button { padding: 10px 15px; border: 1px solid var(--blue); color: #fff; background: var(--blue); }
.quiet-button { padding: 9px 4px; border: 0; color: var(--ink-soft); background: transparent; }
.quiet-button:hover { color: var(--ink); }

.result-count { color: var(--ink-soft); font-size: 13px; }
.character-list { border-top: 1px solid var(--line); }
.character-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  padding: 25px 0;
  border-bottom: 1px solid var(--line);
}
.character-name { display: flex; align-items: center; gap: 11px; font-family: "Songti SC", serif; font-size: 20px; }
.character-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--ink);
  font-family: "Songti SC", serif;
  font-size: 14px;
}
.alias-list { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.alias-chip {
  padding: 8px 10px;
  border: 1px solid #c9c8c2;
  border-radius: 7px;
  background: transparent;
  font-size: 13px;
  cursor: pointer;
}
.alias-chip:hover { border-color: var(--blue); color: var(--blue); }
.alias-chip.is-canonical { color: #fff; border-color: var(--blue-dark); background: var(--blue-dark); cursor: default; }
.alias-chip.is-selected { border-color: var(--warm); color: var(--warm); background: #f4e9e2; }

.alias-toolbar {
  position: sticky;
  bottom: 18px;
  z-index: 5;
  margin: 18px 0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: #fff;
  background: var(--ink);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.alias-toolbar[hidden] { display: none; }
.alias-toolbar div { margin-right: auto; }
.alias-toolbar div span, .alias-toolbar div strong { display: block; }
.alias-toolbar div span, .alias-toolbar label span { color: #aeb9c7; font-size: 10px; }
.alias-toolbar div strong { margin-top: 3px; }
.alias-toolbar label { display: flex; align-items: center; gap: 8px; }
.alias-toolbar select { padding: 8px 28px 8px 10px; border: 0; border-radius: 6px; }
.alias-toolbar .quiet-button { color: #cbd4df; }

.identity-picker {
  display: flex;
  gap: 9px;
  padding: 17px 0;
  border-block: 1px solid var(--line);
  overflow-x: auto;
}
.identity-button {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid #c8c7c1;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.identity-button.is-active { color: #fff; border-color: var(--blue-dark); background: var(--blue-dark); }

.reader {
  position: relative;
  height: min(66vh, 680px);
  min-height: 500px;
  margin-top: 20px;
  overflow: hidden;
  background: #e7edf1;
  box-shadow: inset 0 0 0 1px rgba(20,34,56,.08);
}
.reader-empty {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 40px;
  text-align: center;
}
.reader-glyph {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid #aab7c3;
  border-radius: 50%;
  color: var(--blue-dark);
  font-family: "Songti SC", serif;
  font-size: 30px;
}
.reader-empty p { max-width: 370px; margin: 0 0 22px; color: var(--ink-soft); font-family: "Songti SC", serif; line-height: 1.7; }
.message-stream {
  height: calc(100% - 82px);
  padding: 30px clamp(20px, 5vw, 58px);
  overflow-y: auto;
  scroll-behavior: smooth;
}
.message-stream[hidden] { display: none; }
.message {
  max-width: 72%;
  margin: 0 0 20px;
  animation: message-in 240ms ease both;
}
@keyframes message-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.message.is-self { margin-left: auto; }
.message.is-narration { max-width: 82%; margin: 10px auto 26px; text-align: center; }
.message-speaker { margin: 0 7px 6px; color: var(--ink-soft); font-size: 11px; }
.message.is-self .message-speaker { text-align: right; }
.message-body {
  padding: 13px 16px;
  border-radius: 5px 16px 16px 16px;
  color: var(--ink);
  background: var(--paper-bright);
  font-family: "Songti SC", serif;
  font-size: 15px;
  line-height: 1.65;
  box-shadow: 0 6px 22px rgba(20,34,56,.08);
}
.message.is-self .message-body { color: #fff; background: var(--blue-dark); border-radius: 16px 5px 16px 16px; }
.message.is-narration .message-body { padding: 0; color: #647182; background: transparent; box-shadow: none; font-size: 13px; }
.reader-control {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 82px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid rgba(20,34,56,.1);
  background: rgba(243,246,248,.96);
}
.reader-control[hidden] { display: none; }
.send-original {
  width: min(620px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 12px 12px 17px;
  border: 1px solid #b7c4ce;
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}
.send-original span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: "Songti SC", serif; }
.send-original button { flex: 0 0 auto; padding: 8px 13px; border: 0; border-radius: 7px; color: #fff; background: var(--blue-dark); cursor: pointer; }
.reading-complete { color: var(--ink-soft); font-family: "Songti SC", serif; }

.loading-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  color: #fff;
  text-align: center;
  background: rgba(20, 34, 56, .92);
}
.loading-layer[hidden] { display: none; }
.loading-mark {
  width: 38px;
  height: 38px;
  margin-bottom: 20px;
  border: 2px solid rgba(255,255,255,.28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-layer strong { font-family: "Songti SC", serif; font-size: 24px; }
.loading-layer p { color: #bfc9d5; font-size: 13px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  background: #7b3f38;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 820px) {
  .topbar { height: 64px; padding: 0 18px; }
  .model-status { font-size: 0; }
  .model-status::after { content: "模型"; font-size: 12px; }
  .topbar-actions { gap: 12px; }
  .app-shell { min-height: calc(100vh - 64px); grid-template-columns: 1fr; }
  .stage-rail { padding: 12px 18px; border-right: 0; border-bottom: 1px solid var(--line); }
  .stage-rail > .eyebrow, .rail-note, .stage-link small { display: none; }
  .stage-rail nav { grid-template-columns: repeat(3, 1fr); }
  .stage-link { padding: 10px 4px 10px 28px; }
  .stage-link > span { left: 3px; top: 11px; }
  .stage-link.is-active::after { top: auto; bottom: -12px; width: 100%; height: 2px; }
  .workspace { padding: 34px 18px; }
  .stage-header { display: block; margin-bottom: 24px; }
  .stage-header h1 { font-size: 34px; }
  .mode-switch { width: fit-content; margin-top: 22px; }
  .source-meta input { min-width: 0; max-width: 220px; }
  .character-row { grid-template-columns: 1fr; gap: 14px; }
  .alias-toolbar { align-items: flex-end; flex-wrap: wrap; }
  .alias-toolbar div { width: 100%; }
  .message { max-width: 88%; }
  .reader { min-height: 470px; }
}
