/* Rux site styles.
 *
 * Dark-only and deliberately: the palette is the one the examples ship
 * (Catppuccin Mocha-ish), so the site looks like the thing it documents.
 * Hand-written, no framework; it's a five-page site.
 */

:root {
  --bg: #11111b;
  --surface: #181825;
  --surface-2: #1e1e2e;
  --raised: #313244;
  --line: #313244;
  --ink: #cdd6f4;
  --ink-dim: #a6adc8;
  --ink-faint: #6c7086;
  --accent: #89b4fa;
  --accent-ink: #11111b;
  --green: #a6e3a1;

  --measure: 68ch;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Keyboard-only skip link: visible when focused, out of the way otherwise. */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  z-index: 10;
}
.skip:focus { left: 8px; top: 8px; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

code, pre, kbd {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
}

code {
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

pre {
  background: var(--surface-2) !important;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;          /* long lines scroll here, never the page */
  font-size: 14px;
  line-height: 1.55;
}
pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
}

/* ---- chrome ---------------------------------------------------------- */

.site-head {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.nav {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; }
.brand img { display: block; }

.nav-links { display: flex; gap: 20px; flex-wrap: wrap; }
.nav-links a {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 15px;
}
.nav-links a:hover { color: var(--ink); }

.site-foot {
  border-top: 1px solid var(--line);
  margin-top: 72px;
  padding: 24px;
  color: var(--ink-faint);
  font-size: 14px;
  text-align: center;
}
.site-foot p { max-width: var(--measure); margin: 0 auto; }

/* ---- hero ------------------------------------------------------------ */

.hero {
  max-width: 1080px;
  margin: 0 auto;
  padding: 64px 24px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 48px;
  align-items: center;
}

.hero-copy h1 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.lede {
  color: var(--ink-dim);
  font-size: 1.15rem;
  margin: 0 0 24px;
}

.cta { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.hero-note { color: var(--ink-faint); font-size: 14px; margin: 0; }

.hero-shot img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.caption {
  color: var(--ink-faint);
  font-size: 13px;
  margin: 10px 0 0;
  text-align: center;
}

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 32px; padding-top: 40px; }
}

/* ---- prose ----------------------------------------------------------- */

.prose {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 8px 24px;
}

.prose h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 32px 0 12px;
}
.prose h2 {
  font-size: 1.45rem;
  margin: 44px 0 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  letter-spacing: -0.01em;
}
.prose h3 { font-size: 1.15rem; margin: 28px 0 8px; }

.prose blockquote {
  margin: 24px 0;
  padding: 2px 20px;
  border-left: 3px solid var(--accent);
  color: var(--ink-dim);
}

.prose img { max-width: 100%; height: auto; border-radius: var(--radius); }

.prose hr { border: 0; border-top: 1px solid var(--line); margin: 40px 0; }

/* Tables can be wide; let them scroll rather than the page. */
.table-wrap { overflow-x: auto; }
.prose table {
  border-collapse: collapse;
  width: 100%;
  font-size: 15px;
  margin: 20px 0;
}
.prose th, .prose td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.prose th { background: var(--surface-2); }

/* ---- blog ------------------------------------------------------------ */

.post-meta { color: var(--ink-faint); font-size: 14px; margin: 0 0 4px; }
.back { font-size: 14px; margin: 24px 0 0; }
.back a { color: var(--ink-dim); text-decoration: none; }
.back a:hover { color: var(--ink); }

.post-list { list-style: none; padding: 0; margin: 32px 0 0; }
.post-list li {
  padding: 20px 0;
  border-top: 1px solid var(--line);
}
.post-list h2 {
  border: 0;
  margin: 0 0 6px;
  padding: 0;
  font-size: 1.3rem;
}
.post-list h2 a { text-decoration: none; }
.post-list h2 a:hover { text-decoration: underline; }
.post-list p:last-child { color: var(--ink-dim); margin: 0; }

/* ---- little bits ----------------------------------------------------- */

/* A row of "what works" chips, mirroring the app's own tag pills. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; margin: 20px 0; }
.chips li {
  background: var(--raised);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
}

.note {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 24px 0;
  font-size: 15px;
  color: var(--ink-dim);
}

/* ---------------------------------------------------------------------------
   Docs: sidebar + body
   The two-column grid collapses to one on narrow screens, where the sidebar
   becomes an ordinary block of links above the text rather than a sticky rail.
   --------------------------------------------------------------------------- */

