/* Reset, layout shell, typography */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--text);
  font-family: var(--font); font-size: var(--fs-md); line-height: 1.45;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
h2 { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: var(--fs-md); font-weight: 600; }
a { color: var(--brand); text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--hl); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.hand { font-family: var(--font-hand); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* App shell */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--appbar); color: var(--on-appbar);
  padding: calc(var(--s3) + env(safe-area-inset-top)) var(--s4) var(--s3);
  display: flex; align-items: center; gap: var(--s3);
}
.appbar a, .appbar button { color: inherit; }
.appbar .title { font-weight: 700; font-size: var(--fs-md); line-height: 1.2; flex: 1; min-width: 0; }
.appbar .title small { display: block; font-weight: 400; opacity: .8; font-size: var(--fs-xs); }
.icon-btn {
  width: var(--tap); height: var(--tap); border: 0; background: transparent; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; position: relative;
}
.icon-btn:hover { background: rgba(255,255,255,.14); }
.icon-btn svg { width: 22px; height: 22px; }
.badge-dot {
  position: absolute; top: 6px; right: 5px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--hl); color: #3a2f00; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--appbar);
}
.container { max-width: 960px; margin: 0 auto; padding: var(--s4); }
.stack > * + * { margin-top: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: var(--s3); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

.page-header { padding: var(--s5) var(--s4) var(--s2); max-width: 960px; margin: 0 auto; }
.page-header p { color: var(--muted); margin-top: var(--s1); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: var(--s5) 0 var(--s3); }
.section-title a { font-size: var(--fs-sm); font-weight: 600; }

/* Bottom nav (phone) -> side rail (desktop) */
.nav {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--sheet); border-top: 1px solid var(--rule);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600; position: relative;
}
.nav a svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: var(--brand); }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; width: 28px; height: 4px; border-radius: 0 0 4px 4px; background: var(--brand);
}
.nav .count { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--bad); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: grid; place-items: center; padding: 0 4px; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 220px; }
  .nav {
    top: 0; bottom: auto; width: 220px; height: 100vh; right: auto; padding: var(--s5) var(--s3);
    grid-template-columns: 1fr; grid-auto-flow: row; grid-auto-columns: auto; grid-auto-rows: 48px; align-content: start; gap: var(--s1);
    border-top: 0; border-right: 1px solid var(--rule);
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: var(--s3); padding: 0 var(--s3); border-radius: var(--r-sm); font-size: var(--fs-sm); }
  .nav a[aria-current="page"] { background: var(--brand-soft); }
  .nav a[aria-current="page"]::before { left: 0; top: 10px; width: 4px; height: 28px; border-radius: 0 4px 4px 0; }
  .nav .count { position: static; margin-left: auto; }
  .nav .brand { display: block; }
}
.nav .brand { font-family: var(--font-brand); text-transform: uppercase; font-weight: 800; font-size: var(--fs-xl); color: var(--brand); padding: 0 var(--s3) var(--s4); letter-spacing: -.02em; }
@media (max-width: 899px) { .nav .brand { display: none; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.appbar .wordmark { font-family: var(--font-brand); text-transform: uppercase; font-weight: 800; font-size: 1.7rem; letter-spacing: .02em; line-height: 1; }
.appbar .wordmark small { font-family: var(--font); text-transform: none; font-size: var(--fs-xs); font-weight: 400; letter-spacing: 0; margin-top: 2px; }

/* ---- Logo (Content/Website/logo.jpg is on white, so it always sits in a white badge) ---- */
.logo { display: block; flex: none; width: 36px; height: 36px; border-radius: 50%; background: #fff; object-fit: contain; padding: 2px; }
.logo.lg { width: 96px; height: 96px; padding: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.nav .brand { display: flex; align-items: center; gap: var(--s3); }
.nav .brand .logo { width: 44px; height: 44px; border: 1px solid var(--rule); }
.nav .brand span { font-size: 1.35rem; line-height: 1; }
@media (max-width: 899px) { .nav .brand { display: none; } }

/* ---- Desktop polish ---- */
@media (min-width: 900px) {
  .appbar { padding: var(--s3) var(--s6); }
  .container, .page-header, .ctxbar .in, .pastbar .in { max-width: 1120px; padding-left: var(--s6); padding-right: var(--s6); }
  .page-header { padding-top: var(--s6); }
  .grid.cols-2 { gap: var(--s4); }
  a.card:hover { box-shadow: 0 2px 4px rgba(60,10,25,.08), 0 10px 26px rgba(60,10,25,.10); }
  .nav a { transition: background .15s; }
  .nav a:hover { background: var(--well); }
  .nav a[aria-current="page"]:hover { background: var(--brand-soft); }
  .nav a svg { width: 22px; height: 22px; }
  .sheet { top: 50%; bottom: auto; left: 50%; right: auto; width: 520px; max-width: 92vw; margin: 0; border-radius: var(--r-lg); padding-bottom: var(--s5); transform: translate(-50%, calc(-50% + 40px)); opacity: 0; pointer-events: none; transition: transform .2s, opacity .2s; }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; pointer-events: auto; }
  .sheet::before { display: none; }
}
@media (min-width: 1400px) {
  .container, .page-header, .ctxbar .in, .pastbar .in { max-width: 1280px; }
}

/* ---- Nav: primary tabs + More menu (phone) / full rail (desktop) ---- */
.nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; position: relative; padding: 0; }
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--brand); }
.nav .nav-extra { display: none; }
.sheet .list a.li { text-decoration: none; }
@media (min-width: 900px) {
  .nav .nav-extra { display: flex; }
  .nav .nav-more { display: none; }
  .nav .nav-logout { margin-top: var(--s4); color: var(--bad); border-top: 1px solid var(--rule); border-radius: 0; }
  .nav .nav-logout:hover { background: color-mix(in srgb, var(--bad) 10%, var(--sheet)); }
  .nav { overflow-y: auto; }
}
.sheet { max-height: 90vh; overflow-y: auto; }
@media (min-width: 900px) { .appbar .logo { display: none; } }
