/* ============================================================
   KAYEM Christmas Story — black, warm gold and ivory.
   Mobile first. System fonts only (nothing to download), so the
   first tap on a phone renders immediately.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0c0b09;
  --bg-glow: #2a2215;
  --card: #15130f;
  --card-2: #110f0c;
  --line: #5c4c2e;
  --line-soft: #3a3122;
  --gold: #dcb767;
  --gold-bright: #f3d99a;
  --gold-deep: #a8853f;
  --ivory: #f6eedc;
  --ivory-soft: #d9cfb9;
  --muted: #a49a85;
  --focus: #ffe3a3;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% -8%, var(--bg-glow) 0%, rgba(42, 34, 21, 0) 62%),
    var(--bg);
  color: var(--ivory);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* A faint field of stars behind the top of the page. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    radial-gradient(1px 1px at 12% 8%, #f3d99a 50%, transparent 51%),
    radial-gradient(1px 1px at 82% 5%, #f3d99a 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 68% 16%, #f6eedc 50%, transparent 51%),
    radial-gradient(1px 1px at 27% 22%, #f6eedc 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 28%, #f3d99a 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 6% 34%, #f3d99a 50%, transparent 51%),
    radial-gradient(1px 1px at 48% 3%, #f6eedc 50%, transparent 51%);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 45%);
  mask-image: linear-gradient(to bottom, #000, transparent 45%);
}

a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 6px; }
.xmas-moment-title:focus { outline: none; }

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

.xmas-page {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 36rem;
  margin: 0 auto;
  padding: max(2.25rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* ---------- Header ---------- */

.xmas-head { display: flex; flex-direction: column; align-items: center; margin-bottom: 1.6rem; }

.xmas-star {
  width: 3.4rem;
  height: 3.4rem;
  color: var(--gold);
  margin-bottom: 1rem;
  filter: drop-shadow(0 0 14px rgba(232, 196, 112, 0.35));
}

.xmas-eyebrow {
  margin: 0 0 0.7rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

.xmas-title {
  margin: 0 0 0.65rem;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.1rem, 8.6vw, 2.9rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: var(--gold-bright);
}

.xmas-subtitle { margin: 0; font-size: 0.95rem; line-height: 1.5; color: var(--ivory-soft); }

/* ---------- Card ---------- */

.xmas-card {
  width: 100%;
  padding: clamp(1.4rem, 5.5vw, 2.25rem);
  border-radius: 1.25rem;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--card) 0%, var(--card-2) 100%);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(243, 217, 154, 0.06);
}

.xmas-progress { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.xmas-part,
.xmas-version { margin: 0; text-transform: uppercase; font-weight: 700; }
.xmas-part { font-size: 0.72rem; letter-spacing: 0.16em; color: var(--gold); font-variant-numeric: tabular-nums; }
.xmas-version { font-size: 0.6rem; letter-spacing: 0.14em; color: var(--muted); }

.xmas-bar { height: 3px; margin-top: 0.8rem; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.xmas-bar-fill {
  width: calc(100% / 12);
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-bright));
  transition: width 420ms ease;
}

.xmas-moment { transition: opacity 220ms ease, transform 220ms ease; }
.xmas-moment.is-changing { opacity: 0; transform: translateY(4px); }
body.is-loading .xmas-moment,
body.is-loading .xmas-passage { opacity: 0; visibility: hidden; }
/* If the story can't load, show only the message and Try again. */
body.is-problem .xmas-progress,
body.is-problem .xmas-bar,
body.is-problem .xmas-moment,
body.is-problem .xmas-passage,
body.is-problem .xmas-restart { display: none; }
body.is-problem .xmas-problem { margin: 0 0 1.25rem; }

.xmas-moment-title {
  margin: 1.7rem 0 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.45rem, 6vw, 1.9rem);
  line-height: 1.2;
  color: var(--gold-bright);
  text-wrap: balance;
}

.xmas-note {
  margin: 0.7rem auto 0;
  max-width: 28rem;
  font-size: 0.86rem;
  line-height: 1.5;
  font-style: italic;
  color: var(--muted);
}

.xmas-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  margin: 1rem 0;
  color: var(--gold);
  font-size: 0.75rem;
}
.xmas-divider::before,
.xmas-divider::after { content: ""; width: 3rem; height: 1px; background: linear-gradient(90deg, transparent, var(--line)); }
.xmas-divider::after { transform: scaleX(-1); }

