:root {
  --ink: #123a30;
  --ink-2: #2a5145;
  --ink-soft: #e6ece8;
  --paper: #fffefb;
  --page: #f2f1ea;
  --line: #d8d6cb;
  --line-soft: #e8e6dd;
  --muted: #56655e;
  --moss: #4a6a22;
  --moss-dark: #3a5419;
  --cinnabar: #b5382a;
  --cinnabar-soft: #fbeeeb;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Noto Serif SC", "STSong", "SimSun", serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 12px;
}

[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
}

.wrap {
  width: 100%;
  max-width: 1128px;
  margin: 0 auto;
  padding: 0 24px;
}

.field-row { align-items: start; }
.dropbox.drag-over { outline: 2px solid var(--moss); outline-offset: 2px; }
.question { margin: 1.4rem 0; }
.question > small { display: block; margin-bottom: .6rem; color: var(--muted); }

a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: var(--cinnabar); }

:focus-visible {
  outline: 3px solid var(--cinnabar);
  outline-offset: 2px;
}

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .55; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- 页首 ---------- */

.masthead {
  background: var(--ink);
  color: #f4f6f1;
  padding: 28px 0 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mark {
  position: relative;
  flex: none;
  width: 48px;
  height: 34px;
}

.mark::before,
.mark::after {
  content: "";
  position: absolute;
  top: 2px;
  width: 24px;
  height: 30px;
  background:
    linear-gradient(var(--ink-2), var(--ink-2)) 5px 11px / 13px 1.5px no-repeat,
    linear-gradient(var(--ink-2), var(--ink-2)) 5px 16px / 13px 1.5px no-repeat,
    linear-gradient(var(--ink-2), var(--ink-2)) 5px 21px / 9px 1.5px no-repeat,
    var(--paper);
  border: 2px solid #f4f6f1;
}

.mark::before {
  left: 0;
  border-radius: 10px 0 0 4px / 6px 0 0 4px;
  border-right-width: 1px;
}

.mark::after {
  right: 0;
  border-radius: 0 10px 4px 0 / 0 6px 4px 0;
  border-left-width: 1px;
  background-position: 6px 11px, 6px 16px, 6px 21px, 0 0;
}

.mark .ribbon {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 10px;
  width: 6px;
  height: 22px;
  background: var(--cinnabar);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1.2;
}

.lede {
  margin: 10px 0 0;
  max-width: 44em;
  color: #c9d6cf;
  font-size: 15px;
}

/* 模式分段选择 */

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 22px;
  padding: 6px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 16px 16px 0 0;
  border-bottom: 0;
}

.mode {
  display: grid;
  gap: 2px;
  min-height: 64px;
  padding: 12px 20px;
  text-align: left;
  background: transparent;
  color: #e9efeb;
  border: 1px solid transparent;
  border-radius: 11px;
  transition: background-color .12s, color .12s;
}

.mode:hover { background: rgba(255, 255, 255, .08); }

.mode-name {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .04em;
}

.mode-desc {
  font-size: 13.5px;
  color: #b9c8c0;
}

.mode[aria-pressed="true"] {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.mode[aria-pressed="true"] .mode-desc { color: var(--muted); }

.mode[aria-pressed="true"] .mode-name::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 10px;
  vertical-align: .25em;
  border-radius: 50%;
  background: var(--cinnabar);
}

/* ---------- 编辑台 ---------- */

main { padding: 0 0 56px; }

#workspace { margin: 0; }

#settings {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.desk {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  padding-top: 24px;
}

.sheet {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px 28px;
}

.sheet-fold::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  width: 28px;
  height: 28px;
  background: linear-gradient(225deg, var(--page) 50%, #e4e1d5 50%);
  border-bottom-left-radius: 6px;
  border-top-right-radius: var(--radius);
}

.side { position: sticky; top: 16px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 18px;
}

.section-head h2 {
  margin: 0;
  flex: none;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .05em;
}

.section-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.block + .section-head,
.block + .block { margin-top: 26px; }

.field { display: grid; gap: 6px; }
.field + .field { margin-top: 16px; }

.field-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

.field-row .field + .field { margin-top: 0; }

label, .label {
  font-weight: 600;
  font-size: 15px;
}

