/* ==========================================================================
   TwicePlay — Reset, elements, typography, utilities
   ========================================================================== */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-color: var(--surface-3) transparent;
}

body {
  min-height: 100%;
  /* Guarantees "no horizontal scrolling" on every page, at every width. */
  overflow-x: hidden;
  background-color: var(--bg);
  background-image: var(--grad-mesh);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
picture,
video,
canvas,
svg,
iframe { display: block; max-width: 100%; }

img { height: auto; border: 0; }

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

button { background: none; border: 0; cursor: pointer; }

a { color: inherit; text-decoration: none; }

ul, ol { list-style: none; padding: 0; }

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: -0.022em;
  text-wrap: balance;
}

p { text-wrap: pretty; }

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

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

/* Focus: visible for keyboards, silent for mouse users. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}

/* Custom scrollbars (WebKit) ---------------------------------------------- */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border: 3px solid transparent;
  border-radius: var(--r-pill);
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; }

/* ==========================================================================
   Layout helpers
   ========================================================================== */

.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.page {
  min-height: 60vh;
  padding-block: var(--sp-8) var(--sp-16);
}

.stack > * + * { margin-top: var(--sp-4); }

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

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

[hidden] { display: none !important; }

.text-dim { color: var(--text-dim); }
.text-soft { color: var(--text-soft); }
.text-center { text-align: center; }
.mono { font-family: var(--font-mono); font-size: 0.9em; }
.nowrap { white-space: nowrap; }

/* Gradient brand text ----------------------------------------------------- */
.grad-text {
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ==========================================================================
   Section headers (reused by every rail / grid on the site)
   ========================================================================== */

.section { margin-top: var(--sp-12); }
.section:first-of-type { margin-top: var(--sp-8); }

/* Anchor links (e.g. categories.html#tags) must not land the heading
   underneath the sticky header. */
.section,
.doc-body h2,
[id] { scroll-margin-top: calc(var(--header-h) + var(--sp-5)); }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-5);
}

/* The heading block shrinks before the "view all" link is pushed off-screen. */
.section-head > :first-child { min-width: 0; flex: 1 1 200px; }

.section-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-xl);
}

.section-title .dot {
  width: 9px;
  height: 22px;
  border-radius: var(--r-pill);
  background: var(--grad-brand);
  flex: 0 0 auto;
}

.section-title--accent .dot { background: var(--grad-accent); }

.section-sub {
  margin-top: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.section-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-dim);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-pill);
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  white-space: nowrap;
}

.section-link:hover { color: var(--text); background: var(--surface-2); }
.section-link svg { transition: transform var(--t-mid) var(--ease); }
.section-link:hover svg { transform: translateX(3px); }

/* ==========================================================================
   Motion — entrance animations, respectful of reduced-motion
   ========================================================================== */

@keyframes ph-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

@keyframes ph-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes ph-shimmer {
  from { background-position: -180% 0; }
  to   { background-position: 180% 0; }
}

@keyframes ph-spin { to { transform: rotate(360deg); } }

@keyframes ph-pop {
  0%   { transform: scale(0.94); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.rise { animation: ph-rise var(--t-slow) var(--ease-out) both; }
.fade { animation: ph-fade var(--t-mid) var(--ease) both; }

/* Page-level transition, applied by app.js on load */
.page-enter { animation: ph-rise 420ms var(--ease-out) both; }

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