/* Global stylesheet, loaded on every page on top of tokens.css. The
   workspace adds workspace.css over this. Components are addressed by
   semantic element plus a small set of intent classes; there are no
   utility classes.

   Principles:
   — Every dimension draws from the spacing scale (--space-N) or the
     type scale (--step-N). No off-grid magic numbers.
   — Gap-based containers (flex/grid with `gap`) zero their children's
     margins; margin-based containers rely on margins alone. Never mix.
   — One accent colour, used for emphasis and brand only. State colours
     are independent. */

/* ---------- reset & base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
  font-size: var(--step-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  max-width: var(--measure);
  margin-inline: auto;
  padding: var(--space-8) var(--space-6);
}

main > section { margin-bottom: var(--space-8); }
main > section:last-child { margin-bottom: 0; }

h1, h2, h3, h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.014em;
  line-height: 1.15;
  margin: 0 0 var(--space-4);
  color: var(--fg);
}
h1 { font-size: var(--step-4); letter-spacing: -0.022em; }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h4 { font-size: var(--step-0); }

/* Hero display size — the largest type in the system, used only on the
   landing page. Letter-spacing tightens further at this scale. */
.display {
  font-size: var(--step-5);
  letter-spacing: -0.03em;
  line-height: 1.02;
  font-weight: 600;
}

/* Eyebrow: small mono label above a heading. Carries its own margin so
   it works in margin-based containers; gap-based containers zero it
   via their child rules. */
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--accent);
  letter-spacing: 0.04em;
  margin: 0 0 var(--space-2);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.eyebrow::before {
  content: "";
  width: var(--space-6);
  height: var(--hairline);
  background: var(--accent-2);
  display: inline-block;
}

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

.lead {
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--fg-muted);
}

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

hr { border: 0; border-top: var(--hairline) solid var(--border); margin: var(--space-6) 0; }

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.875em;
  overflow-wrap: anywhere;
}
/* Inside <pre>, code inherits the container's size — the 0.875em
   shrink is for inline code in prose only. */
pre code { font-size: inherit; }

strong { font-weight: 600; }

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

.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.mono { font-family: var(--font-mono); }

/* A secondary explanatory note under a control or section — one consistent
   treatment wherever it appears (the state hint, the usage note, the share
   note). The space-4 top margin wins the margin-collapse against whatever
   precedes it, so the gap above a hint is uniform. */
.hint {
  color: var(--fg-muted);
  font-size: var(--step--1);
  line-height: 1.5;
  margin: var(--space-4) 0 0;
}

/* ---------- site header ---------- */

header.site {
  max-width: var(--measure);
  margin-inline: auto;
  padding: var(--space-5) var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}

.wordmark {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--step-0);
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.wordmark:hover { text-decoration: none; color: var(--fg); }
.wordmark::before {
  content: "▍";
  color: var(--accent-2);
  font-weight: 400;
}

header.site nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: var(--step--1);
}
header.site nav a { color: var(--fg-muted); text-decoration: none; }
header.site nav a:hover { color: var(--fg); text-decoration: none; }

/* ---------- buttons ---------- */

button,
.button {
  font: inherit;
  font-size: var(--step-0);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: var(--hairline) solid var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--transition-fast),
              color var(--transition-fast),
              border-color var(--transition-fast);
}
button:hover,
.button:hover {
  background: var(--fg);
  color: var(--bg);
  text-decoration: none;
  border-color: var(--fg);
}
button:disabled,
.button[aria-disabled="true"] {
  border-color: var(--border);
  color: var(--fg-subtle);
  background: transparent;
  cursor: default;
}

/* Primary: filled with the accent — the one emphasised action on a page. */
.button--primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.button--primary:hover {
  background: var(--accent-hover);
  color: var(--accent-fg);
  border-color: var(--accent-hover);
}

/* Large: for hero CTAs. */
.button--lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--step-0);
}

