*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.6 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--s3); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
p { margin: 0 0 var(--s4); }
a { color: var(--accent); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
main:focus, h1:focus { outline: none; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--s3); top: -4rem; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: var(--s2) var(--s4); border-radius: var(--radius-sm);
}
.skip-link:focus { top: var(--s2); }
.muted { color: var(--text-muted); }
.lead { font-size: 1.1rem; }

.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- Shell layout ---- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  min-height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--s4), env(safe-area-inset-right)) 0 max(var(--s4), env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 700; color: var(--text); text-decoration: none; min-height: 48px; }

.app-nav {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.app-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 48px; font-size: .75rem; color: var(--text-muted); text-decoration: none;
}
.app-nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.app-main {
  max-width: 60rem; margin: 0 auto;
  padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s5)) max(var(--s4), env(safe-area-inset-left));
}

@media (min-width: 900px) {
  body { padding-left: var(--rail-w); }
  .app-nav {
    top: calc(var(--header-h) + env(safe-area-inset-top)); bottom: 0; right: auto;
    width: var(--rail-w); height: auto; flex-direction: column; justify-content: flex-start;
    padding: var(--s2) 0; border-top: 0; border-right: 1px solid var(--border);
  }
  .app-nav a { flex: none; width: 100%; padding: var(--s3) 0; }
  .app-header { margin-left: calc(var(--rail-w) * -1); padding-left: calc(var(--rail-w) + var(--s4)); }
  .app-main { padding-bottom: var(--s6); }
}

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