/* ============================================================
   leanweb.app design system
   Self-contained: tokens, base elements, layout, demo chrome.
   Light & dark from one set of tokens via light-dark();
   manual override with html[data-theme="light|dark"].
   ============================================================ */

/* ---------- tokens ---------- */

:root {
  color-scheme: light dark;

  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;

  --accent: light-dark(#0a9669, #34d399);
  --accent-2: light-dark(#0e8fa8, #22d3ee);
  --accent-ink: light-dark(#066248, #86efcf);
  --accent-soft: light-dark(rgb(10 150 105 / .09), rgb(52 211 153 / .12));
  --accent-line: light-dark(rgb(10 150 105 / .35), rgb(52 211 153 / .4));

  --bg: light-dark(#fbfbfa, #0b0e14);
  --bg-soft: light-dark(#f4f4f1, #0f131c);
  --panel: light-dark(#ffffff, #121722);
  --ink: light-dark(#1a1f27, #e7ecf3);
  --ink-2: light-dark(#5a626e, #96a1b3);
  --ink-3: light-dark(#8b929d, #626e80);
  --line: light-dark(rgb(26 31 39 / .11), rgb(231 236 243 / .09));
  --line-strong: light-dark(rgb(26 31 39 / .2), rgb(231 236 243 / .18));
  --shadow: light-dark(0 1px 2px rgb(26 31 39 / .05), 0 1px 2px rgb(0 0 0 / .35));
  --shadow-lg: light-dark(0 12px 32px -12px rgb(26 31 39 / .18), 0 12px 32px -12px rgb(0 0 0 / .6));

  /* code panels stay dark in both themes */
  --code-bg: #0c111d;
  --code-bar: #101627;
  --code-line: rgb(148 163 184 / .14);
  --code-text: #c8d3e2;
  --code-muted: #77839a;

  --radius: 10px;
  --radius-lg: 14px;
  --nav-h: 60px;
}

html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

/* ---------- base ---------- */

* { box-sizing: border-box; }

html {
  /* rem root — every rem-sized component scales from here */
  font-size: 18px;
  scroll-behavior: smooth;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[id] { scroll-margin-top: calc(var(--nav-h) + 20px); }

h1, h2, h3, h4 {
  color: var(--ink);
  line-height: 1.2;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
  color: var(--ink-2);
}

a {
  color: var(--accent);
  text-decoration: none;

  &:hover { text-decoration: underline; text-underline-offset: 3px; }
}

::selection {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
}

/* inline code in prose */
p code, li code, h2 code, h3 code, td code {
  font-family: var(--font-mono);
  font-size: .84em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: .1em .38em;
  border-radius: 6px;
  white-space: nowrap;
}

/* ---------- demo form controls ----------
   Raw elements inside live-result frames are styled here, so
   sample markup needs no classes to look right on this page. */

leanweb-app-window {
  button {
    font: 500 .88rem/1.2 var(--font-ui);
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 7px 14px;
    cursor: pointer;
    transition: border-color .15s, background .15s;

    &:hover { border-color: var(--accent-line); color: var(--accent-ink); }
    &:active { transform: translateY(1px); }
    &:disabled {
      opacity: .45;
      cursor: not-allowed;
      &:hover { border-color: var(--line-strong); color: var(--ink); }
    }
  }

  input:not([type]), input[type="text"], input[type="number"], select {
    font: 400 .92rem/1.3 var(--font-ui);
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 7px 10px;
    max-width: 100%;
  }

  input[type="number"] { width: 5.5em; }

  input, select, button {
    &:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 1px;
    }
  }

  input[type="checkbox"], input[type="radio"], input[type="range"] {
    accent-color: var(--accent);
  }

  select[multiple] {
    padding: 4px;
    option { padding: 4px 8px; border-radius: 5px; }
  }

  img { max-width: 100%; height: auto; border-radius: 8px; display: block; }
}

/* ---------- layout ---------- */

.wrap {
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: clamp(18px, 4vw, 36px);
}

.section {
  padding-block: clamp(64px, 9vw, 110px) 0;

  .section-head {
    max-width: 720px;
    margin-bottom: clamp(28px, 4vw, 44px);

    .kicker {
      font: 600 .76rem/1 var(--font-mono);
      letter-spacing: .14em;
      text-transform: uppercase;
      color: var(--accent);
      margin-bottom: 14px;
      display: flex;
      align-items: center;
      gap: 10px;

      &::before {
        content: '';
        width: 22px;
        height: 2px;
        border-radius: 2px;
        background: linear-gradient(90deg, var(--accent), var(--accent-2));
      }
    }

    h2 {
      font-size: clamp(1.7rem, 3.2vw, 2.2rem);
      font-weight: 700;
      letter-spacing: -.022em;
      margin-bottom: 12px;
    }

    p { font-size: 1.05rem; max-width: 62ch; }
  }
}

/* ---------- demo blocks ---------- */

.demo {
  padding-block: clamp(36px, 5vw, 52px);
  border-top: 1px solid var(--line);

  .demo-head {
    max-width: 720px;
    margin-bottom: 26px;

    h3 {
      font-size: 1.3rem;
      font-weight: 650;
      letter-spacing: -.015em;
      margin-bottom: 10px;

      code {
        font-family: var(--font-mono);
        font-size: .92em;
        color: var(--accent-ink);
        background: var(--accent-soft);
        border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
        padding: .12em .45em;
        border-radius: 8px;
      }

      .anchor {
        margin-left: 8px;
        color: var(--ink-3);
        font-weight: 400;
        opacity: 0;
        transition: opacity .15s;
        &:hover { color: var(--accent); text-decoration: none; }
      }

      &:hover .anchor { opacity: 1; }
    }
  }

  h4 {
    font-size: 1.02rem;
    font-weight: 650;
    margin: 34px 0 8px;
  }

  h4 + p { margin-bottom: 18px; max-width: 70ch; }

  /* Code panels at full column width — the samples set the width budget
     since the type got bigger — with the live result frame below them. */
  .duo {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;

    .code { display: grid; gap: 12px; min-width: 0; }
  }

  .note {
    margin-top: 18px;
    max-width: 70ch;
    font-size: .95rem;
    padding: 12px 16px;
    border-left: 3px solid var(--accent-line);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--accent-soft);
    color: var(--ink-2);
  }
}

.demo:first-of-type { border-top: none; padding-top: 8px; }

/* ---------- code blocks ---------- */

.code-block {
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;

  .file {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 8px 0 14px;
    background: var(--code-bar);
    border-bottom: 1px solid var(--code-line);
    font: 500 .74rem/1 var(--font-mono);
    letter-spacing: .04em;
    color: var(--code-muted);

    .copy {
      margin-left: auto;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 26px;
      height: 26px;
      border: none;
      border-radius: 6px;
      background: transparent;
      color: var(--code-muted);
      cursor: pointer;

      svg { width: 14px; height: 14px; }

      &:hover { background: rgb(148 163 184 / .12); color: #dbe4f0; }
      &.done { color: #34d399; }
    }
  }

  pre {
    margin: 0;
    overflow-x: auto;

    code {
      display: block;
      padding: 14px 16px;
      font: .84rem/1.75 var(--font-mono);
      color: var(--code-text);
      white-space: pre;
    }
  }
}

/* syntax palette (dark panels in both themes) */
.tk-tag     { color: #7dd3fc; }
.tk-attr    { color: #94a3b8; }
.tk-lw      { color: #34d399; }
.tk-string  { color: #fbd38d; }
.tk-keyword { color: #c4b5fd; }
.tk-number  { color: #fda4af; }
.tk-fn      { color: #7dd3fc; }
.tk-comment { color: #64748b; font-style: italic; }
.tk-punct   { color: #8b98ab; }

/* ---------- demo child-component chrome ----------
   Dashed border = a component boundary in a live result;
   the little label names the tag from the sample code. */

leanweb-app-demos-inputs-child,
leanweb-app-advanced-emit-child,
leanweb-app-advanced-direct-child,
leanweb-app-advanced-bus-pub,
leanweb-app-advanced-bus-sub {
  display: block;
  position: relative;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;

  &::before {
    position: absolute;
    top: -8px;
    left: 12px;
    font: 500 .66rem/1 var(--font-mono);
    letter-spacing: .05em;
    color: var(--ink-3);
    background: var(--panel);
    padding: 1px 6px;
    border-radius: 4px;
  }

  > * + * { margin-top: 10px; }

  p { margin: 0; }
}

leanweb-app-demos-inputs-child::before { content: 'demo-child'; }
leanweb-app-advanced-emit-child::before { content: 'demo-child'; }
leanweb-app-advanced-direct-child::before { content: 'demo-child'; }
leanweb-app-advanced-bus-pub::before { content: 'demo-clock'; }
leanweb-app-advanced-bus-sub::before { content: 'demo-display'; }

/* ---------- shared bits ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 500 .74rem/1 var(--font-mono);
  color: var(--ink-2);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  white-space: nowrap;
}

.ps1 { color: var(--accent); user-select: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;

  svg { width: 18px; height: 18px; }

  &:hover {
    color: var(--ink);
    background: var(--bg-soft);
    border-color: var(--line);
    text-decoration: none;
  }
}

/* ---------- cards (features, cli, howtos, api) ---------- */

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

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

/* (footer component styles live in its own scoped css) */

/* ---------- misc ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
