/* ------------------------------------------------------------------ */
/*  Design system                                          */
/* ------------------------------------------------------------------ */
/*                                                                     */
/*  This stylesheet is the project's single source of truth for the    */
/*  visual system. Every rule below should resolve through a          */
/*  `--token` declared in `:root`; raw hex / raw px outside the token */
/*  block is a code-review smell.                                      */
/*                                                                     */
/*  Token summary                                                      */
/*  ------------                                                       */
/*    * Colour      --fg / --fg-muted / --bg / --card / --border /     */
/*                    --accent / --accent-fg / --danger / --danger-bg / */
/*                    --success / --success-bg / --warning / --warning-bg */
/*                    / --code-bg / --brand                            */
/*    * Type scale  --text-xs ... --text-4xl (1.25 major-third)        */
/*    * Leading     --leading-tight / --leading-normal                 */
/*    * Spacing     --space-1 ... --space-8 (8 px base)                */
/*    * Radius      --radius-sm / --radius / --radius-lg               */
/*    * Elevation   --shadow-sm                                       */
/*    * Focus       --focus-ring                                       */
/*    * Layout      --container (max-width of the prose column)        */
/*                                                                     */
/*  Component class names are kept identical to the contract the views */
/*  and the existing test suite already pin ( /) */
/*  so the redesign never causes a test breakage:                      */
/*                                                                     */
/*    .skip-link                                                        */
/*    header.site / footer.site / a.brand / .who / nav                 */
/*    .card / .muted                                                    */
/*    .btn / .btn.secondary / .btn.danger                              */
/*    .alert.error / .alert.success / .alert.warning                   */
/*    .empty-state / .copy-btn / .secret-block                         */
/*    .announcement-toc                                                  */
/*    .policy-body                                                       */
/*    table / th / td                                                   */
/*    code / pre                                                        */
/*    details / summary                                                 */
/*                                                                     */
/*  The home page (`/`) gets three new component classes:               */
/*                                                                     */
/*    .hero        — a 2-column intro section                           */
/*    .product-shot — the `<figure>` wrapping the hero image            */
/*    .code-sample  — the `<pre>` holding a real PKCE request sample    */
/*    .steps       — the existing "How it works" numbered list         */
/*                                                                     */
/* ------------------------------------------------------------------ */

:root {
  /* The browser should respect a colour-scheme hint so form controls,
     scrollbars, and the address bar tint correctly on first paint
     before the stylesheet has loaded. */
  color-scheme: light dark;

  /* ---------- palette ----------
     The same slate/emerald palette the public template uses
     (`apps/site`), so moving between `/` and the member pages does not
     feel like leaving the site. The stylesheet stays token-driven; a
     redesign changes these values and nothing else. */
  --fg:        #f1f5f9;
  --fg-muted:  #94a3b8;
  --bg:        #020617;
  --card:      #0f172a;
  --border:    #1e293b;
  --accent:    #10b981;
  --accent-fg: #022c22;
  --danger:    #fca5a5;
  --danger-bg: #450a0a;
  --success:   #6ee7b7;
  --success-bg:#052e16;
  --warning:   #fcd34d;
  --warning-bg:#451a03;
  --code-bg:   #0b1220;

  /* `--brand` mirrors `--accent` and is used for the hero gradient and
     the brand mark in the chrome. Keeping a separate name means we can
     shift the brand hue without breaking every state colour at once. */
  --brand:     var(--accent);

  /* AA focus ring: 3:1 against both light and dark bg; reads clearly
     without being noisy. Tied into a token so a future redesign can
     swap to a yellow ring without touching every component. */
  --focus-ring:#34d399;

  /* ---------- type scale (1.25 ratio, anchored on 16 px / 1 rem) ---- */
  --text-xs:   0.78rem;   /* ~12.5 px */
  --text-sm:   0.875rem;  /* 14 px */
  --text-base: 1rem;      /* 16 px */
  --text-md:   1.125rem;  /* 18 px */
  --text-lg:   1.25rem;   /* 20 px */
  --text-xl:   1.563rem;  /* 25 px */
  --text-2xl:  1.953rem;  /* ~31 px */
  --text-3xl:  2.441rem;  /* ~39 px */
  --text-4xl:  3.052rem;  /* ~49 px */

  /* ---------- leading ---------- */
  --leading-tight: 1.2;
  --leading-normal:1.5;

  /* ---------- spacing scale (8 px base) ---------- */
  --space-1:  0.25rem;   /*  4 px */
  --space-2:  0.5rem;    /*  8 px */
  --space-3:  0.75rem;   /* 12 px */
  --space-4:  1rem;      /* 16 px */
  --space-5:  1.5rem;    /* 24 px */
  --space-6:  2rem;      /* 32 px */
  --space-7:  3rem;      /* 48 px */
  --space-8:  4rem;      /* 64 px */

  /* ---------- radius ---------- */
  --radius-sm: 0.25rem;
  --radius:    0.5rem;
  --radius-lg: 0.75rem;

  /* ---------- elevation ---------- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);

  /* ---------- layout ---------- */
  --container: 64rem;
}

