/* DM ORIGINALS: shared foundation. Section files add only what their chapter needs. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--abyss);
  scroll-padding-top: 24px;
  scrollbar-color: var(--navy-600) var(--abyss);
  scrollbar-width: thin;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: var(--step-body);
  line-height: 1.65;
  color: var(--paper);
  /* The water darkens as you go down: lit surface, then the deep, then the abyss */
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(43, 64, 105, 0.55), transparent 62%),
    linear-gradient(180deg, var(--navy-800) 0%, var(--deep) 22%, var(--navy-900) 48%, var(--deep) 74%, var(--abyss) 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  caret-color: var(--tungsten);
  padding-bottom: var(--tabbar-space);
}

::selection { background: var(--tungsten); color: var(--abyss); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--abyss); }
::-webkit-scrollbar-thumb { background: var(--navy-600); border-radius: var(--r-pill); border: 2px solid var(--abyss); }

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.28em; }
a:hover { text-decoration-color: var(--tungsten); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--tungsten);
  outline-offset: 3px;
  border-radius: 6px;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.005em;
  text-wrap: balance;
}
p { text-wrap: pretty; }

/* Latin runs inside Hebrew keep their own direction */
.ltr { direction: ltr; unicode-bidi: isolate; }
/* a short Latin name (D-Call, AI You Ready) never breaks across lines, not even at its hyphen */
.ltr--keep { white-space: nowrap; }
.num { font-family: var(--font-slate); font-weight: 500; font-variant-numeric: tabular-nums lining-nums; letter-spacing: 0.01em; }

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

.skip-link {
  position: fixed; inset-inline-start: 12px; top: 12px; z-index: var(--z-sheet);
  padding: 10px 18px; border-radius: var(--r-pill);
  background: var(--tungsten); color: var(--abyss); font-weight: 500; text-decoration: none;
  transform: translateY(-160%); transition: transform var(--t-micro) var(--ease-out);
}
.skip-link:focus-visible { transform: none; }

/* ------------------------------------------------------------------ layout */

.wrap {
  width: 100%;
  max-width: min(calc(var(--wrap) + 2 * var(--gutter)), calc(100% - 2 * var(--edge) + 2 * var(--gutter)));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.chapter {
  position: relative;
  z-index: var(--z-content);
  padding-block: var(--chapter-pad);
}

/* A chapter opens with a title set like a scene card. No label above it. */
.chapter-title {
  font-size: clamp(1.9rem, 1.2rem + 3vw, 3.25rem);
  max-width: 16ch;
}
/* The one exception: a chapter that turns to the reader (the share chapter) may open with a lead-in
   line. It is set in the title's face, smaller and quieter, so it reads as the first half of the title,
   never as a label */
.chapter-kicker {
  margin-bottom: var(--s-2);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.3rem, 1rem + 1.3vw, 1.85rem);
  line-height: 1.2;
  color: var(--ink-2);
}
.chapter-lede {
  margin-top: var(--s-5);
  font-size: var(--step-body-l);
  line-height: 1.6;
  color: var(--ink-2);
  max-width: 46ch;
}

/* The studio mark sits where a streaming service keeps its logo */
.studio-slate {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 22px);
  inset-inline-start: var(--gutter);
  z-index: var(--z-slate);
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-slate); font-weight: 500;
  font-size: var(--step-micro); letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--paper);
  text-decoration: none;
  min-height: 44px;
  margin-block: -12px;  /* a full-size tap target, drawn in the same place */
}
.studio-slate img { width: 22px; height: auto; }

/* ------------------------------------------------------------------ buttons */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--paper);
  --btn-line: var(--line-strong);
  display: inline-flex; align-items: center; gap: 12px;
  min-height: 48px;
  padding-block: 6px;
  padding-inline: 22px 6px;
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: inset 0 0 0 1px var(--btn-line);
  font-family: var(--font-ui); font-weight: 500; font-size: 1rem; line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: transform 160ms var(--ease-out), background-color var(--t-micro) var(--ease-out), box-shadow var(--t-micro) var(--ease-out), color var(--t-micro) var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn:hover { --btn-line: rgba(242, 238, 230, 0.34); }

/* Button-in-button: the icon lives in its own round well, flush to the far edge */
.btn__icon {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border-radius: 50%;
  background: rgba(242, 238, 230, 0.08);
  transition: transform var(--t-micro) var(--ease-spring), background-color var(--t-micro) var(--ease-out);
}
.btn__icon svg { width: 18px; height: 18px; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover .btn__icon { transform: translateX(-3px) scale(1.06); }
}
.btn--no-icon { padding-inline: 24px; }

