/* Reset, typography and the application shell. */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -0.02em; }
h2 { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.015em; }
h3 { font-size: var(--fs-md); font-weight: 650; letter-spacing: -0.005em; }
h4 { font-size: var(--fs-base); font-weight: 650; }
p  { margin: 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:disabled { cursor: not-allowed; }

svg { display: block; }
img { max-width: 100%; }

/* One focus treatment everywhere. Never removed, only replaced. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-soft); color: var(--text); }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 650; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hidden { display: none !important; }

.visually-hidden {
  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: absolute; left: var(--s4); top: -100px; z-index: 100;
  padding: var(--s2) var(--s4); border-radius: var(--r-md);
  background: var(--accent); color: var(--accent-fg); font-weight: 650;
  text-decoration: none;
}
.skip-link:focus { top: var(--s4); color: var(--accent-fg); }

/* Layout primitives ------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.stack-lg { display: flex; flex-direction: column; gap: var(--s5); min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; min-width: 0; }
.row-tight { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-width: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.push { margin-left: auto; }

/* Two-column working layout: content plus a summary rail.
   Single column until there is genuinely room for both. */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); align-items: start; }
@media (min-width: 62rem) {
  .split { grid-template-columns: minmax(0, 1fr) 22rem; }
  .split > .rail { position: sticky; top: calc(var(--header-h) + var(--s4)); }
}

.grid-cards { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }

/* Shell ------------------------------------------------------------------- */

.shell { display: flex; flex-direction: column; min-height: 100vh; }

.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s4);
  min-height: var(--header-h);
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
}
@supports not (backdrop-filter: blur(1px)) { .appbar { background: var(--surface); } }

.appbar-inner {
  display: flex; align-items: center; gap: var(--s2);
  width: 100%; max-width: var(--shell-max); margin: 0 auto;
  min-width: 0;
}
@media (min-width: 30rem) { .appbar-inner { gap: var(--s4); } }

.brand {
  display: inline-flex; align-items: center; gap: var(--s2);
  color: var(--text); text-decoration: none; font-weight: 650;
  letter-spacing: -0.01em; white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand-mark {
  display: grid; place-items: center; width: 26px; height: 26px; flex: none;
  border-radius: 7px; background: var(--accent); color: var(--accent-fg);
}
.brand-mark svg { width: 16px; height: 16px; }
.brand-name { font-family: var(--font-display); font-size: var(--fs-md); }
/* On a narrow phone the wordmark, the nav, the theme control and the account
   avatar cannot all fit. The mark alone still identifies and links home, and
   .brand carries the accessible name. */
@media (max-width: 26rem) { .brand-name { display: none; } }

/* Allowed to shrink and scroll inside itself, so the nav can never push the
   account controls off the right edge. */
.mainnav { display: flex; gap: var(--s1); min-width: 0; overflow-x: auto; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
  padding: var(--s2) var(--s3); border-radius: var(--r-md);
  color: var(--text-muted); font-size: var(--fs-sm); font-weight: 600;
  text-decoration: none; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.mainnav a:hover { background: var(--surface-2); color: var(--text); }
.mainnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.main {
  flex: 1 1 auto;
  width: 100%; max-width: var(--shell-max);
  margin: 0 auto;
  padding: var(--s5) var(--s4) var(--s8);
}
.main.narrow { max-width: 44rem; }
.main.reading { max-width: 34rem; }

.footer {
  border-top: 1px solid var(--border);
  padding: var(--s4);
  color: var(--text-faint); font-size: var(--fs-xs);
}
.footer-inner {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4);
  max-width: var(--shell-max); margin: 0 auto;
}

/* Page heading ------------------------------------------------------------ */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); }
.page-title { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.page-title p { color: var(--text-muted); font-size: var(--fs-sm); }
.eyebrow {
  color: var(--text-faint); font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase;
}

/* Boot placeholder, replaced as soon as the router renders. */
.boot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s4); min-height: 60vh; color: var(--text-muted);
}
.boot-mark {
  width: 28px; height: 28px; border-radius: var(--r-full);
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
