:root {
  --bg: #F5F2EC;
  --ink: #1B1917;
  --muted: #726D66;
  --muted-2: #9A938B;
  --card: #FDFCF9;
  --line: rgba(35, 30, 24, .085);
  --line-2: rgba(35, 30, 24, .16);
  --clay: #B25A3C;
  --clay-soft: #F2E4DC;
  --sage: #6E7F6A;
  --sage-soft: #E8EDE4;
  --blue: #4E667E;
  --blue-soft: #E4EAF0;
  --gold-soft: #F4EDDC;
  --shadow-1: 0 1px 2px rgba(35, 30, 24, .04), 0 14px 32px -20px rgba(35, 30, 24, .30);
  --shadow-2: 0 2px 4px rgba(35, 30, 24, .05), 0 24px 46px -22px rgba(35, 30, 24, .36);
  --r: 16px;
  --r-sm: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--clay); text-decoration: none; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: rgba(245, 242, 236, .86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--ink); color: #F7F3EB;
  display: grid; place-items: center;
}
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: .3px; }
.brand p { font-size: 11.5px; color: var(--muted-2); margin-top: -2px; }
.topbar .spacer { flex: 1; }

.steps { display: flex; align-items: center; gap: 6px; }
.step {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 13px; color: var(--muted);
  border: 1px solid transparent; transition: .18s;
  white-space: nowrap;
}
.step b {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--line); color: var(--muted);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.step.on { background: var(--card); border-color: var(--line-2); color: var(--ink); box-shadow: var(--shadow-1); }
.step.on b { background: var(--clay); color: #fff; }
.step.done b { background: var(--sage); color: #fff; }

/* ---------------- 通用 ---------------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 20px 80px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-1);
}
.card-h { padding: 16px 18px 10px; display: flex; align-items: baseline; gap: 10px; }
.card-h h2 { font-size: 15px; font-weight: 700; }
.card-h .sub { font-size: 12.5px; color: var(--muted-2); }
.card-b { padding: 4px 18px 18px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: 999px;
  background: var(--ink); color: #F7F3EB;
  font-size: 14px; font-weight: 600;
  transition: .18s; border: 1px solid var(--ink);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn.ghost:hover { background: #fff; }
.btn.clay { background: var(--clay); border-color: var(--clay); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 12px; border-radius: 999px; font-size: 13px;
  background: #fff; border: 1px solid var(--line-2); color: var(--muted);
  transition: .15s; white-space: nowrap;
}
.chip:hover { border-color: var(--clay); color: var(--clay); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #F7F3EB; }
.chip.on.clay { background: var(--clay); border-color: var(--clay); }

.field { display: flex; gap: 12px; padding: 9px 0; align-items: flex-start; }
.field > .lb { width: 46px; flex: 0 0 46px; font-size: 13px; color: var(--muted-2); padding-top: 5px; }
.field > .bd { flex: 1; min-width: 0; }

input[type=text], input[type=search], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: #fff; outline: none;
  transition: .15s; font-size: 14px;
}
input:focus, select:focus, textarea:focus { border-color: var(--clay); box-shadow: 0 0 0 3px var(--clay-soft); }

.hint { font-size: 12px; color: var(--muted-2); }

/* ---------------- 教材列表 ---------------- */
.book-grid {
  display: grid; gap: 12px; margin-top: 12px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  max-height: 460px; overflow: auto; padding-right: 4px;
}
.book {
  display: flex; gap: 12px; padding: 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: #fff; transition: .16s; cursor: pointer;
  text-align: left; width: 100%;
}
.book:hover { border-color: var(--clay); transform: translateY(-1px); box-shadow: var(--shadow-1); }
.book.on { border-color: var(--clay); background: var(--clay-soft); }
.book .cov {
  width: 52px; height: 68px; border-radius: 6px; flex: 0 0 52px;
  background: var(--gold-soft); overflow: hidden; display: grid; place-items: center;
  font-size: 11px; color: var(--muted-2);
}
.book .cov img { width: 100%; height: 100%; object-fit: cover; }
.book .t { font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.book .m { font-size: 11.5px; color: var(--muted-2); margin-top: 3px; }
.book .badge {
  display: inline-block; margin-top: 5px; font-size: 10.5px;
  padding: 1px 7px; border-radius: 999px; background: var(--sage-soft); color: var(--sage);
}
.book .badge.no { background: #F0EDE7; color: var(--muted-2); }

/* ---------------- 题型表 ---------------- */
.tbl { width: 100%; border-collapse: collapse; margin-top: 6px; }
.tbl th, .tbl td { padding: 9px 8px; font-size: 13.5px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { font-size: 12px; color: var(--muted-2); font-weight: 500; }
.tbl td.num { width: 96px; }
.tbl input[type=number] { padding: 6px 8px; font-size: 13px; text-align: center; }
.tbl .sum { font-weight: 700; color: var(--clay); }
.tbl .sub { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }

.totbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-top: 14px; padding: 14px 16px; border-radius: var(--r-sm);
  background: var(--gold-soft);
}
.totbar .big { font-size: 22px; font-weight: 800; color: var(--clay); letter-spacing: -.5px; }
.totbar .spacer { flex: 1; }

/* ---------------- 卷面编辑 ---------------- */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .editor { grid-template-columns: 1fr; } }

.sheet {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px 20px 28px; box-shadow: var(--shadow-1);
  max-height: calc(100vh - 190px); overflow: auto;
}
.sheet-title {
  font-size: 17px; font-weight: 700; text-align: center; padding: 6px 0 14px;
  border-bottom: 1px dashed var(--line-2); margin-bottom: 10px;
}

.blk {
  position: relative; padding: 3px 8px; border-radius: 6px;
  border: 1px solid transparent; transition: .12s; outline: none;
  word-break: break-word;
}
.blk:hover { background: #FBF8F2; border-color: var(--line); }
.blk:focus { background: #fff; border-color: var(--clay); box-shadow: 0 0 0 3px var(--clay-soft); }
.blk[data-t=part] { text-align: center; font-weight: 700; font-size: 16px; padding: 16px 8px 8px; letter-spacing: 1px; }
.blk[data-t=sec] { font-weight: 700; margin-top: 10px; }
.blk[data-t=qh] { padding-left: 0; text-indent: 0; }
.blk[data-t=qi], .blk[data-t=rqi] { padding-left: 22px; color: #333; }
.blk[data-t=p1] { text-align: center; font-weight: 600; margin-top: 10px; }
.blk[data-t=rd] { text-indent: 2em; font-size: 14.5px; line-height: 1.9; }
.blk[data-t=src] { text-align: right; font-size: 12.5px; color: var(--muted-2); }
.blk[data-t=wx] { text-indent: 2em; }
.blk[data-t=line], .blk[data-t=rline] {
  height: 26px; border-bottom: 1px solid var(--line-2); margin: 0 8px; padding: 0;
  border-radius: 0;
}
.blk[data-t=line]:hover, .blk[data-t=rline]:hover { background: #FBF8F2; }
.blk[data-t=blank] { height: 12px; padding: 0; }

.blk .tools {
  position: absolute; right: 4px; top: -12px; display: none; gap: 4px;
  background: var(--ink); border-radius: 999px; padding: 3px 4px; z-index: 5;
}
.blk:hover .tools, .blk:focus .tools { display: flex; }
.blk .tools button {
  color: #F7F3EB; font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
}
.blk .tools button:hover { background: rgba(255,255,255,.16); }

.side { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }
.side .card-b { display: flex; flex-direction: column; gap: 8px; }
.kv { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.kv b { color: var(--ink); font-weight: 600; }

.tip {
  font-size: 12.5px; color: var(--muted); line-height: 1.7;
  background: var(--blue-soft); border-radius: var(--r-sm); padding: 10px 12px;
}
.tip.warn { background: var(--clay-soft); color: #7A3A24; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #F7F3EB; padding: 10px 20px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: .24s; z-index: 90;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.mask {
  position: fixed; inset: 0; background: rgba(27, 25, 23, .34);
  display: none; place-items: center; z-index: 80; padding: 20px;
}
.mask.on { display: grid; }
.modal {
  width: min(520px, 100%); background: var(--card); border-radius: var(--r);
  padding: 20px; box-shadow: var(--shadow-2);
}
.modal h3 { font-size: 15px; margin-bottom: 12px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.loading {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted-2); font-size: 13px; padding: 30px 0; }
.scroll-thin::-webkit-scrollbar { width: 6px; height: 6px; }
.scroll-thin::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

/* ---------- 选教材：折叠式条件行 ---------- */
.pickrow {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 7px 12px; margin-bottom: 8px; border-radius: 999px;
  background: var(--sage-soft); border: 1px solid transparent;
  font-size: 13px; transition: .15s;
}
.pickrow:hover { border-color: var(--line-2); }
.pickrow .pl { color: var(--muted); }
.pickrow b { font-weight: 600; }
.pickrow .pgrow { margin-left: auto; color: var(--clay); font-size: 12.5px; }

/* ---------- 卷面结构（只读） ---------- */
.struct { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.strow {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r-sm);
  font-size: 13.5px; background: var(--gold-soft);
}
.strow:nth-child(even) { background: #F8F5EE; }
.strow .stn {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11.5px;
  background: var(--card); color: var(--clay); font-weight: 600;
}
.strow .stt { flex: 1; min-width: 0; }
.strow .stc { flex: none; color: var(--muted); font-size: 12.5px; }

/* ---------- 出卷进度条 ---------- */
.progwrap {
  position: fixed; inset: 0; z-index: 95; display: none;
  place-items: center; background: rgba(27, 25, 23, .30);
}
.progwrap.on { display: grid; }
.progcard {
  width: min(420px, calc(100vw - 40px));
  background: var(--card); border-radius: var(--r);
  padding: 22px 24px 18px; box-shadow: var(--shadow-2);
}
.progtop { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.progtop b { font-size: 14px; font-weight: 600; }
.progtop span { font-size: 13px; color: var(--clay); font-variant-numeric: tabular-nums; }
.progbar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progbar i {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--clay), #D08A5E);
  transition: width .45s ease;
}
.progcard .hint { margin-top: 10px; }

/* ---------- 整卷预览 ---------- */
.mask.pv { padding: 18px; }
.pvbox {
  width: min(1180px, 100%); height: calc(100vh - 36px);
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; overflow: hidden;
}
.pvh {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.pvh b { font-size: 14px; }
.pvb { flex: 1; min-height: 0; background: #EDE8DF; }
.pvb iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ================= 手机 / 小平板适配 ================= */
/* 老师多用手机点开就出卷，所以窄屏不是「能看」，而是每步都能顺手点 */
@media (max-width: 760px) {
  body { font-size: 15px; }

  /* 顶栏：品牌一行、步骤条横滑一行 */
  .topbar {
    flex-wrap: wrap; gap: 8px; padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .topbar .spacer { display: none; }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand .mark { width: 30px; height: 30px; border-radius: 9px; }
  .brand h1 { font-size: 15px; }
  .brand p { display: none; }
  .steps {
    order: 3; width: 100%; gap: 6px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px; scrollbar-width: none;
  }
  .steps::-webkit-scrollbar { display: none; }
  .step { flex: 0 0 auto; padding: 6px 11px; font-size: 12.5px; }
  #btnSetup { flex: 0 0 auto; padding: 7px 14px; }

  .wrap { padding: 14px 12px 72px; }
  .card { border-radius: 14px; }
  .card-h { padding: 14px 14px 8px; flex-wrap: wrap; gap: 4px 10px; }
  .card-h h2 { font-size: 15px; }
  .card-h .sub { font-size: 12px; line-height: 1.5; }
  .card-b { padding: 2px 14px 14px; }

  /* 「标签 + 内容」改成上下排，输入框才够宽 */
  .field { flex-direction: column; gap: 6px; padding: 8px 0; }
  .field > .lb { width: auto; flex: none; padding-top: 0; font-size: 12.5px; }
  .field input[type=text], .field select { min-height: 42px; }
  .field > .bd > div { width: 100%; }

  /* 教材卡片两列，一屏能看到更多 */
  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px; max-height: none; padding-right: 0;
  }
  .book { flex-direction: column; gap: 8px; padding: 10px; }
  .book .cov { width: 100%; height: 96px; }
  .book .t { font-size: 13px; }
  .book .m { font-size: 11px; }

  /* 按钮要够大，一排放不下就换行 */
  .btn { min-height: 42px; padding: 10px 16px; }
  .btn.sm { min-height: 34px; padding: 6px 12px; }
  .chip { min-height: 34px; }
  .totbar { gap: 10px; padding: 12px 14px; }
  .totbar .btn { flex: 1 1 140px; justify-content: center; }

  /* 卷面结构：题干一行、题数分值另起一行，不被挤成一坨 */
  .strow { flex-wrap: wrap; gap: 4px 8px; padding: 8px 10px; font-size: 13px; }
  .strow .stt { flex: 1 1 100%; order: 3; line-height: 1.5; }
  .strow .stc { margin-left: auto; }

  /* 编辑卷面：单栏，卷面不再内部小滚动条（手机上双滚动很难用） */
  .editor { grid-template-columns: 1fr; gap: 12px; }
  .side { position: static; }
  .sheet {
    padding: 14px 12px 20px; max-height: none; overflow: visible;
    border-radius: 14px;
  }
  .sheet-title { font-size: 15px; padding-bottom: 10px; }
  .blk { padding: 4px 4px; }
  .blk[data-t=qh], .blk[data-t=q], .blk[data-t=wx] { font-size: 14px; line-height: 1.85; }
  .blk[data-t=rd] { font-size: 14px; line-height: 1.9; }
  /* 手机没有 hover：悬浮的「AI 重出」会压住题干，改成收进大题标题行右侧 */
  .blk .tools { display: none !important; }
  .blk[data-t=sec] { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
  .blk[data-t=sec] .tools {
    display: inline-flex !important;
    position: static; float: none; transform: none;
    margin: 0 0 0 auto; top: auto; right: auto; flex: 0 0 auto;
  }
  .blk[data-t=sec] .tools button { padding: 4px 8px; font-size: 11px; }

  /* 弹窗、预览、进度都铺满 */
  .mask { padding: 10px; }
  .modal { width: 100%; max-height: 86vh; overflow: auto; padding: 18px 16px; }
  .mask.pv { padding: 0; }
  .pvbox { width: 100%; height: 100%; border-radius: 0; }
  .pvh { padding: 10px 12px; flex-wrap: wrap; }
  .pvh .hint { flex: 1 1 100%; order: 3; }
  .progcard { width: calc(100vw - 32px); padding: 20px 18px 16px; }

  .toast { bottom: 18px; font-size: 13px; padding: 10px 18px; max-width: 88vw; }
}

/* 横屏小高度（手机横过来看整卷预览） */
@media (max-height: 480px) and (orientation: landscape) {
  .pvh { padding: 6px 10px; }
  .progcard { padding: 14px 16px; }
}
