/* Reset, typography and page layout (top bar, nav, main). Layout stays LTR;
   user text gets dir="auto" in the markup. Logical properties used where it matters. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--font); overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.4rem; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; line-height: 1.3; }
h3 { font-size: .95rem; }
button, input, select, textarea { font: inherit; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }

.boot { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }

/* ---- shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 30; min-height: var(--top-h);
  display: flex; align-items: center; gap: 8px;
  padding: 6px var(--gutter); padding-top: max(6px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-inline-end: auto; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.main { padding: 16px var(--gutter) calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); outline: none; }
.tab > * + * { margin-top: 16px; }
.tab-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tab-head p { color: var(--muted); font-size: .9rem; flex-basis: 100%; margin-top: -8px; }

/* ---- nav: bottom bar on phones ---- */
.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-primary { display: flex; }
.nav-primary > li { flex: 1 1 0; min-width: 0; }
.nav-link {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 100%; min-height: var(--nav-h); padding: 6px 2px; border: 0; background: none;
  color: var(--muted); font-size: .72rem; text-decoration: none; cursor: pointer;
}
.nav-link svg { width: 24px; height: 24px; }
.nav-link[aria-current="page"], .nav-link.is-active { color: var(--accent); font-weight: 600; }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}
.nav-badge {
  position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
.nav-more {
  display: none; position: absolute; bottom: calc(100% + 8px); inset-inline: 8px;
  grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.nav[data-more-open] .nav-more { display: grid; }

/* ---- wide screens: side nav ---- */
@media (min-width: 840px) {
  .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); grid-template-areas: "top top" "banner banner" "nav main"; align-items: start; }
  .topbar { grid-area: top; }
  .banner { grid-area: banner; }
  .nav { grid-area: nav; position: sticky; top: var(--top-h); inset: auto; height: calc(100dvh - var(--top-h)); border-top: 0; border-inline-end: 1px solid var(--border); padding: 12px 8px; }
  .nav-primary, .nav-more { display: flex; flex-direction: column; gap: 2px; position: static; border: 0; box-shadow: none; padding: 0; background: none; }
  .nav-more { margin-top: 2px; }
  .nav-primary > li { flex: none; }
  .nav-link { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: var(--tap); padding: 8px 14px; border-radius: var(--radius-sm); font-size: .95rem; }
  .nav-link[aria-current="page"] { background: var(--accent-soft); }
  .nav-link[aria-current="page"]::before { display: none; }
  .nav-badge { position: static; margin-inline-start: auto; }
  .nav-more-toggle { display: none; }
  .main { grid-area: main; width: 100%; max-width: 880px; padding-bottom: 48px; }
}
@media (max-width: 420px) { .brand-text { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