/* Primary: paper at rest. The bulb's light reaches it only when a hand or focus does. */
.btn--light {
  --btn-bg: var(--paper);
  --btn-fg: var(--abyss);
  --btn-line: transparent;
  box-shadow: 0 12px 26px -14px rgba(2, 5, 14, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.btn--light:hover,
.btn--light:focus-visible,
.btn--light:active { --btn-bg: var(--tungsten); }
.btn--light .btn__icon { background: rgba(5, 9, 20, 0.12); }

.btn--quiet { --btn-bg: rgba(242, 238, 230, 0.04); }

.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

/* Round icon-only control (close, next, previous) */
.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border-radius: 50%;
  background: rgba(242, 238, 230, 0.06);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--paper);
  transition: background-color var(--t-micro) var(--ease-out), transform 160ms var(--ease-out);
}
.icon-btn:hover { background: rgba(242, 238, 230, 0.12); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; }

/* Icons: authored, one stroke weight everywhere */
.ico { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ surfaces */

/* Double bezel: a glass plate seated in a machined tray */
.bezel {
  padding: 6px;
  border-radius: var(--r-shell);
  background: rgba(242, 238, 230, 0.035);
  box-shadow: inset 0 0 0 1px var(--line), 0 40px 80px -40px rgba(2, 5, 14, 0.9);
}
.bezel__core {
  border-radius: var(--r-core);
  background: linear-gradient(180deg, var(--surface-raised), var(--surface-solid));
  box-shadow: inset 0 1px 0 rgba(242, 238, 230, 0.10), inset 0 0 0 1px rgba(242, 238, 230, 0.05);
}

.tag {
  display: inline-flex; align-items: center;
  min-height: 28px; padding-inline: 12px;
  border-radius: var(--r-pill);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font-size: var(--step-small); font-weight: 500; line-height: 1;
  color: var(--ink-2);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ depth reveal */

/* Visible by default. Only when motion is welcome does content wait in the deep. */
.js-motion [data-depth] {
  transition:
    opacity var(--t-reveal) var(--ease-out),
    transform 1100ms var(--ease-out),
    filter var(--t-reveal) var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms);
}
.js-motion [data-depth]:not(.is-in) {
  opacity: 0;
  transform: scale(0.94) translateY(18px);
  filter: blur(10px);
}
/* A chapter boundary is a deeper push: its title surfaces from further down than anything inside it */
.js-motion .chapter-title[data-depth] {
  transition:
    opacity 1100ms var(--ease-out),
    transform 1500ms var(--ease-out),
    filter 1100ms var(--ease-out);
}
.js-motion .chapter-title[data-depth]:not(.is-in) {
  transform: scale(0.8) translateY(32px);
  filter: blur(18px);
}

/* ------------------------------------------------------------------ chapter bar */

.tabbar {
  position: fixed;
  z-index: var(--z-tabbar);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 28px), 480px);
  padding: 5px;
  border-radius: var(--r-pill);
  background: rgba(10, 18, 38, 0.72);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 1px 0 rgba(242, 238, 230, 0.08), 0 18px 40px -16px rgba(2, 5, 14, 0.9);
}
.tabbar ul { list-style: none; padding: 0; display: grid; grid-template-columns: 52px repeat(3, 1fr); gap: 2px; }
.tabbar__up a svg { width: 20px; height: 20px; }
.tabbar a {
  position: relative;
  display: grid; place-items: center;
  min-height: 46px;
  padding-inline: 6px;
  border-radius: var(--r-pill);
  font-size: 0.9375rem; font-weight: 500; line-height: 1.1;
  color: var(--ink-2);
  text-decoration: none; text-align: center;
  white-space: nowrap;
  transition: color var(--t-micro) var(--ease-out), background-color 360ms var(--ease-out), transform 160ms var(--ease-out);
}
.tabbar a:hover { color: var(--paper); }
.tabbar a:active { transform: scale(0.96); }
.tabbar a[aria-current="true"] {
  color: var(--abyss);
  background: var(--paper);
  box-shadow: 0 6px 16px -10px rgba(2, 5, 14, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.tabbar a[aria-current="true"]:hover,
.tabbar a:focus-visible { color: var(--abyss); background: var(--tungsten); }
.tabbar .ltr { font-family: var(--font-slate); font-weight: 500; font-size: 0.75rem; letter-spacing: 0.14em; }
/* wide screens: the bar stands upright on the right edge, halfway down, in reading order from the top */
@media (min-width: 1200px) {
  .tabbar {
    left: auto;
    bottom: auto;
    right: calc(env(safe-area-inset-right, 0px) + 16px);
    top: 50%;
    transform: translateY(-50%);
    width: max-content;
    border-radius: 28px;
  }
  .tabbar ul { grid-template-columns: minmax(84px, max-content); gap: 4px; }
  .tabbar a { min-height: 44px; padding-inline: 12px; }
}

/* ------------------------------------------------------------------ sheet (dialog) */

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--surface-solid);
  color: var(--paper);
  box-shadow: inset 0 1px 0 rgba(242, 238, 230, 0.10), 0 -30px 80px -20px rgba(2, 5, 14, 0.9);
  overflow: hidden;
  z-index: var(--z-sheet);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop {
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.sheet__bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: flex-end;
  padding: 14px 14px 0;
}
.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--gutter) calc(var(--s-10) + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 820px) {
  .sheet {
    inset: 0;
    margin: auto;
    width: min(760px, calc(100% - 64px));
    max-height: min(86dvh, 880px);
    border-radius: 28px;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: sheet-rise var(--t-sheet) var(--ease-spring); }
  .sheet[open]::backdrop { animation: scrim-in 420ms var(--ease-out); }
  @media (min-width: 820px) {
    .sheet[open] { animation: sheet-surface var(--t-sheet) var(--ease-spring); }
  }
}
@keyframes sheet-rise { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheet-surface { from { transform: scale(0.94); opacity: 0; filter: blur(8px); } to { transform: none; opacity: 1; filter: none; } }
@keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
/* Closing by hand: a short fall, faster than the rise. Esc closes at once (keyboard actions never animate). */
@media (prefers-reduced-motion: no-preference) {
  .sheet.is-closing { animation: sheet-sink 200ms var(--ease-out) forwards; }
  .sheet.is-closing::backdrop { animation: scrim-out 200ms var(--ease-out) forwards; }
  @media (min-width: 820px) {
    .sheet.is-closing { animation: sheet-sink-wide 180ms var(--ease-out) forwards; }
  }
}
@keyframes sheet-sink { to { transform: translateY(24%); opacity: 0; } }
@keyframes sheet-sink-wide { to { transform: scale(0.97); opacity: 0; } }
@keyframes scrim-out { to { opacity: 0; } }

html.sheet-open { overflow: hidden; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: calc(var(--tabbar-space) + 10px);
  transform: translate(-50%, 12px);
  max-width: calc(100% - 40px);
  padding: 12px 20px;
  border-radius: var(--r-pill);
  background: var(--paper);
  color: var(--abyss);
  font-weight: 500;
  box-shadow: 0 16px 40px -14px rgba(2, 5, 14, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);  /* leaving: quick */
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); transition: opacity 280ms var(--ease-out), transform 420ms var(--ease-spring); }