/* Dark scheme override. Only token reassignments live here; the rest
   of the stylesheet is dark-mode aware through the tokens. The accent
   hue is shifted lighter so the 4.5:1 contrast on `--bg` still holds
   (the light `--accent` would fail against `#161616`). */
@media (prefers-color-scheme: dark) {
  :root {
    /* The palette is already the dark one; the media query keeps
       `color-scheme` honest for form controls without repainting the
       site in a second scheme. */
    --card:      #0b1220;
  }
}

/* ---------- reset / baseline ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

html {
  /* Smoother word wrapping on narrow viewports. */
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  min-height: 100vh;
  /* Hint that long words should break rather than overflow the column
     (URLs, OIDC client IDs, registration emails). The skip-link test
     reads CSS off disk and asserts on the `.skip-link` rule shape; this
     global word-break doesn't conflict with that contract. */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* The shell is a flex column so the footer can be anchored at the
   bottom of even a short page without `position: fixed`. The <main>
   grows to fill the column; the footer keeps its content-sized height. */
body {
  display: flex;
  flex-direction: column;
}
main { flex: 1 0 auto; }

/* ---------- type rhythm ---------- */
h1, h2, h3 { line-height: var(--leading-tight); margin: 0 0 var(--space-4); }
h1 { font-size: var(--text-2xl); font-weight: 700; }
h2 { font-size: var(--text-lg);  font-weight: 700; margin-top: var(--space-6); }
h3 { font-size: var(--text-md);  font-weight: 700; margin-top: var(--space-5); }
p  { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 0 0 var(--space-4); padding-left: var(--space-5); }
li { margin: var(--space-1) 0; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
a:hover { text-decoration: none; }

/* Keyboard "skip to content" link. Visually hidden by
   default so it does not take layout space, but still in the tab
   order — `display:none` / `visibility:hidden` would remove it from tab
   order, which defeats the point. On focus the link is pulled back
   on-screen at the top-left so a keyboard user sees where they jumped.
   The target is `#main-content` on <main> in views/layout.tsx, and the
   test in `test/skip-link.test.ts` asserts on the shape of this rule. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.skip-link:focus {
  left: var(--space-2);
  top: var(--space-2);
  width: auto;
  height: auto;
  overflow: visible;
  padding: var(--space-2) var(--space-3);
  background: var(--card);
  color: var(--fg);
  border: var(--space-1) solid var(--focus-ring);
  border-radius: var(--radius-sm);
  z-index: 100;
}

/* Visible focus ring for every keyboard-reachable element. The visual
   is intentionally a 2 px solid offset outline so it never depends on
   the element's background colour and so the focus state is obvious
   against both light and dark schemes. The default focus rectangle is
   suppressed because browsers draw a separate ring on top of any
   customised one. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- header / footer / nav ---------- */
header.site {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-wrap: wrap;
}
header.site a.brand {
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
  font-size: var(--text-md);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
header.site a.brand .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--accent-fg);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
}
header.site nav {
  display: flex;
  gap: var(--space-4);
  flex: 1;
  flex-wrap: wrap;
}
header.site nav a {
  color: var(--fg-muted);
  text-decoration: none;
}
header.site nav a:hover,
header.site nav a:focus-visible {
  color: var(--fg);
}
header.site .who {
  color: var(--fg-muted);
  font-size: var(--text-sm);
  text-align: right;
}
header.site .who form { display: inline; margin-left: var(--space-2); }

