:root {
  --paper: #f3efe7;
  --surface: #fffdf9;
  --surface-2: #f8f4ec;
  --ink: #19252c;
  --muted: #7e7b72;
  --line: rgba(39, 51, 54, .12);
  --line-soft: rgba(39, 51, 54, .07);
  --blue: #244c60;
  --blue-deep: #173845;
  --red: #b85e43;
  --shadow: 0 22px 60px rgba(65, 54, 37, .08);
  --serif: "Noto Serif SC", "Songti SC", SimSun, serif;
  --sans: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(900px 620px at 4% -8%, #fffdf9 0%, rgba(255,253,249,0) 70%),
    radial-gradient(700px 520px at 96% 8%, #eaf0f2 0%, rgba(234,240,242,0) 72%),
    var(--paper);
}
button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid rgba(36, 76, 96, .42);
  outline-offset: 2px;
}
em { font-style: normal; }

.page {
  position: relative;
  width: min(1420px, calc(100% - 64px));
  margin: 0 auto;
  padding: 28px 0 48px;
}
.page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(37, 47, 49, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 47, 49, .028) 1px, transparent 1px);
  background-size: 84px 84px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.7), transparent 72%);
}

/* top */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(25,37,44,.24);
  border-radius: 50%;
  font-family: var(--serif);
  font-size: 17px;
}
.brand-copy { display: flex; flex-direction: column; gap: 1px; }
.brand-copy b { font-family: var(--serif); font-size: 20px; letter-spacing: .12em; font-weight: 600; }
.brand-copy small { color: var(--muted); font-size: 8px; letter-spacing: .28em; }

