/* ── Philora Handbuch — Stylesheet ──────────────────────────────────────────
   Dark by default (matches the app); light when the reader's system asks for
   it or the toggle says so. Every colour comes from a token so both themes
   stay in step. Palette derives from src/lib/theme.js (AURORA + INK).
   ------------------------------------------------------------------------ */

@font-face {
  font-family: "Sora";
  src: url("./sora.woff2") format("woff2-variations");
  font-weight: 100 800;
  font-display: swap;
}
@font-face {
  font-family: "InterVar";
  src: url("./inter.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}

/* ── Tokens ─────────────────────────────────────────────────────────────── */

:root {
  /* dark — the brand default */
  --bg:            #05070f;
  --bg-elevated:   #0a0e1c;
  --surface:       #0d1426;
  --surface-hover: #111a30;
  --border:        #16203c;
  --border-strong: #1d2a4d;

  --text:          #e8edf7;
  --text-strong:   #ffffff;
  --muted:         #7486a6;

  --accent:        #28e0f0;
  --accent-quiet:  #0e7d99;
  --violet:        #9a7bff;
  --gold:          #f6c25a;
  --emerald:       #36e0a4;
  --rose:          #ff6b9d;

  --accent-wash:   rgba(40, 224, 240, 0.12);
  --gold-wash:     rgba(246, 194, 90, 0.11);
  --emerald-wash:  rgba(54, 224, 164, 0.10);
  --shadow:        0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);

  --font-display: "Sora", ui-sans-serif, system-ui, sans-serif;
  --font-body:    "InterVar", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono:    ui-monospace, "SFMono-Regular", "Consolas", monospace;

  --sidebar-w: 19rem;
  --measure:   70ch;
  --radius:    0.7rem;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:            #f6f8fc;
    --bg-elevated:   #ffffff;
    --surface:       #ffffff;
    --surface-hover: #eef2f9;
    --border:        #dde4ef;
    --border-strong: #c6d1e2;

    --text:          #17203094;
    --text:          #172030;
    --text-strong:   #060b16;
    --muted:         #5a6b85;

    --accent:        #0e7d99;
    --accent-quiet:  #28e0f0;
    --violet:        #5f44b8;
    --gold:          #9a6a12;
    --emerald:       #0f7a56;
    --rose:          #b83f6b;

    --accent-wash:   rgba(14, 125, 153, 0.09);
    --gold-wash:     rgba(154, 106, 18, 0.10);
    --emerald-wash:  rgba(15, 122, 86, 0.09);
    --shadow:        0 1px 2px rgba(16, 30, 60, .06), 0 8px 24px rgba(16, 30, 60, .07);
  }
}

:root[data-theme="light"] {
  --bg:            #f6f8fc;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-hover: #eef2f9;
  --border:        #dde4ef;
  --border-strong: #c6d1e2;

  --text:          #172030;
  --text-strong:   #060b16;
  --muted:         #5a6b85;

  --accent:        #0e7d99;
  --accent-quiet:  #28e0f0;
  --violet:        #5f44b8;
  --gold:          #9a6a12;
  --emerald:       #0f7a56;
  --rose:          #b83f6b;

  --accent-wash:   rgba(14, 125, 153, 0.09);
  --gold-wash:     rgba(154, 106, 18, 0.10);
  --emerald-wash:  rgba(15, 122, 86, 0.09);
  --shadow:        0 1px 2px rgba(16, 30, 60, .06), 0 8px 24px rgba(16, 30, 60, .07);
}

/* ── Reset & base ───────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 5.5rem; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.7;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: .18em; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

img { max-width: 100%; height: auto; }

/* ── Top bar ────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  height: 3.75rem; padding: 0 1.15rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: .6rem; font-family: var(--font-display); font-weight: 600; color: var(--text-strong); text-decoration: none; letter-spacing: -.01em; flex: none; }
.brand-mark { width: 1.6rem; height: 1.6rem; border-radius: .45rem; background: linear-gradient(135deg, var(--accent), var(--violet)); flex: none; }
.brand-sub { color: var(--muted); font-weight: 400; font-family: var(--font-body); }

.topbar-spacer { flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  background: transparent; border: 1px solid var(--border);
  border-radius: .55rem; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 1.05rem; height: 1.05rem; }

.nav-toggle { display: none; }

/* ── Search ─────────────────────────────────────────────────────────────── */

.search { position: relative; width: min(26rem, 42vw); flex: none; }
.search input {
  width: 100%; height: 2.25rem; padding: 0 2.2rem 0 .8rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: .55rem;
  font: inherit; font-size: .9rem;
}
.search input::placeholder { color: var(--muted); }
.search-key {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: .7rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: .3rem; padding: .05rem .3rem;
  pointer-events: none;
}
.search input:focus + .search-key { display: none; }

