/* ==========================================================================
   PseudoIDE: styles
   ========================================================================== */
:root {
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, "SFMono-Regular", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 8px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

[data-theme="dark"] {
  --bg: #07090e;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(124, 108, 255, .10), transparent 60%),
             radial-gradient(900px 500px at 110% 120%, rgba(34, 211, 238, .07), transparent 60%);
  --panel: #0d1118;
  --panel-2: #10151e;
  --head: #0f141c;
  --line: #1b2230;
  --line-2: #263044;
  --text: #e7eaf2;
  --text-2: #aab2c5;
  --muted: #6b7489;
  --hover: rgba(255, 255, 255, .05);
  --active: rgba(255, 255, 255, .08);
  --accent: #8b7bff;
  --accent-2: #22d3ee;
  --accent-soft: rgba(139, 123, 255, .14);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, .12);
  --err: #ff6b81;
  --err-soft: rgba(255, 107, 129, .10);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .12);
  --shadow: 0 20px 60px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .4);
  --console-in: #7dd3fc;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #eef0f6;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(124, 108, 255, .12), transparent 60%),
             radial-gradient(900px 500px at 110% 120%, rgba(34, 211, 238, .10), transparent 60%);
  --panel: #ffffff;
  --panel-2: #fbfbfe;
  --head: #f7f8fc;
  --line: #e3e6ef;
  --line-2: #d4d9e6;
  --text: #171a24;
  --text-2: #4a5268;
  --muted: #8a92a6;
  --hover: rgba(20, 30, 60, .05);
  --active: rgba(20, 30, 60, .08);
  --accent: #6d5cf6;
  --accent-2: #0891b2;
  --accent-soft: rgba(109, 92, 246, .10);
  --ok: #059669;
  --ok-soft: rgba(5, 150, 105, .10);
  --err: #e11d48;
  --err-soft: rgba(225, 29, 72, .07);
  --warn: #b45309;
  --warn-soft: rgba(217, 119, 6, .10);
  --shadow: 0 20px 60px rgba(30, 40, 80, .18), 0 2px 8px rgba(30, 40, 80, .08);
  --console-in: #0369a1;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  background-image: var(--tex-page, none), var(--bg-grad);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-variant-ligatures: none;
  font-feature-settings: "calt" 0, "liga" 0;
}
button, input { font: inherit; color: inherit; }
kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text-2);
}
code { font-family: var(--font-mono); font-size: .92em; }
.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ------------------------------------------------------------------ Top bar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 14px;
  flex: none;
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding-right: 8px; user-select: none; }
.brand-mark-image { display: block; width: 32px; height: 32px; flex: 0 0 32px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-name span {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { font-size: 10.5px; color: var(--muted); font-weight: 500; letter-spacing: .02em; }

.menus { display: flex; gap: 2px; }
.spacer { flex: 1; }
.actions { display: flex; align-items: center; gap: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-2);
  font-weight: 500; font-size: 12.5px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.btn:active { transform: translateY(1px); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.icon { width: 32px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
.btn.icon:hover { background: var(--hover); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.icon.sm { width: 26px; padding: 0; }
.btn .chev { width: 13px; height: 13px; opacity: .6; }


.btn.run {
  height: 36px; padding: 0 12px 0 10px; margin-left: 6px;
  border: none; color: #fff; font-weight: 600; font-size: 13px;
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 55%, var(--accent-2)) 55%, var(--accent-2) 100%);
  background-size: 160% 100%;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent), inset 0 1px 0 rgba(255,255,255,.25);
  transition: background-position .4s var(--ease), box-shadow .2s, transform .1s;
}
.btn.run:hover { color: var(--on-accent, #fff); background-position: 100% 0; box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 50%, transparent), inset 0 1px 0 rgba(255,255,255,.25); }
.btn.run kbd { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.22); color: #fff; }
.btn.run svg { width: 15px; height: 15px; fill: currentColor; }
.run-icon, .stop-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: rgba(255,255,255,.18); }
.stop-icon { display: none; }
.app.running .btn.run {
  background: linear-gradient(135deg, #ff5f7e, #ff8a5c);
  box-shadow: 0 8px 24px rgba(255, 95, 126, .35), inset 0 1px 0 rgba(255,255,255,.25);
}
.app.running .run-icon { display: none; }
.app.running .stop-icon { display: grid; }

.file-chip {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px; margin-left: 6px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel);
}
.file-chip input { border: none; outline: none; background: transparent; width: 140px; font-family: var(--font-mono); font-size: 12px; color: var(--text); }
.file-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); transition: background .2s, box-shadow .2s; }
.file-chip .dot.dirty { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

/* GitHub star button */
.btn.star { text-decoration: none; margin-right: 4px; color: var(--text); border-color: var(--line-2); background: var(--panel); }
.btn.star .gh { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.btn.star:hover { border-color: color-mix(in srgb, #f5c542 55%, transparent); color: var(--text); }
.btn.star:hover .star-count svg { transform: rotate(-12deg) scale(1.15); }
.star-count { display: inline-flex; align-items: center; gap: 4px; padding-left: 8px; margin-left: 2px; border-left: 1px solid var(--line-2); font-weight: 600; }
.star-count svg { width: 13px; height: 13px; fill: #f5c542; transition: transform .2s var(--ease); }
@media (max-width: 1280px) { .star-label { display: none; } }

/* "Double-tap to edit" pill for touch screens */
.edit-pill {
  height: 24px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer;
}
.edit-pill.editing { color: var(--on-accent, #fff); border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* Dropdown menus */
.menu { position: relative; }
.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0;
  max-height: calc(100vh - 80px); overflow: auto;
  min-width: 240px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none;
  transform-origin: top left;
  transition: opacity .14s, transform .18s var(--ease);
  z-index: 50;
}
.menu.open .dropdown { opacity: 1; transform: none; pointer-events: auto; }
.actions .dropdown { left: auto; right: 0; transform-origin: top right; }
.dropdown > button {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  width: 100%; padding: 8px 10px; border: none; border-radius: 7px;
  background: transparent; color: var(--text); font-size: 12.5px; text-align: left; cursor: pointer;
}
.dropdown > button:hover { background: var(--hover); }
.dropdown .sep { height: 1px; background: var(--line); margin: 5px 4px; }

.dropdown.examples { width: 560px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 8px; }
.ex-group { grid-column: 1 / -1; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 10px 4px; }
.dropdown > .ex-item { display: flex; gap: 10px; align-items: flex-start; justify-content: flex-start; width: 100%; padding: 9px 10px; border-radius: 9px; border: none; background: transparent; text-align: left; cursor: pointer; }
.dropdown > .ex-item:hover { background: var(--hover); }
.ex-item .ex-ico { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-family: var(--font-mono); font-size: 11px; font-weight: 600; }
.ex-text { display: flex; flex-direction: column; min-width: 0; }
.ex-text b { font-size: 12.5px; font-weight: 600; color: var(--text); }
.ex-desc { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.dropdown.settings { width: 320px; padding: 8px; }
.set-title { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 8px 4px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 12.5px; }
.set-row:hover { background: var(--hover); }
.set-row small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.stepper button { width: 26px; height: 24px; border: none; background: var(--panel-2); cursor: pointer; color: var(--text-2); }
.stepper button:hover { background: var(--hover); color: var(--text); }
.stepper output { width: 30px; text-align: center; font-family: var(--font-mono); font-size: 12px; }

.switch {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 34px; height: 20px; border-radius: 999px; margin: 0;
  background: var(--line-2); position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s var(--ease);
}
.switch:checked { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.switch:checked::after { transform: translateX(14px); }

/* ---------------------------------------------------------------- Workspace */
.workspace {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: var(--left, 58%) var(--gap) 1fr;
  padding: 0 var(--gap) 0 var(--gap);
}
.right-col { display: grid; grid-template-rows: var(--top, 38%) var(--gap) 1fr; min-width: 0; min-height: 0; }
.panel {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background-color: var(--panel); background-image: var(--tex-panel, none);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255,255,255,.02) inset, 0 8px 30px rgba(0,0,0,.12);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 40px; padding: 0 8px 0 6px; flex: none;
  background: var(--head); border-bottom: 1px solid var(--line);
}
.panel-body { flex: 1; min-height: 0; position: relative; }
.head-right { display: flex; align-items: center; gap: 4px; }
.hint { font-size: 11.5px; color: var(--muted); padding: 0 6px; }

.tabs { display: flex; align-items: center; gap: 2px; height: 100%; }
.tab {
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 11px; border-radius: 7px; border: none;
  background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 500; cursor: pointer;
  position: relative;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--text-2); background: var(--hover); }
.tab.active { color: var(--text); background: var(--active); }
.tab.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -6px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.editor-panel .tab { font-family: var(--font-mono); font-size: 12px; cursor: default; }

/* Open-file tabs in the editor header */
.file-tabs-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; height: 100%; }
.file-tabs { min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding-bottom: 0; }
.file-tabs::-webkit-scrollbar { display: none; }
.ftab { flex: none; gap: 6px; padding: 0 4px 0 10px; cursor: pointer !important; user-select: none; }
.ftab .i { width: 14px; height: 14px; flex: none; }
.ftab .ftab-name { max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.ftab.md .i { color: var(--accent-2); }
.ftab.active .i { color: var(--accent); }
.ftab.active.md .i { color: var(--accent-2); }
.ftab-close {
  width: 20px; height: 20px; display: grid; place-items: center; flex: none;
  border: none; border-radius: 5px; background: transparent; color: inherit; cursor: pointer;
  opacity: .45; transition: opacity .15s, background .15s, color .15s;
}
.ftab-close svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.ftab:hover .ftab-close, .ftab.active .ftab-close { opacity: .85; }
.ftab-close:hover { opacity: 1 !important; background: var(--hover); color: #ff6b81; }
.ftab-rename {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--accent);
  border-radius: 5px; padding: 1px 5px; outline: none; min-width: 60px;
}
.new-tab {
  flex: none; width: 28px; height: 28px; display: grid; place-items: center;
  border: none; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.new-tab:hover { background: var(--hover); color: var(--text); }
.new-tab .i { width: 15px; height: 15px; }
.md-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2);
  font-size: 11.5px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.md-toggle .i { width: 14px; height: 14px; }
.md-toggle:hover { color: var(--text); border-color: var(--accent); }
.md-toggle.on { color: var(--on-accent, #fff); border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* Rendered Markdown preview */
.md-preview { position: absolute; inset: 0; overflow: auto; outline: none; background: transparent; }
.textured .monaco-editor, .textured .monaco-editor .margin, .textured .monaco-editor-background { background-color: transparent !important; }
.md-body {
  max-width: 820px; margin: 0 auto; padding: 28px 34px 60px;
  color: var(--text-2); font-size: 14.5px; line-height: 1.7; word-wrap: break-word;
}
.md-body > :first-child { margin-top: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { color: var(--text); line-height: 1.3; margin: 1.5em 0 .6em; font-weight: 700; }
.md-body h1 { font-size: 2em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md-body h2 { font-size: 1.5em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md-body h3 { font-size: 1.25em; }
.md-body h4 { font-size: 1.05em; }
.md-body h5, .md-body h6 { font-size: .95em; color: var(--text-2); }
.md-body p, .md-body ul, .md-body ol, .md-body blockquote, .md-body pre, .md-body .md-table { margin: 0 0 1em; }
.md-body ul, .md-body ol { padding-left: 1.8em; }
.md-body li + li { margin-top: .25em; }
.md-body li > ul, .md-body li > ol { margin: .25em 0 0; }
.md-body li.task { list-style: none; margin-left: -1.4em; }
.md-body li.task input { margin: 0 .5em 0 0; vertical-align: -1px; accent-color: var(--accent); }
.md-body strong { color: var(--text); font-weight: 700; }
.md-body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.md-body a:hover { border-bottom-color: var(--accent); }
.md-body code {
  font-family: var(--font-mono); font-size: .86em; padding: .15em .4em; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.md-body pre {
  padding: 14px 16px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line);
  overflow: auto; line-height: 1.6;
}
.md-body pre code { padding: 0; border: none; background: none; font-size: 13px; white-space: pre; }
.md-body blockquote { padding: .4em 1em; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; color: var(--text-2); }
.md-body blockquote > :last-child { margin-bottom: 0; }
.md-body hr { border: none; height: 1px; background: var(--line-2); margin: 1.8em 0; }
.md-body img { max-width: 100%; border-radius: 8px; }
.md-body .md-table { overflow-x: auto; }
.md-body table { border-collapse: collapse; font-size: .95em; }
.md-body th, .md-body td { border: 1px solid var(--line-2); padding: 6px 12px; }
.md-body th { background: var(--panel-2); color: var(--text); font-weight: 600; }
.md-body tr:nth-child(2n) td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.md-body del { opacity: .7; }
.md-empty { color: var(--muted); font-style: italic; }

/* Toast with an action button (e.g. Undo) */
.toast .toast-act {
  pointer-events: auto; margin-left: 4px; padding: 3px 9px; border-radius: 6px; border: none; cursor: pointer;
  background: color-mix(in srgb, var(--bg) 14%, transparent); color: var(--bg); font: inherit; font-weight: 700;
}
.toast .toast-act:hover { background: color-mix(in srgb, var(--bg) 24%, transparent); }
.tab .count { font-size: 10.5px; padding: 0 6px; border-radius: 999px; background: var(--line); color: var(--text-2); line-height: 16px; }

.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.editor-host { position: absolute; inset: 0; }
.editor-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Fallback textarea editor (when Monaco can't load) */
.fallback-editor {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: none; outline: none;
  padding: 14px 16px; background: transparent; color: var(--text);
  font-family: var(--font-mono); font-size: 14px; line-height: 1.6; tab-size: 4;
}

/* Problems badge */
.problems {
  display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--line); background: transparent;
  font-size: 11.5px; font-weight: 500; color: var(--text-2); cursor: pointer;
}
.problems .p-icon { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.problems.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, transparent); background: var(--err-soft); }
.problems.err .p-icon { background: var(--err); }
.problems.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-soft); }
.problems.warn .p-icon { background: var(--warn); }

/* Gutters */
.gutter { position: relative; z-index: 5; }
.gutter::after { content: ""; position: absolute; border-radius: 4px; background: transparent; transition: background .15s; }
.gutter-v { cursor: col-resize; }
.gutter-v::after { left: 2px; right: 2px; top: 40%; bottom: 40%; }
.gutter-h { cursor: row-resize; }
.gutter-h::after { top: 2px; bottom: 2px; left: 40%; right: 40%; }
.gutter:hover::after, .gutter.dragging::after { background: var(--accent); }
body.resizing, body.resizing * { user-select: none !important; }
body.resizing-v { cursor: col-resize; }
body.resizing-h { cursor: row-resize; }

/* ------------------------------------------------------------------ Console */
.console {
  position: absolute; inset: 0; overflow: auto;
  padding: 12px 16px 24px;
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  outline: none;
}
.console .out { color: var(--text); }
.console .in { color: var(--console-in); font-weight: 500; }
.console .sys {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-ui); font-size: 11.5px; color: var(--muted);
  margin: 2px 0 8px; white-space: normal;
}
.console .sys::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.console .sys.done { margin: 10px 0 4px; }
.console .sys .pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.console .sys .pill.ok { background: var(--ok-soft); color: var(--ok); }
.console .sys .pill.bad { background: var(--err-soft); color: var(--err); }
.console .sys .pill.stop { background: var(--warn-soft); color: var(--warn); }
.console .err-box {
  margin: 10px 0 4px; padding: 12px 14px; border-radius: 10px;
  background: var(--err-soft); border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  font-family: var(--font-ui); font-size: 12.5px; line-height: 1.5; white-space: normal;
  animation: pop .25s var(--ease);
}
.err-box .eb-head { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--err); margin-bottom: 4px; }
.err-box .eb-msg { color: var(--text); font-size: 13px; }
.err-box .eb-line {
  margin-left: auto; border: 1px solid color-mix(in srgb, var(--err) 40%, transparent); background: transparent;
  color: var(--err); border-radius: 6px; padding: 2px 8px; font-size: 11.5px; cursor: pointer; font-weight: 600;
}
.err-box .eb-line:hover { background: var(--err-soft); }
.err-box .eb-code {
  margin-top: 8px; padding: 6px 10px; border-radius: 7px; background: var(--panel);
  font-family: var(--font-mono); font-size: 12px; color: var(--text-2); white-space: pre; overflow: auto;
}
.err-box .eb-code b { color: var(--muted); font-weight: 400; margin-right: 10px; }
.err-box .eb-trace { margin-top: 6px; color: var(--text-2); font-size: 12px; }
.err-box .eb-trace a { color: var(--err); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.console .ask { display: inline; }
.console .ask input {
  border: none; outline: none; background: transparent;
  font-family: var(--font-mono); font-size: inherit; color: var(--console-in); font-weight: 500;
  width: 260px; max-width: 100%; padding: 0 0 0 2px; vertical-align: baseline;
  caret-color: var(--accent);
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
}
.console .ask input::placeholder { color: var(--accent); opacity: .55; font-family: var(--font-ui); font-size: 12px; font-weight: 400; }
.console .ask input.typing { border-bottom-color: transparent; }
@keyframes pulse { 50% { opacity: .55; } }
.console .trunc { color: var(--warn); font-family: var(--font-ui); font-size: 12px; }

.console-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; gap: 6px; white-space: normal; font-family: var(--font-ui); }
.ce-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(34, 211, 238, .10)); border: 1px solid var(--line-2); }
.ce-icon svg { width: 22px; height: 22px; fill: var(--accent); }
.ce-title { font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.ce-sub { font-size: 12px; color: var(--muted); }

/* Run status pill */
.run-status { display: inline-flex; align-items: center; gap: 7px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 11.5px; font-weight: 500; color: var(--text-2); background: var(--hover); margin-right: 4px; }
.run-status .rs-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.run-status.running { color: var(--accent); background: var(--accent-soft); }
.run-status.running .rs-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.run-status.waiting { color: var(--accent-2); background: rgba(34, 211, 238, .1); }
.run-status.waiting .rs-dot { background: var(--accent-2); animation: pulse 1s ease-in-out infinite; }
.run-status.ok { color: var(--ok); background: var(--ok-soft); }
.run-status.ok .rs-dot { background: var(--ok); }
.run-status.error { color: var(--err); background: var(--err-soft); }
.run-status.error .rs-dot { background: var(--err); }
.run-status.stopped { color: var(--warn); background: var(--warn-soft); }
.run-status.stopped .rs-dot { background: var(--warn); }

/* -------------------------------------------------------------------- Files */
.files { position: absolute; inset: 0; display: flex; flex-direction: column; }
.files-toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex: none; }
.files-list { flex: 1; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.files-empty { margin: auto; text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.6; padding: 20px; }
.files-empty code { color: var(--text-2); }
.file-card { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); overflow: hidden; transition: border-color .2s; }
.file-card.changed { border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.file-card.open { border-color: var(--line-2); }
.fc-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; cursor: pointer; }
.fc-head:hover { background: var(--hover); }
.fc-head .i { color: var(--accent); }
.fc-name { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-family: var(--font-mono); font-size: 12px; color: var(--text); padding: 3px 4px; border-radius: 5px; }
.fc-name:focus { background: var(--panel); box-shadow: 0 0 0 1px var(--accent); }
.fc-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.fc-badge { font-size: 10.5px; color: var(--ok); background: var(--ok-soft); border-radius: 999px; padding: 1px 7px; font-weight: 600; }
.fc-body { display: none; border-top: 1px solid var(--line); }
.file-card.open .fc-body { display: block; }
.fc-body textarea {
  display: block; width: 100%; min-height: 120px; height: 160px; resize: vertical; border: none; outline: none;
  padding: 10px 12px; background: var(--panel); color: var(--text);
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55;
}


/* -------------------------------------------------------------------- Tests */
.tests { position: absolute; inset: 0; display: flex; flex-direction: column; }
.tests-toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex: none; }
.btn.accent { color: var(--on-accent, #fff); border: none; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2))); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.accent:hover { color: #fff; filter: brightness(1.08); }
.btn.accent:disabled { opacity: .6; cursor: progress; }
.btn.accent .i { width: 13px; height: 13px; fill: currentColor; stroke: none; }
.tests-summary { white-space: nowrap; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.tests-summary:empty { display: none; }
.tests-summary.all { color: var(--ok); background: var(--ok-soft); }
.tests-summary.some { color: var(--err); background: var(--err-soft); }
.tests-summary.busy { color: var(--accent); background: var(--accent-soft); }
.tests-list { flex: 1; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.test-card { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); overflow: hidden; flex: none; }
.test-card.open { border-color: var(--line-2); }
.tc-head { display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px; cursor: pointer; }
.tc-head:hover { background: var(--hover); }
.tc-num { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); min-width: 24px; }
.tc-name { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 12.5px; color: var(--text); padding: 3px 4px; border-radius: 5px; text-overflow: ellipsis; }
.tc-name:focus { background: var(--panel); box-shadow: 0 0 0 1px var(--accent); }
.verdict { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; color: var(--muted); background: var(--hover); }
.verdict.ac { color: var(--ok); background: var(--ok-soft); }
.verdict.wa, .verdict.re, .verdict.ce { color: var(--err); background: var(--err-soft); }
.verdict.tle { color: var(--warn); background: var(--warn-soft); }
.verdict.review { color: var(--warn); background: var(--warn-soft); }
.tests-summary.review { color: var(--warn); background: var(--warn-soft); }
.btn.gen { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--text); }
.btn.gen .i { color: var(--accent); }
.btn.gen:hover { background: var(--accent-soft); }
.btn.gen.busy .i { animation: spin 1.2s linear infinite; }
.btn.approve { height: 26px; padding: 0 9px; font-size: 11.5px; color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.btn.approve:hover { color: var(--ok); filter: brightness(1.15); }
.btn.approve .i { width: 13px; height: 13px; }
.tc-auto { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 5px; flex: none; }
.tc-note { font-size: 12px; line-height: 1.5; color: var(--text-2); padding: 8px 10px; border-radius: 8px; background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); margin-bottom: 10px; }
.tc-note b { color: var(--text); }
.verdict.running { color: var(--accent); background: var(--accent-soft); animation: pulse 1s ease-in-out infinite; }
.tc-body { display: none; border-top: 1px solid var(--line); padding: 8px; background: var(--panel); }
.test-card.open .tc-body { display: block; }
.tc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tc-cols label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tc-cols textarea {
  height: 150px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; outline: none;
  padding: 8px 10px; background: var(--panel-2); color: var(--text);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5; white-space: pre; text-transform: none; letter-spacing: 0; font-weight: 400;
}
.tc-cols textarea:focus { border-color: var(--accent); }
.tc-diff { margin-bottom: 8px; padding: 9px 11px; border-radius: 8px; background: var(--err-soft); border: 1px solid color-mix(in srgb, var(--err) 25%, transparent); font-size: 12px; line-height: 1.6; }
.tc-diff b { color: var(--err); }
.tc-diff code { display: block; white-space: pre-wrap; word-break: break-word; padding: 2px 8px; border-radius: 5px; background: var(--panel); margin: 2px 0 4px; }
.tc-diff .exp { color: var(--ok); }
.tc-diff .got { color: var(--err); }
.tc-out { margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.tc-out summary { cursor: pointer; }
.tc-out pre { max-height: 200px; overflow: auto; margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px; color: var(--text); }
@media (max-width: 1280px) { .tc-cols { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- Reference */
.reference { position: absolute; inset: 0; overflow: auto; padding: 14px 16px 30px; }
.ref-intro { font-size: 12.5px; color: var(--text-2); line-height: 1.55; margin: 0 0 14px; }
.ref-section { margin-bottom: 18px; }
.ref-section h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.ref-card { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); overflow: hidden; display: flex; flex-direction: column; }
.ref-card-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 8px 7px 11px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.ref-card-head button { opacity: 0; transition: opacity .15s; }
.ref-card:hover .ref-card-head button { opacity: 1; }
.ref-card pre { white-space: pre-wrap; margin: 0; padding: 9px 11px; font-family: var(--font-mono); font-size: 12px; line-height: 1.55; border-top: 1px solid var(--line); background: var(--panel); overflow: auto; flex: 1; }
.ref-card .note { font-size: 11px; color: var(--muted); padding: 6px 11px; border-top: 1px solid var(--line); }
.ref-fn { display: grid; grid-template-columns: minmax(180px, auto) 1fr; gap: 3px 14px; font-size: 12px; }
.ref-fn .sig { font-family: var(--font-mono); color: var(--accent); white-space: nowrap; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.ref-fn .d { color: var(--text-2); padding: 6px 0; border-bottom: 1px dashed var(--line); line-height: 1.45; }
.ref-fn .d code { color: var(--muted); display: block; margin-top: 2px; }

/* Syntax colours used in reference snippets */
.tk-kw { color: var(--tk-kw, #c792ea); font-weight: 600; }
.tk-io { color: var(--tk-io, #82aaff); font-weight: 600; }
.tk-ty { color: var(--tk-ty, #ffcb6b); }
.tk-fn { color: var(--tk-fn, #82aaff); }
.tk-num { color: var(--tk-num, #f78c6c); }
.tk-str { color: var(--tk-str, #c3e88d); }
.tk-com { color: var(--tk-com, #5f6b82); font-style: italic; }
.tk-op { color: var(--tk-op, #89ddff); }
.tk-as { color: var(--tk-as, #ff5c8a); font-weight: 700; }

/* --------------------------------------------------------------- Status bar */
.statusbar {
  flex: none; height: 28px; display: flex; align-items: center; gap: 2px; padding: 0 14px;
  font-size: 11.5px; color: var(--muted);
}
.sb-item { padding: 0 8px; white-space: nowrap; }
.sb-lang { color: var(--accent); }

/* ------------------------------------------------------------------- Modal */
.modal {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 30px;
  background: rgba(5, 8, 14, .6); backdrop-filter: blur(6px);
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: min(1000px, 100%); height: min(720px, 100%);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
  animation: pop .25s var(--ease);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px 16px 14px 20px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.modal-body { flex: 1; position: relative; min-height: 0; }
.modal-body pre { margin: 0; padding: 14px 18px; position: absolute; inset: 0; overflow: auto; font-family: var(--font-mono); font-size: 12.5px; }

/* ------------------------------------------------------------------- Toasts */
.toasts { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 9px; padding: 9px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 12.5px; font-weight: 500;
  box-shadow: var(--shadow); animation: toastIn .3s var(--ease);
}
.toast .i { width: 15px; height: 15px; }
.toast.out { animation: toastOut .25s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* Monaco tweaks */
.monaco-editor .error-line { background: var(--err-soft); }
.monaco-editor .error-glyph { background: var(--err); border-radius: 50%; width: 8px !important; height: 8px !important; margin-left: 6px; margin-top: 6px; }
.monaco-editor .current-run-line { background: var(--accent-soft); }
.monaco-hover code { font-family: var(--font-mono); }

/* ------------------------------------------------------------- Responsive */
@media (max-width: 1280px) {
  #inputHint { display: none !important; }
}
@media (max-width: 1100px) {
  .brand-sub, .file-chip { display: none; }
  .dropdown.examples { width: 420px; grid-template-columns: 1fr; }
}
.mobile-nav { display: none; }

/* Phones and small tablets: one panel at a time, switched by a bottom nav. */
@media (max-width: 860px) {
  .app { height: 100vh; height: 100dvh; }
  .topbar { gap: 2px; padding: 0 8px; height: 54px; }
  .brand { padding-right: 2px; }
  .brand-text, .file-chip, #btnFormat, #btnJs, #btnShare, #btnFlow, #btnExam, .statusbar { display: none; }
  .actions .btn.star { display: none !important; }
  .btn.star { width: 32px; padding: 0; justify-content: center; border-color: transparent; background: transparent; margin-right: 0; }
  .btn.star .star-count { display: none !important; }
  .btn.run { margin-left: 4px; padding: 0 12px 0 8px; }
  .btn.run kbd, .menus .btn .chev { display: none; }
  .menus .btn { padding: 0 8px; }

  .dropdown, .actions .dropdown { position: fixed; top: 58px; left: 8px; right: 8px; width: auto; min-width: 0; max-height: calc(100dvh - 140px); transform-origin: top center; }
  .dropdown.examples { width: auto; grid-template-columns: 1fr; }
  .dropdown.settings { width: auto; }

  .workspace { display: flex; flex-direction: column; padding: 0 6px; }
  .gutter { display: none; }
  .workspace > .panel, .right-col { flex: 1; min-height: 0; }
  .right-col { display: flex; flex-direction: column; }
  .right-col > .panel { flex: 1; }
  .app[data-mview="code"] #rightPane,
  .app[data-mview="input"] #leftPane, .app[data-mview="input"] #bottomRight,
  .app[data-mview="output"] #leftPane, .app[data-mview="output"] #topRight { display: none; }

  .panel-head { padding: 0 4px; }
  .tab { padding: 0 9px; }
  .ftab { padding: 0 2px 0 8px; }
  .ftab .ftab-name { max-width: 110px; }
  .ftab-close { width: 26px; height: 26px; opacity: .7; }
  .md-body { padding: 18px 16px 40px; font-size: 14px; }
  .md-toggle span { display: none; }
  .md-toggle { padding: 0 8px; }
  .hint, #inputHint { display: none !important; }
  .run-status { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ce-sub { display: none; }
  .console { padding: 12px 12px 24px; }
  .ref-grid { grid-template-columns: 1fr; }
  .ref-fn { grid-template-columns: 1fr; }
  .ref-fn .sig { border-bottom: none; padding-bottom: 0; }
  .tc-head { flex-wrap: wrap; row-gap: 2px; padding: 6px 6px 6px 10px; }
  .tc-name { flex: 1 1 calc(100% - 40px); }
  .tc-head .verdict { margin-right: auto; margin-left: 30px; }
  .tc-head .btn.icon.sm { width: 32px; height: 30px; }
  .files-toolbar { flex-wrap: wrap; }
  .tests-toolbar .tests-summary { font-size: 11px; padding: 3px 8px; }
  .btn.approve span { display: none; }
  .tc-auto { display: none; }
  #btnCopyOut { display: none !important; }
  .modal { padding: 10px; }

  .mobile-nav {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; flex: none;
    margin: 6px 6px calc(6px + env(safe-area-inset-bottom)); padding: 4px;
    border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
  }
  .mobile-nav button {
    position: relative; display: flex; align-items: center; justify-content: center; gap: 7px;
    height: 42px; border: none; border-radius: 10px; background: transparent;
    color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
    transition: background .15s, color .15s;
  }
  .mobile-nav button.active { color: var(--text); background: var(--active); }
  .mobile-nav button.active .i { color: var(--accent); }
  .mobile-nav .nav-dot { position: absolute; top: 9px; right: 16%; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); display: none; }
  .mobile-nav button.unseen .nav-dot { display: block; }
}
@media (max-width: 380px) {
  .mobile-nav button span { font-size: 11.5px; }
  .menus .btn .i:first-child { display: none; }
}

/* Tests panel: wrap the toolbar and card headers when the panel is narrow */
.tests-toolbar { flex-wrap: wrap; row-gap: 6px; }
#testsList { container-type: inline-size; }
@container (max-width: 520px) {
  .tc-head { flex-wrap: wrap; row-gap: 2px; }
  .tc-name { flex: 1 1 calc(100% - 40px); }
  .tc-head .tc-auto { display: none; }
  .tc-head .verdict { margin-right: auto; margin-left: 30px; }
}

/* Run button: the stop state keeps its own colours; the run state follows the theme */
.btn.run { color: var(--on-accent, #fff); }

/* ------------------------------------------------------------ Theme picker */
.set-theme { width: 100%; border: none; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 8px; }
.set-theme:hover { background: var(--hover); }
.theme-dots { display: inline-flex; gap: 3px; }
.theme-dots i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--line-2); }
.theme-modal { width: min(940px, 100%); height: min(760px, 100%); }
.theme-body { flex: 1; min-height: 0; overflow: auto; padding: 6px 20px 24px; }
.theme-group { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 16px 2px 10px; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.theme-tile {
  display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; text-align: left; cursor: pointer;
  border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel-2); color: var(--text); font: inherit;
  transition: transform .18s var(--ease), border-color .18s, box-shadow .18s;
}
.theme-tile:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 10px 26px rgba(0,0,0,.25); }
.theme-tile.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tt-preview { position: relative; height: 118px; padding: 9px; display: grid; grid-template-columns: 1.55fr 1fr; gap: 6px; }
.tt-pane { border-radius: 6px; border: 1px solid; overflow: hidden; display: flex; flex-direction: column; }
.tt-bar { height: 12px; display: flex; align-items: center; gap: 3px; padding: 0 5px; flex: none; }
.tt-bar i { width: 18px; height: 3px; border-radius: 2px; }
.tt-code { flex: 1; padding: 4px 6px; font-family: var(--font-mono); font-size: 8.4px; line-height: 1.5; white-space: pre; overflow: hidden; }
.tt-side { display: grid; grid-template-rows: 1fr 1fr; gap: 6px; }
.tt-out { flex: 1; padding: 4px 6px; font-family: var(--font-mono); font-size: 8px; line-height: 1.5; white-space: pre; overflow: hidden; }
.tt-run { position: absolute; top: 4px; right: 13px; width: 26px; height: 9px; border-radius: 4px; }
.tt-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px 10px; border-top: 1px solid var(--line); }
.tt-name { font-weight: 600; font-size: 13px; }
.tt-tag { font-size: 11px; color: var(--muted); margin-top: 1px; }
.tt-check { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent, #fff); opacity: 0; transform: scale(.6); transition: all .2s var(--ease); flex: none; }
.tt-check svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.theme-tile.active .tt-check { opacity: 1; transform: none; }
@media (max-width: 860px) {
  .theme-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .tt-preview { height: 96px; }
  .theme-body { padding: 4px 12px 20px; }
}

/* ---------------------------------------------------------------- compiler buddy */
.buddy { position: fixed; right: 18px; bottom: 40px; z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: none; }
.buddy > * { pointer-events: auto; }
.buddy[hidden] { display: none; }
.bd-avatar {
  position: relative; width: 58px; height: 58px; padding: 5px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line-2); background: radial-gradient(circle at 35% 30%, var(--panel-2), var(--panel));
  box-shadow: 0 10px 28px rgba(0,0,0,.35), 0 0 0 3px color-mix(in srgb, var(--bd-accent) 22%, transparent);
  transition: transform .2s, box-shadow .2s;
  animation: bd-bob 4.5s ease-in-out infinite;
}
.bd-avatar:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 14px 30px rgba(0,0,0,.4), 0 0 0 4px color-mix(in srgb, var(--bd-accent) 40%, transparent); }
.bd-avatar.cheer { animation: bd-cheer .7s cubic-bezier(.3,1.6,.5,1), bd-bob 4.5s ease-in-out .7s infinite; }
.buddy.open .bd-avatar { animation: none; }
.bd-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.bd-news { position: absolute; top: 2px; right: 2px; width: 11px; height: 11px; border-radius: 50%; background: var(--bd-accent2); border: 2px solid var(--panel); display: none; }
.bd-avatar.has-news .bd-news { display: block; }
.bd-svg .m { display: none; }
.buddy[data-mood="happy"] .bd-svg .m-happy, .buddy[data-mood="sad"] .bd-svg .m-sad, .buddy[data-mood="think"] .bd-svg .m-think { display: inline; }
.bd-svg .eyes { transform-box: fill-box; transform-origin: center; animation: bd-blink 5s infinite; }
.bd-svg .spin { transform-origin: 32px 33px; animation: bd-spin 24s linear infinite; }
.bd-svg .flicker { transform-origin: 32px 58px; animation: bd-flicker 1.6s ease-in-out infinite; }
.bd-svg .sway { transform-origin: 32px 26px; animation: bd-sway 3s ease-in-out infinite; }
.bd-svg .wave { transform-origin: 32px 44px; animation: bd-sway 2.4s ease-in-out infinite; }
.bd-svg .blink-light { animation: bd-pulse 1.4s ease-in-out infinite; }
.buddy[data-mood="sad"] .bd-avatar { animation: bd-shake .45s ease-in-out 1; }
@keyframes bd-bob { 0%,100% { translate: 0 0; } 50% { translate: 0 -4px; } }
@keyframes bd-cheer { 0% { transform: scale(1); } 35% { transform: scale(1.18) rotate(-8deg); } 65% { transform: scale(.96) rotate(6deg); } 100% { transform: scale(1); } }
@keyframes bd-shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px) rotate(-4deg); } 75% { transform: translateX(4px) rotate(4deg); } }
@keyframes bd-blink { 0%,92%,100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes bd-spin { to { transform: rotate(360deg); } }
@keyframes bd-flicker { 0%,100% { transform: scale(1,1); } 50% { transform: scale(.96,1.05); } }
@keyframes bd-sway { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes bd-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .bd-avatar, .bd-svg * { animation: none !important; } }

.bd-bubble {
  max-width: 280px; padding: 11px 13px; border-radius: 14px 14px 4px 14px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text); font-size: 13px; line-height: 1.45;
  box-shadow: 0 12px 30px rgba(0,0,0,.35); opacity: 0; transform: translateY(6px) scale(.97); transform-origin: bottom right;
  transition: opacity .18s, transform .18s;
}
.bd-bubble.show { opacity: 1; transform: none; }
.bd-bubble code, .bd-text code { font-family: var(--mono, ui-monospace, monospace); font-size: .92em; padding: 1px 5px; border-radius: 5px; background: var(--active, rgba(127,127,127,.15)); }
.bd-bubble-chips, .bd-msg-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bd-bubble-chips button, .bd-msg-chips button, .bd-chips button {
  height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--bd-accent) 45%, var(--line)); background: color-mix(in srgb, var(--bd-accent) 12%, transparent); color: var(--text);
}
.bd-bubble-chips button:hover, .bd-msg-chips button:hover, .bd-chips button:hover { background: color-mix(in srgb, var(--bd-accent) 24%, transparent); }

.bd-panel {
  width: 360px; height: min(520px, calc(100vh - 150px)); display: flex; flex-direction: column; overflow: hidden;
  border-radius: 16px; border: 1px solid var(--line-2); background-color: var(--panel); background-image: var(--tex-panel, none);
  box-shadow: 0 24px 60px rgba(0,0,0,.45); animation: bd-pop .2s ease-out;
}
.bd-panel[hidden] { display: none; }
@keyframes bd-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.bd-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bd-accent) 10%, var(--head, var(--panel))); }
.bd-head-av { width: 38px; height: 38px; flex: none; }
.bd-who { flex: 1; min-width: 0; }
.bd-name { font-weight: 700; font-size: 14px; color: var(--text); }
.bd-role { font-size: 11.5px; color: var(--muted); }
.bd-x { width: 30px; height: 30px; border: none; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.bd-x:hover { background: var(--active, rgba(127,127,127,.15)); color: var(--text); }
.bd-x svg, .bd-form button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.bd-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bd-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.bd-msg.user { justify-content: flex-end; }
.bd-mini { width: 26px; height: 26px; flex: none; }
.bd-text { max-width: calc(100% - 34px); padding: 9px 11px; border-radius: 12px 12px 12px 4px; font-size: 13px; line-height: 1.5; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); overflow-wrap: anywhere; }
.bd-msg.user .bd-text { border-radius: 12px 12px 4px 12px; background: var(--bd-accent); color: var(--on-accent, #fff); border-color: transparent; }
.bd-code { position: relative; margin: 7px 0 3px; }
.bd-code pre { margin: 0; padding: 9px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font-family: var(--mono, ui-monospace, monospace); font-size: 12px; line-height: 1.5; overflow-x: auto; white-space: pre; color: var(--text); }
.bd-insert { position: absolute; top: 5px; right: 5px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11px; font-weight: 600; cursor: pointer; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2); opacity: 0; transition: opacity .15s; }
.bd-code:hover .bd-insert, .bd-insert:focus { opacity: 1; }
@media (hover: none) { .bd-insert { opacity: 1; } }
.bd-chips { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; scrollbar-width: none; }
.bd-chips button { flex: none; }
.bd-form { display: flex; gap: 8px; padding: 10px 12px 12px; }
.bd-form input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: inherit; font-size: 13px; outline: none; }
.bd-form input:focus { border-color: var(--bd-accent); }
.bd-form button { width: 36px; height: 36px; flex: none; border-radius: 10px; border: none; cursor: pointer; background: var(--bd-accent); color: var(--on-accent, #fff); display: grid; place-items: center; }

@media (max-width: 860px) {
  .buddy { right: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); }
  .bd-avatar { width: 48px; height: 48px; padding: 4px; }
  .bd-panel { width: calc(100vw - 24px); height: min(480px, calc(100vh - 170px)); }
  .bd-bubble { max-width: calc(100vw - 90px); }
}
.bd-typing { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.bd-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bd-dot 1.1s ease-in-out infinite; }
.bd-typing i:nth-child(2) { animation-delay: .15s; }
.bd-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bd-dot { 0%,60%,100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.bd-text a { color: var(--bd-accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.bd-wait { margin-left: 6px; font-size: 12px; color: var(--muted); }
.bd-form-card { display: flex; flex-direction: column; gap: 9px; width: 100%; }
.bd-fc-title { font-weight: 600; }
.bd-form-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.bd-form-card select, .bd-form-card textarea {
  width: 100%; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: inherit; font-size: 13px; outline: none;
}
.bd-form-card textarea { resize: vertical; min-height: 90px; }
.bd-form-card select:focus, .bd-form-card textarea:focus { border-color: var(--bd-accent); }
.bd-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.bd-seg label { flex-direction: row; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-2); color: var(--text); font-size: 12.5px; cursor: pointer; }
.bd-seg label:has(input:checked) { border-color: var(--bd-accent); background: color-mix(in srgb, var(--bd-accent) 14%, transparent); }
.bd-file { flex-direction: row !important; align-items: center; padding: 8px 10px; border-radius: 8px; border: 1px dashed var(--line-2); cursor: pointer; color: var(--text) !important; }
.bd-file input { display: none; }
.bd-ms { border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; }
.bd-ms summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text); }
.bd-ms[open] { display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; }
.bd-ms[open] summary { margin-bottom: 2px; }
.bd-ms small { font-size: 11.5px; color: var(--muted); }
.bd-ms textarea { min-height: 70px !important; }
.bd-go { align-self: flex-start; height: 32px; padding: 0 14px; border-radius: 9px; border: none; cursor: pointer; font-weight: 600; font-size: 13px; background: var(--bd-accent); color: var(--on-accent, #fff); }
.bd-go:disabled { opacity: .55; cursor: default; }

/* ---------------------------------------------------------------- debugger */
.btn.debug-btn { gap: 6px; margin-right: 6px; }
.btn.debug-btn .i { color: var(--warn); }
.debugging .btn.debug-btn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.monaco-editor .bp-glyph { cursor: pointer; }
.monaco-editor .bp-glyph::before { content: ""; display: block; width: 10px; height: 10px; margin: 5px 0 0 5px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 2px color-mix(in srgb, #e5484d 30%, transparent); }
.monaco-editor .dbg-line { background: color-mix(in srgb, #f6c343 22%, transparent); }
.monaco-editor .dbg-arrow::after { content: ""; position: absolute; margin: 4px 0 0 4px; width: 0; height: 0; border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 9px solid #f6c343; }
.monaco-editor .margin-view-overlays .cgmr { cursor: pointer; }
.bp-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #e5484d; vertical-align: middle; }

.dbg-bar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 8; display: flex; align-items: center; gap: 2px;
  padding: 4px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--panel-2); box-shadow: 0 10px 30px rgba(0,0,0,.35); max-width: calc(100% - 16px);
}
.dbg-bar[hidden] { display: none; }
.dbg-state { padding: 0 10px 0 8px; font-size: 12px; font-weight: 600; color: var(--warn); white-space: nowrap; }
.dbg-b { white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 9px; border: none; border-radius: 8px; background: transparent; color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer; }
.dbg-b:hover:not(:disabled) { background: var(--active); }
.dbg-b:disabled { opacity: .4; cursor: default; }
.dbg-b svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dbg-b.stop { color: var(--err); }
.dbg-b.stop svg { fill: currentColor; stroke: none; }

.dbg-view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.dbg-seg { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.dbg-seg button { height: 26px; padding: 0 10px; border-radius: 7px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.dbg-seg button.active { color: var(--text); background: var(--active); border-color: var(--line); }
.dbg-seg-note { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.dbg-pane { display: none; flex: 1; overflow: auto; padding: 10px 12px; }
.dbg-pane.active { display: block; }
.dbg-empty { color: var(--muted); font-size: 13px; line-height: 1.6; text-align: center; padding: 24px 12px; }
.dbg-note { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.dv-stack { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.dv-scal { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.dv-var { display: inline-flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; font-family: var(--mono, ui-monospace, monospace); font-size: 12.5px; }
.dv-name { padding: 4px 8px; background: var(--active); color: var(--text-2); }
.dv-val { padding: 4px 9px; color: var(--text); min-width: 22px; }
.dv-empty { color: var(--muted); }
.dv-var.chg { border-color: #f6c343; animation: dv-flash 1.2s ease-out; }
.dv-var.chg .dv-val { background: color-mix(in srgb, #f6c343 18%, transparent); }
.dv-arr { margin-bottom: 14px; }
.dv-arr-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-family: var(--mono, ui-monospace, monospace); }
.dv-arr-title b { color: var(--text); }
.dv-row { display: flex; flex-wrap: wrap; gap: 4px; }
.dv-grid { display: inline-grid; gap: 4px; align-items: center; }
.dv-h { font-size: 10.5px; color: var(--muted); text-align: center; padding: 0 4px; font-family: var(--mono, ui-monospace, monospace); }
.dv-box { position: relative; min-width: 44px; height: 40px; padding: 13px 6px 3px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--panel-2); text-align: center; font-family: var(--mono, ui-monospace, monospace); font-size: 12.5px; color: var(--text); transition: background .3s; }
.dv-box.empty { background: transparent; border-style: dashed; }
.dv-i { position: absolute; top: 2px; left: 0; right: 0; font-size: 9.5px; color: var(--muted); }
.dv-box.empty.chg { border-style: solid; }
.dv-box.chg { border-color: #f6c343; background: color-mix(in srgb, #f6c343 22%, var(--panel-2)); animation: dv-pop .5s ease-out; }
@keyframes dv-pop { 0% { transform: scale(1.18); } 100% { transform: none; } }
@keyframes dv-flash { 0% { box-shadow: 0 0 0 4px color-mix(in srgb, #f6c343 45%, transparent); } 100% { box-shadow: none; } }

table.trace { border-collapse: collapse; font-family: var(--mono, ui-monospace, monospace); font-size: 12.5px; min-width: 100%; }
table.trace th, table.trace td { border: 1px solid var(--line-2); padding: 4px 9px; text-align: center; white-space: nowrap; color: var(--text); }
table.trace th { position: sticky; top: -10px; background: var(--panel-2); font-weight: 700; z-index: 1; }
table.trace td.tl a { color: var(--muted); cursor: pointer; text-decoration: none; }
table.trace td.tl a:hover { color: var(--accent); text-decoration: underline; }
table.trace td.to { text-align: left; color: var(--ok); }
table.trace tbody tr:last-child td { background: color-mix(in srgb, #f6c343 12%, transparent); }
table.trace tr.err td { background: var(--err-soft); }

.disk { display: flex; flex-direction: column; gap: 10px; }
.dk-file { border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; font-family: var(--mono, ui-monospace, monospace); font-size: 12.5px; }
.dk-name { display: flex; align-items: center; gap: 7px; padding: 7px 10px; background: var(--active); font-family: inherit; font-weight: 600; color: var(--text); }
.dk-name .i { width: 15px; height: 15px; }
.dk-name small { margin-left: auto; color: var(--muted); font-weight: 400; }
.dk-tag { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, #f6c343 25%, transparent); color: var(--text); }
.dk-line { display: flex; gap: 10px; padding: 1px 10px; color: var(--text); }
.dk-line span { width: 24px; text-align: right; color: var(--muted); flex: none; }
.dk-line.chg { background: color-mix(in srgb, #f6c343 15%, transparent); }
@media (max-width: 860px) {
  .btn.debug-btn span { display: none; }
  .btn.debug-btn { width: 34px; padding: 0; justify-content: center; margin-right: 2px; }
  .dbg-b span { display: none; }
  .dbg-state { padding: 0 6px; }
}
@media (max-width: 860px) {
  body > .dbg-bar { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 70; }
  body.debugging .buddy { display: none; }
}

/* ---------------------------------------------------------------- flowchart */
.flow-modal { width: min(1200px, 96vw); height: min(860px, 92vh); display: flex; flex-direction: column; }
.flow-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.flow-tools .btn.sm:not(.icon) { height: 30px; padding: 0 10px; font-size: 12px; font-weight: 700; }
.flow-body { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--line); background-color: var(--bg); background-image: radial-gradient(circle, color-mix(in srgb, var(--muted) 35%, transparent) 1px, transparent 1.4px); background-size: 22px 22px; }
.flow-canvas { padding: 12px; width: max-content; margin: 0 auto; }
.fc-svg { display: block; }
.fc-shape { fill: var(--panel-2); stroke: var(--text-2); stroke-width: 1.6; }
.fc-shape-line { stroke: var(--text-2); stroke-width: 1.6; }
.fc-term { fill: var(--accent); stroke: none; }
.fc-node:has(.fc-term) .fc-text { fill: var(--on-accent); font-weight: 700; }
.fc-dec { fill: var(--panel); stroke: var(--accent-2); }
.fc-io { stroke: var(--ok); }
.fc-sub { stroke: var(--warn); }
.fc-line { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linejoin: round; }
.fc-arrowhead { fill: var(--muted); }
.fc-text { font: 13px 'JetBrains Mono', ui-monospace, Consolas, monospace; fill: var(--text); pointer-events: none; }
.fc-label { font: 600 11px Inter, system-ui, sans-serif; fill: var(--muted); }
.fc-title { font: 700 14px Inter, system-ui, sans-serif; fill: var(--text); }
.fc-node[data-line] { cursor: pointer; }
.fc-node[data-line]:hover .fc-shape { filter: brightness(1.25); stroke-width: 2.4; }
@media (max-width: 860px) { .flow-modal { width: 100vw; height: 100%; } }

/* ---------------------------------------------------------------- exam mode */
.exam-modal { width: min(560px, 100%); }
.exam-form { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.ex-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.ex-field select { height: 36px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: inherit; font-size: 13.5px; font-weight: 500; }
.ex-len { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2); cursor: pointer; color: var(--text); font-size: 13.5px; }
.ex-len input { grid-row: span 2; accent-color: var(--accent); }
.ex-len small { color: var(--muted); font-weight: 400; font-size: 12px; }
.ex-len:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.ex-rules { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 12.5px; line-height: 1.7; }
.ex-noai { padding: 10px 12px; border-radius: 9px; background: var(--warn-soft); color: var(--text); font-size: 12.5px; }
.ex-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
#examMsg { font-size: 12.5px; color: var(--muted); margin-right: auto; }

.topbar .exam-bar { position: static; transform: none; margin: 0 auto; flex: 0 1 auto; min-width: 0; box-shadow: none; }
.exam-bar {
  position: fixed; top: 9px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 6px 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel-2); box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 46vw;
}
.exam-bar[hidden] { display: none; }
.exam-bar .i { width: 16px; height: 16px; color: var(--accent); flex: none; }
.ex-title { font-size: 12.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ex-clock { font-family: var(--mono, ui-monospace, monospace); font-weight: 700; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.exam-bar.warn .ex-clock { color: var(--warn); }
.exam-bar.late { border-color: var(--err); animation: ex-pulse 1s ease-in-out infinite; }
.exam-bar.late .ex-clock { color: var(--err); }
@keyframes ex-pulse { 50% { box-shadow: 0 0 0 4px var(--err-soft); } }
.ex-submit { height: 28px; padding: 0 14px; border-radius: 999px; border: none; cursor: pointer; font-weight: 700; font-size: 12.5px; background: var(--accent); color: var(--on-accent, #fff); white-space: nowrap; }
.ex-submit:disabled { opacity: .6; cursor: progress; }
.ex-quit { width: 26px; height: 26px; border-radius: 50%; border: none; background: transparent; color: var(--muted); font-size: 17px; cursor: pointer; }
.ex-quit:hover { background: var(--active); color: var(--text); }
@media (max-width: 860px) {
  .exam-bar { top: auto; bottom: calc(86px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); }
  body.in-exam .buddy, body.in-task .buddy { bottom: calc(136px + env(safe-area-inset-bottom)); }
  body.debugging.in-exam .dbg-bar { bottom: calc(132px + env(safe-area-inset-bottom)); }
}
@media (min-width: 861px) and (max-width: 1240px) {
  body.in-exam #btnFormat, body.in-exam #btnJs, body.in-exam #btnShare, body.in-exam .btn.star { display: none; }
  body.in-task #btnFormat, body.in-task #btnJs, body.in-task #btnShare, body.in-task .btn.star, body.in-task #btnFlow { display: none; }
  .topbar .ex-title { display: none; }
}

/* ------------------------------------------------------------------ badges */
.badge-modal { width: min(820px, 100%); max-height: min(760px, 100%); }
.badge-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 20px 20px; }
.badge-sum { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 13px; margin: 6px 0 14px; }
.badge-sum .bg-prog { flex: 1; margin: 0; }
.bg-prog { height: 6px; border-radius: 4px; background: var(--line-2); overflow: hidden; margin-top: 8px; }
.bg-prog.big { height: 8px; }
.bg-prog i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s var(--ease); }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.bg-card { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel-2); }
.bg-card .bg-icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; font-size: 24px; border-radius: 50%;
  background: var(--line); filter: grayscale(1); opacity: .45; }
.bg-card.got { border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2)); }
.bg-card.got .bg-icon { filter: none; opacity: 1; background: color-mix(in srgb, var(--accent) 18%, var(--panel)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent); }
.bg-text { min-width: 0; flex: 1; }
.bg-name { font-weight: 600; font-size: 13.5px; }
.bg-desc { font-size: 12px; color: var(--text-2); margin-top: 2px; line-height: 1.4; }
.bg-when { font-size: 11px; color: var(--muted); margin-top: 5px; }
.bg-card.got .bg-when { color: var(--ok); }
.bg-reward { margin-top: 8px; font: inherit; font-size: 11.5px; font-weight: 600; padding: 4px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
.bg-reward:disabled { cursor: default; opacity: .6; border-style: dashed; background: none; }
.bg-reward:not(:disabled):hover { background: var(--accent); color: var(--on-accent, #fff); }
.badge-foot { margin-top: 16px; text-align: right; }
.badge-foot button { font: inherit; font-size: 12px; background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; }
.set-badge { font-size: 16px; }
.rare-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.rare-head span { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; }
.rare-head button { font: inherit; text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 600; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; }
.theme-tile { position: relative; }
.theme-tile.rare { border-color: color-mix(in srgb, var(--accent) 40%, var(--line-2)); }
.tt-rare { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 1px 6px; border-radius: 999px; vertical-align: 2px;
  background: linear-gradient(135deg, #e9c25b, #b07cff); color: #160f22; }
.theme-tile.locked .tt-preview { filter: grayscale(.85) brightness(.6) blur(.6px); }
.theme-tile.locked:hover { transform: none; border-color: var(--line-2); box-shadow: none; cursor: not-allowed; }
.tt-lock { position: absolute; z-index: 2; top: 40px; left: 50%; transform: translateX(-50%); width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0,0,0,.6); color: #fff; }
.tt-lock svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.theme-tile.locked .tt-tag { white-space: normal; line-height: 1.35; }
@media (max-width: 860px) {
  .badge-grid { grid-template-columns: 1fr; }
  .badge-body { padding: 4px 12px 16px; }
  .tt-lock { top: 30px; }
}

/* -------------------------------------------------------------- split view */
.panel-body.split #editor, .panel-body.split #mdPreview { right: calc((1 - var(--split, .5)) * 100%); }
.split-pane { position: absolute; top: 0; bottom: 0; right: 0; width: calc((1 - var(--split, .5)) * 100%); display: flex; flex-direction: column;
  border-left: 1px solid var(--line-2); }
.split-gutter { position: absolute; left: -5px; top: 0; bottom: 0; width: 9px; cursor: col-resize; z-index: 6; }
.split-gutter:hover, .resizing-col .split-gutter { background: linear-gradient(90deg, transparent 3px, var(--accent) 3px, var(--accent) 5px, transparent 5px); }
.resizing-col, .resizing-col * { cursor: col-resize !important; user-select: none; }
/* The split side's controls live in the same bar as the file tabs, above the right-hand editor. */
.split-head { order: 3; align-self: stretch; flex: none; width: calc((1 - var(--split, .5)) * 100% - 2px); margin-right: -8px; display: flex; align-items: center; gap: 4px; padding: 0 6px 0 8px; border-left: 1px solid var(--line-2); }
.split-head[hidden] { display: none; }
#leftPane.split-on .head-right .md-toggle span { display: none; }
#leftPane.split-on .head-right .md-toggle { padding: 0 8px; }
.split-head select { flex: 1; min-width: 0; height: 28px; padding: 0 22px 0 9px; border-radius: 7px 7px 0 0; border: 0; border-bottom: 2px solid var(--accent); background: var(--panel); color: var(--text); font: inherit; font-size: 12.5px; font-weight: 600; outline: none; cursor: pointer; }
.split-head select:focus { border-color: var(--accent); }
.split-b { height: 26px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line-2); background: none; color: var(--text-2); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; display: grid; place-items: center; }
.split-b.icon { width: 26px; padding: 0; }
.split-b svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.split-b:hover { color: var(--text); border-color: var(--accent); }
.split-body { position: relative; flex: 1; min-height: 0; }
.split-body .md-body { padding: 20px 22px 40px; font-size: 14px; }
.split-toggle.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
@media (max-width: 860px) { #btnSplit, [data-action="split"] { display: none !important; } }

/* -------------------------------------------------------------- classroom */
.acc-btn { padding: 0; }
.acc-av { width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent, #fff); }
.acc-av.t { background: linear-gradient(135deg, #e9c25b, #c48a2c); color: #1a1306; }
.class-modal { width: min(900px, 100%); max-height: min(760px, 100%); }
.class-body { flex: 1; min-height: 0; overflow: auto; padding: 6px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
#classTitle { display: flex; align-items: center; gap: 6px; }
.cl-back { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line-2); background: none; color: var(--text); cursor: pointer; display: grid; place-items: center; }
.cl-back svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cl-code { font-family: var(--font-mono); font-weight: 700; letter-spacing: .12em; padding: 3px 8px; border-radius: 7px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); font-size: 12.5px; }
.cl-code.big { font-size: 14px; }
.cl-empty { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13px; display: grid; justify-items: center; gap: 6px; }
.cl-empty p { margin: 0; max-width: 460px; line-height: 1.5; }
.cl-empty b { color: var(--text); }
.cl-auth, .cl-new { display: flex; flex-direction: column; gap: 12px; max-width: 460px; width: 100%; margin: 8px auto 0; }
.cl-new { max-width: none; }
.cl-f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.cl-f.half { max-width: 260px; }
.cl-f input, .cl-f textarea, .cl-row-form input {
  height: 36px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: inherit; font-size: 13.5px; font-weight: 400; outline: none; }
.cl-f textarea { height: auto; padding: 9px 11px; resize: vertical; line-height: 1.5; }
.cl-f textarea.mono { font-family: var(--font-mono); font-size: 12.5px; }
.cl-f input:focus, .cl-f textarea:focus, .cl-row-form input:focus { border-color: var(--accent); }
.cl-note { font-weight: 400; font-size: 12.5px; color: var(--text-2); line-height: 1.5; padding: 9px 11px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); }
.cl-role { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cl-role label { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2); cursor: pointer; font-size: 13px; }
.cl-role input { display: none; }
.cl-role small { color: var(--muted); font-size: 11.5px; }
.cl-role label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.cl-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
#clMsg { font-size: 12.5px; color: var(--muted); margin-right: auto; }
#clMsg:empty { display: none; }
#clMsg.err { color: var(--err); }
.cl-switch { font-size: 12.5px; color: var(--muted); text-align: center; }
.cl-switch a { color: var(--accent); font-weight: 600; }
.cl-row-form { display: flex; gap: 8px; }
.cl-row-form input { flex: 1; min-width: 0; }
.cl-list { display: flex; flex-direction: column; gap: 8px; }
.cl-card { display: flex; align-items: center; gap: 12px; justify-content: space-between; text-align: left; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer; }
.cl-card > div { min-width: 0; flex: 1; }
.cl-card:not(.static):hover { border-color: var(--accent); }
.cl-card.static { cursor: default; }
.cl-name { font-weight: 600; font-size: 13.5px; }
.cl-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cl-pill { font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.cl-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; margin: 4px 0 8px; }
.cl-h small { font-weight: 400; color: var(--muted); }
.cl-h > .btn, .cl-h > .cl-link { margin-left: auto; }
.btn.sm { height: 28px; padding: 0 11px; font-size: 12.5px; }
.cl-split { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; }
.cl-people { display: flex; flex-direction: column; gap: 6px; }
.cl-person { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.cl-person > div { flex: 1; min-width: 0; }
.cl-person small { color: var(--muted); font-size: 11.5px; display: block; overflow: hidden; text-overflow: ellipsis; }
.cl-link { background: none; border: 0; padding: 0; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--accent); cursor: pointer; }
.cl-link.danger { color: var(--muted); }
.cl-link.danger:hover { color: var(--err); }
.cl-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); }
.cl-st { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; background: var(--line); color: var(--text-2); }
.cl-st.ok { background: var(--ok-soft, color-mix(in srgb, var(--ok) 18%, transparent)); color: var(--ok); }
.cl-st.part { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.cl-st.bad { background: color-mix(in srgb, var(--err) 16%, transparent); color: var(--err); }
.cl-table-wrap { overflow: auto; border: 1px solid var(--line-2); border-radius: 11px; }
.cl-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cl-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line-2); background: var(--panel-2); }
.cl-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.cl-table tr:last-child td { border-bottom: 0; }
.cl-class { display: flex; flex-direction: column; }
.task-bar .i { color: var(--ok); }
.tb-title { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.tb-title:hover { color: var(--text); text-decoration: underline; }
@media (max-width: 860px) {
  .cl-split { grid-template-columns: 1fr; }
  .class-body { padding: 4px 12px 14px; }
  .cl-card.static { flex-wrap: wrap; }
  .cl-role { grid-template-columns: 1fr; }
}
@media (max-width: 860px) { #btnTheme { display: none; } }

/* -------------------------------------------------------------- login page */
.gate { position: fixed; inset: 0; z-index: 400; overflow: auto; display: flex; justify-content: center; align-items: flex-start;
  padding: max(5vh, 24px) 20px 40px; background: var(--bg);
  background-image: radial-gradient(60% 45% at 50% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%), var(--tex-page, none); }
.gate[hidden] { display: none; }
.g-theme { position: fixed; top: 16px; right: 18px; z-index: 1; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 1.5px solid var(--line-2); background: var(--panel); color: var(--accent); transition: border-color .15s, transform .15s; }
.g-theme:hover { border-color: var(--accent); transform: rotate(-12deg); }
.g-theme:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.g-theme svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.gated { overflow: hidden; }
body.gated .buddy, body.gated .toasts { z-index: 410; }
body.gated .buddy { display: none; }
.gate-box { width: 100%; max-width: 420px; margin: auto 0; display: flex; flex-direction: column; align-items: center; animation: g-in .35s var(--ease) both; }
@keyframes g-in { from { opacity: 0; transform: translateY(10px); } }
.g-logo { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 14px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); box-shadow: 0 0 40px color-mix(in srgb, var(--accent) 35%, transparent); }
.g-logo img { width: 54px; height: 54px; border-radius: 12px; }
.g-title { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -.02em; color: var(--accent); text-align: center; }
.g-sub { margin: 6px 0 0; font-size: 13.5px; color: var(--text-2); text-align: center; line-height: 1.5; }
.g-form { width: 100%; display: flex; flex-direction: column; gap: 14px; margin-top: 26px; }
.g-field { position: relative; display: flex; align-items: center; height: 54px; border-radius: 14px; border: 1.5px solid var(--line-2); background: var(--panel); transition: border-color .15s, box-shadow .15s; }
.g-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.g-field > svg { width: 20px; height: 20px; margin: 0 4px 0 16px; flex: none; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.g-field input, .g-field select { flex: 1; min-width: 0; height: 100%; padding: 16px 12px 0; border: 0; background: none; color: var(--text); font: inherit; font-size: 15px; outline: none; appearance: none; }
.g-field select { cursor: pointer; padding-right: 36px; }
.g-field select option { background: var(--panel); color: var(--text); }
.g-field:has(select)::after { content: ""; position: absolute; right: 16px; top: 24px; border: 5px solid transparent; border-top-color: var(--muted); pointer-events: none; }
.g-label { position: absolute; left: 52px; top: 50%; transform: translateY(-50%); font-size: 15px; color: var(--muted); pointer-events: none; transition: all .15s var(--ease); }
.g-field input:focus ~ .g-label, .g-field input:not(:placeholder-shown) ~ .g-label, .g-field select:valid ~ .g-label { top: 14px; font-size: 11px; font-weight: 600; color: var(--accent); }
.g-field select:valid ~ .g-label { color: var(--muted); }
.g-eye { width: 44px; height: 100%; border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; flex: none; }
.g-eye svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.g-eye:hover { color: var(--text); }
.g-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.g-field { min-width: 0; }
.g-field input { width: 100%; }
.g-two .g-label { left: 50px; }
.g-right { display: flex; justify-content: flex-end; margin-top: -4px; }
.g-form a { color: var(--accent); font-weight: 600; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 7px; }
.g-form a:hover { text-decoration: underline; }
.g-form a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.g-msg { font-size: 13px; color: var(--text-2); text-align: center; min-height: 0; }
.g-msg:empty { display: none; }
.g-msg.err { color: var(--err); }
.g-btn { height: 54px; border-radius: 14px; border: 0; cursor: pointer; font: inherit; font-size: 17px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent, #fff); box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 30%, transparent); transition: transform .15s, filter .15s; }
.g-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.g-btn:disabled { opacity: .65; cursor: progress; transform: none; }
.g-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.g-or { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; margin: 6px 0; }
.g-or::before, .g-or::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.g-alt { display: flex; justify-content: space-around; gap: 12px; flex-wrap: wrap; }
.g-alt.one { justify-content: center; margin-top: 6px; }
.g-form a.g-skip { color: var(--text-2); }
.g-role { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 14px; background: var(--panel); border: 1.5px solid var(--line-2); }
.g-role label { display: grid; place-items: center; height: 40px; border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.g-role input { display: none; }
.g-role label:has(input:checked) { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent, #fff); }
@media (max-width: 420px) { .g-two { grid-template-columns: 1fr; } .g-title { font-size: 27px; } }
