/* Base: reset, typography, app shell layout (sidebar / topbar / main / drawer). */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}
body::before { /* faint moonlight on the water */
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 78% -8%, rgba(120, 150, 230, .13), transparent 60%),
    radial-gradient(600px 300px at 8% 108%, rgba(255, 122, 89, .06), transparent 60%);
}
[data-theme="light"] body::before {
  background:
    radial-gradient(900px 420px at 78% -8%, rgba(79, 163, 217, .12), transparent 60%),
    radial-gradient(600px 300px at 8% 108%, rgba(200, 72, 42, .06), transparent 60%);
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--sea); text-underline-offset: 2px; }
a:hover { color: var(--text); }
h1, h2, h3, h4 { margin: 0 0 var(--s-2); line-height: 1.15; font-weight: 400; }
h1, h2 { font-family: var(--font-display); letter-spacing: .005em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); font-weight: 700; }
h4 { font-size: var(--fs-sm); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
p { margin: 0 0 var(--s-3); }
small, .small { font-size: var(--fs-sm); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
::selection { background: var(--accent); color: var(--accent-ink); }

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

.sr-only {
  position: absolute !important; 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(--s-3); top: -60px; z-index: 100;
  background: var(--accent); color: var(--accent-ink); padding: var(--s-2) var(--s-3); border-radius: var(--radius-sm);
}
.skip-link:focus { top: var(--s-3); }

/* ---------------- App shell ---------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.shell.is-bare { grid-template-columns: minmax(0, 1fr); }
.shell.is-bare .sidebar, .shell.is-bare .topbar { display: none; }

.sidebar {
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  border-right: 1px solid var(--line);
  z-index: 40;
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
  text-decoration: none; color: var(--text);
}
.sidebar__brand .wordmark { font-family: var(--font-display); font-size: 1.45rem; line-height: 1; }
.sidebar__brand .wordmark small { display: block; font-family: var(--font-body); font-size: var(--fs-xs); color: var(--text-3); letter-spacing: .12em; text-transform: uppercase; margin-top: 4px; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 0 var(--s-3) var(--s-4); scrollbar-width: thin; }
.nav-section { margin-top: var(--s-3); }
.nav-section__label {
  font-size: 0.6875rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-3); padding: 0 var(--s-3) var(--s-2);
}
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 6px var(--s-3);
  border-radius: var(--radius-sm);
  color: var(--text-2); text-decoration: none;
  font-size: var(--fs-sm); font-weight: 700;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"]::before { /* the pearl marker */
  content: ''; position: absolute; left: -6px; top: 50%; width: 8px; height: 8px; margin-top: -4px;
  border-radius: 50%; background: var(--nacre); box-shadow: 0 0 10px rgba(236, 231, 246, .55);
}
.nav-link .count {
  margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--accent-ink); font-size: var(--fs-xs); text-align: center; line-height: 20px;
}

.sidebar__foot { border-top: 1px solid var(--line); padding: var(--s-3) var(--s-5) var(--s-4); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-2) var(--s-6);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar__title { font-family: var(--font-display); font-size: 1.35rem; white-space: nowrap; margin: 0; }
.icon-btn.topbar__menu { display: none; }
.topbar__ticker { flex: 1; min-width: 0; }
.topbar__tools { display: flex; align-items: center; gap: var(--s-2); }

.view { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-6) var(--s-6) var(--s-12); }
.shell.is-bare .view { max-width: none; padding: 0; }
#view:focus, #view:focus-visible { box-shadow: none; outline: none; }
.view-enter { animation: view-in 260ms var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.drawer-scrim { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(84vw, 300px);
    transform: translateX(-102%); transition: transform 240ms var(--ease);
    background: var(--bg-2); box-shadow: var(--shadow-2);
  }
  .shell.drawer-open .sidebar { transform: none; }
  .shell.drawer-open .drawer-scrim {
    display: block; position: fixed; inset: 0; z-index: 35; background: rgba(2, 5, 12, .55);
  }
  .topbar { padding: var(--s-2) var(--s-4); flex-wrap: wrap; gap: var(--s-2) var(--s-3); }
  .icon-btn.topbar__menu { display: inline-grid; }
  .topbar__title { flex: 1; font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; }
  .topbar__ticker { order: 10; flex-basis: 100%; }
  .view { padding: var(--s-4) var(--s-4) var(--s-10); }
}
@media (max-width: 520px) {
  .topbar .search { display: none; }
  .topbar .search-toggle { display: inline-flex; }
}

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