.opt {
  margin-left: 6px;
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input:not([type]),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  background: #fff;
  border: 1px solid #c9c7bb;
  border-radius: 8px;
  transition: border-color .12s;
}

input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(18, 58, 48, .14);
}

textarea { min-height: 88px; resize: vertical; line-height: 1.6; }

select {
  appearance: none;
  padding-right: 36px;
  background:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%) calc(100% - 18px) 50% / 6px 6px no-repeat,
    linear-gradient(-45deg, transparent 50%, var(--ink) 50%) calc(100% - 12px) 50% / 6px 6px no-repeat,
    #fff;
}

#key { font-family: var(--mono); letter-spacing: .02em; }

/* 上传区 */

.uploads {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 18px;
}

.upload { display: grid; gap: 8px; align-content: start; }

.upload-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.dropbox {
  position: relative;
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 128px;
  padding: 18px 16px;
  text-align: center;
  background:
    linear-gradient(90deg, transparent calc(50% - .5px), var(--line-soft) calc(50% - .5px), var(--line-soft) calc(50% + .5px), transparent calc(50% + .5px)),
    #fbfaf5;
  border: 1.5px dashed #b9b7a9;
  border-radius: 10px;
  transition: border-color .12s, background-color .12s;
}

.dropbox input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropbox:hover,
.dropbox:focus-within,
.dropbox.is-over,
.dropbox[data-over] {
  border-color: var(--ink);
  background-color: var(--ink-soft);
}

.dropbox:focus-within { outline: 3px solid var(--cinnabar); outline-offset: 2px; }

.drop-main {
  position: relative;
  padding: 2px 10px;
  background: #fbfaf5;
  font-weight: 700;
  font-size: 15.5px;
}

.dropbox:hover .drop-main,
.dropbox:focus-within .drop-main,
.dropbox.is-over .drop-main,
.dropbox[data-over] .drop-main { background: var(--ink-soft); }

.drop-sub {
  position: relative;
  padding: 0 8px;
  background: inherit;
  font-size: 13px;
  color: var(--muted);
}

.formats {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.formats strong { color: var(--cinnabar); font-weight: 600; }

/* 文件列表（由脚本插入） */

.file-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  counter-reset: file;
}

.file-list:empty { display: none; }

.file-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 0 6px 2px;
  border-bottom: 1px solid var(--line-soft);
  counter-increment: file;
}

#materials-list li::before {
  content: counter(file);
  flex: none;
  width: 1.6em;
  font-family: var(--serif);
  font-weight: 700;
  color: var(--cinnabar);
  text-align: right;
}

.file-list .filename {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14.5px;
}

.file-list .file-actions {
  display: flex;
  flex: none;
  gap: 4px;
}

.file-actions button {
  min-width: 36px;
  min-height: 34px;
  padding: 2px 10px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
}

.file-actions button:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--ink-soft);
}

/* 生成方式面板 */

.panel-note {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--ink-soft);
  border-radius: 8px;
  font-size: 14px;
}

.warn {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--cinnabar);
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 12px;
}

#get-key {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  font-weight: 600;
}

#get-key:not([href]) { color: var(--muted); text-decoration: none; pointer-events: none; }

#destination {
  margin: 16px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13.5px;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#destination:empty { display: none; }

.tutor {
  margin-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.tutor summary {
  display: flex;
  align-items: center;
  min-height: 46px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.tutor summary::-webkit-details-marker { display: none; }

.tutor summary::before {
  content: "";
  width: 7px;
  height: 7px;
  margin: 0 12px 0 2px;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: rotate(-45deg);
  transition: transform .12s;
}

.tutor[open] summary::before { transform: rotate(45deg); }

.tutor-body { padding: 0 0 4px 22px; font-size: 14px; }
.tutor-body p { margin: 0 0 8px; }

#key-hint:empty { display: none; }
#key-doc:not([href]) { display: none; }

#copy-help p { margin: 0 0 10px; font-size: 14.5px; }
#copy-help p:last-child { margin-bottom: 0; }

/* 提交 */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  margin-top: 24px;
  padding: 20px 28px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

#run {
  min-height: 52px;
  min-width: 220px;
  padding: 12px 28px;
  background: var(--moss);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .08em;
}

#run:hover:not(:disabled) { background: var(--moss-dark); }

#cancel, .ghost {
  min-height: 48px;
  padding: 10px 20px;
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  font-weight: 600;
}

