:root {
  --bg: #0b0e13;
  --panel: #10141b;
  --panel-2: #0d1117;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.13);
  --text: #e9edf2;
  --dim: #8b95a3;
  --faint: #5a6472;
  --red: #f0506e;
  --green: #4fd18b;
  --yellow: #f5c451;
  --blue: #7cbcff;
  --accent: #ffd166;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13.5px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
kbd { font-family: var(--mono); font-size: 10.5px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 4px; }

/* ---------- header ---------- */
.bar { height: 58px; display: flex; align-items: center; gap: 18px; padding: 0 14px; border-bottom: 1px solid var(--line); background: #0d1016; }
.brand { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.brand .logo { font-weight: 750; letter-spacing: 0.16em; font-size: 12.5px; text-transform: uppercase; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .logo::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); }
.brand .logo b { color: var(--dim); font-weight: 600; }
.brand .sub { color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fieldsel, .who { display: flex; flex-direction: column; gap: 2px; }
.fieldsel span, .who span { font-size: 10px; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
select, input { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 8px; outline: none; height: 30px; }
input { width: 170px; }
select:focus, input:focus { border-color: rgba(255, 209, 102, 0.6); }
input.bad { border-color: var(--red); }
.actions { display: flex; align-items: center; gap: 8px; }
.primary { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 18px 0 12px; border: 0; border-radius: 8px; background: var(--accent);
  color: #1a1405; font-weight: 700; cursor: pointer; }
.primary svg { width: 18px; height: 18px; fill: currentColor; }
.primary:hover { background: #ffdc85; }
.primary:disabled { opacity: 0.55; cursor: progress; }
.ghost { display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px;
  background: transparent; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 600; }
.ghost:hover { background: rgba(255, 255, 255, 0.05); }
.chev { width: 16px; height: 16px; fill: currentColor; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 42px; z-index: 20; width: 300px; background: #121720; border: 1px solid var(--line-2); border-radius: 10px;
  padding: 6px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5); }
.menu-pop button { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 7px; padding: 8px 10px; cursor: pointer; }
.menu-pop button:hover { background: rgba(255, 255, 255, 0.06); }
.menu-pop b { display: block; font-weight: 650; }
.menu-pop span { color: var(--dim); font-size: 12px; }

/* ---------- layout ---------- */
main { display: flex; height: calc(100vh - 58px); }
.left { display: flex; flex-direction: column; min-width: 0; width: var(--code-w, 40%); flex: none; background: var(--panel-2); }
.right { min-width: 0; flex: 1 1 auto; position: relative; }
body.code-collapsed .left, body.code-collapsed .vsplit { display: none; }

/* drag handles */
.vsplit { flex: none; width: 7px; margin: 0 -3px; z-index: 5; cursor: col-resize; position: relative; touch-action: none; }
.vsplit::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 1px; background: var(--line-2); transition: background 0.15s, width 0.15s, left 0.15s; }
.vsplit:hover::after, .vsplit.drag::after { background: var(--accent); width: 3px; left: 2px; }
.hsplit { flex: none; height: 7px; margin: -3px 0; z-index: 5; cursor: row-resize; position: relative; touch-action: none; }
.hsplit::after { content: ""; position: absolute; left: 0; right: 0; top: 3px; height: 1px; background: transparent; transition: background 0.15s, height 0.15s, top 0.15s; }
.hsplit:hover::after, .hsplit.drag::after { background: var(--accent); height: 3px; top: 2px; }
body.dragging, body.dragging * { user-select: none; }
body.dragging-x, body.dragging-x * { cursor: col-resize !important; }
body.dragging-y, body.dragging-y * { cursor: row-resize !important; }
body.dragging iframe { pointer-events: none; }   /* keep the drag alive over the replay */

/* collapsed code: a slim rail to bring it back */
.rail { flex: none; width: 34px; border: 0; border-right: 1px solid var(--line); background: #0d1016; color: var(--dim); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 12px; }
.rail:hover { color: var(--text); background: #11151c; }
.rail svg { width: 18px; height: 18px; fill: currentColor; }
.rail span { writing-mode: vertical-rl; font-size: 10.5px; font-weight: 650; letter-spacing: 0.14em; text-transform: uppercase; }
.icon-btn { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 5px; background: transparent;
  color: var(--dim); cursor: pointer; padding: 0; }
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; transition: transform 0.2s; }
#resultHead { cursor: default; }
body.result-collapsed #output, body.result-collapsed .hsplit { display: none; }
body.result-collapsed #toggleResult svg { transform: rotate(-90deg); }
#viewer { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 10.5px; font-weight: 650; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--dim); border-bottom: 1px solid var(--line); background: #0d1016; }
.pane-head.sub { border-top: 1px solid var(--line); }
.pane-head .file { font-family: var(--mono); text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--text); font-weight: 500; }
.pane-head .hint { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--faint); }
.link { background: none; border: 0; color: var(--dim); cursor: pointer; text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 500; padding: 0; }
.link:hover { color: var(--text); text-decoration: underline; }
.status { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.status.ok::before { background: var(--green); }
.status.busy::before { background: var(--accent); animation: pulse 1s infinite; }
.status.bad { color: var(--red); }
.status.bad::before { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.3; } }

#editor { flex: 1 1 auto; min-height: 80px; position: relative; }
#output { flex: none; height: var(--out-h, 34%); min-height: 60px; overflow: auto; padding: 12px 14px; font-size: 13px; }
.muted { color: var(--dim); margin: 0; }

/* result */
.res { display: grid; grid-template-columns: 4px 1fr auto; gap: 0 12px; margin-bottom: 10px; }
.res .accentbar { background: var(--green); border-radius: 2px; }
.res.bad .accentbar { background: var(--red); }
.res.best .accentbar { background: var(--accent); }
.res.neutral .accentbar { background: var(--dim); }
.res .kicker { font-size: 10.5px; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.res .title { font-size: 15px; font-weight: 650; margin-top: 2px; }
.res .why { color: var(--dim); font-size: 12.5px; margin-top: 2px; }
.res .why .mono { font-family: var(--mono); color: #c8d0da; }
.res .nums { display: flex; gap: 16px; align-items: center; }
.res .num { text-align: right; }
.res .num b { display: block; font: 650 22px/1.1 var(--mono); }
.res .num span { font-size: 10px; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.tasks { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 4px 0 8px; }
.tasks span { font-size: 11.5px; border-radius: 4px; padding: 1px 7px; background: rgba(255, 255, 255, 0.05); color: var(--dim); }
.tasks span.done { background: rgba(79, 209, 139, 0.13); color: var(--green); }
.msgs { list-style: none; margin: 6px 0; padding: 0; }
.msgs li { border-left: 2px solid var(--yellow); padding: 3px 10px; margin: 4px 0; color: var(--yellow); font-size: 12.5px; }
.msgs li.bad { border-color: var(--red); color: #ffc2cd; background: rgba(240, 80, 110, 0.07); }
.msgs li .ln { font-family: var(--mono); color: var(--faint); margin-left: 6px; }
.console { margin-top: 8px; font-family: var(--mono); font-size: 12px; color: #b5bfcc; }
.console .t { color: var(--faint); margin-right: 10px; }
.console-head { font-size: 10.5px; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-top: 10px; }

/* ---------- CodeMirror theme ---------- */
.CodeMirror { height: 100%; font-family: var(--mono); font-size: 13.5px; line-height: 1.6; }
.cm-s-ftj.CodeMirror { background: var(--panel-2); color: #c8d0da; }
.cm-s-ftj .CodeMirror-gutters { background: var(--panel-2); border-right: 1px solid var(--line); }
.cm-s-ftj .CodeMirror-linenumber { color: #4b5563; padding: 0 8px 0 4px; }
.cm-s-ftj .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.cm-s-ftj div.CodeMirror-selected, .cm-s-ftj.CodeMirror-focused div.CodeMirror-selected { background: rgba(124, 188, 255, 0.2); }
.cm-s-ftj .CodeMirror-matchingbracket { color: var(--accent) !important; text-decoration: underline; }
.cm-s-ftj .cm-keyword { color: #f089b7; }
.cm-s-ftj .cm-string { color: #e9c77b; }
.cm-s-ftj .cm-number { color: #8fe0bd; }
.cm-s-ftj .cm-comment { color: #677182; font-style: italic; }
.cm-s-ftj .cm-builtin { color: #7cbcff; }
.cm-s-ftj .cm-property { color: #7cbcff; }
.cm-s-ftj .cm-def { color: #b9a2ff; }
.cm-s-ftj .cm-variable-2 { color: #b9a2ff; }
.cm-s-ftj .cm-operator { color: #c8d0da; }
.cm-s-ftj .cm-error { color: var(--red); background: none; }
.CodeMirror .run-line { background: rgba(255, 209, 102, 0.13); box-shadow: inset 2px 0 0 var(--accent); }
.CodeMirror .run-outer { background: rgba(255, 209, 102, 0.05); }
.CodeMirror .err-line { background: rgba(240, 80, 110, 0.15); box-shadow: inset 2px 0 0 var(--red); }
.ftj-marks { width: 50px; }
.gmark { font: 650 10px/1.6 var(--sans); color: var(--green); background: rgba(79, 209, 139, 0.14); border-radius: 3px; margin: 3px 4px 0; text-align: center; }
.gmark.bad { color: var(--red); background: rgba(240, 80, 110, 0.16); }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; transition: 0.25s; z-index: 50;
  background: #151b24; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 16px; font-weight: 550; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  pointer-events: none; max-width: min(560px, calc(100vw - 32px)); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .brand .sub { display: none; }
  .fieldsel select { max-width: 150px; }
  input { width: 130px; }
}
@media (max-width: 900px) {
  .bar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 10px; }
  .brand { width: 100%; }
  main { flex-direction: column; height: auto; }
  .left { width: 100% !important; height: 70vh; }
  .right { height: 75vh; flex: none; }
  .vsplit, .rail, #collapseCode { display: none !important; }
  body.code-collapsed .left { display: flex; }
}