.mode-tabs {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,253,249,.74);
  box-shadow: 0 6px 18px rgba(65,54,37,.04);
}
.mode-tab {
  min-width: 80px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
  transition: background .18s ease, color .18s ease;
}
.mode-tab.is-active { background: var(--ink); color: #fffdf9; }

.top-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
}
.local-note { color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.local-note i { display: inline-block; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: #6f9c7d; }
.text-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: #5d6668;
  font-size: 11.5px;
  letter-spacing: .08em;
}
.text-btn:hover { color: var(--blue); }

/* workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(430px, 500px);
  gap: 24px;
  align-items: start;
}
.composer {
  position: relative;
  min-height: calc(100vh - 142px);
  padding: 32px 36px 28px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255,253,249,.92);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #9a6f3d;
  font-size: 9px;
  letter-spacing: .22em;
  text-transform: uppercase;
}
.eyebrow span {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid rgba(154,111,61,.30);
  border-radius: 50%;
  font-size: 8px;
  letter-spacing: 0;
}
h1 {
  margin: 22px 0 12px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(30px, 3.2vw, 48px);
  line-height: 1.26;
  letter-spacing: .02em;
}
h1 em { color: var(--blue); }
.lede {
  max-width: 560px;
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.label-row label, .field > label, .field-label {
  color: #5f6461;
  font-size: 11px;
  letter-spacing: .06em;
}
.label-row span { color: #aaa49a; font-size: 10px; }
textarea, input[type="text"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbf8f2;
  color: var(--ink);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
textarea { resize: vertical; line-height: 1.75; }
textarea::placeholder, input::placeholder { color: #aaa79e; }
textarea:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: rgba(36,76,96,.48);
  background: #fffdf9;
  box-shadow: 0 0 0 4px rgba(36,76,96,.075);
}
#promptInput {
  display: block;
  min-height: 156px;
  padding: 16px 17px;
  font-size: 14px;
}
.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}
.examples button {
  height: 29px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf9;
  color: #6d665b;
  font-size: 10.5px;
}
.examples button:hover { border-color: rgba(36,76,96,.30); color: var(--blue); background: #f6fafb; }

.context-grid {
  display: grid;
  grid-template-columns: 1.4fr .8fr .8fr;
  gap: 12px;
  margin-top: 22px;
}
.field { min-width: 0; }
.field > label { display: block; margin-bottom: 6px; }
.field select { height: 40px; padding: 0 10px; font-size: 12px; }
.grade-field { grid-row: span 2; }
.stage-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  margin-bottom: 7px;
}
.stage-row button {
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #8a8478;
  font-size: 10.5px;
}
.stage-row button.is-active { background: var(--ink); color: #fffdf9; }
#gradeSelect { height: 38px; }

.advanced {
  margin-top: 18px;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
}
.advanced summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #77736a;
  font-size: 11px;
  cursor: pointer;
  list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::after { content: "＋"; color: #9a958a; }
.advanced[open] summary::after { content: "－"; }
.advanced summary span { margin-left: auto; margin-right: 10px; color: #b0aa9f; font-size: 9px; }
.advanced-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-top: 13px;
}
.field-wide { grid-column: 1 / -1; }
#materialInput { min-height: 74px; padding: 10px 12px; font-size: 12px; }

.composer-actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding-top: 24px;
}
.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  height: 50px;
  border: 0;
  border-radius: 13px;
  background: var(--ink);
  color: #fffdf9;
  font-size: 13px;
  letter-spacing: .08em;
  box-shadow: 0 12px 26px rgba(25,37,44,.14);
  transition: transform .16s ease, background .16s ease;
}
.primary-btn:hover { background: var(--blue-deep); transform: translateY(-1px); }
.primary-btn:disabled { opacity: .55; cursor: default; transform: none; }
.primary-btn i { font-style: normal; font-size: 18px; line-height: 1; }
.cancel-btn {
  width: 110px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fffdf9;
  color: #7d7568;
  font-size: 11px;
}
.status {
  min-height: 17px;
  margin: 10px 0 0;
  color: #8a8175;
  font-size: 10.5px;
  letter-spacing: .02em;
}
.status.is-busy { color: var(--blue); }

/* paper */
.paper-panel {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 142px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(238,233,223,.82);
}
.paper-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 13px;
}
.quiet-btn {
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,253,249,.72);
  color: #655f55;
  font-size: 10.5px;
}
.quiet-btn:hover { background: #fffdf9; color: var(--blue); }
.paper-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 4px;
}
.a4 {
  width: min(100%, 440px);
  min-height: 610px;
  padding: 40px 38px 30px;
  display: flex;
  flex-direction: column;
  background: #fffdf9;
  color: #24251f;
  box-shadow: 0 18px 46px rgba(65,54,37,.12);
}
.paper-head { border-bottom: 1px solid rgba(53,48,37,.18); padding-bottom: 18px; }
.paper-kicker { color: #9d875d; font-size: 8px; letter-spacing: .22em; }
.paper-head h2 { margin: 13px 0 7px; font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: .06em; }
.paper-meta { margin: 0; color: #8a8171; font-size: 9px; line-height: 1.7; }
.paper-body { flex: 1; padding-top: 22px; color: #3d3b34; font-size: 11px; line-height: 1.75; }
.paper-empty { margin: 70px 0 0; color: #a79d8c; font-family: var(--serif); font-size: 13px; line-height: 2; text-align: center; }
.paper-sec { margin: 0 0 18px; }
.paper-sec h3 {
  margin: 0 0 5px;
  color: #2a3e48;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
}
.paper-sec p { margin: 0 0 4px; white-space: pre-wrap; }
.paper-sec ul { margin: 0; padding-left: 16px; }
.paper-sec li { margin: 2px 0; }
.paper-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding-top: 13px;
  border-top: 1px solid rgba(53,48,37,.14);
  color: #958974;
  font-size: 8px;
  letter-spacing: .06em;
}
.paper-foot i { width: 2px; height: 2px; border-radius: 50%; background: #bba98b; }
.paper-under {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 3px 1px;
  color: #8e8577;
  font-size: 9px;
  letter-spacing: .05em;
}
.paper-under button { border: 0; background: transparent; color: #6d5e46; font-size: 9px; }

/* mobile tabs */
.mobile-tabs {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 60;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,253,249,.91);
  box-shadow: 0 18px 40px rgba(55,45,30,.14);
  backdrop-filter: blur(18px) saturate(130%);
}
.mobile-tabs button {
  height: 44px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #837c70;
  font-size: 11px;
}
.mobile-tabs button.is-active { background: var(--ink); color: #fffdf9; }

/* drawer */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(24,29,29,.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  z-index: 81;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: min(400px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(35,29,19,.22);
  transform: translateX(calc(100% + 26px));
  transition: transform .26s cubic-bezier(.2,.8,.2,1);
}
.drawer.is-open { transform: translateX(0); }
.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.drawer-head h2 { margin: 8px 0 0; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: #6f685c;
  font-size: 18px;
  line-height: 1;
}
.drawer-body { overflow: auto; padding: 10px 20px 22px; }
.history-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.history-item:hover .history-title { color: var(--blue); }
.history-meta { display: flex; justify-content: space-between; gap: 10px; color: #a39a8b; font-size: 9px; }
.history-title { margin: 6px 0 4px; color: #37352e; font-size: 12.5px; line-height: 1.6; }
.history-empty { padding: 34px 0; color: #a39a8b; font-size: 12px; text-align: center; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24,29,29,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.modal.is-open { opacity: 1; pointer-events: auto; }
.modal-card {
  width: min(520px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(35,29,19,.24);
}
.modal-head { display: flex; justify-content: space-between; gap: 16px; }
.modal-head h2 { margin: 8px 0 0; font-family: var(--serif); font-size: 23px; font-weight: 600; }
.modal-note { margin: 15px 0 10px; color: #837b70; font-size: 11px; line-height: 1.75; }
.code-area { width: 100%; min-height: 130px; padding: 11px; font-family: Consolas, monospace; font-size: 10px; resize: vertical; }
.modal-actions { display: flex; gap: 7px; margin-top: 11px; flex-wrap: wrap; }
.primary-small {
  height: 32px;
  padding: 0 13px;
  border: 0;
  border-radius: 9px;
  background: var(--ink);
  color: #fffdf9;
  font-size: 10.5px;
}
.toast {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 10px);
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(25,37,44,.92);
  color: #fffdf9;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .page { width: min(100% - 36px, 1000px); }
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); gap: 18px; }
  .composer { padding: 26px; }
  .context-grid { grid-template-columns: 1fr 1fr; }
  .grade-field { grid-column: 1 / -1; grid-row: auto; }
}

@media (max-width: 860px) {
  .page { width: calc(100% - 24px); padding: 16px 0 92px; }
  .topbar { grid-template-columns: 1fr auto; margin-bottom: 16px; gap: 12px; }
  .mode-tabs { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; display: grid; grid-template-columns: 1fr 1fr; }
  .mode-tab { min-width: 0; }
  .top-actions { gap: 10px; }
  .local-note { display: none; }
  .workspace { display: block; }
  .composer { min-height: 0; padding: 22px 17px 18px; border-radius: 22px; }
  h1 { font-size: 32px; margin-top: 18px; }
  .lede { font-size: 12px; margin-bottom: 22px; }
  #promptInput { min-height: 132px; font-size: 13px; }
  .context-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grade-field { grid-column: 1 / -1; }
  .composer-actions { margin-top: 18px; padding-top: 16px; }
  .paper-panel {
    position: fixed;
    z-index: 70;
    inset: 8px 8px 72px;
    min-height: 0;
    border-radius: 22px;
    transform: translateY(calc(100% + 90px));
    transition: transform .26s cubic-bezier(.2,.8,.2,1);
    overflow: hidden;
  }
  body.paper-open .paper-panel { transform: translateY(0); }
  .paper-stage { padding: 2px; align-items: flex-start; }
  .a4 { width: 100%; min-height: 0; padding: 28px 23px 22px; }
  .paper-head h2 { font-size: 23px; }
  .paper-body { font-size: 10.5px; }
  .paper-under { padding-bottom: 4px; }
  .mobile-tabs { display: grid; }
  .paper-toolbar .quiet-btn { display: none; }
}
@media (max-width: 420px) {
  .brand-copy small { display: none; }
  .top-actions .text-btn { font-size: 10.5px; }
  h1 { font-size: 28px; }
  .context-grid { grid-template-columns: 1fr; }
  .grade-field { grid-column: auto; }
  .advanced-body { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
}

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff !important; }
  .page { width: 100%; padding: 0; }
  .topbar, .mobile-tabs, .composer, .paper-toolbar, .paper-under, .drawer, .scrim, .modal, .toast { display: none !important; }
  .workspace { display: block; }
  .paper-panel { position: static; min-height: 0; padding: 0; border: 0; border-radius: 0; background: #fff; box-shadow: none; }
  .paper-stage { display: block; overflow: visible; padding: 0; }
  .a4 { width: 210mm; min-height: 297mm; padding: 20mm 18mm; box-shadow: none; }
}

.preview-tag {
  padding: 3px 7px;
  border: 1px solid rgba(184,94,67,.22);
  border-radius: 999px;
  color: #a95b42;
  font-size: 9px;
  letter-spacing: .08em;
}
@media (max-width: 520px) { .preview-tag { display: none; } }
