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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--bar-h) + 16px);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -0.009em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
  overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); color: var(--text); }
h1 { font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -0.022em; }
h2 { font-size: 24px; line-height: 1.17; font-weight: 650; letter-spacing: -0.018em; }
h3 { font-size: 17px; line-height: 1.3; font-weight: 600; letter-spacing: -0.012em; }
h4 { font-size: 13px; line-height: 1.3; font-weight: 600; letter-spacing: 0; color: var(--text-2); }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; letter-spacing: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-s); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed; left: 12px; top: -80px; z-index: 30;
  padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-accent);
}
.skip-link:focus-visible { top: 8px; }

/* ── top bar: frosted, hairline under, never glued content ─────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--bar-h);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--hairline);
}
.topbar__inner {
  max-width: 1280px; height: 100%; margin: 0 auto;
  padding: 0 max(24px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: var(--s-5);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand__mark { width: 24px; height: 24px; }
.brand__mark rect { fill: var(--text); }
.brand__mark path { stroke: var(--bg); stroke-width: 1.8; stroke-linecap: round; fill: none; }
.brand__name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.topnav { display: flex; gap: 2px; }
.topnav a {
  padding: 6px 12px; border-radius: var(--r-pill);
  color: var(--text-2); font-size: 13px; font-weight: 500;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.topnav a:hover { color: var(--text); text-decoration: none; background: var(--bg-hover); }
.topnav a[aria-current="page"] { color: var(--text); background: var(--fill-quiet); }

.session { margin-left: auto; display: inline-flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-2); min-width: 0; }
.session__who { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Admin: view the console as another account (js/main.js, js/me.js). */
.viewas { display: inline-flex; align-items: center; gap: 6px; }
.viewas__label { color: var(--text-2); }
.viewas-select {
  font: inherit; font-size: 12px; color: var(--text); background: var(--bg-elevated);
  border: 0; border-radius: var(--r-pill); padding: 4px 10px;
  box-shadow: inset 0 0 0 0.5px var(--hairline-strong); cursor: pointer; max-width: 200px;
}
.viewas-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.viewas-ribbon {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 13px; color: var(--text);
  background: var(--review-soft); box-shadow: inset 0 -0.5px 0 var(--hairline-strong);
}
.viewas-ribbon[hidden] { display: none; }
.viewas-ribbon__back {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--accent); background: none;
  border: 0; padding: 2px 4px; cursor: pointer;
}
.session:not([hidden]) + .env-flag { margin-left: 0; }
.env-flag {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 10px; border-radius: var(--r-pill);
  font-size: 12px; color: var(--text-2);
  box-shadow: inset 0 0 0 0.5px var(--hairline-strong);
  white-space: nowrap;
}
.env-flag strong { color: var(--text); font-weight: 600; }

/* Light / dark toggle (js/theme.js). Sits right of the env flag; shows the
   mode you would switch TO — a sun while dark, a moon while light. */
.theme-toggle {
  margin-left: 10px; display: inline-grid; place-items: center;
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-2); cursor: pointer;
  box-shadow: inset 0 0 0 0.5px var(--hairline-strong);
  transition: color .15s ease, background-color .15s ease;
}
.theme-toggle:hover { color: var(--text); background: var(--bg-sunken); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle__moon { display: none; }
.theme-toggle[data-showing="light"] .theme-toggle__sun { display: none; }
.theme-toggle[data-showing="light"] .theme-toggle__moon { display: block; }
.env-flag__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--review);
  box-shadow: 0 0 0 3px var(--review-soft);
}
/* Production is a different kind of place: an inverted pill, a red rule along
   the top of the page, and the words said in full. With every write switched
   off the dot goes grey; the pill and the rule stay, because it is still
   production. */
.env-flag[data-kind="live"], .env-flag[data-kind="off"] {
  background: var(--prod-ink); color: var(--prod-on-ink); box-shadow: none;
}
.env-flag[data-kind="live"] strong, .env-flag[data-kind="off"] strong {
  color: var(--prod-on-ink); letter-spacing: 0.04em; text-transform: uppercase; font-size: 11px;
}
.env-flag[data-kind="live"] .env-flag__dot { background: var(--prod); box-shadow: 0 0 0 3px var(--prod-soft); }
.env-flag[data-kind="off"] .env-flag__dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--prod-on-ink-2); }
.env-flag[data-kind="unknown"] .env-flag__dot { background: var(--blocked); box-shadow: 0 0 0 3px var(--blocked-soft); }
:root[data-env="live"] .topbar, :root[data-env="off"] .topbar { box-shadow: inset 0 3px 0 var(--prod); }

.mock-ribbon {
  max-width: 1280px; margin: 12px auto 0; padding: 8px 16px;
  border-radius: var(--r-m);
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 13px; font-weight: 500; text-align: center;
  width: calc(100% - 48px);
}

.main {
  max-width: 1280px; margin: 0 auto;
  padding: var(--s-7) 24px var(--s-8);
  min-height: calc(100dvh - var(--bar-h));
}

.noscript { padding: 48px; text-align: center; color: var(--text-2); }

/* entry motion: short, heavy, transform + opacity only */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
.enter { animation: rise 520ms var(--ease-out) both; }
.enter-2 { animation: rise 520ms var(--ease-out) 60ms both; }
.enter-3 { animation: rise 520ms var(--ease-out) 120ms both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important; scroll-behavior: auto !important;
  }
}

@media (max-width: 900px) {
  .env-flag__rest {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  /* Production says the whole sentence on a phone too: a strip under the bar. */
  .env-flag[data-kind="live"] .env-flag__rest, .env-flag[data-kind="off"] .env-flag__rest {
    top: 100%; left: 0; right: 0; width: auto; height: auto; clip: auto; overflow: visible;
    padding: 6px 16px; text-align: center; white-space: normal;
    background: var(--prod-ink); color: var(--prod-on-ink); font-size: 12px; font-weight: 500;
  }
  .env-flag[data-kind="live"] .env-flag__sep, .env-flag[data-kind="off"] .env-flag__sep { display: none; }
  /* the strip hangs under the bar; the bar keeps room for it in the flow */
  :root[data-env="live"] .topbar, :root[data-env="off"] .topbar { margin-bottom: 30px; }
}

@media (max-width: 760px) {
  body { font-size: 15px; }
  h1 { font-size: 28px; }
  h2 { font-size: 21px; }
  .topbar__inner { padding: 0 16px; gap: var(--s-3); }
  .brand__name { display: none; }
  .session__who { display: none; }
  .topnav a { padding: 6px 10px; }
  .main { padding: var(--s-5) 16px var(--s-7); }
  .mock-ribbon { width: calc(100% - 32px); }
}

/* main takes focus on navigation for screen readers; it is not a control */
.main:focus, .main:focus-visible { box-shadow: none; }
