/* The demo's own styling, loaded after the site theme's stylesheet.

   Every rule is scoped to the page's `.demo` wrapper, so nothing here reaches
   the site's header, footer or search dialog. The colours are the theme's own
   tokens, which is what makes the demo follow the header's theme toggle; the
   few the theme has no token for -- a soft accent fill, warning and error --
   are defined here for both palettes, in the same dark-first way the theme
   defines its own. Deliberately plain otherwise: the interesting stylesheets
   are the ones compiled in the preview frame. */

.demo {
  --demo-bg: var(--bg);
  --demo-surface: var(--surface);
  --demo-border: var(--border);
  --demo-text: var(--text);
  --demo-muted: var(--text-dim);
  --demo-accent: var(--accent);
  --demo-accent-ink: var(--accent-ink);
  --demo-accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --demo-warn: #e4b062;
  --demo-warn-soft: #2b2415;
  --demo-error: #ff8a80;
  --demo-error-soft: #2e1a18;
  --demo-radius: 8px;

  font-size: 15px;
  line-height: 1.55;
}

/* The light palette, applied the two ways the theme applies its own: by the
   operating system while the reader has not chosen, and by the toggle. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .demo {
    --demo-warn: #8a5a00;
    --demo-warn-soft: #fdf3e0;
    --demo-error: #b3261e;
    --demo-error-soft: #fdecea;
  }
}

:root[data-theme="light"] .demo {
  --demo-warn: #8a5a00;
  --demo-warn-soft: #fdf3e0;
  --demo-error: #b3261e;
  --demo-error-soft: #fdecea;
}

.demo .wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

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

.demo code,
.demo pre {
  font-family: var(--mono);
}

.demo code {
  font-size: 0.92em;
}

/* Intro ------------------------------------------------------------------- */

.demo-intro {
  border-bottom: 1px solid var(--demo-border);
  background: var(--demo-surface);
  padding: 32px 0 24px;
}

.demo-intro h1 {
  margin: 0 0 8px;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.demo .lede {
  margin: 0;
  max-width: 68ch;
  color: var(--demo-muted);
}

.demo .facts {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin: 20px 0 0;
}

.demo .facts div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.demo .facts dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--demo-muted);
}

.demo .facts dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
}

/* Presets ----------------------------------------------------------------- */

.demo .presets {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 24px 0 0;
}

.demo .preset {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 16px;
  min-width: 150px;
  text-align: left;
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.demo .preset:hover {
  border-color: var(--demo-accent);
}

.demo .preset[aria-current="true"] {
  border-color: var(--demo-accent);
  background: var(--demo-accent-soft);
}

.demo .preset-name {
  font-weight: 600;
}

.demo .preset-meta {
  font-size: 12px;
  color: var(--demo-muted);
  font-family: var(--mono);
}

.demo .preset-note {
  margin: 12px 0 0;
  color: var(--demo-muted);
  font-size: 13px;
  min-height: 1.2em;
}

/* Panes ------------------------------------------------------------------- */

.demo .panes {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 16px;
  margin: 16px 0 40px;
  align-items: start;
}

@media (max-width: 940px) {
  .demo .panes {
    grid-template-columns: minmax(0, 1fr);
  }
}

.demo .pane {
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.demo .pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--demo-border);
}

.demo .pane-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--demo-muted);
}

.demo .pane-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.demo .inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--demo-muted);
}

.demo .button {
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--demo-accent);
  color: var(--demo-accent-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.demo .button:disabled {
  opacity: 0.55;
  cursor: default;
}

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

/* Theme controls ---------------------------------------------------------- */

.demo .controls {
  padding: 12px 14px;
  border-bottom: 1px solid var(--demo-border);
}

.demo .controls-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.demo .controls-head h3 {
  margin: 0;
  font-size: 13px;
}

.demo .control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 14px;
}

.demo .control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.demo .control label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--demo-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.demo .control input,
.demo .control select {
  font: inherit;
  font-size: 13px;
  padding: 5px 6px;
  border: 1px solid var(--demo-border);
  border-radius: 6px;
  background: var(--demo-bg);
  color: var(--demo-text);
  min-width: 0;
}

.demo .control input[type="color"] {
  padding: 2px;
  height: 30px;
  cursor: pointer;
}

.demo .controls-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--demo-warn);
  background: var(--demo-warn-soft);
  padding: 6px 8px;
  border-radius: 6px;
}

/* Source ------------------------------------------------------------------ */

.demo #source {
  flex: 1;
  width: 100%;
  min-height: 340px;
  padding: 14px;
  border: 0;
  resize: vertical;
  background: var(--demo-surface);
  color: var(--demo-text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
}

.demo #source:focus {
  outline: 2px solid var(--demo-accent);
  outline-offset: -2px;
}

/* Output ------------------------------------------------------------------ */

.demo .tabs {
  display: flex;
  gap: 2px;
}

.demo .tab {
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--demo-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.demo .tab:hover {
  color: var(--demo-text);
}

.demo .tab[aria-selected="true"] {
  background: var(--demo-accent-soft);
  border-color: var(--demo-border);
  color: var(--demo-text);
  font-weight: 600;
}

.demo .badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--demo-border);
  color: var(--demo-text);
  font-size: 11px;
  font-family: var(--mono);
  text-align: center;
}

.demo .status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--demo-border);
  font-size: 12px;
  color: var(--demo-muted);
  font-family: var(--mono);
}

.demo .status[data-state="working"] {
  color: var(--demo-accent);
}

.demo .status[data-state="error"] {
  color: var(--demo-error);
  background: var(--demo-error-soft);
}

.demo .stats {
  text-align: right;
}

.demo .views {
  min-height: 420px;
}

.demo .view {
  height: 100%;
}

.demo #preview {
  display: block;
  width: 100%;
  height: 560px;
  border: 0;
  background: #fff;
}

.demo pre {
  margin: 0;
  padding: 14px;
  max-height: 560px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
}

.demo .log {
  max-height: 560px;
  overflow: auto;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 12px;
}

.demo .log-entry {
  padding: 7px 0;
  border-bottom: 1px solid var(--demo-border);
  white-space: pre-wrap;
  word-break: break-word;
}

.demo .log-entry:last-child {
  border-bottom: 0;
}

.demo .log-where {
  color: var(--demo-muted);
}

.demo .log-empty {
  padding: 14px 0;
  color: var(--demo-muted);
}

.demo .error {
  padding: 12px 14px;
  border-top: 1px solid var(--demo-border);
  background: var(--demo-error-soft);
}

.demo .error h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--demo-error);
}

.demo .error pre {
  padding: 0;
  max-height: 240px;
  color: var(--demo-text);
}

/* Notes ------------------------------------------------------------------- */

.demo .notes {
  margin: 0 0 32px;
}

.demo .notes h2 {
  font-size: 18px;
  margin: 0 0 14px;
}

.demo .note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.demo .note-grid article {
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  padding: 14px 16px;
}

.demo .note-grid h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.demo .note-grid p {
  margin: 0;
  color: var(--demo-muted);
  font-size: 13px;
}

.demo .demo-credits {
  margin: 0 0 40px;
  color: var(--demo-muted);
  font-size: 13px;
}
