:root {
  --bg: #e9edf1; --panel: #ffffff; --ink: #18212b; --muted: #5b6672; --line: #d6dce3;
  --accent: #1f5f8b; --accent-ink: #ffffff; --warn: #b4441c; --ok: #2f7d4f; --need: #fff2e5;
  --agent: #e8eef4; --user: #1f5f8b; --user-ink: #ffffff; --chatbg: #f7f8fa;
  --mono: ui-monospace, "SFMono-Regular", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; }
.progress { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; max-width: 360px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.savestate { margin-left: auto; font-size: 13px; color: var(--muted); }
.savestate.bad { color: var(--warn); } .savestate.ok { color: var(--ok); }
.previewbar { background: #fff6d6; border-bottom: 1px solid #e8d48a; padding: 6px 16px; font-size: 14px; }
.wrap { max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px 28px; }
.panel.narrow { max-width: 680px; margin: 0 auto; }
h1 { font-size: 24px; margin: 0 0 12px; } h2 { font-size: 18px; margin: 28px 0 8px; }
.lead { color: var(--muted); }
button, .button { font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); padding: 10px 20px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
.actions { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.code { font-family: var(--mono); font-size: 20px; }

/* surveys */
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.q { padding: 14px 10px; border-top: 1px solid var(--line); }
.q legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.choices { display: grid; gap: 6px; } .choices label { display: flex; gap: 8px; align-items: center; }
.num { font: inherit; padding: 8px; width: 120px; border: 1px solid var(--line); border-radius: 6px; }
.other { display: block; margin-top: 8px; font: inherit; padding: 8px; width: 100%; max-width: 360px; border: 1px solid var(--line); border-radius: 6px; }
.scale { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.scale label { display: flex; flex-direction: column; align-items: center; font-size: 13px; padding: 0 6px; }
.scale .anchor { font-size: 13px; color: var(--muted); max-width: 120px; }
.matrix { border-top: 1px solid var(--line); }
.mhead { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(7, 1fr); gap: 4px; position: sticky; top: 52px; background: var(--panel); padding: 8px 0; font-size: 12px; color: var(--muted); text-align: center; border-bottom: 1px solid var(--line); z-index: 2; }
.mrow { display: grid; grid-template-columns: minmax(220px, 2fr) 7fr; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.mrow legend { float: left; padding: 0 8px 0 0; }
.mrow .opts { display: grid; grid-template-columns: repeat(7, 1fr); }
.mrow .opts label { display: flex; justify-content: center; padding: 6px 0; cursor: pointer; }
.mrow .opts .ol { display: none; }
.need { background: var(--need); border-radius: 6px; }
.missing { color: var(--warn); font-weight: 600; }
@media (max-width: 760px) {
  .mhead { display: none; }
  .mrow { grid-template-columns: 1fr; }
  .mrow .opts { grid-template-columns: 1fr; }
  .mrow .opts label { justify-content: flex-start; gap: 8px; }
  .mrow .opts .ol { display: inline; font-size: 14px; }
}

/* feed card */
.card { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; max-width: 560px; margin: 0 auto; box-shadow: 0 1px 2px rgba(0,0,0,.05); text-align: left; }
.cardhead { display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 14px; }
.cardhead .logo { width: 26px; height: 26px; border-radius: 50%; background: #2d3a4a; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.cardhead .src { font-weight: 600; } .cardhead .date { color: var(--muted); margin-left: auto; }
.card .pic { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #e3e1dc; }
.card .pic.placeholder { background: linear-gradient(135deg, #e6e3dd, #d3d8de); }
.card h3 { font-size: 19px; line-height: 1.3; margin: 12px 14px 6px; }
.card .dek { margin: 0 14px 12px; color: #3d434a; }
.card .listen { margin: 0 14px 14px; padding: 6px 14px; font-size: 14px; }
.card .draft { position: absolute; top: 10px; right: -34px; transform: rotate(35deg); background: #c0392b; color: #fff; font-size: 11px; font-weight: 700; padding: 3px 40px; }

/* timed test */
.testarea { max-width: 600px; margin: 0 auto; }
.testhead { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.timer.warn { color: var(--warn); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.bar span { display: block; height: 100%; background: var(--accent); transition: width .2s linear; }
.question { text-align: center; font-weight: 600; margin: 18px 0 10px; }
.judge { display: flex; gap: 14px; justify-content: center; }
.judge .tf { min-width: 140px; padding: 12px 24px; font-size: 17px; }

/* chat, shared */
body.coach { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.coach .wrap { flex: 1; min-height: 0; width: 100%; padding-top: 16px; padding-bottom: 16px; display: flex; flex-direction: column; }
.coach .wrap > .intro { overflow-y: auto; }
.intro .introhead { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.intro .introhead h1 { margin: 0; }
.avatar.lg { width: 56px; height: 56px; }
.steps { padding-left: 22px; margin: 8px 0 16px; } .steps li { margin: 6px 0; padding-left: 4px; }
.chat { max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; overflow: hidden;
  box-shadow: 0 12px 32px -18px rgba(24, 33, 43, .35); }
.chathead { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.who { display: flex; flex-direction: column; line-height: 1.2; }
.agentname { font-weight: 700; font-size: 17px; }
.status { font-size: 13px; color: var(--muted); }
.storyprog { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.storycount { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.storydots { display: flex; gap: 3px; }
.storydots i { width: 14px; height: 4px; border-radius: 2px; background: var(--line); }
.storydots i.d { background: var(--accent); } .storydots i.c { background: var(--accent); opacity: .4; }
.avatar { width: 42px; height: 42px; border-radius: 50%; } .avatar.sm { width: 30px; height: 30px; flex: none; }
.log { position: relative; flex: 1; overflow-y: auto; padding: 20px 18px 12px; display: flex; flex-direction: column; gap: 10px;
  background: var(--chatbg); }
.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 100%; }
.msg.agent .body { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: 82%; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: var(--user-ink); max-width: 78%; }
.msg.share .body { max-width: 92%; width: 560px; }
.shared .card { margin: 0; max-width: none; box-shadow: none; }
.controls { border-top: 1px solid var(--line); padding: 12px 18px 14px; display: grid; gap: 10px; background: var(--panel); }
.step { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.steptext { flex: 1; min-width: 220px; }
.step .judge { gap: 10px; }
.steptitle { margin: 0; font-weight: 700; }
.stephint { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.step > button { margin-left: auto; }
.step .judge .tf { min-width: 112px; padding: 10px 18px; }
.recap { display: flex; justify-content: flex-start; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.recap span { padding: 4px 12px; border-radius: 999px; background: var(--chatbg); border: 1px solid var(--line); }
.askwrap { display: grid; gap: 4px; }
.ask { display: flex; gap: 8px; align-items: flex-end; }
.ask textarea { flex: 1; font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; resize: none; min-height: 42px; background: #fff; color: var(--ink); }
.ask textarea:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.asknote { margin: 0; font-size: 12px; color: var(--muted); text-align: left; }
.controls > .asknote { text-align: center; }

/* relational register */
.reg-relational .msg.agent .bubble { background: var(--agent); border-radius: 18px 18px 18px 6px; }
.reg-relational .msg.user .bubble { border-radius: 18px 18px 6px 18px; }
.reg-relational .shared .card { border-radius: 14px; }
.reg-relational .status.working { color: var(--accent); }
.typing { display: inline-flex; gap: 5px; align-items: center; height: 22px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #7d8a98; animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* transactional register: same window, machine chrome */
.sysmark { width: 38px; height: 38px; border-radius: 4px; background: #3c4652; position: relative; flex: none; }
.sysmark::after { content: ""; position: absolute; inset: 12px; border: 2px solid #c9d1da; border-radius: 1px; }
.sysmark.lg { width: 52px; height: 52px; } .sysmark.lg::after { inset: 16px; }
.reg-transactional .chat { border-radius: 6px; }
.reg-transactional .chathead { background: #eef0f2; }
.reg-transactional .agentname, .reg-transactional .status, .reg-transactional .storycount { font-family: var(--mono); }
.reg-transactional .agentname { font-size: 15px; letter-spacing: .02em; }
.reg-transactional .status.working { color: #3c4652; animation: blink 1s steps(2, start) infinite; }
.reg-transactional .log { background: #f3f4f5; }
.reg-transactional .msg.agent .body { max-width: 92%; }
.reg-transactional .msg.agent .bubble { background: #fff; border: 1px solid #d3d8de; border-left: 3px solid #5b6672; border-radius: 2px; font-family: var(--mono); font-size: 14px; }
.reg-transactional .msg.user .bubble { border-radius: 2px; font-family: var(--mono); font-size: 14px; background: #3c4652; }
.reg-transactional .shared .card { border-radius: 2px; }
.reg-transactional .recap span { border-radius: 2px; font-family: var(--mono); font-size: 13px; }
.reg-transactional .ask textarea { border-radius: 2px; font-family: var(--mono); font-size: 14px; }
.reg-transactional .storydots i { border-radius: 0; }
.processing { font-family: var(--mono); font-size: 13px; letter-spacing: .12em; color: #3c4652; animation: blink 1s steps(2, start) infinite; }
.processing::after { content: " \2588"; }
@keyframes blink { to { visibility: hidden; } }
@media (max-width: 600px) {
  .coach .wrap { padding: 0; } .chat { border-radius: 0; border-left: 0; border-right: 0; }
  .msg.agent .body, .msg.share .body { max-width: 100%; } .storydots { display: none; }
  .step .judge { width: 100%; } .judge .tf, .step .judge .tf { min-width: 0; flex: 1; }
}

/* debrief */
.wrong li { margin-bottom: 6px; }
.answers table { border-collapse: collapse; width: 100%; font-size: 14px; margin-top: 8px; }
.answers td, .answers th { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; }

/* admin */
.admin .wrap { max-width: 1400px; }
.grid { border-collapse: collapse; font-size: 13px; width: 100%; background: #fff; }
.grid th, .grid td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
.grid.kv { width: auto; } .grid.small td { font-size: 12px; }
.grid tr.short td { background: #fff2e5; }
.exports a { margin-right: 16px; }
.transcript { background: #fff; border: 1px solid var(--line); padding: 12px; font-size: 14px; }
.tm { padding: 6px 0; border-bottom: 1px dashed var(--line); } .tm.user .ttext { color: var(--accent); }
.tmeta { font-size: 11px; color: var(--muted); } .ttext { white-space: pre-wrap; }
.reset input { font: inherit; padding: 6px; }
.meta { color: var(--muted); font-size: 14px; }
@media (prefers-reduced-motion: reduce) { .typing span, .processing { animation: none; } }
.choices.inline { display: flex; gap: 24px; }
.consent ul { margin-top: 0; }
@media print { .top, .previewbar, .actions, #consentform, .missing { display: none; } .panel { border: 0; } }

.testform { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 8px 0 16px; }
.testform label { display: flex; flex-direction: column; font-size: 14px; gap: 4px; }
form.inline { display: inline; }
.quick .button { margin-right: 6px; }
.reg-transactional .controls button, .reg-transactional .intro button { border-radius: 2px; font-family: var(--mono); letter-spacing: .03em; }
