/* TapVault site stylesheet. One file, no fonts, no third-party requests. */
@layer tokens, base, layout, components, pages;

/* ---------- tokens ---------- */
@layer tokens {
  :root {
    color-scheme: light dark;

    /* Light scheme: cool neutrals, forest-green accent (about #285a40) */
    --bg: oklch(0.975 0.004 160);
    --surface: oklch(0.945 0.008 160);
    --text: oklch(0.24 0.012 160);
    --muted: oklch(0.46 0.018 160);
    --line: oklch(0.86 0.01 160);
    --accent: oklch(0.43 0.075 156);
    --on-accent: oklch(0.98 0.006 150);

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2.5rem;
    --space-7: 4rem;
    --space-8: 6rem;

    /* Shape */
    --radius: 10px;
    --radius-lg: 16px;
    --measure: 68ch;
    --page: 72rem;

    /* Fluid type */
    --step--1: clamp(0.84rem, 0.82rem + 0.1vw, 0.9rem);
    --step-0: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
    --step-1: clamp(1.15rem, 1.08rem + 0.35vw, 1.35rem);
    --step-2: clamp(1.4rem, 1.25rem + 0.75vw, 1.85rem);
    --step-3: clamp(1.8rem, 1.45rem + 1.7vw, 2.8rem);
    --step-4: clamp(2.2rem, 1.6rem + 3vw, 3.9rem);

    --font: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --shadow: 0 1px 2px oklch(0.2 0.02 160 / 0.08), 0 8px 24px oklch(0.2 0.02 160 / 0.06);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --bg: oklch(0.2 0.008 160);
      --surface: oklch(0.25 0.01 160);
      --text: oklch(0.94 0.006 160);
      --muted: oklch(0.76 0.012 160);
      --line: oklch(0.36 0.012 160);
      --accent: oklch(0.78 0.11 156);
      --on-accent: oklch(0.2 0.02 156);
      --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 8px 24px oklch(0 0 0 / 0.3);
    }
  }
}

/* ---------- base ---------- */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 6rem;
  }

  body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: var(--step-0) / 1.6 var(--font);
    -webkit-font-smoothing: antialiased;
  }

  main { flex: 1 0 auto; }

  h1, h2, h3, h4 {
    line-height: 1.15;
    letter-spacing: -0.02em;
    text-wrap: balance;
    margin: 0 0 var(--space-3);
  }
  h1 { font-size: var(--step-4); letter-spacing: -0.03em; font-weight: 700; }
  h2 { font-size: var(--step-3); font-weight: 650; }
  h3 { font-size: var(--step-1); font-weight: 650; }
  h4 { font-size: var(--step-0); font-weight: 650; }

  p, ul, ol, dl, figure { margin: 0 0 var(--space-4); }
  p { text-wrap: pretty; }

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

  img, picture, svg { display: block; max-width: 100%; height: auto; }

  code, kbd, samp {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 0.1em 0.35em;
    overflow-wrap: anywhere;
  }

  ::selection { background: var(--accent); color: var(--on-accent); }

  :focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
  }

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

/* ---------- layout ---------- */
@layer layout {
  .container {
    width: 100%;
    max-width: var(--page);
    margin-inline: auto;
    padding-inline: max(16px, 4vw);
  }

  .skip-link {
    position: absolute;
    inset-block-start: var(--space-2);
    inset-inline-start: var(--space-2);
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 600;
    transform: translateY(-200%);
    transition: transform 0.15s ease;
  }
  .skip-link:focus { transform: none; outline-color: var(--text); }

  .site-header {
    position: sticky;
    inset-block-start: 0;
    z-index: 50;
    background: color-mix(in oklch, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
    border-block-end: 1px solid var(--line);
  }
  .site-header .container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-5);
    min-height: 3.5rem;
    padding-block: var(--space-2);
  }
  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text);
    font-weight: 700;
    font-size: var(--step-1);
    letter-spacing: -0.02em;
    text-decoration: none;
  }
  .brand img, .brand svg { width: 1.6rem; height: 1.6rem; }

  .site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
  }
  .site-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .site-nav a {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-size: var(--step--1);
    font-weight: 550;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .site-nav a:hover { color: var(--text); background: var(--surface); }
  .site-nav a[aria-current="page"] {
    color: var(--text);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
  }

  .site-footer {
    margin-block-start: 0;
    padding-block: var(--space-6);
    background: var(--surface);
    border-block-start: 1px solid var(--line);
    color: var(--muted);
    font-size: var(--step--1);
  }
  .site-footer p { max-width: var(--measure); }
  .site-footer a { color: var(--text); }
  .site-footer nav, .site-footer ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    margin: 0 0 var(--space-4);
    padding: 0;
    list-style: none;
  }

  section:not(.hero, .band, .scope) { padding-block: var(--space-6); }
}

