/* Ours — global styles (Warm Editorial Sanctuary · Night Edition) */
html, body {
  margin: 0;
  padding: 0;
}

body {
  overscroll-behavior-y: none;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

/* Responsive visibility helpers — keep utility classes out of the
   Tailwind-CDN cascade path (its `hidden` + `md:flex` ordering is broken).
   These bespoke helpers are the only responsive show/hide mechanism. */
.hidden-md-flex {
  display: none;
}
@media (min-width: 768px) {
  .hidden-md-flex {
    display: flex;
  }
}
.sm-only {
  display: none;
}
@media (max-width: 639.98px) {
  .sm-only {
    display: flex;
  }
}

/* Visually hidden, exposed to screen readers */
.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;
}

/* Keyboard focus — darker boundary token, shape + color signal */
:focus-visible {
  outline: 2px solid var(--line-strong);
  outline-offset: 2px;
  border-radius: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

.on-dark :focus-visible,
.on-dark:focus-visible {
  outline-color: var(--amber-glow);
}

/* Reading / writing measure */
.reading-width {
  max-width: var(--reading-width);
  margin-left: auto;
  margin-right: auto;
}

.writing-width {
  max-width: var(--writing-width);
  margin-left: auto;
  margin-right: auto;
}

.frame-width {
  max-width: var(--frame-width);
  margin-left: auto;
  margin-right: auto;
}

.wide-frame {
  max-width: var(--wide-frame);
  margin-left: auto;
  margin-right: auto;
}

/* Hairline helpers */
.rule-t { border-top: 1px solid var(--hairline); }
.rule-b { border-bottom: 1px solid var(--hairline); }

/* Small-caps kickers — sans, used sparingly for small metadata only */
.label-caps {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}

.on-dark .label-caps {
  color: rgba(244, 239, 229, 0.66);
}

/* Display copy always renders in the editorial serif */
.display-copy {
  font-family: var(--serif);
  font-weight: 400;
}

/* Sans-for-controls helper: buttons/labels/metadata stay grotesk */
.sans {
  font-family: var(--sans);
}

/* ── Entrance primitives (restrained; hero carries the strongest motion) ── */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes line-in { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes mask-up { from { transform: translateY(112%); } to { transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ember-breathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.06); }
}

.anim-rise { animation: rise .55s cubic-bezier(.22,.61,.36,1) both; }
.anim-line { transform-origin: left; animation: line-in .8s cubic-bezier(.22,.61,.36,1) both; }
.anim-fade { animation: fade-in .9s ease both; }

/* Headline line mask: wrap each line in .mask-line > span */
.mask-line { display: block; overflow: hidden; }
.mask-line > span { display: inline-block; animation: mask-up .7s cubic-bezier(.22,.61,.36,1) both; }
.mask-line:nth-child(2) > span { animation-delay: .1s; }

/* Stagger helper — pair with inline animation-delay styles */
.stagger > * { animation: rise .55s cubic-bezier(.22,.61,.36,1) both; }

/* Buttons — sans controls, restrained radii, small motion */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--ember); color: var(--on-ember);
  font: 500 14px/1 var(--sans); letter-spacing: .02em;
  height: 48px; padding: 0 26px; border: 0; cursor: pointer; border-radius: var(--r-lg);
  transition: background .2s ease, transform .2s ease;
}
.btn-primary:hover { background: var(--ember-hover); transform: translateY(-1px); }
.btn-primary:active { background: var(--ember-active); transform: translateY(0); }
.btn-primary:disabled { opacity: .6; transform: none; cursor: default; }
.btn-primary .ar { transition: transform .25s ease; }
.btn-primary:hover .ar { transform: translateX(4px); }

/* Ghost button — parchment fill, darker boundary */
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card); color: var(--ink);
  font: 500 13.5px/1 var(--sans); letter-spacing: .02em;
  height: 44px; padding: 0 20px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}
.btn-ghost:hover { background: var(--surface-subtle); transform: translateY(-1px); }

.btn-danger {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--error); color: #fff;
  font: 500 13.5px/1 var(--sans);
  height: 44px; padding: 0 20px; border: 0; border-radius: var(--r-lg); cursor: pointer;
}
.btn-danger:hover { opacity: .92; }