main {
  max-width: var(--container);
  margin: var(--space-6) auto;
  padding: 0 var(--space-5);
  width: 100%;
}

footer.site {
  border-top: 1px solid var(--border);
  background: var(--card);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  padding: var(--space-5);
  text-align: center;
  flex-shrink: 0;
}
footer.site nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: center;
  margin-bottom: var(--space-3);
}
footer.site a {
  color: var(--fg-muted);
  text-decoration: none;
}
footer.site a:hover,
footer.site a:focus-visible { color: var(--fg); text-decoration: underline; }

/* ---------- components ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.muted {
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

label {
  display: block;
  margin: var(--space-3) 0 var(--space-1);
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="url"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
textarea {
  min-height: 4.5rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

.btn {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  line-height: var(--leading-tight);
}
.btn:hover { filter: brightness(0.95); }
.btn.secondary {
  background: var(--card);
  color: var(--fg);
  border-color: var(--border);
}
.btn.secondary:hover { background: var(--code-bg); }
.btn.danger {
  background: var(--danger);
  color: var(--accent-fg);
  border-color: var(--danger);
}

.alert {
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-3) 0;
  border: 1px solid transparent;
}
.alert.error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}
.alert.success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}
.alert.warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning);
}

table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}
th, td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--fg-muted);
  font-weight: 600;
  font-size: var(--text-sm);
}

code {
  background: var(--code-bg);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.9em;
}
pre {
  background: var(--code-bg);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  margin: 0 0 var(--space-4);
}
pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.row .grow { flex: 1; }

details { margin-top: var(--space-2); }
summary {
  cursor: pointer;
  color: var(--fg-muted);
}

/* Privacy-policy body. Rendered as a <pre> so line
   breaks in the admin-authored body survive as written; the lack of
   border/background keeps the policy card visually consistent with
   the rest of the page (CSS `pre` defaults are inherited from the
   site stylesheet — explicit overrides here ensure the visitor
   sees the plain body without a code block background). */
.policy-body {
  background: transparent;
  border: 0;
  border-radius: 0;
  font-family: inherit;
  font-size: inherit;
  margin: var(--space-2) 0 var(--space-4);
  padding: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.empty-state {
  text-align: center;
  color: var(--fg-muted);
  padding: var(--space-7) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.copy-btn {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  margin-left: var(--space-2);
}
.copy-btn:hover { background: var(--code-bg); }

.secret-block {
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-family: ui-monospace, SFMono-Regular, monospace;
  word-break: break-all;
  font-size: var(--text-sm);
  border: 1px solid var(--warning);
}

/* Announcement TOC: a small boxed list of anchor
   links to the body's headings. Sits between the page title and
   the body inside the announcement card; not on the index / home
   card. The print test scans the @media print block below, so
   this screen rule sits above it and does not interfere with
   the print scan. */
.announcement-toc {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  padding: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-4);
}
.announcement-toc h2 {
  font-size: var(--text-base);
  margin: 0 0 var(--space-2);
  color: var(--fg-muted);
}
.announcement-toc ol {
  margin: 0;
  padding-left: var(--space-5);
}
.announcement-toc li {
  margin: var(--space-1) 0;
}

/* ------------------------------------------------------------------ */
/*  Home-page composition                                  */
/* ------------------------------------------------------------------ */
/*                                                                     */
/*  The home page composes four new component classes into the same     */
/*  shell the rest of the site uses. The classes are kept DOM-local:   */
/*  the same `.card` / `.btn` rules cover a generic card and the       */
/*  `.hero` / `.product-shot` / `.code-sample` / `.steps` rules only   */
/*  shape the home page.                                               */
/* ------------------------------------------------------------------ */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-7);
  align-items: center;
  padding: var(--space-7) 0 var(--space-6);
}
.hero h1 {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-4);
}
.hero p {
  font-size: var(--text-md);
  color: var(--fg-muted);
  max-width: 36rem;
}
.hero-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-5);
}
.hero-actions .btn { font-size: var(--text-md); padding: var(--space-3) var(--space-5); }

