/* Base / reset / app shell */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: 1.15;
  margin: 0;
  letter-spacing: -0.015em;
  font-weight: 700;
}
h1 { font-size: var(--fs-2xl); letter-spacing: -0.025em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); font-weight: 650; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
ul, ol { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; width: 100%; }
::selection { background: var(--scrub-soft); color: var(--ink); }

:focus-visible {
  outline: 2.5px solid var(--scrub);
  outline-offset: 2px;
  border-radius: 6px;
}

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-5) var(--s-4) var(--s-4);
  border-right: 1px solid var(--line);
  background: var(--paper);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px var(--s-2) var(--s-4);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.03em;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--scrub);
  display: grid; place-items: center;
  color: var(--scrub-ink);
  flex: none;
}
.brand-mark svg { width: 22px; height: 22px; }

.nav-create { margin: 0 0 var(--s-3); }

.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--s-3); }
.nav-group-label {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  padding: var(--s-2) var(--s-3) var(--s-1);
  font-weight: 500;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px var(--s-3);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 500;
  font-size: .95rem;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.nav-link svg { width: 19px; height: 19px; stroke-width: 1.9; flex: none; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}
.nav-link[aria-current="page"] svg { color: var(--scrub); }
.nav-link .nav-meta { margin-left: auto; }
.nav-count {
  font-size: var(--fs-xs);
  font-weight: 700;
  min-width: 22px; height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--amber-soft);
  color: var(--amber);
  display: inline-grid; place-items: center;
}
:root[data-theme="dark"] .nav-count { color: var(--amber); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s-2); }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: var(--s-2);
  border-radius: var(--r-md);
  transition: background var(--t-fast);
}
.user-chip:hover { background: var(--surface-2); }
.user-chip .who { line-height: 1.25; min-width: 0; }
.user-chip .who b { display: block; font-size: var(--fs-sm); }
.user-chip .who span { font-size: var(--fs-xs); color: var(--ink-3); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--scrub-soft); color: var(--scrub);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700;
  flex: none;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-8);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t-med);
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .mobile-brand { display: none; }
.search {
  flex: 1; max-width: 460px;
  display: flex; align-items: center; gap: var(--s-2);
  height: 40px; padding: 0 var(--s-3);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: var(--ink-3);
  border: 1px solid transparent;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.search:focus-within { border-color: var(--scrub); background: var(--surface); }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; color: var(--ink); font-size: var(--fs-sm); }
.search svg { width: 17px; height: 17px; }
.kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line-strong); color: var(--ink-3);
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-1); }

.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-6) var(--s-8) var(--s-16);
  animation: page-in 320ms var(--ease-out);
}
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Mobile bottom nav */
.tabbar { display: none; }

@media (max-width: 1080px) {
  :root { --sidebar-w: 84px; }
  .sidebar { padding: var(--s-4) var(--s-3); align-items: center; }
  .sidebar .brand > span:not(.brand-mark), .nav-group-label, .nav-link span, .nav-link .nav-meta, .user-chip .who, .nav-create .btn-label { display: none; }
  .brand { padding: 0 0 var(--s-4); }
  .nav-link { width: 48px; height: 44px; justify-content: center; padding: 0; }
  .nav-create .btn { width: 48px; height: 48px; padding: 0; justify-content: center; }
  .nav-group { margin-bottom: var(--s-2); padding-bottom: var(--s-2); border-bottom: 1px solid var(--line); }
  .page { padding: var(--s-6) var(--s-6) var(--s-16); }
  .topbar { padding: 0 var(--s-6); }
}

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--s-4); padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .topbar .mobile-brand { display: flex; padding: 0; font-size: 1.15rem; }
  .topbar .mobile-brand .brand-mark { width: 30px; height: 30px; }
  .topbar .search { display: none; }
  .page { padding: var(--s-4) var(--s-4) var(--s-10); }
  h1 { font-size: var(--fs-xl); }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; font-weight: 500; color: var(--ink-3);
    padding: 6px 0; border-radius: var(--r-sm);
    -webkit-tap-highlight-color: transparent;
  }
  .tab svg { width: 22px; height: 22px; stroke-width: 1.9; }
  /* The picture sits level with the other tabs' icons (same centre line), not lower or higher. */
  .tab-avatar { width: 30px; height: 30px; font-size: 12px; margin: -4px 0; }
  .tab[aria-current="page"] .tab-avatar { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--scrub); }
  .tab[aria-current="page"] { color: var(--scrub); }
  .tab-create {
    width: 48px; height: 48px; margin: -14px auto 0;
    border-radius: 16px;
    background: var(--scrub); color: var(--scrub-ink);
    display: grid; place-items: center;
    box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--scrub) 60%, transparent);
  }
}

/* Focus pages (quiz, card study, case): no tab bar on phones */
@media (max-width: 720px) {
  body.focus-page .tabbar { display: none; }
  body.focus-page .page { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  body.focus-page .qp-foot { bottom: 0; padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom)); }
}

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

.page.no-enter { animation: none; }

/* Help and legal pages opened from the landing page: the landing page's header, no sidebar.
   Mirrors .lp-nav in landing/shared.css; keep them in step. */
.site-shell { min-height: 100vh; background: var(--paper); }
.site-nav { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--paper) 86%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.site-wrap { width: min(1200px, 100%); margin: 0 auto; padding: 0 var(--s-6); display: flex; align-items: center; gap: var(--s-6); min-height: 68px; }
.site-brand { display: inline-flex; align-items: center; gap: 10px; font: 700 1.05rem/1 var(--font-display); color: var(--ink); text-decoration: none; }
.site-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--scrub); color: #fff; display: grid; place-items: center; flex: none; }
.site-mark svg { width: 20px; height: 20px; }
.site-links { display: flex; gap: var(--s-1); margin-left: auto; }
.site-links a { padding: 10px 12px; border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.site-links a:hover { color: var(--ink); background: var(--surface-2); }
.site-cta { display: flex; gap: var(--s-2); }
.site-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px; border-radius: var(--r-sm); font: 600 var(--fs-sm)/1 var(--font-body); border: 1px solid transparent; transition: background var(--t-fast) ease, transform var(--t-fast) ease; }
.site-btn:active { transform: translateY(1px); }
.site-btn-ghost { color: var(--ink); }
.site-btn-ghost:hover { background: var(--surface-2); }
.site-btn-primary { background: var(--scrub); border-color: var(--scrub); color: var(--scrub-ink); box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--scrub) 70%, transparent); }
.site-btn-primary:hover { background: var(--scrub-strong); }
@media (max-width: 860px) { .site-links { display: none; } .site-cta { margin-left: auto; } }
@media (max-width: 600px) { .site-wrap { padding: 0 var(--s-4); } }
@media (max-width: 420px) { .site-cta .site-btn-ghost { display: none; } }
/* Footer for those pages: mirrors .lp-footer in landing/shared.css */
.site-footer { border-top: 1px solid var(--line); padding: var(--s-10) 0 var(--s-12); font-size: var(--fs-sm); color: var(--ink-2); }
.site-footer-in { display: grid; gap: var(--s-6); min-height: 0; }
.site-footer-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-4); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }
.site-footer nav a { padding: 6px 0; }
.site-footer nav a:hover { color: var(--ink); text-decoration: underline; }
.site-footer .fine { font-size: var(--fs-xs); color: var(--ink-3); max-width: 90ch; display: grid; gap: 6px; }
