/* base.css — reset, type, focus, and the app frame (sidebar / tab bar / main). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-deep); text-underline-offset: 3px; }
h1, h2, h3, h4 { font-family: var(--font-brand); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: .005em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 .75em; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s5) 0; }
[hidden] { display: none !important; }
::selection { background: var(--sun-soft); color: var(--text); }

/* One visible focus style everywhere, strong enough to follow with a TV remote. */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}
.tv :focus-visible, .tv .is-focused { outline-width: 5px; outline-offset: 5px; }

.icon { width: 1.25em; height: 1.25em; flex: none; stroke-width: 2; }
.icon-sm { width: 1em; height: 1em; }
.icon-lg { width: 1.6em; height: 1.6em; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row { display: flex; align-items: center; gap: var(--s3); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.spacer { flex: 1; }
.num { font-variant-numeric: tabular-nums; }

/* Scrollbars that match the paper rather than the operating system's grey. */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* ------------------------------------------------------------------ frame */
#app { min-height: 100vh; min-height: 100dvh; }

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}
.shell-side {
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  gap: var(--s2);
  padding: calc(var(--s5) + var(--safe-top)) var(--s4) var(--s4) calc(var(--s4) + var(--safe-left));
  border-right: 1px solid var(--line);
  background: var(--surface);
  z-index: var(--z-bar);
}
.shell-main {
  min-width: 0;
  padding-bottom: calc(var(--player-h, 0px) + var(--s6));
}
.shell-brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s2) var(--s4);
  text-decoration: none; color: var(--text);
}
.shell-brand .bear { width: 46px; height: auto; flex: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--s3);
  min-height: var(--tap);
  padding: 0 var(--s3);
  border-radius: var(--r-md);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 700;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav a[aria-current="page"] .icon { color: var(--accent-deep); }
.nav-label { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding: var(--s4) var(--s3) var(--s1); }
.shell-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s2); }

/* Phone: the sidebar becomes a tab bar along the bottom. */
.tabbar { display: none; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .shell-side { display: none; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; /* one column per place the library has */
    padding: 4px var(--safe-right) calc(4px + var(--safe-bottom)) var(--safe-left);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    border-top: 1px solid var(--line);
    z-index: var(--z-bar);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px;
    color: var(--text-3); text-decoration: none;
    font-size: 11px; font-weight: 800;
  }
  .tabbar a .icon { width: 24px; height: 24px; }
  .tabbar a[aria-current="page"] { color: var(--text); }
  .tabbar a[aria-current="page"] .icon { color: var(--accent-deep); }
  .shell-main { padding-bottom: calc(64px + var(--safe-bottom) + var(--player-h, 0px) + var(--s4)); }
}

/* Tablet: a narrow rail with the labels under the icons. */
@media (min-width: 761px) and (max-width: 1100px) {
  .shell { grid-template-columns: 92px minmax(0, 1fr); }
  .shell-side { padding-left: var(--s2); padding-right: var(--s2); align-items: stretch; }
  .shell-brand { justify-content: center; padding: 0 0 var(--s4); }
  .shell-brand .wordmark, .nav-label, .shell-side .hide-rail { display: none; }
  .nav a { flex-direction: column; gap: 2px; padding: var(--s2) 0; font-size: 11px; text-align: center; }
  .nav a .icon { width: 24px; height: 24px; }
}

/* Page header inside main. */
.page { padding: calc(var(--s5) + var(--safe-top)) var(--gutter) var(--s6); max-width: 1680px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }

/* A full-screen route (reader, player, remote) hides the frame entirely. */
.fullscreen-route { position: fixed; inset: 0; z-index: 10; background: var(--bg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; scroll-behavior: auto !important; }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  transition-duration: 1ms !important; animation-duration: 1ms !important;
}
