:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #616e7c;
  --line: #d9dee5;
  --accent: #1d5fa8;
  --accent-soft: #e6eef8;
  --ai: #5b4bb7;
  --ai-soft: #efedfa;
  --ok: #217a4b;
  --ok-soft: #e4f3ea;
  --warn: #a5560c;
  --warn-soft: #fdf1e3;
  --err: #b42323;
  --err-soft: #fbe9e9;
  --radius: 8px;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.65; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.35; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .7em; }
ol, ul { margin: 0 0 .7em; padding-left: 1.5em; }
table { border-collapse: collapse; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: #1f3550; color: #fff; min-height: 48px; }
.topbar .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .progress { opacity: .85; font-size: .9rem; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .timer { font-variant-numeric: tabular-nums; font-weight: 600; padding: 2px 10px; border-radius: 6px; background: rgba(255,255,255,.12); white-space: nowrap; }
.topbar .timer.warn { background: #c27a1a; }
.topbar .timer.over { background: var(--err); }
.topbar .code { opacity: .7; font-size: .85rem; }

/* generic layout */
.page { max-width: 860px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 10vh auto; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btn { border: 1px solid var(--line); background: #fff; padding: 8px 18px; border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: #9aa5b1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #174d89; }
.btn.ai { background: var(--ai); border-color: var(--ai); color: #fff; }
.btn.small { padding: 3px 10px; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: #e6b3b3; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tag { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: .8rem; background: var(--accent-soft); color: var(--accent); }
.tag.ai { background: var(--ai-soft); color: var(--ai); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.err { background: var(--err-soft); color: var(--err); }
.notice { padding: 10px 14px; border-radius: 6px; background: var(--accent-soft); margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); color: #6b3a07; }
.notice.ai { background: var(--ai-soft); }
.notice.err { background: var(--err-soft); color: var(--err); }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; background: #fff; }
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus, select:focus { outline: 2px solid #9cc0e8; border-color: var(--accent); }
label.field { display: block; font-weight: 600; margin: 10px 0 4px; }

/* items */
.item { padding: 16px 0; border-bottom: 1px solid #eef0f3; }
.item:last-child { border-bottom: none; }
.item .stem { white-space: pre-wrap; margin-bottom: 8px; }
.item .qnum { font-weight: 600; color: var(--accent); margin-right: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 6px 0; }
.choices label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.likert { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.likert .anchor { font-size: .82rem; color: var(--muted); }
.likert label { display: inline-flex; flex-direction: column; align-items: center; font-size: .8rem; cursor: pointer; }
.claim { margin: 10px 0 10px 12px; padding-left: 12px; border-left: 3px solid var(--line); }
.req { color: var(--err); margin-left: 2px; }
table.data { margin: 8px 0; font-size: .92rem; }
table.data th, table.data td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
table.data th { background: #f3f5f8; }

/* workspace */
.ws { display: grid; grid-template-columns: minmax(260px, 27%) 1fr minmax(320px, 31%); gap: 12px; padding: 12px;
  height: calc(100vh - 48px); }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.pane > .head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.pane > .head h3 { margin: 0; font-size: 1rem; }
.pane > .body { padding: 12px 14px; overflow: auto; flex: 1; min-height: 0; }
.pane > .foot { padding: 10px 14px; border-top: 1px solid var(--line); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 1px solid var(--line); border-bottom: none; background: #f3f5f8; padding: 4px 10px; border-radius: 6px 6px 0 0; cursor: pointer; font-size: .88rem; }
.tabs button.on { background: #fff; font-weight: 600; position: relative; top: 1px; }
.mat .mtitle { font-weight: 600; margin-bottom: 6px; }
.mat .mbody { white-space: pre-wrap; }
.mat .note { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.plan dt { font-weight: 600; margin-top: 6px; }
.plan dd { margin: 0 0 4px 0; }
.qrow { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: start; margin-bottom: 8px; }
.qrow .sel { padding-top: 6px; white-space: nowrap; font-size: .85rem; }
.qrow .sel input { margin-right: 4px; }
.rowtools { display: flex; gap: 8px; margin: 4px 0 12px; }
.savestate { font-size: .8rem; color: var(--muted); margin-left: auto; }
textarea.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: #fff1bf; } to { background: #fff; } }

/* ai pane */
.ai .head { background: var(--ai-soft); }
.lock { margin: auto; text-align: center; padding: 24px; color: var(--muted); }
.lock .big { font-size: 2rem; }
.sugg { border: 1px solid #d8d3f2; background: #faf9ff; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.sugg .intro { color: var(--ai); font-weight: 600; margin-bottom: 6px; }
.sugg .it { padding: 8px 0; border-top: 1px dashed #dcd8f0; }
.sugg .it:first-of-type { border-top: none; }
.sugg .it .txt { margin-bottom: 4px; }
.sugg .it .ops { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg { margin: 8px 0; display: flex; }
.msg .bubble { max-width: 90%; padding: 8px 12px; border-radius: 10px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--accent-soft); white-space: pre-wrap; }
.msg.assistant .bubble { background: #f4f2fc; border: 1px solid #e4e0f6; }
.msg.assistant .bubble p:last-child, .msg.assistant .bubble ol:last-child, .msg.assistant .bubble ul:last-child { margin-bottom: 0; }
.msg.typing .bubble::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--ai); }
@keyframes blink { 50% { opacity: 0; } }
.chatbox { display: flex; gap: 8px; align-items: flex-end; }
.chatbox textarea { min-height: 44px; max-height: 140px; }

/* modal & toast */
.mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.dialog { background: #fff; border-radius: 10px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px 24px; }
.dialog .quote { background: var(--ai-soft); border-left: 3px solid var(--ai); padding: 8px 12px; margin: 8px 0 12px; white-space: pre-wrap; font-size: .92rem; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 8px; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

/* admin & coder */
.shell { max-width: 1400px; margin: 0 auto; padding: 12px 16px 40px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; margin: 8px 0 14px; }
.nav button { border: 1px solid var(--line); background: #fff; padding: 6px 14px; border-radius: 6px; cursor: pointer; }
.nav button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
table.grid { width: 100%; border-collapse: collapse; background: #fff; font-size: .88rem; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
table.grid th { background: #f3f5f8; position: sticky; top: 48px; z-index: 1; }
table.grid tr.test td { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.row input[type=text], .row input[type=number], .row select { width: auto; }
.topbar .btn { color: var(--ink); }
.tl { list-style: none; padding: 0; margin: 0; }
.tl > li { display: grid; grid-template-columns: 64px 34px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid #eef0f3; }
.tl .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.tl .who { font-size: .8rem; }
.tl .who.ai { color: var(--ai); }
.tl .who.learner { color: var(--accent); }
.tl .who.system { color: var(--muted); }
.tl .what { white-space: pre-wrap; word-break: break-word; }
.tl > li.codable { background: #fcfdff; }
.diff del { background: #fbdada; text-decoration: line-through; }
.diff ins { background: #d6f3df; text-decoration: none; }
.diff .f { font-weight: 600; margin-top: 4px; }
.codeform { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px; margin-top: 6px; padding: 8px; background: #f6f8fb; border-radius: 6px; }
.codeform label { font-size: .78rem; color: var(--muted); display: block; }
.codeform select, .codeform input { padding: 3px 6px; font-size: .85rem; }
.split { display: grid; grid-template-columns: 1fr 430px; gap: 14px; align-items: start; }
.sticky { position: sticky; top: 60px; max-height: calc(100vh - 72px); overflow: auto; }
.resp { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.resp .ans { white-space: pre-wrap; margin-bottom: 8px; }
.resp .ans .lab { color: var(--muted); font-size: .85rem; }
.dimrow { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.dimrow .dim { display: flex; gap: 6px; align-items: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }

@media (max-width: 1100px) {
  .ws { grid-template-columns: 1fr; height: auto; }
  .pane > .body { max-height: none; }
  .split { grid-template-columns: 1fr; }
  .sticky { position: static; max-height: none; }
}
@media (max-width: 600px) {
  .card { padding: 18px 16px; }
  .page { padding: 0 12px; }
  .topbar { flex-wrap: wrap; }
}