/* ------------------------------------------------------------------ end credits */

.credits {
  position: relative;
  padding-block: var(--chapter-pad) calc(var(--s-8) + var(--tabbar-space));
  text-align: center;
  overflow: hidden;
}
.credits__role {
  margin-top: var(--s-3);
  font-size: var(--step-body);
  color: var(--ink-2);
}
.credits__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step-display-xl);
  line-height: 1;
}
.credits__line {
  margin: var(--s-6) auto 0;
  max-width: 36ch;
  color: var(--ink-2);
  font-size: var(--step-body-l);
}
.credits__actions {
  margin-top: var(--s-6);
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s-3);
}
.credits__mark { width: 56px; margin: 0 auto var(--s-5); opacity: 0.9; }
.credits__fine {
  margin-top: var(--s-10);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  font-size: var(--step-micro);
  color: var(--ink-3);
}
.credits__fine .ltr { font-family: var(--font-slate); font-weight: 500; letter-spacing: 0.3em; text-transform: uppercase; }
.credits__legal a { color: var(--ink-2); text-underline-offset: 0.22em; padding-block: 8px; }
.credits__legal a:hover { color: var(--tungsten); }

/* ------------------------------------------------------------------ grain */

.grain {
  position: fixed; inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 1.1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ------------------------------------------------------------------ preferences */

@media (prefers-reduced-motion: reduce) {
  /* Transitions go to zero (not 1ms) so a reveal and a focus() in the same step still land:
     a 1ms visibility transition leaves the element hidden for the first frame. */
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}
@media (prefers-reduced-transparency: reduce) {
  .tabbar { background: var(--surface-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .sheet::backdrop { background: rgba(5, 9, 20, 0.92); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (forced-colors: active) {
  .tabbar a[aria-current="true"] { outline: 2px solid CanvasText; }
  .btn { border: 1px solid ButtonText; }
}
