/* ============================ Base & app shell ============================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
img, video, svg { display: block; max-width: 100%; }
/* Default icon size (zero specificity — any component rule overrides it). */
:where(svg[aria-hidden="true"]) { width: 1.15em; height: 1.15em; flex: none; }
img { object-fit: cover; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-3xl); font-weight: 700; }
h2 { font-size: var(--fs-xl); font-weight: 700; }
h3 { font-size: var(--fs-lg); font-weight: 600; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
::selection { background: var(--ember); color: #fff; }

:focus { outline: none; }
:focus-visible { box-shadow: var(--focus); border-radius: var(--r-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: fixed; left: var(--s-4); top: -60px; z-index: 1000; background: var(--ember); color: #fff;
  padding: var(--s-2) var(--s-4); border-radius: var(--r-pill); transition: top var(--t-med) var(--ease);
}
.skip-link:focus { top: var(--s-4); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 3px solid var(--bg); }

/* ------------------------------ Shell grid -------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "side top" "side main";
  min-height: 100vh;
}
.shell.has-player { padding-bottom: var(--player-h); }

.sidebar {
  grid-area: side;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-5) var(--s-3);
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.shell.has-player .sidebar { height: calc(100vh - var(--player-h)); }
.brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-1) var(--s-3) var(--s-4);
  font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--gradient-brand);
  display: grid; place-items: center; box-shadow: var(--glow-ember); flex: none;
}
.brand-mark svg { width: 20px; height: 20px; color: #fff; }
.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3);
  padding: var(--s-4) var(--s-3) var(--s-2);
}
.nav-link {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px var(--s-3); border-radius: var(--r-md);
  color: var(--text-2); font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-link svg { width: 20px; height: 20px; flex: none; }
.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"] svg { color: var(--ember); }
.nav-link .nav-badge { margin-left: auto; }
.sidebar-footer { margin-top: auto; padding: var(--s-3); font-size: var(--fs-xs); color: var(--text-3); }

.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-6);
  background: var(--glass-strong);
  backdrop-filter: saturate(140%) blur(18px);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar .mobile-brand { display: none; }
.topbar-search { flex: 1; max-width: 520px; position: relative; }
.topbar-search input {
  width: 100%; height: 42px; padding: 0 var(--s-4) 0 42px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.topbar-search input:focus { border-color: var(--violet); background: var(--surface-2); box-shadow: none; }
.topbar-search svg { position: absolute; left: 14px; top: 11px; width: 20px; height: 20px; color: var(--text-3); pointer-events: none; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }

.main { grid-area: main; min-width: 0; }
.view { max-width: var(--content-max); margin: 0 auto; padding: var(--s-8) var(--s-8) var(--s-16); }
.view.full-bleed { max-width: none; padding: 0 0 var(--s-16); }
.view-enter { animation: viewIn var(--t-slow) var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bottom-nav { display: none; }

/* Tablet: condensed sidebar */
@media (max-width: 1100px) {
  .shell { grid-template-columns: var(--sidebar-w-condensed) 1fr; }
  .sidebar { padding: var(--s-4) var(--s-2); align-items: center; }
  .brand span, .nav-link span, .nav-label, .sidebar-footer, .nav-link .nav-badge { display: none; }
  .brand { padding: var(--s-1) 0 var(--s-4); }
  .nav-link { justify-content: center; padding: 12px; }
  .view { padding: var(--s-6) var(--s-6) var(--s-16); }
}

/* Mobile: bottom navigation */
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; grid-template-areas: "top" "main"; padding-bottom: var(--bottomnav-h); }
  .shell.has-player { padding-bottom: calc(var(--bottomnav-h) + 64px); }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--s-4); gap: var(--s-3); }
  .topbar .mobile-brand { display: flex; }
  .topbar-search { display: none; }
  .topbar-search.open { display: block; position: absolute; left: var(--s-3); right: var(--s-3); top: 11px; max-width: none; }
  .view { padding: var(--s-5) var(--s-4) var(--s-12); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-elev);
    border-top: 1px solid var(--line);
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 11px; color: var(--text-3);
  }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--text); }
  .bottom-nav a[aria-current="page"] svg { color: var(--ember); }
  h1 { font-size: var(--fs-2xl); }
}
/* Headings receive programmatic focus on navigation (for screen readers) — no visible ring. */
h1[tabindex="-1"]:focus, h1[tabindex="-1"]:focus-visible { box-shadow: none; outline: none; }