#cancel:hover, .ghost:hover:not(:disabled) { background: var(--ink-soft); }

#status {
  flex: 1 1 240px;
  margin: 0;
  font-size: 14.5px;
  color: var(--muted);
  white-space: pre-wrap;
}

#status[data-kind="error"] {
  padding: 10px 14px;
  background: var(--cinnabar-soft);
  color: var(--cinnabar);
  border-radius: 8px;
}

/* ---------- 复制兜底 ---------- */

.output {
  margin-top: 32px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px 28px;
}

.output-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.output-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: .04em;
}

#prompt-text {
  min-height: 260px;
  font-family: var(--mono);
  font-size: 13.5px;
  background: #fbfaf5;
}

/* ---------- 复习讲义 ---------- */

#result { padding: 30px 32px 36px; }

#result .output-head {
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--ink);
}

#result .output-head h2 { font-size: 30px; }

.reader {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

#chapter-nav {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 2px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

#chapter-nav:empty { display: none; }

#chapter-nav button {
  min-height: 40px;
  padding: 7px 10px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}

#chapter-nav button:hover { background: var(--ink-soft); color: var(--ink); }

#chapter-nav button[aria-current="true"] {
  background: var(--ink-soft);
  color: var(--ink);
  font-weight: 700;
}

#chapters {
  max-width: 44em;
  font-size: 16.5px;
  line-height: 1.85;
}

.chapter {
  scroll-margin-top: 16px;
  padding-bottom: 32px;
}

.chapter + .chapter {
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.chapter h3 {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1.35;
  letter-spacing: .03em;
}

.chapter h4 {
  margin: 26px 0 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-2);
}

.chapter p { margin: 0 0 12px; }

.chapter ul, .chapter ol { margin: 0 0 14px; padding-left: 1.4em; }
.chapter li { margin: 4px 0; }
.chapter li::marker { color: var(--cinnabar); }

.chapter p,
.chapter li,
.chapter details > :not(summary) {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chapter strong { color: var(--ink); }

.chapter code {
  padding: 1px 5px;
  background: var(--ink-soft);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: .9em;
}

.chapter details {
  margin: 10px 0 18px;
  background: #fbfaf5;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.chapter summary {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--cinnabar);
  cursor: pointer;
  list-style: none;
}

.chapter summary::-webkit-details-marker { display: none; }

.chapter summary::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 12px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .12s;
}

.chapter details[open] summary::before { transform: rotate(45deg); }

.chapter details > :not(summary) {
  margin: 0;
  padding: 0 18px 14px 35px;
}

.chapter details > :not(summary) + :not(summary) { padding-top: 0; }

/* ---------- 新手帮助 ---------- */

.help {
  margin-top: 40px;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 24px;
  padding-top: 22px;
  border-top: 2px solid var(--ink);
}

.help h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: .05em;
}

.help dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
  margin: 0;
}

.help dt { font-weight: 700; margin-bottom: 4px; }
.help dd { margin: 0; font-size: 14.5px; color: var(--muted); }

.colophon {
  margin-top: 32px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 窄屏 ---------- */

@media (max-width: 880px) {
  .desk { grid-template-columns: 1fr; }
  .side { position: static; }
  .reader { grid-template-columns: 1fr; gap: 20px; }
  #chapter-nav {
    position: static;
    display: flex;
    gap: 6px;
    max-height: none;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  #chapter-nav button { flex: none; max-width: 16em; border: 1px solid var(--line); }
  .help { grid-template-columns: 1fr; gap: 12px; }
  .help dl { grid-template-columns: 1fr; gap: 14px; }
}

@media (max-width: 600px) {
  .wrap { padding: 0 14px; }
  .masthead { padding-top: 20px; }
  .brand h1 { font-size: 27px; }
  .modes { grid-template-columns: 1fr; }
  .mode { min-height: 60px; }
  .sheet, .output, #result { padding: 20px 18px 22px; }
  .field-row, .uploads { grid-template-columns: 1fr; }
  .actions { padding: 16px 18px; }
  #run, #cancel { width: 100%; }
  .file-actions button { min-width: 44px; min-height: 44px; }
  #chapters { font-size: 16px; }
  .chapter h3 { font-size: 22px; }
  .chapter details > :not(summary) { padding-left: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