.docs-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 40px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

.docs-nav {
  position: sticky;
  top: 24px;
  align-self: start;
  font-size: 15px;
  /* Long sidebars scroll on their own rather than pushing the page. */
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

.docs-nav-group { margin: 20px 0 6px; font-weight: 600; }
.docs-nav-group a { color: var(--ink); text-decoration: none; }
.docs-nav ul { list-style: none; margin: 0; padding: 0 0 0 12px; }
.docs-nav li { margin: 4px 0; }
.docs-nav a { color: var(--ink-dim); text-decoration: none; }
.docs-nav a:hover { color: var(--ink); }
.docs-nav a.is-current { color: var(--accent); font-weight: 600; }

.docs-body { max-width: var(--measure); margin: 0; }

/* Search ------------------------------------------------------------------ */

.docs-search { position: relative; margin: 0 0 8px; }

.docs-search input {
  width: 100%;
  padding: 8px 12px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.docs-search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.docs-search-results {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  margin: 6px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  max-height: 60vh;
  overflow-y: auto;
}
.docs-search-results li { margin: 0; }
.docs-search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink-dim);
  text-decoration: none;
}
.docs-search-results a:hover { background: var(--raised); color: var(--ink); }
.docs-search-results strong { display: block; color: var(--ink); font-size: 14px; }
.docs-search-results span { display: block; font-size: 12.5px; line-height: 1.45; }

/* Prev / next -------------------------------------------------------------- */

.docs-seq {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.docs-seq .next { margin-left: auto; text-align: right; }

.docs-more { color: var(--ink-faint); font-size: 14px; margin-bottom: 4px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  .docs-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 24px 20px 56px;
  }
  .docs-nav {
    position: static;
    max-height: none;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
  }
}

/* ── Playground ─────────────────────────────────────────────────────────── */
/* Two panes: source on the left, the wasm canvas on the right. Below 860px
   they stack, matching the docs breakpoint. */

.pg {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}
.pg-head { margin-bottom: 24px; }
.pg-head h1 { margin: 0 0 8px; }
.pg-head .lede { max-width: var(--measure); color: var(--ink-dim); margin: 0; }