.results {
  position: absolute; top: calc(100% + .4rem); left: 0; right: 0;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: min(28rem, 70vh); overflow-y: auto; padding: .35rem;
  display: none;
}
.results[data-open="true"] { display: block; }
.results a { display: block; padding: .5rem .6rem; border-radius: .45rem; text-decoration: none; color: var(--text); }
.results a:hover, .results a[aria-selected="true"] { background: var(--surface-hover); }
.results .r-title { display: block; font-weight: 550; color: var(--text-strong); font-size: .92rem; line-height: 1.35; }
.results .r-meta { display: block; font-size: .78rem; color: var(--muted); line-height: 1.45; margin-top: .1rem; }
.results .r-empty { padding: .8rem .6rem; color: var(--muted); font-size: .9rem; }
.results mark { background: var(--accent-wash); color: var(--accent); border-radius: .2rem; }

/* ── Shell ──────────────────────────────────────────────────────────────── */

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); align-items: start; }

.sidebar {
  position: sticky; top: 3.75rem;
  height: calc(100vh - 3.75rem); overflow-y: auto;
  padding: 1.5rem 1rem 3rem 1.15rem;
  border-right: 1px solid var(--border);
  font-size: .9rem;
  scrollbar-width: thin;
}
.sidebar h2 {
  font-family: var(--font-display); font-size: .72rem; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
  margin: 1.5rem 0 .5rem; padding-left: .55rem;
}
.sidebar h2:first-child { margin-top: 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.sidebar a {
  display: flex; align-items: baseline; gap: .4rem;
  padding: .34rem .55rem; border-radius: .45rem;
  color: var(--text); text-decoration: none; line-height: 1.4;
}
.sidebar a:hover { background: var(--surface-hover); }
.sidebar a[aria-current="page"] { background: var(--accent-wash); color: var(--accent); font-weight: 550; }
.sidebar .gear { font-size: .72rem; opacity: .75; flex: none; }

.content { min-width: 0; padding: 2.5rem 2rem 5rem; }
.content-inner { max-width: var(--measure); margin: 0 auto; }

/* ── Page header ────────────────────────────────────────────────────────── */

.eyebrow { font-family: var(--font-display); font-size: .74rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--violet); margin: 0 0 .5rem; }

.content h1 {
  font-family: var(--font-display); font-weight: 600; letter-spacing: -.02em;
  font-size: clamp(1.85rem, 1.3rem + 1.6vw, 2.4rem); line-height: 1.18;
  color: var(--text-strong); margin: 0 0 .7rem; text-wrap: balance;
}

.meta { display: flex; flex-wrap: wrap; gap: .45rem; margin: 0 0 2rem; font-size: .8rem; }
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .16rem .55rem; border-radius: 100px; border: 1px solid var(--border-strong); color: var(--muted); }
.pill-setup { background: var(--gold-wash); border-color: color-mix(in srgb, var(--gold) 35%, transparent); color: var(--gold); }

/* ── Prose ──────────────────────────────────────────────────────────────── */

.content h2 {
  font-family: var(--font-display); font-weight: 600; letter-spacing: -.012em;
  font-size: 1.3rem; line-height: 1.3; color: var(--text-strong);
  margin: 2.6rem 0 .8rem; padding-top: 1.4rem; border-top: 1px solid var(--border);
  text-wrap: balance;
}
.content h2:first-of-type { border-top: none; padding-top: 0; margin-top: 2rem; }
.content h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.06rem; color: var(--text-strong); margin: 1.9rem 0 .5rem; text-wrap: balance; }

