/* Wren TV docs (wrentv.com/docs). Palette: Ember #E04A2A, Ink #1C1A21, Cream #F7F1E8.
   Dark is the default; Auto follows the system, and the theme menu can pin either. */
:root {
  --ember: #E04A2A;
  --accent: #ef6545;
  --bg: #141218;
  --bg-2: #1C1A21;
  --bg-3: #27242d;
  --hover: #f7f1e80d;
  --line: #34303b;
  --line-soft: #f7f1e814;
  --text: #F7F1E8;
  --text-2: #ddd5ca;
  --muted: #b2aaa2;
  --code-bg: #0e0c11;
  --inline-code: #f7f1e814;
  --header: #141218e0;
  --shadow: 0 30px 80px #000a;
  --note: #6aa8ff; --tip: #4cc38a; --warning: #f0b232; --important: #c792ea;
  --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --accent: #c43c1e;
    --bg: #fbf8f3;
    --bg-2: #f3ede4;
    --bg-3: #e9e1d6;
    --hover: #1c1a210a;
    --line: #ddd4c8;
    --line-soft: #1c1a2112;
    --text: #1C1A21;
    --text-2: #34303b;
    --muted: #6b645c;
    --code-bg: #f1ebe2;
    --inline-code: #1c1a210f;
    --header: #fbf8f3e6;
    --shadow: 0 30px 80px #1c1a2133;
    --note: #2f6fd6; --tip: #1f8a5b; --warning: #a86d00; --important: #8a4fc2;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --accent: #c43c1e;
  --bg: #fbf8f3;
  --bg-2: #f3ede4;
  --bg-3: #e9e1d6;
  --hover: #1c1a210a;
  --line: #ddd4c8;
  --line-soft: #1c1a2112;
  --text: #1C1A21;
  --text-2: #34303b;
  --muted: #6b645c;
  --code-bg: #f1ebe2;
  --inline-code: #1c1a210f;
  --header: #fbf8f3e6;
  --shadow: 0 30px 80px #1c1a2133;
  --note: #2f6fd6; --tip: #1f8a5b; --warning: #a86d00; --important: #8a4fc2;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 84px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 16px/1.7 Figtree, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.skip { position: absolute; left: 12px; top: -60px; z-index: 50; padding: 8px 14px; border-radius: 8px; background: var(--ember); color: #fff; font-weight: 700; text-decoration: none; }
.skip:focus { top: 12px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20; height: 64px; display: flex; align-items: center; gap: 16px; padding: 0 24px;
  background: var(--header); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex-shrink: 0; }
.brand img { width: 30px; height: 30px; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -.01em; }
.brand-tag { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; }
.search-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; max-width: 340px; margin-left: 32px; padding: 8px 10px 8px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); cursor: pointer; font-size: 15px; text-align: left;
}
.search-btn:hover { border-color: var(--muted); }
.search-btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.search-btn span { flex: 1; }
kbd { font-family: inherit; font-size: 12px; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; background: var(--bg); white-space: nowrap; }
.top-links { margin-left: auto; display: flex; align-items: center; gap: 20px; font-size: 15px; font-weight: 600; }
.top-links a { text-decoration: none; color: var(--muted); white-space: nowrap; }
.top-links a:hover { color: var(--text); }
.top-links .btn-sm { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 9px; background: var(--ember); color: #fff; }
.top-links .btn-sm:hover { color: #fff; filter: brightness(1.08); }
.top-links .btn-sm svg { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.icon-btn { display: none; place-items: center; width: 40px; height: 40px; margin-left: -8px; border: 0; border-radius: 9px; background: none; cursor: pointer; }
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr) 240px; max-width: 1440px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 64px; height: calc(100vh - 64px); height: calc(100dvh - 64px); overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 16px 0 24px; border-right: 1px solid var(--line-soft); display: flex; flex-direction: column;
}
.sidebar nav { flex: 1; }
.nav-group { margin-bottom: 22px; }
.nav-title { margin: 0 0 6px 10px; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-group a { display: block; padding: 5px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-size: 15px; line-height: 1.45; }
.nav-group a:hover { background: var(--hover); color: var(--text); }
.nav-group a[aria-current="page"] { background: color-mix(in srgb, var(--ember) 14%, transparent); color: var(--accent); font-weight: 700; }
.sidebar-foot { position: sticky; bottom: 0; padding: 14px 0 18px 10px; background: var(--bg); border-top: 1px solid var(--line-soft); }
.theme { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.theme select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; }
.scrim { display: none; }

/* ---------- content ---------- */
.content { padding: 40px 56px 64px; min-width: 0; }
.doc { max-width: 760px; }
.crumb { margin: 0 0 8px; font-size: 13px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.doc h1 { margin: 0; font-size: clamp(32px, 4vw, 42px); line-height: 1.12; font-weight: 800; letter-spacing: -.02em; }
.lead { margin: 14px 0 8px; font-size: 19px; color: var(--muted); line-height: 1.55; }
.doc h2, .doc h3, .doc h4 { position: relative; line-height: 1.25; letter-spacing: -.01em; }
.doc h2 { margin: 48px 0 12px; padding-top: 24px; border-top: 1px solid var(--line-soft); font-size: 26px; font-weight: 750; }
.doc h3 { margin: 32px 0 8px; font-size: 20px; font-weight: 700; }
.doc h4 { margin: 24px 0 6px; font-size: 17px; font-weight: 700; }
.anchor { position: absolute; left: -1.1em; padding-right: .3em; color: var(--muted); text-decoration: none; opacity: 0; transition: opacity .15s; font-weight: 600; }
.doc h2 .anchor { top: 24px; }
.doc :is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; }
.doc p, .doc ul, .doc ol { margin: 0 0 16px; color: var(--text-2); }
.doc li { margin: 4px 0; }
.doc li > ul, .doc li > ol { margin: 4px 0 0; }
.doc strong { color: var(--text); font-weight: 700; }
.doc a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.doc a:hover { text-decoration-color: currentColor; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.doc img { max-width: 100%; height: auto; border-radius: var(--radius); }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86em; background: var(--inline-code); padding: 2px 6px; border-radius: 5px; overflow-wrap: anywhere; }
pre { position: relative; margin: 0 0 18px; padding: 16px 18px; border-radius: var(--radius); background: var(--code-bg); border: 1px solid var(--line); overflow-x: auto; font-size: 14px; line-height: 1.6; }
pre code { background: none; padding: 0; font-size: inherit; overflow-wrap: normal; white-space: pre; color: var(--text); }
pre .lang { position: absolute; top: 8px; right: 12px; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
pre:has(.copy) .lang { display: none; }
.copy { position: absolute; top: 8px; right: 8px; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; cursor: pointer; opacity: 0; transition: opacity .15s; }
pre:hover .copy, .copy:focus { opacity: 1; }
.copy:hover { color: var(--text); }
@media (hover: none) { .copy { opacity: 1; } }

.table-wrap { margin: 0 0 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 9px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
th { background: var(--bg-2); font-weight: 700; color: var(--text); white-space: nowrap; }
td { color: var(--text-2); }
tr:last-child td { border-bottom: 0; }

blockquote { margin: 0 0 18px; padding: 2px 18px; border-left: 3px solid var(--line); color: var(--muted); }
.callout { --c: var(--note); margin: 0 0 18px; padding: 14px 18px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); background: color-mix(in srgb, var(--c) 8%, transparent); }
.callout.tip { --c: var(--tip); }
.callout.warning { --c: var(--warning); }
.callout.important { --c: var(--important); }
.callout-title { margin: 0 0 4px !important; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--c) !important; }
.callout > :last-child { margin-bottom: 0; }

.pager { max-width: 760px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 56px; }
.pager a { display: grid; gap: 2px; padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; transition: border-color .15s; }
.pager a:hover { border-color: var(--accent); }
.pager .next { text-align: right; grid-column: 2; }
.pager .next .pager-label { justify-content: flex-end; }
.pager-label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.pager-label svg { width: 15px; height: 15px; }
.pager-title { font-weight: 700; color: var(--accent); }
.doc-foot { max-width: 760px; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line-soft); font-size: 14px; color: var(--muted); }

/* ---------- on this page ---------- */
.toc { position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 64px); overflow-y: auto; padding: 40px 24px 24px 8px; font-size: 14px; }
.toc-title { margin: 0 0 8px; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc a { display: block; margin-left: -1px; padding: 4px 0 4px 14px; border-left: 2px solid transparent; text-decoration: none; color: var(--muted); line-height: 1.4; }
.toc .d3 a { padding-left: 26px; font-size: 13.5px; }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

/* ---------- search ---------- */
.search { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; background: #0009; backdrop-filter: blur(3px); }
.search-box { width: 100%; max-width: 620px; max-height: 75vh; display: flex; flex-direction: column; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.search-field { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.search-field svg { width: 19px; height: 19px; color: var(--muted); flex-shrink: 0; }
.search-field input { flex: 1; min-width: 0; padding: 16px 0; border: 0; background: none; font-size: 17px; outline: none; }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.search-results:empty { display: none; }
.search-results a { display: block; padding: 10px 12px; border-radius: 9px; text-decoration: none; }
.search-results a[aria-selected="true"] { background: color-mix(in srgb, var(--ember) 14%, transparent); }
.search-results .r-title { display: block; font-weight: 700; }
.search-results .r-page { color: var(--muted); font-weight: 500; font-size: 13px; }
.search-results .r-text { display: block; margin-top: 2px; font-size: 14px; color: var(--muted); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.search-results mark { background: none; color: var(--accent); font-weight: 700; }
.search-results .empty { padding: 18px 12px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .toc { display: none; }
  .content { padding: 36px 40px 56px; }
}
@media (max-width: 900px) {
  .top { padding: 0 16px; gap: 10px; }
  .icon-btn { display: grid; }
  .search-btn { margin-left: auto; max-width: none; width: 40px; padding: 0; height: 40px; justify-content: center; border-color: transparent; background: none; color: var(--text); }
  .search-btn span, .search-btn kbd { display: none; }
  .search-btn svg { width: 20px; height: 20px; }
  .top-links { margin-left: 0; }
  .top-links > a:not(.btn-sm) { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 30; top: 64px; left: 0; bottom: 0; height: auto; width: min(300px, 86vw);
    padding-top: 20px; background: var(--bg); border-right: 1px solid var(--line); transform: translateX(-100%); transition: transform .22s ease; visibility: hidden;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  body.nav-open .scrim { display: block; position: fixed; inset: 64px 0 0; z-index: 25; background: #0008; }
  body.nav-open { overflow: hidden; }
  .content { padding: 28px 16px 48px; }
  .anchor { display: none; }
}
@media (max-width: 520px) {
  .top-links .btn-sm { padding: 7px 10px; }
  .brand-tag { display: none; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .lead { font-size: 17px; }
  .doc h2 { font-size: 23px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