.xmas-verse,
.xmas-verse blockquote { margin: 0; }
.xmas-verse p {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.3rem, 5.6vw, 1.65rem);
  line-height: 1.5;
  color: var(--ivory);
  overflow-wrap: break-word;
  text-wrap: pretty;
}

.xmas-ref {
  margin: 1.1rem 0 0;
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.xmas-finale {
  margin: 1.1rem 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--gold-bright);
}

/* ---------- Full passage ---------- */

.xmas-passage {
  margin: 1.75rem 0 1.25rem;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: rgba(0, 0, 0, 0.22);
}
.xmas-passage summary {
  min-height: 3.1rem;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--gold-bright);
  border-radius: 0.75rem;
  -webkit-tap-highlight-color: transparent;
}
.xmas-passage summary::-webkit-details-marker { display: none; }
.xmas-passage-mark { width: 1.3rem; height: 1.3rem; flex: none; transition: transform 200ms ease; }
.xmas-passage[open] .xmas-passage-mark { transform: rotate(45deg); }
.xmas-passage-body {
  padding: 0.9rem 1rem 1.1rem;
  border-top: 1px solid var(--line-soft);
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--ivory);
}
.xmas-passage[open] .xmas-passage-body { animation: xmas-reveal 240ms ease; }
.xmas-passage-ref {
  margin: 0 0 0.6rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--gold);
}
.xmas-passage-body p.xmas-v { margin: 0 0 0.7rem; }
.xmas-passage-body p.xmas-v:last-child { margin-bottom: 0; }
.xmas-passage-body p.is-featured { color: var(--gold-bright); }
.xmas-passage-body sup {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--gold-deep);
  padding-right: 0.3rem;
  vertical-align: 0.45em;
  line-height: 0;
}

/* ---------- Buttons ---------- */

.xmas-next {
  width: 100%;
  min-height: 3.4rem;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  border: 0;
  border-radius: 0.75rem;
  background: linear-gradient(120deg, #d9b466 0%, #f1d697 100%);
  color: #1a1610;
  font-weight: 750;
  font-size: 1rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transition: filter 150ms ease, transform 150ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.xmas-next:hover { filter: brightness(1.06); }
.xmas-next:active { transform: scale(0.99); }
.xmas-next:disabled { opacity: 0.55; cursor: default; filter: none; transform: none; }

.xmas-restart {
  display: block;
  min-height: 2.75rem;
  margin: 0.85rem auto 0;
  padding: 0.5rem 0.75rem;
  border: 0;
  background: transparent;
  color: var(--ivory-soft);
  font-size: 0.85rem;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 0.25em;
  cursor: pointer;
  touch-action: manipulation;
}
.xmas-restart:hover { color: var(--gold-bright); }
.xmas-restart:disabled { visibility: hidden; }

.xmas-problem { margin: 1rem 0 0; font-size: 0.95rem; line-height: 1.5; color: var(--ivory-soft); }

/* ---------- About + footer ---------- */

.xmas-about { margin: 1.6rem auto 0.5rem; max-width: 26rem; font-size: 0.78rem; line-height: 1.5; color: var(--muted); }
.xmas-about p { margin: 0.25rem 0; }
.xmas-about-mark { display: block; margin-bottom: 0.4rem; color: var(--gold-deep); font-size: 0.8rem; }
.xmas-unsaved { color: var(--gold-bright); }

.xmas-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}
/* Narrow screens: the Scripture credit takes its own centred line, without a dangling separator. */
@media (max-width: 40rem) {
  .xmas-foot > span[aria-hidden="true"] { display: none; }
  .xmas-foot > span:last-child { flex-basis: 100%; }
}
.xmas-brand { color: var(--gold); text-decoration: none; font-weight: 600; }
.xmas-brand:hover { text-decoration: underline; }
.xmas-source { color: inherit; text-decoration: underline; text-decoration-color: rgba(220, 183, 103, 0.5); text-underline-offset: 2px; }
.xmas-source:hover { color: var(--gold); }

@keyframes xmas-reveal { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

@media (min-width: 640px) {
  .xmas-page { padding-top: 3.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .xmas-moment, .xmas-bar-fill, .xmas-next, .xmas-passage-mark { transition: none; }
  .xmas-passage[open] .xmas-passage-body { animation: none; }
}

@media (forced-colors: active) {
  .xmas-bar-fill { background: Highlight; }
  .xmas-next { border: 1px solid ButtonText; }
}
