:root {
  --bg: #f5f3ee;
  --card: #fff;
  --text: #23211d;
  --muted: #6b665c;
  --line: #e2ded4;
  --brand: #2f6f5e;
  --ok: #1f6b43;
  --ok-bg: #e5f2ea;
  --warn: #7a5200;
  --warn-bg: #fdf1d6;
  --bad: #a42a1f;
  --bad-bg: #fbe5e2;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 16px;
  background: var(--brand);
  color: #fff;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar span { font-size: 13px; opacity: .85; }

.banner, .notice {
  padding: 10px 16px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
}
.notice { border-radius: 8px; }

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
}

.card {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card h2 { margin: 4px 0 8px; font-size: 17px; }
.hero { display: flex; flex-direction: column; gap: 14px; text-align: center; }
.hero .field { text-align: left; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 18px;
  background: var(--card);
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 10px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.big { width: 100%; min-height: 54px; margin-top: 8px; font-size: 18px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.busy::before, .loading::before {
  content: "";
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading { display: flex; align-items: center; justify-content: center; }
@keyframes spin { to { transform: rotate(360deg); } }

.link {
  min-height: 44px;
  margin-top: 4px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; }
.btn:focus-within, :focus-visible { outline: 3px solid #e9a23b; outline-offset: 2px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; margin-bottom: 4px; font-weight: 600; }
.field small { display: block; color: var(--warn); line-height: 1.5; }

textarea, select, input[type="password"], input[type="text"], input[type="date"] {
  width: 100%;
  padding: 10px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 20px; height: 20px; flex: none; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; }

.photo { display: block; max-width: 100%; max-height: 360px; margin: 8px auto; border-radius: 8px; }
.muted { color: var(--muted); font-size: 14px; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.filters.stacked { grid-template-columns: 1fr; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.item { display: flex; align-items: flex-start; gap: 12px; }
.item input { margin-top: 4px; }
.item a { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.item p { margin: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px !important; font-size: 12px; }
.tags span { padding: 1px 8px; background: var(--bg); border-radius: 20px; color: var(--muted); }
.tags .ok { background: var(--ok-bg); color: var(--ok); }
.tags .bad { background: var(--bad-bg); color: var(--bad); }

.question, .child { white-space: pre-wrap; overflow-wrap: anywhere; }
.child { color: var(--muted); }
.tip { padding: 8px 12px; background: var(--ok-bg); border-radius: 8px; color: var(--ok); }
.verdict { padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.verdict.passed { background: var(--ok-bg); color: var(--ok); }
.verdict.review { background: var(--warn-bg); color: var(--warn); }
.verdict.failed { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.steps { padding-left: 22px; }
.steps li { margin-bottom: 6px; }
.answer { font-weight: 700; }
.variant { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px dashed var(--line); }
summary { min-height: 36px; color: var(--brand); cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; }
.section-title { margin: 20px 0 10px; font-size: 16px; }
.item-head { display: flex; gap: 10px; color: var(--muted); font-size: 13px; }
.item-head b { color: var(--text); }

/* 录入：照片列表、逐题核对、全屏看照片 */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 8px; }
.photo-grid figure { margin: 0; }
.photo-grid img { display: block; width: 100%; height: 160px; object-fit: contain; background: var(--bg); border-radius: 8px; cursor: zoom-in; }
.photo-grid figcaption { display: flex; align-items: center; gap: 2px; font-size: 13px; color: var(--muted); }
.photo-grid figcaption span { flex: 1; }
.photo-grid figcaption button { min-width: 36px; min-height: 36px; background: none; border: 0; color: var(--brand); font-size: 18px; cursor: pointer; }
.answer-editor { display: grid; gap: 6px; }
.answer-editor label { display: flex; align-items: flex-start; gap: 6px; }
.answer-editor span { flex: none; width: 6.5em; padding-top: 10px; color: var(--muted); font-size: 14px; }
.answer-editor textarea { flex: 1; min-width: 0; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 14px; }
.pager .btn { min-height: 38px; padding: 4px 12px; }
.review.skipped { opacity: .6; }
.zoomable { cursor: zoom-in; }
.busy-tag { background: var(--warn-bg) !important; color: var(--warn) !important; }
.viewer { position: fixed; inset: 0; z-index: 10; overflow: auto; background: rgba(0, 0, 0, .9); text-align: center; }
.viewer img { max-width: 100%; max-height: calc(100vh - 40px); margin-top: 8px; cursor: zoom-in; }
.viewer img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-close { position: fixed; top: 8px; right: 8px; z-index: 11; width: 44px; height: 44px; background: rgba(255, 255, 255, .9); border: 0; border-radius: 50%; font-size: 26px; cursor: pointer; }
.viewer-tip { margin: 4px 0 12px; color: #ccc; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; background: var(--ok-bg); color: var(--ok); border-radius: 20px; font-size: 14px; }
.chip button { min-width: 28px; min-height: 28px; background: none; border: 0; color: inherit; font: inherit; cursor: pointer; }
.card select[aria-label="添加知识点"] { margin-bottom: 12px; }

/* 知识点页：树。单元 → 小节 → 知识点，每个知识点一行 */
.tree, .tree ul { margin: 0; padding: 0; list-style: none; }
.tree { font-size: 15px; line-height: 1.5; }
.tree > li + li { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.tree ul ul { margin-left: 7px; padding-left: 14px; border-left: 1px solid var(--line); }
.tree summary { display: flex; align-items: center; gap: 8px; min-height: 30px; color: var(--text); list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.t-unit > summary { font-weight: 700; }
.t-unit > summary::before, .t-point > summary::before { content: "▸"; width: 10px; color: var(--muted); font-size: 12px; }
.t-unit[open] > summary::before, .t-point[open] > summary::before { content: "▾"; }
.t-no { min-width: 28px; color: var(--brand); }
.t-tag { padding: 0 6px; background: var(--warn-bg); color: var(--warn); border-radius: 4px; font-size: 12px; font-weight: 400; }
.t-section { display: block; padding: 4px 0 0 18px; color: var(--muted); font-size: 13px; }
.t-point > summary { padding-left: 2px; }
.t-point[open] > summary { color: var(--brand); }
.t-detail { margin: 0 0 8px 18px; padding: 6px 10px; background: var(--bg); border-radius: 6px; font-size: 14px; }
.t-detail p { margin: 0 0 4px; }
.t-detail a { display: block; color: var(--brand); }
.tree summary { margin: 0 -6px; padding: 0 6px; border-radius: 6px; cursor: pointer; transition: background-color .15s; }
.t-detail a { margin: 0 -4px; padding: 0 4px; border-radius: 4px; }
@media (hover: hover) {
  .tree summary:hover { background: var(--ok-bg); color: var(--brand); }
  .t-detail a:hover { background: var(--ok-bg); }
}
.count { margin-left: auto; padding: 0 8px; background: var(--bad-bg); color: var(--bad); border-radius: 20px; font-size: 12px; font-weight: 700; }

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1;
  padding: 14px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}
.tabs a[aria-current] { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }

/* 宽屏：导航放左侧 */
@media (min-width: 900px) {
  .topbar { position: relative; z-index: 2; }
  .tabs {
    inset: 0 auto 0 0;
    z-index: 1;
    flex-direction: column;
    width: 160px;
    padding: 84px 0 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .tabs a { flex: none; padding: 12px 24px; text-align: left; font-size: 16px; }
  .tabs a[aria-current] { box-shadow: inset 3px 0 0 var(--brand); }
  main { margin-left: max(176px, calc((100% - 680px) / 2)); padding-bottom: 32px; }
  .banner { margin-left: 160px; }
}

/* 更宽时，知识点页放宽，树按单元分两栏 */
@media (min-width: 1100px) {
  main[data-page="points"] { max-width: 1100px; margin-left: max(176px, calc((100% - 1100px) / 2)); }
  main[data-page="points"] .tree { columns: 2; column-gap: 40px; }
  main[data-page="points"] .tree > li { break-inside: avoid; margin: 0 0 6px; padding: 0 0 6px; border-bottom: 1px solid var(--line); }
  main[data-page="points"] .tree > li + li { margin-top: 0; padding-top: 0; border-top: 0; }
  .toast { bottom: 24px; }
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 16px;
  background: #2b2925;
  color: #fff;
  border-radius: 10px;
}

/* 打印卷：屏幕上是预览，打印时只剩卷子本身 */
.sheet { padding: 20px; background: #fff; color: #000; border: 1px solid var(--line); }
.sheet h2 { margin: 0 0 8px; text-align: center; font-size: 20px; }
.sheet-info { text-align: center; }
.card-q { padding: 10px 0 14px; border-bottom: 1px dashed #888; break-inside: avoid; }
.card-q p { margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: 0 16px; }
.card-meta > * { white-space: nowrap; }
.card-q img { display: block; max-width: 70%; max-height: 70mm; margin: 4px 0; }
.lines { border-bottom: 1px solid #ccc; background: repeating-linear-gradient(transparent 0 8.5mm, #ddd 8.5mm 9mm); }
.lines-2 { height: 18mm; }
.lines-3 { height: 27mm; }
.lines-4 { height: 36mm; }
.sheet-answers { margin-top: 24px; padding-top: 16px; border-top: 2px dashed #999; }
.sheet-a { break-inside: avoid; margin-bottom: 10px; }
.sheet-a p { margin: 0; }
.sheet-steps { font-size: 13px; color: #333; }

@page { size: A4; margin: 16mm; }

@media print {
  body { background: #fff; font-size: 12pt; }
  .topbar, .banner, .tabs, .toast, .no-print, .empty { display: none !important; }
  main { max-width: none; padding: 0; }
  .sheet { padding: 0; border: 0; }
  .sheet-answers { break-before: page; margin: 0; padding: 0; border: 0; }
}
