/* SabiRuby Playground. "Sabi" is rust: oxidised iron on a cool steel ground. */
:root {
  --ground: #EEF1F2;
  --surface: #FFFFFF;
  --ink: #1B2126;
  --muted: #5A6670;
  --rule: #D3DADE;
  --rust: #9A3F17;
  --rust-ink: #FFFFFF;
  --rust-soft: #F4E3D9;
  --focus: #9A3F17;
  --ok: #2F7A4E;
  --ok-soft: #DDEFE3;
  --err: #B3261E;
  --err-soft: #FBE4E1;
  --selection: #F0D5C4;
  --gutter: #F6F8F9;
  --hl-keyword: #9A3F17;
  --hl-string: #2F6B4F;
  --hl-number: #7A4DA8;
  --hl-symbol: #8A5A00;
  --hl-comment: #7B8790;
  --hl-constant: #1F5C8F;
  --hl-variable: #1B2126;
  --font-display: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --font-ui: "IBM Plex Sans JP", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #111619;
    --surface: #182025;
    --ink: #E3E8EB;
    --muted: #9AA7B0;
    --rule: #2B353C;
    --rust: #E08A5C;
    --rust-ink: #1B120D;
    --rust-soft: #3A2419;
    --focus: #E08A5C;
    --ok: #7CC79A;
    --ok-soft: #1D3226;
    --err: #F2B8B5;
    --err-soft: #3B1F1D;
    --selection: #4A3023;
    --gutter: #151C20;
    --hl-keyword: #E08A5C;
    --hl-string: #9ED3B0;
    --hl-number: #C9A7F0;
    --hl-symbol: #E6C07A;
    --hl-comment: #78858E;
    --hl-constant: #8CC2EE;
    --hl-variable: #E3E8EB;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #111619;
  --surface: #182025;
  --ink: #E3E8EB;
  --muted: #9AA7B0;
  --rule: #2B353C;
  --rust: #E08A5C;
  --rust-ink: #1B120D;
  --rust-soft: #3A2419;
  --focus: #E08A5C;
  --ok: #7CC79A;
  --ok-soft: #1D3226;
  --err: #F2B8B5;
  --err-soft: #3B1F1D;
  --selection: #4A3023;
  --gutter: #151C20;
  --hl-keyword: #E08A5C;
  --hl-string: #9ED3B0;
  --hl-number: #C9A7F0;
  --hl-symbol: #E6C07A;
  --hl-comment: #78858E;
  --hl-constant: #8CC2EE;
  --hl-variable: #E3E8EB;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  padding-inline: 16px;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding-block: 14px 12px;
}
.brand { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.brand h1 { margin: 0; font-family: var(--font-display); font-size: 1.35rem; font-weight: 700; letter-spacing: 0.01em; line-height: 1.3; }
.brand h1 span { color: var(--rust); }
.tagline { margin: 0; color: var(--muted); font-size: 0.8rem; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

button, select {
  font: inherit;
  font-size: 0.86rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 12px;
  line-height: 1.4;
  cursor: pointer;
}
button:hover:not(:disabled), select:hover { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button.primary { background: var(--rust); color: var(--rust-ink); border-color: var(--rust); font-weight: 600; padding-inline: 18px; }
button[aria-pressed="true"] { background: var(--rust-soft); border-color: var(--rust); color: var(--rust); }
select { max-width: 16rem; padding-right: 8px; }

/* panes, in the order of the pipeline: code -> AST -> bytecode -> result */
.panes {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 12px;
  padding-bottom: 10px;
}
.pane {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
}
.pane[hidden] { display: none; }
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--rule);
  min-height: 40px;
}
.pane-head h2 { margin: 0; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.step {
  display: inline-grid;
  place-items: center;
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  background: var(--rust-soft);
  color: var(--rust);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0;
}
.editor-pane { flex-grow: 1.25; }
.output-pane { flex-grow: 0.9; }
.pane-note { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor { flex: 1; min-height: 0; overflow: auto; }
.output {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 8;
}
.tree { white-space: pre; overflow-wrap: normal; font-size: 12px; line-height: 1.45; }
.output .err { display: block; color: var(--err); background: var(--err-soft); border-radius: 4px; padding: 6px 8px; margin-top: 6px; }
.output .note { color: var(--muted); }
.status {
  border-top: 1px solid var(--rule);
  padding: 6px 12px;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 32px;
}
.status strong { color: var(--ink); font-weight: 500; }

.compare { display: flex; align-items: center; gap: 8px; }
.compare button { font-size: 0.78rem; padding: 3px 10px; }
.chip { font-size: 0.75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.ng { background: var(--err-soft); color: var(--err); }

/* CodeMirror */
.cm-editor { height: 100%; font-size: 13px; background: var(--surface); color: var(--ink); }
.cm-editor.cm-focused { outline: none; }
.cm-scroller { font-family: var(--font-mono); line-height: 1.55; }
.cm-gutters { background: var(--gutter); color: var(--muted); border-right: 1px solid var(--rule); }
.cm-activeLineGutter { background: var(--rust-soft); color: var(--ink); }
.cm-activeLine { background: color-mix(in srgb, var(--rust-soft) 45%, transparent); }
.cm-content { caret-color: var(--rust); }
.cm-cursor { border-left-color: var(--rust); }
.cm-selectionBackground, .cm-focused .cm-selectionBackground, ::selection { background: var(--selection) !important; }
.cm-matchingBracket { background: var(--rust-soft); outline: 1px solid var(--rust); }

/* ---- debugging: the toolbar, the listing rows, the VM panes (web/debug.js) */
/* `hidden` alone would lose to `.controls { display: flex }`, which is how the step buttons
   once showed on a page nobody had asked to debug */
.controls[hidden] { display: none; }
.debug-controls { width: 100%; justify-content: flex-end; padding-bottom: 10px; gap: 8px; }
/* what the debug button opens, beside it: one size smaller, so the mode reads as the heading */
.debug-steps { gap: 6px; }
.debug-steps button { font-size: 0.82rem; }
.debug-steps button.primary { padding-inline: 14px; }
.debug-steps .sep { width: 1px; align-self: stretch; margin-inline: 4px; background: var(--rule); }

/* the bytecode listing as rows */
#dump .insn { display: block; }
#dump .ln { color: var(--muted); }
#dump .op { cursor: help; border-bottom: 1px dotted var(--rule); }
#dump .op:hover { color: var(--rust); border-bottom-color: var(--rust); }
#dump .irep-head { display: block; color: var(--hl-constant); font-weight: 500; margin-top: 6px; }
#dump .irep-note { display: block; color: var(--muted); }
#dump .insn.current { background: var(--rust-soft); outline: 1px solid var(--rust); border-radius: 3px; }
#dump .insn.caller { background: color-mix(in srgb, var(--rust-soft) 40%, transparent); }
/* the call the VM is inside: its own instructions are in mrblib, which this pane does not list */
#dump .insn.calling { background: var(--rust-soft); outline: 1px dashed var(--rust); border-radius: 3px; }
.banner {
  padding: 6px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--rust-soft);
  color: var(--ink);
  font-size: 0.75rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.banner[hidden] { display: none; }
.cm-currentVmLine { background: var(--rust-soft); }

/* the VM pane */
.vm-pane { flex-grow: 1.1; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.tabs button { font-size: 0.78rem; padding: 3px 9px; border-color: transparent; background: transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--rust-soft); color: var(--rust); border-color: var(--rust); font-weight: 600; }
.vm-body { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; font-size: 0.8rem; }
.vm-h { margin: 14px 0 6px; font-size: 0.76rem; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.vm-note-line { margin: 8px 0; color: var(--muted); font-size: 0.75rem; line-height: 1.5; }

.vm-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.vm-table th, .vm-table td { text-align: left; padding: 3px 8px 3px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.vm-table th { font-weight: 500; font-size: 0.72rem; color: var(--muted); }
.vm-table td:last-child { white-space: normal; }
.vm-table tbody tr[tabindex] { cursor: pointer; }
.vm-table tbody tr:hover { background: var(--gutter); }
.vm-table tr.selected { background: var(--rust-soft); }
.vm-table tr.innermost td:first-child { font-weight: 600; }
.vm-table tr.matched { background: var(--ok-soft); }
.vm-table tr.unwound { color: var(--muted); }

.regs { list-style: none; margin: 0; padding: 0; font-family: var(--font-mono); font-size: 0.76rem; }
.regs li { display: grid; grid-template-columns: 2.6rem 6rem 1fr 5rem; gap: 8px; padding: 1px 0; }
.regs .reg { color: var(--muted); }
.regs .rname { color: var(--hl-variable); }
.regs .rval { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.regs .rval.oid { color: var(--hl-constant); }
.regs .rclass { color: var(--muted); text-align: right; }

.cards { display: flex; flex-wrap: wrap; gap: 8px; }
.card { flex: 1 1 12rem; border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; }
.card.current { border-color: var(--rust); background: color-mix(in srgb, var(--rust-soft) 35%, transparent); }
.card h4 { margin: 0 0 6px; font-size: 0.78rem; }
.card dl, .figures { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-variant-numeric: tabular-nums; }
.card dt, .figures dt { color: var(--muted); font-size: 0.72rem; }
.card dd, .figures dd { margin: 0; text-align: right; }
.figures { max-width: 22rem; }
.gc-buttons { display: flex; gap: 8px; margin: 10px 0 4px; }
.gc-buttons button { font-size: 0.78rem; }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: 6.5rem 1fr 8rem; align-items: center; gap: 8px; padding: 1px 0; }
.bars .bar-name { font-family: var(--font-mono); font-size: 0.74rem; cursor: help; }
.bars .bar { display: block; height: 9px; background: var(--gutter); border-radius: 999px; overflow: hidden; }
.bars .bar-fill { display: block; height: 100%; background: var(--rust); }
.bars .bar-num { text-align: right; color: var(--muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }

@keyframes flash-in { from { background: var(--ok-soft); } to { background: transparent; } }
@keyframes flash-out { from { background: var(--rust-soft); } to { background: transparent; } }
@media (prefers-reduced-motion: no-preference) {
  .vm-table tr.flash-new { animation: flash-in 1.2s ease-out; }
  .vm-table tr.flash-detach { animation: flash-out 1.2s ease-out; }
}
@media (prefers-reduced-motion: reduce) {
  .vm-table tr.flash-new { background: var(--ok-soft); }
  .vm-table tr.flash-detach { background: var(--rust-soft); }
}

/* the opcode tooltip */
.tip {
  position: fixed;
  z-index: 10;
  max-width: min(30rem, calc(100vw - 16px));
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  font-size: 0.78rem;
  line-height: 1.55;
}
.tip .tip-name { font-family: var(--font-mono); font-weight: 500; color: var(--rust); }
.tip .tip-ops { color: var(--muted); font-size: 0.72rem; font-family: var(--font-mono); }
.tip .tip-def { display: block; margin: 6px 0; font-family: var(--font-mono); font-size: 0.74rem; background: var(--gutter); border-radius: 4px; padding: 4px 6px; }
.tip .tip-sum { margin: 4px 0 0; }
.tip .tip-foot { margin-top: 6px; color: var(--muted); font-size: 0.72rem; }

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding-block: 4px 12px;
  font-size: 0.75rem;
  color: var(--muted);
}
.foot a { color: var(--rust); }
#version { font-family: var(--font-mono); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  max-width: calc(100% - 32px);
}

/* narrower: two rows in the same reading order (code, AST / bytecode, result) */
@media (max-width: 1280px) {
  body { height: auto; min-height: 100%; }
  .panes { flex-wrap: wrap; }
  .pane { flex: 1 1 calc(50% - 6px); height: 46vh; min-height: 280px; }
  .regs li { grid-template-columns: 2.4rem 5rem 1fr; }
  .regs .rclass { display: none; }
}
@media (max-width: 760px) {
  .panes { flex-direction: column; flex-wrap: nowrap; }
  .pane { flex: none; height: auto; }
  .editor-pane { height: 55vh; }
  .ast-pane, .dump-pane { height: 50vh; }
  .output-pane { min-height: 40vh; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: border-color 0.12s, background-color 0.12s; }
}