/* ---------- components ---------- */
@layer components {
  /* Hero: copy beside picture on wide, stacked on narrow */
  .hero { padding-block: var(--space-6) var(--space-7); }
  .hero .container, .hero.container {
    display: grid;
    gap: var(--space-6);
    align-items: center;
  }
  .hero p.lead, .hero .lead {
    font-size: var(--step-1);
    color: var(--muted);
    max-width: 38ch;
  }
  .hero picture, .hero img {
    width: 100%;
    max-width: 34rem;
    margin-inline: auto;
    border-radius: var(--radius-lg);
  }
  .hero img { aspect-ratio: 1; object-fit: cover; box-shadow: var(--shadow); }
  @media (min-width: 52rem) {
    .hero .container, .hero.container { grid-template-columns: 1.1fr 0.9fr; }
  }

  /* Button row: keep the button and the adjacent link apart */
  .hero p:has(> .button) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-5);
  }

  /* Illustration figure: fill the column up to a comfortable width, centred */
  .container > figure { margin-block: var(--space-5); }
  .container > figure svg { width: 100%; max-width: 44rem; margin-inline: auto; }

  /* Space between a step list and the link that follows it */
  .steps + p { margin-block-start: var(--space-5); }

  .eyebrow {
    margin: 0 0 var(--space-3);
    color: var(--accent);
    font-size: var(--step--1);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* Availability notice, deliberately not a button */
  .notice {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-block: var(--space-4);
    padding: 0.5rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    font-size: var(--step--1);
    font-weight: 550;
  }
  .notice::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--accent);
    flex: none;
  }

  /* Numbered flow */
  .steps {
    display: grid;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
  }
  .steps > li {
    position: relative;
    counter-increment: step;
    padding: var(--space-4) var(--space-4) var(--space-4) 3.5rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .steps > li::before {
    content: counter(step);
    position: absolute;
    inset-block-start: var(--space-4);
    inset-inline-start: var(--space-4);
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--step--1);
    font-weight: 700;
  }
  .steps h3 { margin-bottom: var(--space-1); }
  .steps p:last-child { margin-bottom: 0; }
  @media (min-width: 52rem) {
    .steps { grid-template-columns: repeat(3, 1fr); }
  }

  /* Cards respond to their container's width.
     Markup contract: <div class="cards-wrap"><ul class="cards">...</ul></div>
     .cards-wrap is the query container; .cards (the grid) must sit inside it,
     because a container query cannot style the container element itself. */
  .cards-wrap {
    container: cards / inline-size;
  }
  .cards {
    display: grid;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  @container cards (min-width: 38rem) {
    .cards { grid-template-columns: repeat(3, 1fr); }
  }
  .card {
    padding: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    transition: border-color 0.15s ease;
  }
  .card:hover { border-color: var(--accent); }
  .card h3 { margin-bottom: var(--space-2); }
  .card p:last-child { margin-bottom: 0; }
  .card p { color: var(--muted); }

  /* Scope: what is and is not supported */
  .scope {
    padding: var(--space-5);
    background: var(--bg);
    border: 1px solid var(--line);
    border-inline-start: 4px solid var(--accent);
    border-radius: var(--radius);
  }
  .scope h2, .scope h3 { font-size: var(--step-2); }
  .scope ul { padding-inline-start: 1.2em; }
  .scope li + li { margin-block-start: var(--space-2); }
  .scope dl { display: grid; gap: var(--space-2) var(--space-4); }
  @media (min-width: 40rem) {
    .scope dl { grid-template-columns: max-content 1fr; }
  }
  .scope dt { font-weight: 650; }
  .scope dd { margin: 0; color: var(--muted); }

  /* Full-bleed tinted band, e.g. support call-out */
  .band {
    padding-block: var(--space-6);
    background: var(--surface);
    border-block: 1px solid var(--line);
  }
  .band .container > * { max-width: 52rem; }
  .band p { color: var(--muted); }

  /* Buttons and link buttons */
  .button {
    display: inline-block;
    padding: 0.65rem 1.2rem;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.15s ease;
  }
  .button:hover { opacity: 0.9; }

  /* Long-form reading */
  .prose { max-width: var(--measure); }
  .prose > * + h2 { margin-block-start: var(--space-6); }
  .prose > * + h3 { margin-block-start: var(--space-5); }
  .prose h2 { font-size: var(--step-2); }
  .prose h3 { font-size: var(--step-1); }
  .prose ul, .prose ol { padding-inline-start: 1.4em; }
  .prose li + li { margin-block-start: var(--space-1); }
  .prose table {
    width: 100%;
    border-collapse: collapse;
    margin-block-end: var(--space-4);
    font-size: var(--step--1);
  }
  .prose th, .prose td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--line);
    text-align: start;
    vertical-align: top;
  }
  .prose th { color: var(--muted); font-weight: 650; }
  .prose pre {
    overflow-x: auto;
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .prose pre code { background: none; border: 0; padding: 0; }

  /* Troubleshooting disclosures (not the TOC) */
  details:not(.toc) { border-block-end: 1px solid var(--line); padding-block: var(--space-3); }
  details:not(.toc):first-of-type { border-block-start: 1px solid var(--line); }
  details:not(.toc) > summary { cursor: pointer; font-weight: 600; }
  details:not(.toc) > :not(summary) { margin: var(--space-3) 0 0 var(--space-4); color: var(--muted); }
  details:not(.toc) > p:last-child { margin-bottom: 0; }

  .callout {
    margin-block: var(--space-4);
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-inline-start: 4px solid var(--accent);
    border-radius: var(--radius);
  }
  .callout > :last-child { margin-bottom: 0; }

  /* Table of contents: a <details>; collapsed on narrow, pinned on wide */
  .toc {
    margin-block-end: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: var(--step--1);
  }
  .toc > summary {
    padding: var(--space-3) var(--space-4);
    font-weight: 650;
    cursor: pointer;
    list-style-position: inside;
  }
  .toc ul, .toc ol {
    margin: 0;
    padding: 0 var(--space-4) var(--space-3) calc(var(--space-4) + 1em);
  }
  .toc li { margin-block: var(--space-1); }
  .toc a { color: var(--muted); text-decoration: none; }
  .toc a:hover { color: var(--accent); text-decoration: underline; }
}

/* ---------- pages ---------- */
@layer pages {
  .page-head { padding-block: var(--space-6) var(--space-4); }
  .page-head p { color: var(--muted); max-width: var(--measure); font-size: var(--step-1); }

  /* Wide: sidebar TOC beside the prose */
  @media (min-width: 64rem) {
    .container:has(> .toc) {
      display: grid;
      grid-template-columns: 15rem minmax(0, 1fr);
      column-gap: var(--space-7);
      row-gap: 0;
      align-items: start;
    }
    .container:has(> .toc) > * { grid-column: 2; }
    .container:has(> .toc) > .toc {
      grid-column: 1;
      grid-row: 1 / span 40;
      position: sticky;
      inset-block-start: 5rem;
      margin: var(--space-4) 0 0;
      max-height: calc(100vh - 6.5rem);
      overflow-y: auto;
    }
    /* Show the list even when the details element is closed (where supported);
       elsewhere the TOC stays a working collapsible. */
    @supports selector(::details-content) {
      .toc > summary { pointer-events: none; cursor: default; list-style: none; }
      .toc > summary::-webkit-details-marker { display: none; }
      .toc::details-content {
        content-visibility: visible;
        display: block;
      }
    }
  }
}
