/* play.mu-lang.dev
 *
 * Shares the design tokens of mu-lang.dev so the playground reads as part of
 * the same project, and defines the editor's colours as tokens too, which is
 * what lets one Ace theme follow the visitor's light/dark setting instead of
 * needing two themes and a switch.
 */

:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --bg-soft: #fbfaf7;
  --ink: #151515;
  --muted: #5e5e5e;
  --accent: #2f87ff;
  --accent-strong: #7047ff;
  --accent-warm: #11d2a8;
  --danger: #c0392b;
  --border: #d8d2c8;
  --radius-md: 8px;
  --radius-sm: 6px;
  --font-sans: "Space Grotesk", "Trebuchet MS", sans-serif;
  --font-serif: "Fraunces", "Georgia", serif;
  --font-mono: "IBM Plex Mono", "Menlo", "Courier New", monospace;

  --editor-bg: #fbfaf7;
  --editor-gutter: #f0ece2;
  --editor-active: rgba(47, 135, 255, 0.07);
  --editor-selection: rgba(47, 135, 255, 0.22);

  --syn-keyword: #a626a4;
  --syn-string: #1a7f37;
  --syn-number: #b26100;
  --syn-comment: #7a7568;
  --syn-builtin: #0550ae;
  --syn-call: #2f5fd0;
  --syn-punct: #6a6a6a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-soft: #151a20;
    --ink: #f1f4f8;
    --muted: #b5bcc7;
    --accent: #2f87ff;
    --accent-strong: #8a46f0;
    --accent-warm: #11d2a8;
    --danger: #ff7b72;
    --border: #2a313c;

    --editor-bg: #10151b;
    --editor-gutter: #151a20;
    --editor-active: rgba(255, 255, 255, 0.045);
    --editor-selection: rgba(138, 70, 240, 0.30);

    --syn-keyword: #d68bff;
    --syn-string: #7ee787;
    --syn-number: #ffb454;
    --syn-comment: #7d8590;
    --syn-builtin: #79c0ff;
    --syn-call: #a5c8ff;
    --syn-punct: #9aa4b2;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.18em; }

/* --- toolbar -------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.logo { display: flex; align-items: baseline; gap: 0.4rem; color: var(--ink); }
.logo:hover { text-decoration: none; }
.logo-mark { font-family: var(--font-serif); font-size: 1.35rem; font-weight: 700; color: var(--accent-strong); }
.logo-text { font-weight: 600; }
.logo-sub { color: var(--muted); font-size: 0.82rem; }

.bar .spacer { flex: 1 1 auto; }

.bar select,
.bar button {
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.34rem 0.7rem;
  cursor: pointer;
}
.bar select { max-width: 15rem; }
.bar button:hover:not(:disabled) { border-color: var(--accent-strong); color: var(--accent-strong); }
.bar button:disabled { opacity: 0.5; cursor: progress; }
.bar button.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  font-weight: 600;
}
.bar button.primary:hover:not(:disabled) { filter: brightness(1.1); color: #fff; }
.bar button kbd {
  font-family: var(--font-mono);
  font-size: 0.75em;
  opacity: 0.75;
  margin-left: 0.35rem;
}

.bar-links { display: flex; gap: 0.85rem; font-size: 0.86rem; }
.bar-links a { color: var(--muted); }
.bar-links a:hover { color: var(--ink); }

/* On a wide screen these are simply members of the toolbar; the wrapper exists
   so a narrow screen can put all of them on one scrollable second row. */
.bar-row2 { display: contents; }

/* --- pane tabs (mobile only) ---------------------------------------------- */

.pane-tabs { display: none; }

.pane-tabs button {
  font: inherit;
  font-size: 0.86rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}
.pane-tabs button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.pane-tabs button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-left: -1px; }
.pane-tabs button[aria-selected="true"] {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  font-weight: 600;
}

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

.split {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  min-height: 0;
}

/* On a phone the editor and the output cannot both be usefully on screen: a
   60/40 split left the output pane entirely below the fold, so a visitor ran a
   program and saw nothing. One pane at a time, chosen by tabs, and running
   switches to the output -- which is the answer they asked for.
   
   The page itself does not scroll: 100dvh rather than 100vh, so the browser's
   collapsing address bar cannot push the Run button off the screen. */
@media (max-width: 820px) {
  body { height: 100dvh; overflow: hidden; }

  .bar { gap: 0.4rem 0.5rem; padding: 0.45rem 0.7rem; }
  .bar kbd { display: none; }
  .logo-sub { display: none; }
  .bar select { max-width: none; flex: 1 1 auto; min-width: 0; }
  .bar .spacer { display: none; }

  /* Everything after Run goes on one row that scrolls sideways rather than
     wrapping onto a third. */
  .bar-row2 {
    display: flex;
    flex: 1 0 100%;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .bar-row2::-webkit-scrollbar { display: none; }
  .bar-row2 > * { flex: 0 0 auto; }

  /* A row that scrolls has to look like one, or a clipped "Copy link" reads as
     a rendering bug rather than an invitation. The mask sits on the element
     box, so it stays at the right edge while the content moves under it -- and
     fades nothing at all when everything already fits. */
  .bar-row2 {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 1.6rem), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 1.6rem), transparent);
    padding-right: 1.6rem;
  }

  .pane-tabs { display: inline-flex; }
  .bar-links { gap: 0.7rem; }

  .split { grid-template-columns: minmax(0, 1fr); }
  .pane.output-pane { border-left: none; }

  body[data-pane="code"] .output-pane,
  body[data-pane="output"] .editor-pane { display: none; }

  /* Touch targets: 0.34rem of padding is a 28px button. */
  .bar button { padding: 0.45rem 0.8rem; }
  .pane-tabs button { padding: 0.45rem 0.9rem; }
}

.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane.output-pane { border-left: 1px solid var(--border); background: var(--bg-soft); }

#editor { flex: 1 1 auto; min-height: 0; font-size: 14px; }
.ace_editor { font-family: var(--font-mono) !important; }

.pane-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  flex: 0 0 auto;
}
.pane-title { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; }

.status { margin-left: auto; font-family: var(--font-mono); font-size: 0.78rem; }
.status[data-state="ok"] { color: var(--accent-warm); }
.status[data-state="error"] { color: var(--danger); }
.status[data-state="timeout"] { color: var(--syn-number); }
.status[data-state="refused"] { color: var(--syn-number); }
.status[data-state="busy"] { color: var(--muted); }

#output {
  flex: 1 1 auto;
  margin: 0;
  padding: 0.85rem 0.9rem 2rem;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
#output .msg-error { color: var(--danger); }
#output .msg-note { color: var(--muted); }

.example-note {
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
  flex: 0 0 auto;
}
.example-note:empty { display: none; }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--ink);
  color: var(--bg);
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast[data-show="true"] { opacity: 1; transform: translateX(-50%) translateY(0); }