.anchor { color: var(--muted); text-decoration: none; opacity: 0; margin-left: .4rem; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus-visible { opacity: 1; }

.content p { margin: 0 0 1.1rem; }
.content strong { color: var(--text-strong); font-weight: 600; }

.content ul, .content ol { margin: 0 0 1.2rem; padding-left: 1.3rem; display: flex; flex-direction: column; gap: .45rem; }
.content li { padding-left: .2rem; }
.content li::marker { color: var(--muted); }
.content ol li::marker { font-variant-numeric: tabular-nums; }

.content hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.content code {
  font-family: var(--font-mono); font-size: .875em;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .3rem; padding: .1em .35em;
}
.content pre {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem; overflow-x: auto; margin: 0 0 1.2rem;
}
.content pre code { background: none; border: none; padding: 0; font-size: .85rem; }

.content blockquote {
  margin: 0 0 1.2rem; padding: .1rem 0 .1rem 1rem;
  border-left: 3px solid var(--violet); color: var(--text);
}
.content blockquote p:last-child { margin-bottom: 0; }

/* Tables — the manual leans on these heavily, so they get real care. */
.table-wrap { overflow-x: auto; margin: 0 0 1.4rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.content table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.content thead th {
  text-align: left; font-family: var(--font-display); font-weight: 600; font-size: .78rem;
  letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  padding: .7rem .85rem; border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.content tbody td { padding: .65rem .85rem; border-top: 1px solid var(--border); vertical-align: top; }
.content tbody tr:first-child td { border-top: none; }
.content tbody tr:hover { background: var(--surface-hover); }
.content td:first-child { color: var(--text-strong); }

/* Screenshot placeholders — rendered wherever the image file is not there yet. */
.shot {
  margin: 0 0 1.5rem; padding: 1.4rem 1.2rem;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--bg-elevated); text-align: center;
}
.shot-id { display: inline-block; font-family: var(--font-mono); font-size: .72rem; letter-spacing: .04em; color: var(--accent); background: var(--accent-wash); border-radius: .3rem; padding: .12rem .45rem; margin-bottom: .55rem; }
.shot-note { margin: 0; font-size: .86rem; color: var(--muted); line-height: 1.55; }
figure.shot-done { margin: 0 0 1.5rem; padding: 0; border: none; background: none; }
figure.shot-done img { border: 1px solid var(--border); border-radius: var(--radius); display: block; }
figure.shot-done figcaption { margin-top: .5rem; font-size: .82rem; color: var(--muted); text-align: center; }

/* ── On this page ───────────────────────────────────────────────────────── */

.onpage { display: none; }
@media (min-width: 1280px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 15rem; }
  .onpage {
    display: block; position: sticky; top: 3.75rem;
    max-height: calc(100vh - 3.75rem); overflow-y: auto;
    padding: 2.5rem 1.15rem 3rem 0; font-size: .85rem;
  }
  .onpage h2 { font-family: var(--font-display); font-size: .72rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin: 0 0 .6rem; }
  .onpage ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .1rem; border-left: 1px solid var(--border); }
  .onpage a { display: block; padding: .22rem 0 .22rem .75rem; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.45; }
  .onpage a:hover { color: var(--text); }
  .onpage a.active { color: var(--accent); border-left-color: var(--accent); }
}

/* ── Footer nav ─────────────────────────────────────────────────────────── */

.pagenav { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; margin-top: 3.5rem; padding-top: 1.6rem; border-top: 1px solid var(--border); }
.pagenav a {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; color: var(--text-strong);
  transition: border-color .15s, background .15s;
}
.pagenav a:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.pagenav .dir { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pagenav .next { text-align: right; grid-column: 2; }
.pagenav .prev { grid-column: 1; }

.updated { margin-top: 2rem; font-size: .8rem; color: var(--muted); }

/* ── Home ───────────────────────────────────────────────────────────────── */

.home-hero { margin: 0 auto 3rem; max-width: var(--measure); }
.home-hero h1 { font-size: clamp(2.1rem, 1.4rem + 2.4vw, 3rem); }
.lede { font-size: 1.1rem; color: var(--muted); margin: 0 0 1.6rem; }
.cta {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem 1.1rem; border-radius: .6rem;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  color: #05070f; font-weight: 600; text-decoration: none; font-family: var(--font-display);
}
:root[data-theme="light"] .cta, :root:not([data-theme="dark"]) .cta { color: #ffffff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cta { color: #05070f; } }

.section-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); margin: 0 auto; max-width: 62rem; }
.section-card { padding: 1.1rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.section-card h3 { margin: 0 0 .3rem; font-family: var(--font-display); font-size: 1rem; color: var(--text-strong); }
.section-card p { margin: 0 0 .7rem; font-size: .88rem; color: var(--muted); }
.section-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; }
.section-card a { text-decoration: none; }
.section-card a:hover { text-decoration: underline; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-flex; order: -1; }
  .search { width: auto; flex: 1; }
  .search-key { display: none; }
  .brand-sub { display: none; }
  .sidebar {
    position: fixed; inset: 3.75rem auto 0 0; z-index: 35;
    width: min(20rem, 84vw); height: calc(100dvh - 3.75rem);
    background: var(--bg-elevated); border-right: 1px solid var(--border-strong);
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar[data-open="true"] { transform: none; box-shadow: var(--shadow); }
  .scrim { position: fixed; inset: 3.75rem 0 0; z-index: 34; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .22s; }
  .scrim[data-open="true"] { opacity: 1; pointer-events: auto; }
  .content { padding: 1.75rem 1.15rem 4rem; }
  .pagenav { grid-template-columns: 1fr; }
  .pagenav .next, .pagenav .prev { grid-column: 1; text-align: left; }
}

@media print {
  .topbar, .sidebar, .onpage, .pagenav, .scrim { display: none; }
  .shell { display: block; }
  .content { padding: 0; }
  a { color: inherit; }
}
