/* The Origin playground.
 *
 * Two panes, a bar, a footer that says where the code goes. Light and dark are the
 * viewer's choice, not ours: everything is a token, redefined once under
 * prefers-color-scheme. */

:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e2e2df;
  --accent: #2f5d7c;
  --accent-ink: #ffffff;
  --err: #a33a2c;
  --err-bg: #fdf4f2;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Syntax */
  --syn-keyword: #8250a8;
  --syn-type: #2f6f5e;
  --syn-fn: #2f5d7c;
  --syn-num: #9a5518;
  --syn-str: #3f7a3f;
  --syn-interp: #8250a8;
  --syn-comment: #8a8a85;
  --syn-op: #55606b;
  --syn-invalid: #a33a2c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1c1f24;
    --ink: #e6e6e3;
    --muted: #939aa4;
    --line: #2c3138;
    --accent: #6ea8cc;
    --accent-ink: #10141a;
    --err: #e08b7d;
    --err-bg: #2a1e1c;

    --syn-keyword: #c99ae0;
    --syn-type: #7fc9b0;
    --syn-fn: #8fc3e6;
    --syn-num: #e0a36b;
    --syn-str: #93c98d;
    --syn-interp: #c99ae0;
    --syn-comment: #7a828c;
    --syn-op: #a8b2bd;
    --syn-invalid: #e08b7d;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--sans);
}

/* ---------- bar ---------- */

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { font-size: 1rem; letter-spacing: .01em; }
.brand .sub { color: var(--muted); margin-left: .4rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .75rem;
  align-items: center;
}

.controls label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: var(--muted);
  font-size: .85rem;
}

button, select {
  font: inherit;
  font-size: .875rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .3rem .7rem;
}

button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  font-size: inherit;
}

/* An anchor styled as a button, for the bar's link between the two pages. */
a.button {
  display: inline-block;
  font-size: .875rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .3rem .7rem;
  text-decoration: none;
}
a.button:hover { border-color: var(--accent); }

/* ---------- the tutorial page ---------- */
/*
   One column of prose and pictures, on the same ground as the playground and with the same
   type. It is a second page rather than a panel on the first: someone learning is reading,
   and someone playing is running.
*/

.doc {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem 1.1rem 2.5rem;
  box-sizing: border-box;
}

.doc h1 { font-size: 1.6rem; margin: .2rem 0 .6rem; letter-spacing: -.01em; }
.doc .lede { color: var(--muted); max-width: 60ch; }

.doc .step { margin: 2.2rem 0; }

.doc .step h2 {
  font-size: 1.05rem;
  margin: 0 0 .5rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--line);
}

.doc .step p { max-width: 62ch; }

.doc .step img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: .9rem 0 .5rem;
  border-radius: 8px;
}

.doc .prints { color: var(--muted); font-size: .9rem; }

.doc code {
  font: 12.5px/1.4 var(--mono);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .05rem .3rem;
}

.step-actions { display: flex; gap: 1rem; align-items: baseline; }
.step-note { font-size: .85rem; }

/* ---------- panes ---------- */

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  min-height: 0;
}

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
}

.pane-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: .35rem .75rem;
  border-bottom: 1px solid var(--line);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.muted { color: var(--muted); text-transform: none; letter-spacing: normal; }

/* The textarea is the fallback editor and the pre-upgrade one, so it has to look like the
   real thing rather than like a form field. */
#src {
  flex: 1;
  width: 100%;
  border: 0;
  resize: none;
  padding: .75rem;
  font: 13px/1.6 var(--mono);
  color: var(--ink);
  background: var(--panel);
  tab-size: 4;
}
#src:focus { outline: none; }

/* The input box is the browser's standing in for standard input (spec/18-input.md). It is
   the same field as the editor at a fixed small height, so it costs the program a few lines
   of room rather than half the pane. */
.stdin-head { border-top: 1px solid var(--line); }

.stdin {
  width: 100%;
  height: 5.5rem;
  border: 0;
  resize: vertical;
  padding: .75rem;
  font: 13px/1.6 var(--mono);
  color: var(--ink);
  background: var(--panel);
  tab-size: 4;
}
.stdin:focus { outline: none; }

.streams { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: auto; }

.streams pre {
  margin: 0;
  padding: .75rem;
  font: 13px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

#stderr:empty { display: none; }
#stderr { color: var(--err); background: var(--err-bg); border-top: 1px solid var(--line); }

/* spec §7: the playground's own words are never the program's. They are visually distinct
   from both streams and never written into either. */
.host {
  border-top: 1px solid var(--line);
  padding: .5rem .75rem;
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
  min-height: 2rem;
}
.host.bad { color: var(--err); }

/* ---------- footer ---------- */

/* The notes have to be here and have to be readable -- a visitor should learn where their
   code lives without asking. They should not cost a third of the window to say it, so on a
   wide screen they sit side by side and the panes keep the height. */
footer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: .6rem .9rem .7rem;
  font-size: .75rem;
  line-height: 1.45;
  color: var(--muted);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: .2rem 1.75rem;
}
footer p { margin: .15rem 0; max-width: 62ch; }
footer strong { color: var(--ink); }
footer code {
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 .25em;
}

/* ---------- editor ----------
 *
 * CodeMirror ships its own light-only defaults for the chrome around the text -- gutter,
 * active line, cursor, selection -- and they are wrong on a dark background: the active
 * line comes out as a pale bar across the editor. Everything it draws is re-pointed at the
 * same tokens as the rest of the page, so the editor follows the viewer's theme like every
 * other surface here. */

.cm-editor { height: 100%; font: 13px/1.6 var(--mono); background: var(--panel); color: var(--ink); }
.cm-editor.cm-focused { outline: none; }
.cm-scroller { font-family: var(--mono); }
.cm-content { caret-color: var(--ink); }

.cm-editor .cm-gutters {
  background: var(--panel);
  color: var(--muted);
  border-right: 1px solid var(--line);
}
.cm-editor .cm-activeLine { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.cm-editor .cm-activeLineGutter {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--ink);
}
.cm-editor .cm-cursor, .cm-editor .cm-dropCursor { border-left-color: var(--ink); }
.cm-editor .cm-selectionBackground,
.cm-editor.cm-focused .cm-selectionBackground,
.cm-editor ::selection {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
}
.cm-editor .cm-matchingBracket {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}

.tok-keyword { color: var(--syn-keyword); }
.tok-type { color: var(--syn-type); }
.tok-fn { color: var(--syn-fn); }
.tok-num { color: var(--syn-num); }
.tok-str { color: var(--syn-str); }
.tok-interp { color: var(--syn-interp); font-weight: 600; }
.tok-comment { color: var(--syn-comment); font-style: italic; }
.tok-op { color: var(--syn-op); }
.tok-invalid { color: var(--syn-invalid); text-decoration: underline wavy; }