.product-shot {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
.product-shot img {
  display: block;
  width: 100%;
  height: auto;
}
.product-shot figcaption {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* The "How it works" ordered list — the existing `<ol>` inside the
   `<div class="card steps">` gets a thin left bar and a numbered marker
   so it reads as a process, not a generic bullet list. The label
   ("How it works") remains the card's `<h2>`. */
.steps {
  padding-left: var(--space-5);
}
.steps > li {
  padding-left: var(--space-2);
  margin: var(--space-3) 0;
}
.steps > li::marker {
  color: var(--accent);
  font-weight: 700;
}

/* The "real code sample" block on the home page — sits inside a `.card`
   so the surrounding card padding governs spacing. The label paragraph
   above it identifies what's being shown so a visitor doesn't have to
   guess; the `<pre>` underneath uses the same `pre` rules as every
   other page so the visual treatment is consistent. */
.code-sample-wrap {
  margin-top: var(--space-4);
}
.code-sample-wrap .code-label {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.code-sample {
  margin: 0;
  white-space: pre;
  /* Wide tables and code samples scroll horizontally inside their card
     rather than pushing the page out of the viewport — a common
     360 px overflow trap. */
  max-width: 100%;
  overflow-x: auto;
}

/* ------------------------------------------------------------------ */
/*  Responsive: 360 px up                                  */
/* ------------------------------------------------------------------ */
/*                                                                     */
/*  The site renders correctly from 360 px upward. The hero collapses  */
/*  to a single column, the site header wraps the brand / nav / sign-  */
/*  in on its own lines, and the prose gutters shrink so nothing       */
/*  introduces horizontal scrollbars. Two breakpoints:                 */
/*                                                                     */
/*    * `max-width: 640px`  — tablet/mobile portrait layout            */
/*    * `max-width: 420px`  — narrow phones (the 360 px target)        */
/* ------------------------------------------------------------------ */

@media (max-width: 640px) {
  main {
    margin: var(--space-5) auto;
    padding: 0 var(--space-4);
  }

  .hero {
    grid-template-columns: 1fr;
    gap: var(--space-5);
    padding: var(--space-5) 0;
  }
  .hero h1 { font-size: var(--text-2xl); }

  .card { padding: var(--space-4); }

  header.site {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }
  header.site nav {
    order: 3;
    width: 100%;
    flex-basis: 100%;
  }
  header.site .who {
    margin-left: auto;
  }

  /* Tables get a horizontal scroll wrapper when their columns don't
     fit — the announcement index and the admin tables run wider than
     the viewport at 360 px. */
  table { font-size: var(--text-sm); }

  footer.site { padding: var(--space-4); }
}

@media (max-width: 420px) {
  /* 360 px target: every global margin/gutter should be a multiple of
     --space-2 so the layout is consistent with itself even at the
     narrowest end. */
  :root {
    --space-5: 1.25rem;
    --space-6: 1.5rem;
  }

  body { font-size: var(--text-sm); }
  h1 { font-size: var(--text-xl); }
  h2 { font-size: var(--text-md); }

  main { padding: 0 var(--space-3); }
  .card { padding: var(--space-4); }
  .hero h1 { font-size: var(--text-xl); }
  .hero p { font-size: var(--text-base); }

  .btn { width: 100%; text-align: center; }
  .hero-actions .btn { width: auto; }

  /* On the narrowest phones the figure caption wraps to two lines and
     the rounded corners fight the viewport — flatten them so the hero
     still reads as one block. */
  .product-shot { border-radius: var(--radius); }
}

/* ------------------------------------------------------------------ */
/*  Print: announcement print path (, untouched)             */
/* ------------------------------------------------------------------ */

@media print {
  body.announcement-page header.site,
  body.announcement-page footer {
    display: none !important;
  }
  body.announcement-page main {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  body.announcement-page .card {
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
  }
  body.announcement-page .announcement-body {
    overflow: visible;
    white-space: pre-wrap;
  }
  body.announcement-page [data-testid="announcement-detail-back"] {
    display: none;
  }
}
