/* Layout: a toolbar above two full-height panes, code on the left and output
   on the right; the panes stack on narrow screens. */
:root {
  --bg: #f2f3f7;
  --fg: #1b1e2b;
  --muted: #5f6478;
  --rule: #d9dbe5;
  --panel: #ffffff;
  --panel-edge: #dfe1ea;
  --out: #eceef5;
  --accent: #2f4fd8;
  --accent-fg: #ffffff;
  --error-line: #fde3e4;
  --selection: rgba(47, 79, 216, 0.2);

  --t-cmd: #2f4fd8;
  --t-var: #0a7d6b;
  --t-kw: #9b2c8f;
  --t-str: #4d7a12;
  --t-esc: #b45a00;
  --t-num: #b45a00;
  --t-type: #1f6fb2;
  --t-key: #6b4fbf;
  --t-com: #8a8fa3;
  --t-op: #6a6f84;
  --t-err: #c0262d;

  --font-ui: "Recursive", "Segoe UI", system-ui, sans-serif;
  --font-code: "Recursive", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --code-size: 14px;
  --code-line: 1.6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161f; --fg: #e6e8f0; --muted: #9aa0b6; --rule: #2a2e3d;
    --panel: #1b1e2a; --panel-edge: #2c3042; --out: #10121a;
    --accent: #8ea2ff; --accent-fg: #10121a; --error-line: #3d1d22; --selection: rgba(142, 162, 255, 0.3);
    --t-cmd: #8ea2ff; --t-var: #4fd1b8; --t-kw: #e58ad9; --t-str: #a8d46a; --t-esc: #ffad5c;
    --t-num: #ffad5c; --t-type: #6fb8f5; --t-key: #b9a3ff; --t-com: #6e748c;
    --t-op: #9aa0b6; --t-err: #ff7a7f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  font-variation-settings: "CASL" 0, "MONO" 0;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ----- toolbar ----- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; }
.wordmark {
  font-size: 26px;
  font-weight: 800;
  text-decoration: none;
  color: var(--fg);
  letter-spacing: -0.02em;
  font-variation-settings: "CASL" 1, "MONO" 0, "slnt" -8;
}
.wordmark span { color: var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.links { display: flex; gap: 16px; margin-left: auto; font-size: 14px; }
.links a { color: var(--muted); text-decoration: none; }
.links a:hover { color: var(--fg); text-decoration: underline; }

button, select {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, a:focus-visible, textarea:focus-visible, .output:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
button.primary:disabled { opacity: 0.6; cursor: progress; }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
kbd { font-family: var(--font-code); font-variation-settings: "MONO" 1; font-size: 11px; opacity: 0.8; }
select { max-width: 15rem; }

/* ----- panes ----- */
.panes {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 12px;
}
@media (max-width: 820px) {
  .panes { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(260px, 1.4fr) minmax(180px, 1fr); }
  .links { margin-left: 0; }
}
.pane { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; }
.pane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--muted);
}
.pane-head .muted { text-transform: none; letter-spacing: 0; font-weight: 400; font-variant-numeric: tabular-nums; }

/* ----- editor: a transparent textarea over a highlighted copy ----- */
.editor {
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  overflow: hidden;
}
.gutter, .paint, textarea {
  font-family: var(--font-code);
  font-variation-settings: "MONO" 1, "CASL" 0;
  font-size: var(--code-size);
  line-height: var(--code-line);
  tab-size: 4;
}
.gutter {
  padding: 14px 10px 14px 14px;
  text-align: right;
  color: var(--t-com);
  user-select: none;
  overflow: hidden;
  border-right: 1px solid var(--panel-edge);
  font-variant-numeric: tabular-nums;
}
.gutter div.error { color: var(--t-err); font-weight: 700; }
.surface { position: relative; min-width: 0; min-height: 0; }
.paint, textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 14px 16px;
  white-space: pre;
  overflow: auto;
  border: 0;
  word-wrap: normal;
}
.paint { pointer-events: none; color: var(--fg); overflow: hidden; }
.paint .error-band {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(var(--code-size) * var(--code-line));
  background: var(--error-line);
  z-index: -1;
}
.paint code { position: relative; z-index: 0; display: block; font: inherit; }
textarea {
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--fg);
  outline: none;
}
/* The selection must be translucent: the text it covers is painted underneath. */
textarea::selection { background: var(--selection); color: transparent; }

.t-cmd { color: var(--t-cmd); font-weight: 650; }
.t-fname { color: var(--t-cmd); font-weight: 750; }
.t-var { color: var(--t-var); }
.t-kw { color: var(--t-kw); font-weight: 600; }
.t-str { color: var(--t-str); }
.t-esc { color: var(--t-esc); }
.t-num { color: var(--t-num); }
.t-type { color: var(--t-type); font-style: italic; }
.t-key { color: var(--t-key); }
.t-com { color: var(--t-com); font-style: italic; }
.t-op, .t-punct { color: var(--t-op); }
.t-assign { color: var(--fg); }

/* ----- output ----- */
.output {
  margin: 0;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px;
  background: var(--out);
  border-radius: 10px;
  font-family: var(--font-code);
  font-variation-settings: "MONO" 1;
  font-size: var(--code-size);
  line-height: var(--code-line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.output .printed { color: var(--fg); }
.output .result { color: var(--fg); }
.output .error { color: var(--t-err); }
.output .empty { color: var(--muted); font-style: italic; }
.output .divider { display: block; border-top: 1px dashed var(--rule); margin: 8px 0; }
.output .jump { color: inherit; text-decoration: underline; cursor: pointer; background: none; border: 0; padding: 0; font: inherit; }
.output.bytecode { white-space: pre; overflow-wrap: normal; font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
}
@media (prefers-reduced-motion: no-preference) {
  .toast { transition: opacity 0.2s; }
}
