:root {
  --paper: #f7f3ea;
  --paper-2: #f1ebdd;
  --surface: #fffdf8;
  --surface-2: #fbf7ee;
  --ink: #20302a;
  --ink-soft: #46564e;
  --muted: #7b857e;
  --line: #e3dccd;
  --line-strong: #d5cbb8;
  --jade: #1f6f5c;
  --jade-deep: #175646;
  --jade-soft: #e4f1eb;
  --gold: #b98634;
  --gold-soft: #f6ecd7;
  --danger: #a83b32;
  --danger-soft: #f8e7e4;
  --ok: #2f7a4f;
  --ok-soft: #e6f2ea;
  --warn: #a66a1f;
  --warn-soft: #f8eeda;
  --shadow: 0 10px 30px rgba(46, 55, 47, 0.08);
  --shadow-soft: 0 4px 16px rgba(46, 55, 47, 0.06);
  --radius: 20px;
  --radius-sm: 14px;
  --topbar: 62px;
  --tabbar: 66px;
  --serif: "Songti SC", "Noto Serif SC", "STSong", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(31, 111, 92, 0.09), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(185, 134, 52, 0.08), transparent 55%),
    var(--paper);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: radial-gradient(rgba(64, 61, 48, 0.12) 0.6px, transparent 0.6px);
  background-size: 5px 5px;
  z-index: 0;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--jade); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.hidden, [hidden] { display: none !important; }

/* ---------- shell ---------- */
.app-shell {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 18px);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--topbar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink);
  text-align: left;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--jade), var(--jade-deep));
  color: #fdfaf1;
  font-family: var(--serif);
  font-size: 21px;
  box-shadow: 0 5px 14px rgba(31, 111, 92, 0.28);
}
.brand-text {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.05;
}
.brand-text small {
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 500;
  margin-top: 3px;
}
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  transition: background 0.18s ease, transform 0.18s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 21px; height: 21px; }

main { padding: 0 18px; }
.screen { display: none; animation: screen-in 0.32s ease both; }
.screen.active { display: block; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(680px, 100%);
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 18px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}
.tabbar button {
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
}
.tabbar button span { font-size: 20px; line-height: 1; }
.tabbar button em { font-style: normal; }
.tabbar button.active { color: var(--jade); font-weight: 600; }

/* ---------- home ---------- */
.hero { padding: 30px 4px 22px; }
.hero-kicker {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.28em;
  color: var(--jade);
  font-weight: 600;
}
.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(32px, 9vw, 44px);
  line-height: 1.24;
  letter-spacing: 0.02em;
}
.hero h1 em {
  font-style: normal;
  color: var(--jade);
  padding: 0 2px;
  background-image: linear-gradient(transparent 74%, rgba(185, 134, 52, 0.24) 74%);
  background-repeat: no-repeat;
}
.hero-sub {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.12em;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.upload-card {
  position: relative;
  aspect-ratio: 4 / 4.6;
  min-height: 200px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--line-strong);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
.upload-card:active { transform: scale(0.99); }
.upload-card.has-image { border-style: solid; border-color: var(--jade); }
.upload-card.dragover { border-color: var(--jade); background: var(--jade-soft); }
.upload-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
}
.upload-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 17px;
  background: var(--jade-soft);
  color: var(--jade);
  margin-bottom: 2px;
}
.upload-icon.pencil { background: var(--gold-soft); color: var(--gold); }
.upload-icon svg { width: 26px; height: 26px; }
.upload-title { font-family: var(--serif); font-size: 17px; font-weight: 700; }
.upload-title i {
  font-family: var(--sans);
  font-style: normal;
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 3px;
}
.upload-hint { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.upload-actions { display: flex; gap: 6px; margin-top: 7px; }
.upload-actions button,
.upload-actions .upload-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 11px;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.upload-actions button:first-child,
.upload-actions .upload-action:first-child {
  background: var(--jade-soft);
  border-color: transparent;
  color: var(--jade-deep);
  font-weight: 600;
}
.upload-preview { position: absolute; inset: 0; }
.upload-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 45%, rgba(12, 24, 18, 0.62));
}
.preview-actions {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 8px;
}
.preview-actions button {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 8px 0;
  font-size: 12px;
  background: rgba(255, 253, 248, 0.92);
  color: var(--ink);
  font-weight: 600;
}
.preview-actions button + button { background: rgba(255, 253, 248, 0.2); color: #fff; }

.field-group { margin: 20px 0 16px; }
.field-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 8px;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid var(--line);
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 9px 4px;
  font-size: 13px;
  color: var(--ink-soft);
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.segmented button.active {
  background: var(--surface);
  color: var(--jade-deep);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(46, 55, 47, 0.09);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
.btn:active { transform: scale(0.985); }
.btn.primary {
  background: linear-gradient(145deg, var(--jade), var(--jade-deep));
  color: #fdfaf1;
  box-shadow: 0 8px 20px rgba(31, 111, 92, 0.24);
}
.btn.primary:disabled { opacity: 0.45; box-shadow: none; }
.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-soft); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.big { padding: 16px 20px; font-size: 16px; border-radius: 16px; }
.btn.small { padding: 8px 13px; font-size: 12.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn-arrow { font-size: 18px; line-height: 1; }
.privacy-note {
  margin: 12px 4px 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}

.recent-section { margin-top: 28px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}
.section-head.small { margin: 22px 0 10px; }
.section-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: 0.02em;
}
.section-head .muted { font-size: 11px; color: var(--muted); }
.text-btn {
  border: 0;
  background: none;
  color: var(--jade);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 2px;
}
.text-btn.danger { color: var(--danger); }
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
}
.recent-topic { font-size: 13.5px; font-weight: 600; }
.recent-meta { font-size: 11px; color: var(--muted); }

