/* ==========================================================================
   Base: reset, typography, focus, utilities
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5 {
  margin: 0 0 .4em;
  line-height: 1.22;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--ink);
}

h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.7rem); letter-spacing: -.03em; }
h2 { font-size: clamp(1.3rem, 1.05rem + 1.1vw, 1.75rem); letter-spacing: -.02em; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 .85em; color: var(--ink-2); }
p.lead { font-size: 1.08rem; color: var(--ink-2); max-width: 68ch; }

a {
  color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
  transition: color .15s var(--ease);
}
a:hover { color: var(--accent-2); }

img { max-width: 100%; display: block; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  font-family: inherit;
}

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

code, kbd, samp { font-family: var(--mono); font-size: .9em; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.6rem 0;
}

::selection { background: var(--brand-tint); color: var(--ink); }

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

/* --- scrollbars --------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: content-box; }

/* --- utilities ---------------------------------------------------------- */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }
.wrap-narrow { width: 100%; max-width: 820px; margin: 0 auto; padding: 0 22px; }

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap-gap { flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack-lg { display: flex; flex-direction: column; gap: 22px; }
.grid { display: grid; gap: 18px; }

.center { text-align: center; }
.muted { color: var(--ink-3); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.mono { font-family: var(--mono); }
.serif { font-family: var(--serif); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.tr-text { font-feature-settings: "kern" 1; }

/* thin top progress bar used while views load */
.loadbar {
  position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 400;
  background: transparent; pointer-events: none;
}
.loadbar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--gold), var(--accent));
  transition: width .25s var(--ease), opacity .3s;
}
.loadbar.done i { opacity: 0; }

/* skeleton shimmer for lazy content */
.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.fade-up { animation: fadeUp .34s var(--ease-out) both; }

@keyframes popIn {
  0%   { opacity: 0; transform: scale(.94); }
  100% { opacity: 1; transform: scale(1); }
}
.pop-in { animation: popIn .22s var(--ease-out) both; }

@media print {
  .app-header, .app-footer, .rail, .reader-toolbar, .no-print { display: none !important; }
  body { background: #fff; }
}