.pg-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.pg-pane {
  display: flex;
  flex-direction: column;
  /* Without this a pane will not shrink below its content, which on a phone
     means the canvas pushes the page wider than the screen. */
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.pg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.pg-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--ink-faint);
}
.pg-status { font-size: 12px; color: var(--ink-faint); }
.pg-status.is-error { color: #f38ba8; }

.pg-btn {
  padding: 5px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.pg-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.pg-actions { display: flex; align-items: center; gap: 8px; }
/* Format is the secondary action: present, but not competing with Run. */
.pg-btn-quiet {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--line);
}
.pg-btn-quiet:hover { color: var(--ink); border-color: var(--ink-faint); }

/* The editor is a transparent <textarea> over a highlighted <pre>. Every text
   metric below is shared by both layers. Change one, change the other, or the
   colouring slides out from under the caret. */
.pg-editwrap {
  position: relative;
  min-height: 640px;
  /* ayu-dark's background, so the editor matches the code blocks elsewhere on
     the site (config.toml pins the same theme for fences). */
  background: #0d1017;
}
.pg-code,
.pg-editor {
  margin: 0;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  border: 0;
}
.pg-code {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: #bfbdb6;
  pointer-events: none;
  /* The global `pre` rule sets a background with !important, which would paint
     over the editor; its border would also shift this layer a pixel out of step
     with the textarea. Both are undone here. */
  background: none !important;
  border-radius: 0;
}
/* The textarea never wraps (wrap="off"), so this layer must not either, or the
   two drift a line apart on every long line. `white-space: pre` alone was not
   enough in practice, and sizing the content to `max-content` removes the
   constraint that made a wrap possible at all. */
.pg-code code {
  display: block;
  width: max-content;
  min-width: 100%;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}
.pg-editor {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 640px;
  overflow: auto;
  background: transparent;
  /* The glyphs come from the <pre> underneath; only the caret and the selection
     highlight are the textarea's own. */
  color: transparent;
  caret-color: #bfbdb6;
  resize: none;
}
.pg-editor::selection { background: #409fff40; color: transparent; }
.pg-editor:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Token colours: ayu-dark, matching the site's code fences. The class set is
   deliberately small; see the SCOPES table in crates/rux-highlight. */
.hl-comment   { color: #acb6bf8c; font-style: italic; }
.hl-string    { color: #aad94c; }
.hl-escape    { color: #d2a6ff; }
.hl-number    { color: #d2a6ff; }
.hl-const     { color: #d2a6ff; }
.hl-keyword   { color: #ff8f40; }
.hl-operator  { color: #f29668; }
.hl-tag       { color: #39bae6; }
.hl-function  { color: #ffb454; }
.hl-attr      { color: #ffb454; }
.hl-directive { color: #ff8f40; }
.hl-selector  { color: #39bae6; }
.hl-property  { color: #59c2ff; }
.hl-value     { color: #aad94c; }
.hl-interp    { color: #f29668; }
.hl-punct     { color: #bfbdb699; }
.hl-var       { color: #bfbdb6; }

/* The canvas is a fixed logical size (a phone-ish 420x640), centred rather than
   stretched, since scaling it would lie about the layout being demonstrated. */
.pg-stage {
  display: flex;
  /* `safe` matters: with plain `center`, content wider than the container
     overflows equally in both directions and the left edge becomes unreachable,
     which is how a 420px canvas on a 360px phone rendered as "ello, world" with
     the H cut off. `safe` falls back to flex-start rather than clipping. The
     canvas is sized to fit in JS, so this is the backstop, not the mechanism. */
  justify-content: safe center;
  padding: 14px;
  background: var(--bg);
  /* Scroll rather than scale on a narrow viewport. winit drives the canvas's
     CSS width/height to match the surface, and taps are hit-tested against that
     same geometry, so shrinking it with `max-width` would misalign every tap
     by the scale factor. Overflow is the honest option. */
  overflow: auto;
}
.pg-stage canvas {
  flex: none;
  border-radius: 8px;
  /* The canvas is an app, not a document. Without this the browser claims the
     gesture for page panning and Rux never sees the drag, so its own scrolling
     never works on a touchscreen. The cost is that a finger starting on the
     canvas cannot scroll the page; there is plenty of page either side of it. */
  touch-action: none;
  /* No long-press text selection and no blue flash on tap: both belong to a
     document, and this is a running application. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pg-note {
  margin-top: 20px;
  color: var(--ink-dim);
}

/* Parse errors from the runtime, shown under the canvas. */
.pg-error {
  margin: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #2a1720;
  color: #f38ba8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* "Try it" on a runnable code block. Positioned against the <pre>, which the
   script marks with .has-tryit so only those blocks become containers. */
.prose pre.has-tryit { position: relative; }
.tryit {
  position: absolute;
  top: 8px;
  right: 10px;
  padding: 3px 10px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-dim);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  text-decoration: none;
}
.tryit:hover { color: var(--ink); border-color: var(--accent); }

@media (max-width: 860px) {
  .pg { padding: 24px 20px 56px; }
  .pg-grid { grid-template-columns: minmax(0, 1fr); }
  .pg-editwrap, .pg-editor { min-height: 340px; }
}

/* Phones. Every horizontal pixel spent on chrome is one the canvas cannot have,
   and the canvas is the point of the page. */
/* Phones. Every horizontal pixel spent on chrome is one the canvas cannot have.
   Note what is NOT here: any change to `.pg-grid`. It stays a grid with
   `minmax(0, 1fr)` columns, because that zero minimum is what lets the column
   shrink below the canvas's own width. Switching it to flex re-introduced the
   `min-width: auto` default, the pane refused to shrink under a 420px canvas,
   the page scrolled sideways, and the sizing code then measured that overflowed
   width and kept picking 420. Do not swap the grid out. */
@media (max-width: 560px) {
  .pg { padding: 16px 10px 40px; }
  .pg-head h1 { font-size: 1.6rem; }
  .pg-stage { padding: 8px; }
  .pg-bar { padding: 8px; }
  .pg-editwrap, .pg-editor { min-height: 380px; }
}
