:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e4e8ec;
  --accent: #10b981;
  --accent-d: #0c8f6a;
  --accent-soft: #e7f7f1;
  --t2: #6366f1;
  --t2-soft: #ecedff;
  --t3: #f59e0b;
  --t3-d: #b45309;
  --t3-soft: #fef3c7;
  --wrong: #ef4444;
  --wrong-soft: #fdeaea;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 6px 20px rgba(16,24,40,.06);
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* Boot error banner */
.boot-error {
  margin: 12px 16px 0;
  padding: 12px 16px;
  border: 1px solid #f3c2c2;
  background: var(--wrong-soft);
  color: #a12626;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.6;
}
.boot-error b { color: #8a1f1f; }
.boot-error code {
  background: #fff; border: 1px solid #f0cfcf; border-radius: 6px;
  padding: 1px 6px; font-size: 12.5px;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-text h1 { margin: 0; font-size: 18px; letter-spacing: .3px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.mode-switch { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode-btn {
  border: 0; background: transparent; cursor: pointer;
  padding: 8px 16px; border-radius: 999px; font-size: 14px; color: var(--muted); font-weight: 600;
  transition: all .15s;
}
.mode-btn.active { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.mode-btn[data-mode="T2"].active { background: var(--t2); }
.mode-btn[data-mode="T3"].active { background: var(--t3); color: #fff; }

/* Layout */
.layout { display: grid; grid-template-columns: 320px 1fr; align-items: start; }
.sidebar {
  border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column;
  position: sticky; top: 60px; height: calc(100vh - 60px); min-height: 0;
}
.search-box { padding: 14px; border-bottom: 1px solid var(--line); }
.search-box input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; outline: none; background: var(--bg);
}
.search-box input:focus { border-color: var(--accent); background: #fff; }
.tree { flex: 1; overflow-y: auto; padding: 8px 6px 16px; }
.tree-foot { padding: 8px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

/* Tree */
.node { user-select: none; }
.node.date {
  font-size: 12px; font-weight: 700; color: var(--muted);
  padding: 10px 10px 4px; letter-spacing: .4px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.node.date:hover { color: var(--ink); }
.node.article {
  font-size: 12px; line-height: 1.5; padding: 6px 10px 6px 22px;
  border-radius: 8px; cursor: pointer; color: var(--ink);
}
.node.article:hover { background: var(--accent-soft); }
.node.article.active { background: var(--accent-soft); color: var(--accent-d); font-weight: 600; }
.caret { width: 12px; display: inline-block; transition: transform .15s; color: var(--muted); font-size: 10px; }
.collapsed > .children { display: none; }
.children { margin: 0; }
.node.article.done { color: var(--accent-d); }
.node.article.done::after { content: " ✓"; font-weight: 800; }

/* Stage */
.stage { padding: 22px 30px 48px; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.breadcrumb b { color: var(--ink); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px; max-width: 980px;
}
.scene-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.tag {
  font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 8px; color: #fff; background: var(--accent);
}
.tag.T2 { background: var(--t2); }
.tag.T3 { background: var(--t3); }
.scenario { font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ---- Prompt blocks (T2 / T3) ---- */
.prompt-box {
  background: #fbfcfd; border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 16px; font-size: 15px; line-height: 1.75;
}
.prompt-box h4 { margin: 0 0 10px; font-size: 15px; color: var(--ink); }
.prompt-box .scenario-text { white-space: pre-wrap; margin-bottom: 12px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.meta-chip {
  font-size: 12.5px; background: var(--t2-soft); color: #3730a3;
  border-radius: 8px; padding: 5px 10px; font-weight: 600;
}
.meta-chip.subject { background: var(--t3-soft); color: var(--t3-d); }
.bullets { margin: 0; padding-left: 20px; }
.bullets li { margin-bottom: 6px; }
.closing-note { margin-top: 10px; font-size: 13px; color: var(--muted); font-style: italic; }

/* T3 discussion */
.discussion { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; }
.speaker { margin-bottom: 12px; }
.speaker .who {
  font-size: 13px; font-weight: 800; margin-bottom: 4px;
  color: var(--t2); display: flex; align-items: center; gap: 8px;
}
.speaker.prof .who { color: var(--t3-d); }
.speaker .role-tag {
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--bg); border-radius: 6px; padding: 2px 6px;
}
.speaker .say { font-size: 14.5px; line-height: 1.7; color: var(--ink); }

/* ---- Essay editor ---- */
.editor-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 0 8px; flex-wrap: wrap; gap: 8px;
}
.editor-head .lbl { font-size: 14px; font-weight: 700; }
.counter { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.low { color: var(--wrong); font-weight: 700; }
.essay {
  width: 100%; min-height: 240px; resize: vertical;
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  font-size: 15px; line-height: 1.8; font-family: inherit; outline: none;
  background: #fff; color: var(--ink);
}
.essay:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.essay:disabled { background: #f7f9fa; color: var(--muted); }

/* ---- T1 sentence builder ---- */
.item-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px;
  background: #fff;
}
.item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.item-no {
  font-size: 12px; font-weight: 800; color: #fff; background: var(--accent);
  border-radius: 6px; padding: 3px 8px; flex: none;
}
.item-verdict { font-size: 12.5px; font-weight: 700; margin-left: auto; flex: none; }
.item-verdict.ok { color: var(--accent-d); }
.item-verdict.no { color: var(--wrong); }
.ctx-line { font-size: 13.5px; color: var(--muted); line-height: 1.6; margin-bottom: 8px; }

.sentence {
  font-size: 16px; line-height: 2.6; color: var(--ink);
  background: #fbfcfd; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 12px;
}
.sentence.correct { border-color: var(--accent); background: var(--accent-soft); }
.sentence.wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.lit { white-space: pre-wrap; }

.slot {
  display: inline-block; min-width: 74px; padding: 3px 10px; margin: 0 3px;
  border: 1px dashed #b9c3cc; border-radius: 8px; background: #fff;
  font-size: 15px; font-weight: 600; color: var(--accent-d);
  text-align: center; vertical-align: middle; cursor: pointer;
  transition: all .12s; line-height: 1.5;
}
.slot.empty { color: #b9c3cc; }
.slot.empty::after { content: "拖入"; font-size: 11px; font-weight: 500; letter-spacing: .5px; }
.slot.over { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.slot.drop-ok { border-color: var(--accent); }
.slot.reveal-ok { color: var(--accent-d); border-style: solid; border-color: var(--accent); background: #fff; }
.slot.reveal-bad { color: var(--wrong); border-style: solid; border-color: var(--wrong); background: #fff; }

.bank { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 2px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 13px; font-size: 14px; cursor: grab; user-select: none;
  box-shadow: 0 1px 2px rgba(16,24,40,.06); transition: all .12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent-d); }
.chip.dragging { opacity: .4; }
.chip.used { visibility: hidden; display: none; }
.bank-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.bank-wrap { margin-bottom: 4px; }
.bank-empty { font-size: 12.5px; color: var(--muted); font-style: italic; }

.reveal-line { font-size: 13.5px; line-height: 1.7; margin-top: 10px; }
.reveal-line b { color: var(--ink); }
.reveal-line .ans { color: var(--accent-d); font-weight: 700; }
.reveal-line .mine { color: var(--wrong); }
.expl { font-size: 13px; color: var(--muted); line-height: 1.7; margin-top: 6px; }
.distract-note { font-size: 12.5px; color: var(--t3-d); margin-top: 6px; }

/* Countdown */
.countdown-wrap { position: relative; width: 120px; height: 120px; margin: 8px 0 4px; }
.ring { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--bg); stroke-width: 9; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .25s linear, stroke .2s; }
.ring-fg.t2 { stroke: var(--t2); }
.ring-fg.t3 { stroke: var(--t3); }
.countdown-wrap.danger .ring-fg { stroke: var(--wrong); }
.countdown-wrap.danger .cd-num { color: var(--wrong); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.cd-num { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cd-status { font-size: 11px; color: var(--muted); margin-top: 2px; text-align: center; padding: 0 6px; }

/* Buttons */
.actions { display: flex; gap: 10px; margin: 16px 0 6px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: #fff; cursor: pointer; border-radius: 10px;
  padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--ink); transition: all .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-d); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); padding: 11px 22px; font-size: 15px; }
.btn-primary:hover { background: var(--accent-d); color: #fff; }
.btn-primary:disabled { background: #c7ced4; border-color: #c7ced4; }
.nav { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.nav-pos { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { font-size: 12px; color: var(--muted); margin-top: 14px; }

/* ---- Grading report ---- */
.result { margin-top: 18px; border-top: 2px solid var(--line); padding-top: 16px; }
.result h3 { margin: 0 0 12px; font-size: 15px; }
.rp-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.score-badge {
  width: 76px; height: 76px; border-radius: 50%; flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--accent-soft); border: 3px solid var(--accent);
}
.score-badge .num { font-size: 30px; font-weight: 800; color: var(--accent-d); line-height: 1; }
.score-badge .of { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rp-summary { font-size: 14px; line-height: 1.7; color: var(--ink); flex: 1; min-width: 240px; }

.dims { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 16px; }
.dim {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fbfcfd;
}
.dim .dn { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.dim .dv { font-size: 13.5px; line-height: 1.6; }
.bar { height: 6px; border-radius: 4px; background: var(--line); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.dim.t2 .bar > i { background: var(--t2); }
.dim.t3 .bar > i { background: var(--t3); }

.rp-sec { margin-bottom: 16px; }
.rp-sec > .rp-t {
  font-size: 13.5px; font-weight: 800; margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.rp-t::before { content: ""; width: 3px; height: 13px; background: var(--accent); border-radius: 2px; }
.rp-sec.warn .rp-t::before { background: var(--wrong); }
.rp-sec.essay .rp-t::before { background: var(--t3); }

.iss { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #fff; }
.iss .orig { font-size: 13.5px; color: var(--wrong); text-decoration: line-through; line-height: 1.6; }
.iss .fix { font-size: 13.5px; color: var(--accent-d); font-weight: 600; line-height: 1.6; }
.iss .why { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-top: 4px; }
.iss .kind {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 6px; background: var(--t2-soft); color: #3730a3; margin-bottom: 6px;
}

.model-essay {
  background: var(--t3-soft); border: 1px solid #f6dfa4; border-radius: 12px;
  padding: 14px 16px; font-size: 14.5px; line-height: 1.85; white-space: pre-wrap;
}
.tip-list { margin: 0; padding-left: 20px; }
.tip-list li { font-size: 13.5px; line-height: 1.75; margin-bottom: 5px; }

.grading {
  display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted);
  padding: 16px 0;
}
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; flex: none;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.api-err {
  border: 1px solid #f3c2c2; background: var(--wrong-soft); color: #a12626;
  border-radius: 10px; padding: 12px 14px; font-size: 13.5px; line-height: 1.7;
}

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