/* Destructive: stays quiet until hovered, then reads as danger. */
.button--danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* A row of sibling actions (e.g. retry / delete). */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}
.actions:last-child { margin-bottom: 0; }
/* Any wrapping <form> in an action row is a layout pass-through, not a spaced
   block: its default bottom margin would offset the centred row (only the last
   form's margin is reset, so a leading form sits higher than its siblings).
   Zero it so the row's own gap is the single source of spacing. */
.actions form,
.notebook__actions form { margin: 0; }

/* ---------- forms ---------- */

/* Forms get the same default bottom margin as paragraphs so they flow in
   margin-based containers. Flex rows reset it where it would mis-centre a
   wrapping form (see .actions above); the .inline-form pass-through
   (display: contents) drops the form box entirely. */
form { margin: 0 0 var(--space-4); }
form:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: var(--step--1);
  font-family: var(--font-mono);
  color: var(--fg-muted);
  margin-bottom: var(--space-2);
}

input[type="text"],
input[type="email"] {
  font: inherit;
  padding: var(--space-3) var(--space-4);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: inherit;
  width: 100%;
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}
input[type="text"]:focus,
input[type="email"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

.field { margin-bottom: var(--space-4); }

/* ---------- card ---------- */

.card {
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  background: var(--bg);
  box-shadow: var(--shadow);
}

/* Card with a left accent rail — for emphasised content. */
.card--accent {
  border-left: 3px solid var(--accent-2);
}

/* A subsection heading inside a card (e.g. "Share") gets clear air above
   so each block reads as its own section — matching the 32px rhythm the
   section-head sets above it. Never the first child in our cards, but the
   guard keeps it honest. */
.card h3 { margin-top: var(--space-6); }
.card h3:first-child { margin-top: 0; }

/* ---------- copyable value ---------- */

.copyable {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.copyable:last-child { margin-bottom: 0; }
.copyable code {
  flex: 1 1 0;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  white-space: nowrap;
  overflow-wrap: normal;
  overflow-x: auto;
}
.copy {
  font-family: var(--font-mono);
  padding: var(--space-2) var(--space-3);
}
.copy[data-copied="true"] { color: var(--success); border-color: var(--success); }

/* ---------- notice / banner ---------- */

.notice {
  border: var(--hairline) solid var(--border);
  border-left-width: 3px;
  border-left-color: var(--fg);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4);
}
.notice:last-child { margin-bottom: 0; }
.notice--error { border-left-color: var(--danger); background: var(--danger-bg); }

/* A POST rendered as a single inline button: the wrapping <form> shouldn't add
   a box or break the surrounding flex row (e.g. .actions, the workspace bar). */
.inline-form { display: contents; }

/* ---------- spinner & status page ---------- */

.spinner {
  width: var(--size-spinner);
  height: var(--size-spinner);
  border: 2px solid var(--border);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@media (prefers-reduced-motion: reduce) {
  /* Stop the spin entirely; a dimmed ring still reads as "working". */
  .spinner { animation: none; opacity: 0.5; }
  /* And don't animate the usage bar's width. */
  .usage-fill { transition: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.status {
  min-height: 60vh;
  display: grid;
  place-items: center;
  text-align: center;
}
/* Gap-based container — zero children's margins so gap is the only
   vertical spacing. */
.status-card {
  max-width: 44ch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.status-card > * { margin: 0; }
/* The eyebrow's leading accent rule is a left-aligned flourish; in this centred
   card it shifts the label right of the heading. Drop it so the label centres
   cleanly with everything else. */
.status-card .eyebrow::before { display: none; }
.status-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--fg-muted);
}

/* ---------- lists in prose ---------- */

main ul { padding-left: var(--space-4); margin: 0 0 var(--space-4); }
main li { margin-bottom: var(--space-2); }

/* ---------- hero ---------- */

/* Margin-based container — the hero uses explicit margins, not gap, so
   it can mix the display heading with a lead and CTA row that each
   need their own rhythm. No top padding: main's top padding is the
   only air above the headline, so the page opens flush under the nav. */
.hero {
  padding: 0 0 var(--space-7);
  border-bottom: var(--hairline) solid var(--border);
}
/* The hero carries its own bottom padding and a border — the default
   section margin would pile on top. */
main > section.hero { margin-bottom: 0; }
.hero .eyebrow { margin-bottom: var(--space-3); }
.hero h1 { margin-bottom: var(--space-5); }
.hero .lead { margin-bottom: var(--space-6); }

/* ---------- dashboard page header ---------- */

/* The dashboard's page-header rhymes with the hero: the same posture, no
   top padding of its own (main's top padding carries the air above the
   headline). The h1 stays at step-4 (not the hero's display size) — an app
   page shouldn't shout as loud as the landing page. No closing hairline —
   the notebook card below already provides a visual boundary, so a rule
   here would just be clutter. */
.dash-head {
  padding: 0 0 var(--space-7);
}
main > section.dash-head { margin-bottom: var(--space-8); }
.dash-head .eyebrow { margin-bottom: var(--space-3); }
.dash-head h1 { margin-bottom: var(--space-5); }
.dash-head .dash-meta { margin-bottom: 0; }

/* ---------- feature grid ---------- */

.features {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}
/* Gap-based container — zero children's margins. */
.feature {
  padding: var(--space-5);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.feature > * { margin: 0; }
.feature-icon {
  width: var(--size-icon-lg);
  height: var(--size-icon-lg);
  color: var(--accent);
}
.feature-icon svg { width: 100%; height: 100%; }
.feature h3 { font-size: var(--step-1); }
.feature p { color: var(--fg-muted); font-size: var(--step--1); line-height: 1.5; }

/* ---------- FAQ ---------- */

/* Permanently-open Q&A rows, hairline-divided. The same width as the rest
   of the page — no narrower measure — so the questions line up with the
   sections above and below. Margin-based: each row carries its own border. */
.faq { border-top: var(--hairline) solid var(--border); }
.faq-item {
  border-bottom: var(--hairline) solid var(--border);
  padding: var(--space-5) 0;
}
.faq-question {
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: -0.014em;
  margin: 0 0 var(--space-3);
  color: var(--fg);
}
.faq-answer p { color: var(--fg-muted); }

/* ---------- notebook preview ---------- */

/* A framed screenshot of a fresh notebook. The image already carries its
   own header bar, so the frame is just a hairline border around it. */
.preview {
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.preview-img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- CTA band ---------- */

/* Gap-based container — zero children's margins. */
.cta {
  padding: var(--space-8) var(--space-6);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.cta > * { margin: 0; }
.cta p { color: var(--fg-muted); }

/* ---------- section heading ---------- */

/* Margin-based container — the head flows into the section body, so
   margins (not gap) connect the pieces. */
.section-head { margin-bottom: var(--space-6); }
.section-head .eyebrow { margin-bottom: var(--space-2); }
.section-head h2 { margin: 0 0 var(--space-2); }
.section-head p { margin: 0; color: var(--fg-muted); }

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

footer.site {
  max-width: var(--measure);
  margin-inline: auto;
  padding: var(--space-7) var(--space-6) var(--space-6);
  border-top: var(--hairline) solid var(--border);
  margin-top: var(--space-8);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  font-size: var(--step--1);
  color: var(--fg-muted);
}
footer.site nav { display: flex; gap: var(--space-4); }
footer.site nav a { color: var(--fg-muted); text-decoration: none; }
footer.site nav a:hover { color: var(--fg); }

/* ---------- login (Hanko web component) ---------- */

hanko-auth {
  display: block;
  max-width: 22rem;
  --color: var(--fg);
  --color-shade-1: var(--fg-muted);
  --color-shade-2: var(--border);
  --brand-color: var(--accent);
  --brand-color-shade-1: var(--accent-hover);
  --background-color: var(--bg);
  --border-color: var(--border);
  --border-radius: var(--radius);
  --border-style: solid;
  --border-width: var(--hairline);
  --font-family: var(--font-sans);
  --input-background-color: var(--bg);
  --link-color: var(--accent);
}

/* ---------- usage meter ---------- */

.usage-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  margin-bottom: var(--space-3);
}
.usage-figure { color: var(--fg); }
.usage-pct { color: var(--fg-muted); }
.usage-track {
  height: var(--space-2);
  background: var(--bg-sunken);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  background: var(--accent-2);
  transition: width var(--transition-slow);
}
/* ---------- dashboard ---------- */

/* Identity line under the title: mono, muted, with the email picked out. */
.dash-meta {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--fg-muted);
  margin: 0 0 var(--space-6);
}
.dash-meta .mono { color: var(--fg); }

/* State readout: a square swatch (zero-radius, like everything here) plus a
   mono label, coloured by state. */
.nb-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  white-space: nowrap;
}
.nb-status::before {
  content: "";
  width: var(--space-2);
  height: var(--space-2);
  background: var(--fg-subtle);
}
.nb-status--ready::before        { background: var(--success); }
.nb-status--provisioning::before { background: var(--accent); }
.nb-status--failed::before       { background: var(--danger); }
.nb-status--suspended::before    { background: var(--fg-subtle); }

/* The notebook panel reads top-to-bottom: a state + actions bar, then labelled
   sections (usage, share), then a quiet danger footer. */
.notebook__bar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.notebook__actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }

/* Each section inside a notebook card reuses the homepage's section-head
   rhythm — eyebrow + h2 at the same step as a page section, so the blocks
   read as real sections rather than quiet labels. A subsection (Usage, Share,
   Danger zone) opens with air above it, matching the 48px rhythm the page
   sections set above them. The action bar is exempt: it's the card's header,
   not a labelled section, so it sits tight against the card's top padding. */
.notebook__section { margin-top: var(--space-7); }
.notebook__section:first-child { margin-top: 0; }
/* A section-head inside a notebook card tightens its bottom margin so the
   body follows quickly — the card is a denser surface than a page section. */
.notebook__section .section-head { margin-bottom: var(--space-4); }
.notebook__section .section-head h2 { margin: 0; }

/* The status hint under the action bar — quieter than a labelled section: a
   one-line read that bridges the bar and the first section below. Tightens its
   top margin so it clusters with the bar (space-2) rather than opening a new
   section's worth of air (the default space-4). */
.notebook__state-hint { margin-top: var(--space-2); }

.notebook__danger {
  padding-top: var(--space-5);
  border-top: var(--hairline) solid var(--border);
}

/* ---------- raw source view ---------- */

pre.source {
  margin: var(--space-5) 0 0;
  padding: var(--space-5);
  background: var(--bg-sunken);
  border: var(--hairline) solid var(--border);
  font-size: var(--step--1);
  line-height: 1.6;
  max-height: 70vh;
  overflow: auto;
  white-space: pre;
  -moz-tab-size: 2;
  tab-size: 2;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  header.site { padding: var(--space-4) var(--space-4); }
  /* main's top padding stacks with the page header's, so trim it here too —
     otherwise the two together open a wide gap below the nav on small screens. */
  main { padding: var(--space-4) var(--space-4) var(--space-7); }
  footer.site { padding: var(--space-6) var(--space-4) var(--space-5); }
  /* The site header already sits a step below the nav; on small screens the
     page header's full top air is just dead space, so drop the top padding
     here too — main's trimmed top padding is all the air above the headline. */
  .hero { padding: 0 0 var(--space-6); }
  .dash-head { padding: 0 0 var(--space-6); }
  .cta { padding: var(--space-7) var(--space-4); }
  .card { padding: var(--space-5); }
}
