/*
  Bitcoin Canon — Base
  Reset, body, global typography, layout scaffold, utilities.
*/

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

/* Enforce HTML hidden attribute — CSS display rules must not override it */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--f-sans);
  font-size: 1rem;
  background: var(--c-bg);
  color: var(--c-ink);
  /* Subtle warm noise texture */
  background-image:
    radial-gradient(ellipse at 50% -10rem, rgba(184, 137, 42, .04), transparent 40rem),
    linear-gradient(180deg, var(--c-bg) 0%, var(--c-bg-deep, var(--c-bg)) 60%, var(--c-bg) 100%);
}

/* Grain overlay — adds paper texture at 8% opacity */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: .065;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

/* All content sits above the grain */
.masthead, header, main, aside, footer, nav, section,
[id], [class] { position: relative; z-index: 2; }
body::before { z-index: 0; }

/* — Deep-link boot state ——————————————————————— */
.canon-boot { display: none; }

html[data-booting="deep-link"] .canon-boot {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  background:
    radial-gradient(circle at 50% 42%, rgba(184, 137, 42, .09), transparent 18rem),
    var(--c-bg);
  color: var(--c-ink);
}

.canon-boot span {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  margin-bottom: .65rem;
  border: 1px solid var(--c-line-strong);
  border-radius: 50%;
  color: var(--c-muted);
  font: 700 .7rem/1 var(--f-sans);
  letter-spacing: .05em;
  animation: canon-boot-pulse 1.5s ease-in-out infinite;
}

.canon-boot strong {
  font: 500 1.55rem/1 var(--f-serif);
}

.canon-boot em {
  color: var(--c-muted);
  font: italic .9rem/1.4 var(--f-serif);
}

@keyframes canon-boot-pulse {
  50% {
    border-color: var(--c-line-strong);
    box-shadow: 0 0 0 .45rem var(--c-panel-2);
  }
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
button, input, select { font: inherit; }
h1, h2, h3, h4, h5, h6 { margin: 0; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
blockquote { margin: 0; }
mark {
  background: var(--c-panel-2);
  color: inherit;
  border-radius: .2em;
  padding: 0 .06em;
}

/* — Layout containers ——————————————————————— */
.masthead,
.layout,
.footer {
  width: min(var(--content-max), calc(100% - 3rem));
  margin-inline: auto;
}

/* — Ambient blobs — decorative background warmth ——— */
.ambient { display: none; }  /* hidden by default; may be shown on non-reader views */

/* — Reading progress bar —————————————————————— */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 200;
  background: transparent;
  pointer-events: none;
}
.reading-progress span {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: var(--c-ink);
  box-shadow: 0 0 6px var(--c-shadow-2);
  transition: transform .12s linear;
}

/* — Keyboard access ————————————————————————————— */
/* One visible neutral focus ring for the whole edition. Search overrides this
   with the seal ring because search is how the sealed record is found. */
:focus-visible {
  outline: 2px solid var(--c-ink);
  outline-offset: 2px;
  border-radius: 3px;
}

/* First stop on the page: skip the masthead and land on the scripture. */
.skip-link {
  /* fixed, not absolute: a reader who has scrolled and then tabs to it must see
     it at the top of the viewport, not at the top of the document. */
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 300;
  transform: translate(-50%, -120%);
  padding: .55rem 1.1rem;
  font-family: var(--f-sans);
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--c-bg);
  background: var(--c-ink);
  border-radius: 0 0 6px 6px;
  transition: transform var(--fast) var(--ease);
}

/* Reveal on any focus, not just :focus-visible — a skip link is only ever
   reached by keyboard, and it must be on screen the instant it takes focus. */
.skip-link:focus {
  transform: translate(-50%, 0);
  outline-offset: -4px;
}

/* The skip link's destination. It is a landmark, not a control, so it takes
   focus without drawing a ring; the scroll position is the visible feedback. */
#canonMain:focus {
  outline: none;
}

/* Background must not scroll while a modal sheet owns the screen. */
body.modal-open {
  overflow: hidden;
  touch-action: none;
}

/* — Utility —————————————————————————————————— */
.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;
}

.eyebrow,
.sidebar-kicker {
  margin: 0 0 .6rem;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .7rem;
  font-weight: 700;
  font-family: var(--f-sans);
}

h1 {
  font-family: var(--f-serif);
  font-size: clamp(3.4rem, 8vw, 7.2rem);
  line-height: .86;
  letter-spacing: -.05em;
  font-weight: 500;
  color: var(--c-ink);
}

h2 {
  font-family: var(--f-serif);
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: .95;
  letter-spacing: -.03em;
  font-weight: 500;
}

h3 {
  font-family: var(--f-serif);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1;
  letter-spacing: -.02em;
  font-weight: 500;
}

h4 {
  font-family: var(--f-serif);
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  line-height: 1.1;
  font-weight: 500;
}

/* — App shell toast —————————————————————————— */
.app-shell-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1rem;
  background: var(--c-panel-2);
  border: 1px solid var(--c-line-strong);
  border-radius: 999px;
  color: var(--c-ink);
  font-size: .82rem;
  box-shadow: 0 12px 40px var(--c-shadow);
}
.app-shell-toast button {
  border: 1px solid var(--c-line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--c-muted);
  padding: .25rem .65rem;
  font-size: .75rem;
}
.app-shell-toast[hidden] { display: none; }

/* — App install button ———————————————————————— */
.app-install-button {
  border: 1px solid var(--c-line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--c-muted);
  padding: .42rem .75rem;
  font-size: .78rem;
}
.app-install-button[hidden] { display: none; }

/* — Back to top ————————————————————————————————— */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 1.75rem;
  z-index: 80;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--c-line-strong);
  background: color-mix(in srgb, var(--c-bg) 88%, transparent);
  backdrop-filter: blur(12px);
  color: var(--c-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(.5rem);
  transition: opacity var(--mid) var(--ease), transform var(--mid) var(--ease), color var(--fast) var(--ease), border-color var(--fast) var(--ease);
  pointer-events: none;
}
.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:focus,
.back-to-top:focus-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:hover {
  color: var(--c-ink);
  border-color: var(--c-line-strong);
}
@media (max-width: 760px) {
  .back-to-top { bottom: 5rem; right: 1rem; }
}

/* Reduced-motion is an edition-wide contract. Keep it last so it wins over
   every loaded component sheet without requiring a parallel selector list. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
