:root {
  --navy: #003b71; --navy2: #0b5394; --ink: #1d2733; --muted: #5a6573; --line: #d5dbe3; --bg: #f5f7fa;
  --good: #16703a; --bad: #b3261e; --warn: #8a5a00; --on: #e8f4ec; --explain: #fff6dc; --off: #fde8e6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: #fff; padding: 6px; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 6px 12px; cursor: pointer; min-height: 36px; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.submit { background: var(--good); color: #fff; border-color: var(--good); }
button.secondary { background: #fff; }
button:disabled { opacity: .55; cursor: not-allowed; }
.linkish { background: none; border: none; color: var(--navy2); text-decoration: underline; padding: 0 4px; min-height: 0; }
a { color: var(--navy2); }
.top { display: flex; justify-content: space-between; align-items: center; background: var(--navy); color: #fff; padding: 8px 14px; gap: 10px; flex-wrap: wrap; }
.top .linkish, .top a { color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand .sub { font-weight: 400; opacity: .8; font-size: .85em; }
.logo { background: #fff; color: var(--navy); border-radius: 5px; padding: 2px 6px; font-family: monospace; }
.right { display: flex; gap: 10px; align-items: center; font-size: .9em; flex-wrap: wrap; }
.engine { background: rgba(255,255,255,.15); padding: 2px 8px; border-radius: 10px; }
.engine.ready { background: #2e7d4f; }
.notice { background: #fff3cd; padding: 8px 14px; border-bottom: 1px solid #e6d18a; }
.banner { padding: 8px 14px; border-bottom: 1px solid var(--line); }
.banner-on { background: var(--on); } .banner-explain { background: var(--explain); } .banner-off { background: var(--off); }
.panes { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(380px, 2fr) minmax(260px, 1fr); gap: 0; height: calc(100vh - 92px); }
.pane { overflow: auto; padding: 12px 14px; border-right: 1px solid var(--line); background: #fff; }
.pane.middle { background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.pane h1 { font-size: 1.3em; margin: 0 0 4px; }
.meta { color: var(--muted); margin: 0 0 10px; font-size: .9em; }
.prompt { line-height: 1.5; }
.prompt pre, .chat pre { background: #f0f3f7; padding: 8px; border-radius: 6px; overflow: auto; }
.prompt code, .chat code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; }
.hintbox { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 10px; }
.hints li { margin: 6px 0; background: #f7f9fc; padding: 6px 8px; border-radius: 6px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }
.saved { color: var(--muted); font-size: .85em; }
.editor { border: 1px solid var(--line); background: #fff; border-radius: 6px; min-height: 260px; flex: 1 1 50%; overflow: auto; }
.editor .cm-editor { height: 100%; font-size: 15px; }
.editor .cm-scroller { font-family: ui-monospace, Consolas, "Courier New", monospace; }
.cm-errline { background: #fde8e6 !important; }
.cm-stepline { background: #fff1b8 !important; }
.run-status { font-size: .92em; min-height: 1.2em; } .run-status.good { color: var(--good); } .run-status.bad { color: var(--bad); } .run-status.wait { color: var(--warn); }
.problems { background: #fff; border: 1px solid #f0c2bd; border-radius: 6px; padding: 6px 12px; }
.problems h3, .results h3 { margin: 6px 0; font-size: 1em; }
.problems ul, .results ul { padding-left: 18px; margin: 4px 0; }
.problems li { margin: 6px 0; } .problems li.warning { color: var(--warn); }
.term-label { font-size: .85em; margin: 2px 0 0; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.terminal { background: #10161e; color: #e6edf3; font-family: ui-monospace, Consolas, monospace; padding: 10px; border-radius: 6px; min-height: 140px; max-height: 40vh; overflow: auto; white-space: pre-wrap; margin: 0; flex: 0 0 auto; }
.terminal .typed { color: #8fd3ff; }
.term-input { background: transparent; border: none; border-bottom: 1px solid #8fd3ff; color: #8fd3ff; font: inherit; min-width: 12ch; outline: none; }
.stepper { display: flex; gap: 6px; align-items: center; background: #fff8d6; padding: 6px; border-radius: 6px; flex-wrap: wrap; }
.stepper input[type=range] { flex: 1; min-width: 120px; }
.results li { margin: 6px 0; } .results li.pass { color: var(--good); } .results li.fail { color: var(--bad); }
.results .detail { color: var(--ink); font-size: .92em; margin: 4px 0 0 18px; }
.chat { border: 1px solid var(--line); border-radius: 6px; padding: 8px; height: calc(100% - 210px); min-height: 200px; overflow: auto; background: #fafbfd; }
.chat .empty { color: var(--muted); font-size: .92em; }
.msg { margin: 8px 0; padding: 8px 10px; border-radius: 8px; line-height: 1.45; }
.msg.user { background: #e3edf9; margin-left: 20px; }
.msg.assistant { background: #fff; border: 1px solid var(--line); margin-right: 10px; }
.msg.thinking { color: var(--muted); font-style: italic; }
.msg .note { font-size: .8em; color: var(--warn); margin-top: 4px; }
.chat-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.chat-form textarea { width: 100%; font: inherit; padding: 6px; border-radius: 6px; border: 1px solid var(--line); }
.small { font-size: .85em; color: var(--muted); }
.tutor-off { background: var(--off); border-radius: 8px; padding: 10px; }
dialog { border: none; border-radius: 10px; padding: 18px 22px; max-width: 560px; width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog label { display: block; margin: 10px 0; font-weight: 600; }
dialog input { display: block; width: 100%; font: inherit; padding: 8px; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; text-transform: uppercase; }
dialog textarea { width: 100%; font-family: ui-monospace, monospace; font-size: .85em; }
dialog .row { display: flex; gap: 8px; margin-top: 8px; }
.err { color: var(--bad); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; }
.picker { list-style: none; padding: 0; } .picker h3 { margin: 14px 0 4px; }
.picker ul { list-style: none; padding-left: 10px; } .picker li { margin: 4px 0; }
.tag { font-size: .75em; background: #e8edf3; padding: 1px 6px; border-radius: 8px; color: var(--muted); }
#picker { max-width: 760px; margin: 20px auto; background: #fff; padding: 16px 24px; border-radius: 10px; }
body.exam .top { background: #7a1f1a; }
@media (max-width: 1000px) {
  .panes { grid-template-columns: 1fr; height: auto; }
  .pane { border-right: none; border-bottom: 1px solid var(--line); }
  .chat { height: 300px; }
  .editor { min-height: 300px; }
}
/* teacher view */
.t-main { max-width: 1200px; margin: 16px auto; padding: 0 12px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; margin-bottom: 14px; }
.card label { font-weight: 600; }
.card input:not([type=checkbox]):not([type=range]), .card select { font: inherit; padding: 6px; border: 1px solid var(--line); border-radius: 6px; margin-left: 4px; }
#t-login label { display: block; margin: 10px 0; } #t-login input { display: block; width: 100%; max-width: 360px; margin: 4px 0 0 !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.switch-row { display: grid; gap: 8px; margin-bottom: 10px; }
.switch { display: flex; gap: 8px; align-items: flex-start; font-weight: 400 !important; }
.switch input { width: 20px; height: 20px; margin-top: 2px; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92em; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.flagged { background: #fff8e1; }
.tr { border-top: 1px solid var(--line); padding: 8px 0; }
.flag { color: var(--warn); font-weight: 600; }
dialog.wide { max-width: 1000px; }
.codeview { background: #10161e; color: #e6edf3; padding: 10px; border-radius: 6px; max-height: 50vh; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.codeview .ln { color: #6b7785; } .codeview .added { background: #1f4d2b; }
.flags li { color: var(--warn); }
#d-checks li.pass { color: var(--good); } #d-checks li.fail { color: var(--bad); }
.alert { background: #fde8e6; border: 2px solid var(--bad); border-radius: 10px; padding: 12px 16px; margin-bottom: 14px; }
.flag.crisis { color: var(--bad); }
.step-vars { flex-basis: 100%; font-family: ui-monospace, Consolas, monospace; font-size: .9em; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.step-vars .vlabel { font-family: system-ui, sans-serif; font-weight: 600; }
.step-vars .var { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; }
.step-vars .var.changed { background: #fff1b8; border-color: #e0b800; font-weight: 600; }
.pane.right { display: flex; flex-direction: column; }
#tutor { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#tutor[hidden], .tutor-off[hidden] { display: none; }
#tutor h2 { margin: 0 0 4px; }
#tutor .chat { flex: 1; height: auto; min-height: 220px; }
@media (max-width: 1000px) { #tutor .chat { flex: none; height: 300px; } }
[hidden] { display: none !important; }

/* Editor help: completion details, parameter hints, hover */
.cm-tooltip.cm-tooltip-autocomplete > ul { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; max-height: 18em; }
.cm-tooltip.cm-completionInfo, .ide-sighelp, .ide-hover { max-width: 520px; }
.ide-doc, .ide-sighelp { padding: 6px 9px; font-size: 13.5px; line-height: 1.4; }
.ide-doc p, .ide-sighelp p { margin: 5px 0 0; font-family: system-ui, sans-serif; color: #333; }
.ide-sig, .ide-sigline code { font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; color: #1a1a1a; }
.ide-sigline b { color: #003b71; background: #e4eefa; border-radius: 2px; }
.ide-signav { display: inline-flex; align-items: center; gap: 3px; margin-right: 8px; color: #555; font-size: 12px; white-space: nowrap; }
.ide-signav button { border: 1px solid #bbb; background: #fff; border-radius: 3px; font-size: 9px; padding: 1px 4px; cursor: pointer; min-height: 0; }
.ide-param { color: #003b71 !important; }
.cm-tooltip.ide-wrap, .cm-tooltip:has(> .ide-sighelp), .cm-tooltip:has(> .ide-hover) { background: #fffef7; border: 1px solid #c9c2a0; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
