/* =========================================================================
   Base: reset, typography, layout primitives, accessibility.
   ========================================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--chalk);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-synthesis-weight: none;
  transition: background-color var(--dur-slow) var(--ease-out),
              color var(--dur-slow) var(--ease-out);
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--ink);
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-md); letter-spacing: var(--tracking-snug); }
h4 { font-size: var(--text-base); font-family: var(--font-sans); font-weight: 600; }

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

a {
  color: inherit;
  text-decoration-color: var(--chalk-line-strong);
  text-underline-offset: 0.2em;
  transition: text-decoration-color var(--dur) var(--ease-out);
}
a:hover { text-decoration-color: currentColor; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}
button { background: none; border: none; padding: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; }

ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }

/* Numbers that sit in columns or tick upward must not jitter. */
time, .tabular, .time-display { font-variant-numeric: tabular-nums; }

/* --- Focus ---------------------------------------------------------------
   Visible on keyboard, invisible on mouse, never removed entirely. */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: 999;
  padding: var(--space-3) var(--space-4);
  background: var(--ink);
  color: var(--chalk);
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: top var(--dur) var(--ease-out);
}
.skip-link:focus-visible { top: var(--space-4); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Type helpers -------------------------------------------------------- */
.serif { font-family: var(--font-serif); }
.display {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}
.lede {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--ink-soft);
  max-width: var(--reading-max);
}
.prose {
  font-family: var(--font-serif);
  line-height: var(--leading-relaxed);
  max-width: var(--reading-max);
}
.meta {
  font-size: var(--text-sm);
  color: var(--ink-faint);
}
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 {
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.clamp-3 {
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}

/* --- Layout primitives --------------------------------------------------- */
.stack > * + * { margin-top: var(--flow, var(--space-4)); }
.stack-sm { --flow: var(--space-2); }
.stack-lg { --flow: var(--space-6); }

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.row-wrap { flex-wrap: wrap; }
.row-top { align-items: flex-start; }
.spacer { flex: 1 1 auto; }

.container {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--space-5);
}
@media (max-width: 640px) {
  .container { padding-inline: var(--space-4); }
}

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }

/* A section title with a hairline running to the edge. The rule is doing
   work here: it separates groups so cards do not have to. */
.section-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.section-head h2 {
  font-size: var(--text-md);
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  flex: none;
}
.section-head::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--chalk-line);
}
.section-head .section-action { flex: none; }

hr.rule {
  border: none;
  height: 1px;
  background: var(--chalk-line);
  margin: var(--space-6) 0;
}

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

.shell {
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}
.shell-main {
  min-width: 0;
  padding: var(--space-7) 0 calc(var(--space-9) + var(--miniplayer-height));
}

/* The rail's own responsive rule lives in components.css, beside the rule
   that gives it `display: flex`. A media query adds no specificity, so an
   override written here would simply lose to the later stylesheet. */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .shell-main {
    padding-top: var(--space-5);
    padding-bottom: calc(var(--tabbar-height) + var(--miniplayer-height) + var(--space-6));
  }
}

.page-head { margin-bottom: var(--space-7); }
.page-head h1 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-2);
}
@media (max-width: 640px) {
  .page-head h1 { font-size: var(--text-xl); }
  .page-head { margin-bottom: var(--space-5); }
}

/* -------------------------------------------------------------------------
   Navigation cross-fade.

   Native View Transitions, so there is no animation library and browsers
   without the API simply swap instantly. Short enough to read as a change of
   page rather than as an effect being performed at you.
   ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) {
    animation: vt-out 110ms var(--ease-out) both;
  }
  ::view-transition-new(root) {
    animation: vt-in 220ms var(--ease-out) both;
  }
}
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(4px); } }

/* Tactile feedback: a press should feel like it went down.
   Applied to the surfaces that act like buttons but are not <button>. */
.row-item:active,
.tab-button:active,
.space-card:active,
.transcript-line:active {
  transform: scale(0.995);
}
.row-item, .tab-button, .space-card, .transcript-line {
  transition: transform var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur) var(--ease-out);
}
@media (prefers-reduced-motion: reduce) {
  .row-item:active,
  .tab-button:active,
  .space-card:active,
  .transcript-line:active { transform: none; }
}