/* Editorial question row — typography-first selection (no card grid) */
.q-row {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  border-top: 1px solid var(--hairline); cursor: pointer;
  padding: 28px 8px 28px 0; position: relative;
  transition: background .25s ease;
}
.q-row:last-child { border-bottom: 1px solid var(--hairline); }
.q-row .q-text {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(24px, 3.4vw, 34px); line-height: 1.28; color: var(--ink-2);
  transition: color .25s ease;
}
.q-row .q-arrow {
  display: inline-block; margin-left: 10px; opacity: 0; transform: translateX(-6px);
  transition: opacity .25s ease, transform .25s ease; color: var(--ember);
  font-family: var(--serif);
}
.q-row:hover .q-text, .q-row:focus-visible .q-text { color: var(--ink); }
.q-row:hover .q-arrow, .q-row:focus-visible .q-arrow { opacity: 1; transform: none; }
.q-row[aria-pressed="true"] .q-text { color: var(--ink); }
.q-row[aria-pressed="true"] { background: linear-gradient(90deg, var(--ember-soft), transparent 75%); }
.q-row[aria-pressed="true"]::before {
  content: ""; position: absolute; left: 0; top: -1px; bottom: -1px; width: 3px; background: var(--ember);
}
.q-row[aria-pressed="true"] .q-state { color: var(--ember); }
.q-row .q-state {
  font-family: var(--sans); font-size: 11px; letter-spacing: .18em; text-transform: uppercase;
  font-weight: 600; color: var(--ink-3); display: inline-flex; align-items: center; gap: 8px;
  transition: color .2s ease;
}
.q-row .q-check { display: none; font-size: 12px; }
.q-row[aria-pressed="true"] .q-check { display: inline; }

/* Preview strip (shared entries) — editorial swipe on mobile, row list on desktop */
.shelf {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 320px);
  gap: var(--gutter); overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 8px; scrollbar-width: thin;
}
.shelf > * { scroll-snap-align: start; }
@media (min-width: 900px) {
  .shelf {
    grid-auto-flow: row; grid-template-columns: repeat(3, 1fr);
    grid-auto-columns: unset; overflow: visible;
  }
  .shelf > * { min-width: 0; }
}

/* Prevent overflow from long words in narrow columns */
p, h1, h2, h3, blockquote, li {
  overflow-wrap: break-word;
}

img, svg, video {
  max-width: 100%;
}

/* ── Night Edition global adjustments ─────────────────────────────────
 * The dark values live in tokens.css (token names unchanged). A few
 * baseline rules encoded light-theme assumptions and are re-balanced here,
 * without touching markup:
 *  1. The writing sheet's single soft shadow was tuned for ivory paper.
 *  2. Buttons/labels are set in --sans with warm-ivory default color.
 *  3. Inputs and native date pickers must follow the dark color-scheme.
 *  4. The hero melts into the page through a fixed paper gradient.
 */

/* Writing sheet shadow (editor.js inline style) — dark-depth equivalent */
.bg-card[style*="box-shadow"] {
  box-shadow: 0 18px 44px -30px rgba(0, 0, 0, 0.8) !important;
}

button, input, select, textarea {
  color: var(--ink);
}

.btn-primary,
.btn-ghost,
.btn-danger {
  color: var(--on-ember);
}
.btn-ghost {
  color: var(--ink);
}

input, select, textarea {
  color-scheme: dark;
}

input::placeholder, textarea::placeholder {
  color: var(--ink-3);
}

/* Fireplace-dark → dark editorial canvas: a fixed backdrop behind every
   page so the approved hero never ends in a hard seam while scrolling. */
[data-paper-gradient] {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    var(--walnut-900) 0%,
    var(--walnut-800) 34vh,
    #241D16 60vh,
    var(--paper) 96vh
  );
}

/* #app surfaces stay transparent so the backdrop shows through; the hero
   (bg-walnut-900) and dark band sections keep painting themselves. */
#app {
  background: transparent;
}

/* Visible, quiet scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: #4A4133;
  border-radius: 999px;
  border: 3px solid #1C1712;
}
::-webkit-scrollbar-track {
  background: transparent;
}

html {
  scroll-behavior: smooth;
}

@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;
  }
}

button {
  font: inherit;
  cursor: pointer;
}

textarea {
  font: inherit;
  resize: vertical;
}

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