.tips-card {
  display: flex;
  gap: 12px;
  margin: 26px 0 4px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--jade-soft), color-mix(in srgb, var(--gold-soft) 60%, var(--jade-soft)));
  color: var(--jade-deep);
}
.tips-icon { font-size: 20px; line-height: 1.2; opacity: 0.8; }
.tips-card strong { display: block; font-size: 13px; margin-bottom: 4px; }
.tips-card p { margin: 0; font-size: 12px; line-height: 1.65; color: color-mix(in srgb, var(--jade-deep) 78%, white); }

/* ---------- result ---------- */
#screen-result { padding-bottom: 12px; }
.result-toolbar {
  position: sticky;
  top: calc(var(--topbar) + env(safe-area-inset-top));
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -18px;
  padding: 6px 12px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.toolbar-title {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.toolbar-actions { display: flex; }
.result-head { padding: 18px 2px 4px; }
.result-eyebrow { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  color: var(--ink-soft);
}
.badge.course.prob { background: var(--jade-soft); color: var(--jade-deep); }
.badge.course.calc { background: var(--gold-soft); color: #7d5718; }
.badge.course.other { background: var(--surface-2); color: var(--ink-soft); }
.topic { font-size: 11.5px; color: var(--muted); }
.result-title {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: clamp(22px, 6.2vw, 28px);
  line-height: 1.55;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.result-title p { margin: 0; }
.meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}
.difficulty { display: inline-flex; gap: 3px; align-items: center; }
.difficulty i { width: 5px; height: 5px; border-radius: 50%; background: var(--line-strong); }
.difficulty i.on { background: var(--gold); }
.starred { color: var(--gold); font-size: 11px; }

.tabs {
  position: sticky;
  top: calc(var(--topbar) + env(safe-area-inset-top) + 54px);
  z-index: 24;
  display: flex;
  gap: 4px;
  margin: 14px -18px 0;
  padding: 0 14px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  background: linear-gradient(180deg, var(--paper) 70%, transparent);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.tab.active {
  background: var(--surface);
  color: var(--jade-deep);
  font-weight: 600;
  box-shadow: var(--shadow-soft);
}
.tab-count {
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--jade-soft);
  color: var(--jade-deep);
  font-size: 10px;
  display: inline-grid;
  place-items: center;
}
.panel { display: none; padding-top: 4px; }
.panel.active { display: block; }

.idea-card {
  margin: 8px 0 6px;
  padding: 17px 18px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--jade-deep), #24806a);
  color: #f4fbf7;
  box-shadow: 0 12px 26px rgba(23, 86, 70, 0.22);
  position: relative;
  overflow: hidden;
}
.idea-card::after {
  content: "“";
  position: absolute;
  right: 12px;
  top: -18px;
  font-family: var(--serif);
  font-size: 100px;
  opacity: 0.13;
  line-height: 1;
}
.idea-label {
  font-size: 10px;
  letter-spacing: 0.24em;
  opacity: 0.72;
  margin-bottom: 7px;
}
.idea-card .idea-text {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
}
.idea-card .idea-text p { margin: 0; }
.idea-card .katex { color: inherit; }

.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; gap: 13px; position: relative; padding-bottom: 22px; }
.step:last-child { padding-bottom: 4px; }
.step::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 30px;
  bottom: -2px;
  width: 1px;
  background: var(--line);
}
.step:last-child::before { display: none; }
.step-index {
  flex: 0 0 27px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--jade-soft);
  color: var(--jade-deep);
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
  z-index: 1;
}
.step-body { min-width: 0; flex: 1; }
.step-title { margin: 2px 0 7px; font-size: 14.5px; font-weight: 700; letter-spacing: 0.01em; }
.step-content { font-size: 14px; line-height: 1.82; color: var(--ink-soft); }
.step-content p { margin: 0 0 8px; }
.step-content p:last-child { margin-bottom: 0; }
.step-why { margin-top: 9px; }
.step-why summary {
  font-size: 11.5px;
  color: var(--jade);
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.step-why summary::-webkit-details-marker { display: none; }
.step-why summary::before { content: "↳"; opacity: 0.7; }
.step-why .md {
  margin-top: 7px;
  padding: 10px 12px;
  border-left: 2px solid var(--jade);
  background: var(--jade-soft);
  border-radius: 0 10px 10px 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.answer-card {
  position: relative;
  margin: 20px 0 14px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}
.answer-label {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 8px;
}
.answer-text { font-size: 16px; line-height: 1.7; }
.answer-text p { margin: 0; }
.copy-answer {
  position: absolute;
  right: 12px;
  bottom: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 10px;
}

.check-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  padding: 12px 14px;
  margin: 12px 0 4px;
}
.check-box summary { font-size: 12px; color: var(--muted); cursor: pointer; }
.check-box .md { margin-top: 8px; font-size: 12.5px; line-height: 1.75; color: var(--ink-soft); }

.knowledge-grid { display: grid; gap: 9px; }
.knowledge-card {
  padding: 13px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.knowledge-name { font-size: 13px; font-weight: 700; margin-bottom: 5px; }
.knowledge-formula { font-size: 13px; color: var(--jade-deep); }
.knowledge-reminder { margin-top: 6px; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.knowledge-reminder p { margin: 0; }

.pitfall-list { display: flex; flex-direction: column; gap: 8px; }
.pitfall {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
}
.pitfall summary {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 12px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.pitfall summary::-webkit-details-marker { display: none; }
.pitfall-mark {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  margin-top: 1px;
}
.pitfall-body { padding: 0 14px 13px 41px; font-size: 12px; line-height: 1.7; color: var(--ink-soft); }
.pitfall-body p { margin: 0 0 6px; }
.pitfall-body p:last-child { margin: 0; }

.callout {
  margin: 12px 0;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.7;
  border: 1px solid var(--line);
}
.callout.soft { background: var(--surface-2); color: var(--ink-soft); }
.callout.warn { background: var(--warn-soft); border-color: transparent; color: #6b4a1a; }
.callout.warn strong { color: #5b3e12; }
.callout .btn { margin-top: 10px; }
.review-banner { margin-top: 12px; }
.review-banner ul { margin: 7px 0; padding-left: 1.15em; }
.review-banner li { margin: 3px 0; }
.review-answer { margin: 7px 0 0; font-weight: 700; }
.review-answer .md { display: inline; font-weight: 600; }
.error-detail { margin-top: 10px; font-size: 11px; }
.error-detail summary { cursor: pointer; color: var(--muted); }
.error-detail pre {
  white-space: pre-wrap;
  word-break: break-all;
  background: rgba(255, 255, 255, 0.55);
  padding: 8px 9px;
  border-radius: 8px;
  font-size: 10px;
  line-height: 1.55;
}
.error-detail .btn { margin-top: 7px; }

/* variants */
.variants-intro h2 { margin: 14px 0 5px; font-family: var(--serif); font-size: 20px; }
.variants-intro p { margin: 0 0 16px; font-size: 12px; color: var(--muted); }
.variant-list { display: flex; flex-direction: column; gap: 12px; }
.variant-card {
  padding: 15px 15px 13px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}
.variant-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.level-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--jade-soft);
  color: var(--jade-deep);
}
.level-badge.up { background: var(--gold-soft); color: #7d5718; }
.level-badge.mix { background: #eae6f6; color: #57458c; }
.variant-no { font-size: 10px; color: var(--muted); letter-spacing: 0.12em; }
.variant-question { font-size: 14px; line-height: 1.8; }
.variant-question p { margin: 0; }
.variant-actions { display: flex; gap: 8px; margin-top: 12px; }
.chip-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--ink-soft);
}
.chip-btn.primary { background: var(--jade-soft); border-color: transparent; color: var(--jade-deep); font-weight: 600; }
.variant-fold {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 12.5px;
  line-height: 1.75;
}
.variant-fold.open { display: block; animation: fold-in 0.2s ease; }
@keyframes fold-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.fold-label { font-size: 9.5px; letter-spacing: 0.18em; color: var(--muted); margin-bottom: 4px; }
.variant-sketch { margin-top: 10px; }
.variant-sketch summary { font-size: 11px; color: var(--muted); cursor: pointer; }
.variant-sketch .md { margin-top: 7px; font-size: 12.5px; line-height: 1.75; color: var(--ink-soft); }

/* grading */
.grade-top { display: flex; gap: 17px; align-items: center; padding: 14px 0 4px; }
.score-ring {
  position: relative;
  flex: 0 0 88px;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: conic-gradient(var(--jade) calc(var(--score) * 1%), var(--line) 0);
  display: grid;
  place-items: center;
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--paper);
}
.score-ring span {
  position: relative;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  color: var(--jade-deep);
  line-height: 1;
}
.score-ring small { position: absolute; bottom: 17px; font-size: 10px; color: var(--muted); }
.grade-summary { min-width: 0; }
.section-kicker {
  font-size: 9.5px;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 5px;
}
.grade-summary .md { font-size: 13px; line-height: 1.7; }
.grade-summary .md p { margin: 0; }

.first-error {
  margin: 17px 0;
  padding: 15px;
  border-radius: 15px;
  background: var(--danger-soft);
  color: #5f241f;
  font-size: 12.5px;
  line-height: 1.7;
}
.first-error-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.55);
  color: var(--danger);
}
.first-error .muted { font-size: 10.5px; color: #8b4a44; }
.first-error-what { font-weight: 700; font-size: 13px; margin: 0 0 7px; }
.first-error-what p { margin: 0; }
.first-error p { margin: 0 0 7px; }
.first-error p:last-child { margin-bottom: 0; }
.fix-box {
  background: rgba(255, 255, 255, 0.55);
  border-radius: 9px;
  padding: 9px 11px;
  margin-top: 4px;
  font-size: 12.5px;
}
.grading-steps { display: flex; flex-direction: column; gap: 9px; }
.grading-step {
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 13px;
  border-left: 3px solid var(--line-strong);
}
.grading-step.ok { border-left-color: var(--ok); }
.grading-step.partial { border-left-color: var(--warn); }
.grading-step.bad { border-left-color: var(--danger); }
.grading-step.skip { border-left-color: var(--muted); }
.grading-step-head { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.grading-step.ok .status-dot { background: var(--ok); }
.grading-step.partial .status-dot { background: var(--warn); }
.grading-step.bad .status-dot { background: var(--danger); }
.grading-step-no { font-size: 10px; letter-spacing: 0.12em; color: var(--muted); }
.status-label { margin-left: auto; font-size: 10px; font-weight: 700; }
.grading-step.ok .status-label { color: var(--ok); }
.grading-step.partial .status-label { color: var(--warn); }
.grading-step.bad .status-label { color: var(--danger); }
.grading-student { font-size: 13px; line-height: 1.7; color: var(--ink); }
.grading-student p { margin: 0; }
.grading-comment { margin-top: 5px; font-size: 11.5px; line-height: 1.65; color: var(--muted); }
.corrected {
  padding: 15px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.85;
}
.encourage {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  padding: 14px;
  border-radius: 14px;
  background: var(--gold-soft);
  color: #6b4a1a;
}
.encourage-icon { flex: 0 0 22px; font-size: 16px; }
.encourage .md { font-size: 12.5px; line-height: 1.75; }
.encourage .md p { margin: 0; }
.grade-actions { margin-top: 14px; }
.section-head.small h2 { font-size: 16px; }

/* source */
.source-block {
  margin: 14px 0;
  padding: 15px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.8;
}
.source-block .section-kicker { margin-bottom: 7px; }

/* chat */
.chat-section { margin-top: 28px; padding-top: 4px; border-top: 1px dashed var(--line-strong); }
.chat-messages { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.chat-hint { margin: 4px 0 12px; font-size: 12px; color: var(--muted); text-align: center; }
.chat-msg { display: flex; gap: 8px; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.75;
}
.chat-msg.user .chat-bubble {
  background: var(--jade);
  color: #f7fcf9;
  border-color: transparent;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble { border-bottom-left-radius: 4px; }
.chat-avatar {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--jade-deep);
  color: #f7fcf9;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 12px;
  margin-top: 2px;
}
.chat-bubble p:first-child { margin-top: 0; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
  position: sticky;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 6px);
  z-index: 20;
  padding: 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}
.chat-form input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 11px; outline: none; font-size: 13px; }
.chat-form button {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: var(--jade);
  color: #fff;
  font-size: 18px;
  display: grid;
  place-items: center;
}
.chat-form button:disabled { opacity: 0.4; }
.typing { display: inline-flex; gap: 3px; align-items: center; height: 18px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: typing 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }

/* ---------- history ---------- */
.page-head { padding: 30px 2px 18px; }
.page-head h1 { margin: 0; font-family: var(--serif); font-size: 32px; letter-spacing: 0.02em; }
.page-head p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.search-bar svg { flex: 0 0 18px; width: 18px; height: 18px; color: var(--muted); }
.search-bar input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 12px 0; font-size: 13px; }
.filter-row { display: flex; gap: 7px; overflow-x: auto; padding: 13px 0 15px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 11.5px;
  color: var(--ink-soft);
}
.chip.active { background: var(--jade); border-color: var(--jade); color: #fff; }
.history-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.history-card {
  position: relative;
  display: flex;
  gap: 10px;
  padding: 14px 14px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}
.history-main { flex: 1; min-width: 0; }
.history-top { display: flex; align-items: center; gap: 7px; }
.history-topic { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-plain {
  margin: 7px 0 8px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-meta { display: flex; align-items: center; gap: 9px; font-size: 10px; color: var(--muted); }
.mini-score { color: var(--jade); font-weight: 700; }
.history-star {
  align-self: flex-start;
  border: 0;
  background: transparent;
  color: var(--gold);
  font-size: 18px;
  line-height: 1;
  padding: 2px;
}
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon { font-size: 34px; color: var(--line-strong); margin-bottom: 10px; }
.empty-state h3 { margin: 0 0 7px; font-family: var(--serif); font-size: 18px; color: var(--ink-soft); }
.empty-state p { margin: 0; font-size: 12px; line-height: 1.7; }

/* ---------- settings ---------- */
.settings-card {
  margin-bottom: 13px;
  padding: 17px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}
.settings-card h2 { margin: 0; font-family: var(--serif); font-size: 17px; }
.settings-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.status-pill {
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.status-pill.ok { background: var(--ok-soft); color: var(--ok); }
.status-pill.bad { background: var(--danger-soft); color: var(--danger); }
.settings-card .field-label { margin-top: 12px; }
.settings-card input, .settings-card select, .modal-card textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 13px;
  outline: none;
}
.settings-card input:focus, .settings-card select:focus, .modal-card textarea:focus {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-soft);
}
.input-with-btn { display: flex; gap: 7px; align-items: center; }
.input-with-btn input { flex: 1; min-width: 0; }
.settings-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.field-hint { margin: 9px 0 0; font-size: 10.5px; color: var(--muted); line-height: 1.6; }
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 0 4px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.check-row input { width: auto; margin: 2px 0 0; accent-color: var(--jade); }
.check-row small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.settings-card.advanced summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}
.settings-card.advanced summary::-webkit-details-marker { display: none; }
.settings-card.advanced summary small { font-size: 10px; color: var(--muted); }
.settings-card.about p { margin: 8px 0 0; font-size: 12px; line-height: 1.7; color: var(--ink-soft); }
.settings-card.about p.muted { color: var(--muted); font-size: 10.5px; }

/* ---------- loading ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.loading-card {
  width: min(360px, 100%);
  padding: 28px 24px 20px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(34, 47, 39, 0.16);
  text-align: center;
}
.orb { position: relative; width: 66px; height: 66px; margin: 0 auto 16px; }
.orb span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--jade);
  opacity: 0;
  animation: orb 2.6s ease-out infinite;
}
.orb span:nth-child(2) { animation-delay: 0.55s; }
.orb span:nth-child(3) { animation-delay: 1.1s; }
.orb::after {
  content: "题";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: var(--jade);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 19px;
}
@keyframes orb {
  0% { transform: scale(0.55); opacity: 0.85; }
  100% { transform: scale(1.35); opacity: 0; }
}
.loading-card h2 { margin: 0; font-family: var(--serif); font-size: 21px; }
.loading-card > p { margin: 7px 0 17px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.stage-list { display: flex; flex-direction: column; gap: 7px; text-align: left; }
.stage {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--muted);
  padding: 5px 0;
  transition: color 0.2s ease;
}
.stage i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.stage.active { color: var(--ink); font-weight: 600; }
.stage.active i { background: var(--jade); box-shadow: 0 0 0 4px var(--jade-soft); }
.stage.done { color: var(--jade); }
.stage.done i { background: var(--jade); }
.loading-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 17px; font-size: 11px; color: var(--muted); }
.loading-tip { margin: 13px 0 0 !important; font-size: 10px !important; color: var(--muted); }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: end center;
  padding: 18px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 30, 24, 0.45); backdrop-filter: blur(3px); }
.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: 88dvh;
  overflow: auto;
  padding: 24px 22px calc(20px + env(safe-area-inset-bottom));
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(20, 30, 24, 0.3);
  animation: modal-in 0.28s ease both;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.onboarding-card { text-align: left; }
.onboard-mark {
  width: 50px;
  height: 50px;
  border-radius: 15px;
  background: var(--jade);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 26px;
  margin-bottom: 15px;
}
.modal-card h2 { margin: 0; font-family: var(--serif); font-size: 23px; }
.modal-lede { margin: 8px 0 18px; font-size: 12px; line-height: 1.7; color: var(--muted); }
.modal-card textarea { resize: vertical; min-height: 76px; font-family: var(--mono); font-size: 12px; }
.modal-card .settings-actions { margin-top: 13px; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 14px; }
.onboard-help { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); font-size: 11px; color: var(--muted); line-height: 1.65; }
.onboard-help strong { color: var(--ink-soft); }
.onboard-help p { margin: 4px 0 0; }
.regrade-drop {
  position: relative;
  height: 210px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
}
.regrade-drop img { width: 100%; height: 100%; object-fit: cover; }
.regrade-drop > div { color: var(--muted); font-size: 12px; }
.regrade-drop > div span { font-size: 30px; display: block; margin-bottom: 6px; }
.regrade-drop p { margin: 0; }

/* ---------- crop ---------- */
.crop-modal { z-index: 95; }
.crop-card {
  width: min(720px, 100%);
  padding: 15px 15px calc(14px + env(safe-area-inset-bottom));
  max-height: 94dvh;
}
.crop-head h2 { margin: 0; font-family: var(--serif); font-size: 20px; }
.crop-head p { margin: 4px 0 11px; font-size: 11px; color: var(--muted); }
.crop-stage {
  position: relative;
  height: 56dvh;
  background: #101613;
  border-radius: 14px;
  overflow: hidden;
}
.crop-stage img { display: block; }
.crop-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
@media (max-width: 680px) {
  .crop-stage { height: 52dvh; }
  .crop-actions .btn { flex: 1; padding: 10px 8px; font-size: 12px; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(10px);
  z-index: 120;
  max-width: min(88vw, 420px);
  padding: 10px 15px;
  border-radius: 999px;
  background: rgba(26, 39, 32, 0.92);
  color: #fdfaf1;
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(120, 40, 32, 0.94); }

/* ---------- math / markdown ---------- */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 6px 0 9px; padding-left: 1.25em; }
.md li { margin: 3px 0; }
.md strong { font-weight: 700; }
.md blockquote {
  margin: 9px 0;
  padding: 7px 12px;
  border-left: 2px solid var(--jade);
  background: var(--jade-soft);
  color: var(--ink-soft);
  border-radius: 0 8px 8px 0;
}
.md code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}
.md pre { overflow-x: auto; padding: 10px; background: var(--surface-2); border-radius: 10px; }
.katex { font-size: 1.02em; }
.katex-display { margin: 9px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* ---------- desktop ---------- */
@media (min-width: 720px) {
  main { padding: 0 28px; }
  .app-shell { border-left: 1px solid color-mix(in srgb, var(--line) 40%, transparent); border-right: 1px solid color-mix(in srgb, var(--line) 40%, transparent); background: color-mix(in srgb, var(--paper) 55%, transparent); }
  .upload-card { aspect-ratio: 4 / 3.4; }
  .topbar { padding-left: 28px; padding-right: 28px; }
  .tabs, .result-toolbar { margin-left: -28px; margin-right: -28px; }
  .modal { place-items: center; }
  .modal-card { animation-name: modal-pop; }
  @keyframes modal-pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
}

@media (max-width: 380px) {
  .upload-card { aspect-ratio: auto; min-height: 206px; }
  .upload-icon { width: 44px; height: 44px; }
  .upload-icon svg { width: 23px; height: 23px; }
  .upload-title { font-size: 15px; }
  .upload-hint { font-size: 10.5px; }
  .result-title { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

html[data-theme="dark"] {
  --paper: #151b18;
  --paper-2: #1b2320;
  --surface: #202a26;
  --surface-2: #26322d;
  --ink: #ecf2ed;
  --ink-soft: #c3cec7;
  --muted: #8f9c94;
  --line: #334039;
  --line-strong: #435148;
  --jade: #58b49a;
  --jade-deep: #2f7d68;
  --jade-soft: #203a32;
  --gold: #d4a557;
  --gold-soft: #382f1f;
  --danger: #e08378;
  --danger-soft: #3a2522;
  --ok: #7bc79b;
  --ok-soft: #1f3528;
  --warn: #e0ad63;
  --warn-soft: #3a2f1c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.22);
}
html[data-theme="dark"] body::before { opacity: 0.18; }
html[data-theme="dark"] .brand-mark { color: #10201a; }
html[data-theme="dark"] .idea-card { color: #f2fbf7; }
html[data-theme="dark"] .answer-card, html[data-theme="dark"] .settings-card, html[data-theme="dark"] .history-card, html[data-theme="dark"] .variant-card, html[data-theme="dark"] .knowledge-card, html[data-theme="dark"] .pitfall, html[data-theme="dark"] .grading-step, html[data-theme="dark"] .source-block, html[data-theme="dark"] .corrected, html[data-theme="dark"] .loading-card, html[data-theme="dark"] .modal-card { border-color: var(--line); }
html[data-theme="dark"] .score-ring::before { background: var(--surface); }