/* ───────────────────────── tokens ─────────────────────────
   The canvas reads the hex tokens below (paper … accent-3) at runtime,
   so a palette change here restyles the drawings too. Keep them as #hex. */
:root {
  --paper: #f3efe3;
  --paper-2: #e6dfcb;
  --grid-minor: #d5e3d6;
  --grid-major: #a8c8b3;
  --ink: #1e2a32;
  --ink-soft: #56646e;
  --ink-faint: #94a19f;
  --accent: #c4432b;
  --accent-2: #2a62a6;
  --accent-3: #4c8a3a;
  --is-dark: 0;

  --hud-line: rgba(30, 42, 50, 0.26);
  --glass: rgba(243, 239, 227, 0.42);
  --glass-strong: rgba(243, 239, 227, 0.66);
  --glass-blur: blur(14px) saturate(140%);
  --shadow: 0 1px 0 rgba(30, 42, 50, 0.05), 0 10px 30px rgba(30, 42, 50, 0.10);

  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --hand: 'Architects Daughter', 'Bradley Hand', cursive;
  color-scheme: light;
}

/* blueprint */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12161a;
    --paper-2: #0c0f12;
    --grid-minor: #1b2026;
    --grid-major: #272e36;
    --ink: #dae7f1;
    --ink-soft: #8fb0c7;
    --ink-faint: #567893;
    --accent: #ff8a65;
    --accent-2: #6cc2ff;
    --accent-3: #9ad27a;
    --is-dark: 1;
    --hud-line: rgba(143, 176, 199, 0.30);
    --glass: rgba(18, 22, 26, 0.42);
    --glass-strong: rgba(18, 22, 26, 0.68);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12161a;
  --paper-2: #0c0f12;
  --grid-minor: #1b2026;
  --grid-major: #272e36;
  --ink: #dae7f1;
  --ink-soft: #8fb0c7;
  --ink-faint: #567893;
  --accent: #ff8a65;
  --accent-2: #6cc2ff;
  --accent-3: #9ad27a;
  --is-dark: 1;
  --hud-line: rgba(143, 176, 199, 0.30);
  --glass: rgba(18, 22, 26, 0.42);
  --glass-strong: rgba(18, 22, 26, 0.68);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ───────────────────────── base ───────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
#sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
/* every button is frosted glass over the drawing */
button {
  font: inherit;
  color: inherit;
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
::selection { background: var(--accent); color: var(--paper); }

/* ───────────────────────── HUD ───────────────────────── */
.hud { position: fixed; z-index: 5; }

.hud-top {
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 9px;
  border: 1px solid var(--hud-line);
  text-align: left;
  cursor: pointer;
}
.brand-mark {
  width: 34px;
  height: 34px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 229;
}
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand:hover .brand-mark { stroke: var(--accent); }
.brand-kicker {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.brand-name {
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1;
}

.tools { display: flex; gap: 6px; }
.tool {
  min-width: 40px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--hud-line);
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.tool:hover, .brand:hover { border-color: var(--ink); }
.tool[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* every so often a soft point of accent light travels once around each button's border,
   fading in, gliding the full circuit and fading out; staggered so they take turns.
   The layer sits over the 1px border, masked to a ring; a rotating conic gradient is the light. */
@property --sheen-a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
button { position: relative; }
button::after {
  content: '';
  position: absolute;
  inset: -1px; /* over the border */
  padding: 1.5px;
  border-radius: inherit;
  background: conic-gradient(from var(--sheen-a), transparent 0 52%, color-mix(in srgb, var(--accent) 55%, transparent) 72%, var(--accent) 86%, transparent 97%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  animation: sheen 11s linear infinite;
  animation-delay: var(--sheen-delay, 0s);
  pointer-events: none;
}
.tour-btn::after { inset: 0; } /* borderless: trace the button's own edge */
button:disabled::after { display: none; }
@keyframes sheen {
  0%, 74% { --sheen-a: 0deg; opacity: 0; animation-timing-function: cubic-bezier(0.45, 0, 0.35, 1); }
  79% { opacity: 1; }
  93% { opacity: 1; }
  100% { --sheen-a: 360deg; opacity: 0; }
}
/* Spread each glimmer across the 11s cycle instead of clustering the toolbar. */
.brand { --sheen-delay: -8.2s; }
#btn-cv { --sheen-delay: -6s; }
#btn-sound { --sheen-delay: -3.8s; }
#btn-theme { --sheen-delay: -1.6s; }
.fab { --sheen-delay: 0.6s; }
.drawer-close { --sheen-delay: -7.1s; }
.tour-btn.prev { --sheen-delay: -4.9s; }
.tour-btn.next { --sheen-delay: -2.7s; }

.fab {
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  margin-left: -30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hud-line);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: opacity 0.35s ease, visibility 0.35s, transform 0.25s ease, border-color 0.2s;
}
.fab svg { width: 24px; height: 24px; margin-left: 3px; fill: currentColor; }
.fab:hover { border-color: var(--accent); color: var(--accent); transform: scale(1.06); }
body.drawer-open .fab { opacity: 0; visibility: hidden; transform: scale(0.8); }

.scene-dial { display: none; }

.hud-readout {
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.scale { display: flex; align-items: center; gap: 8px; }
.scale i {
  display: block;
  height: 6px;
  border: 1px solid var(--ink-soft);
  border-top: 0;
}

.hud-hint {
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  font-family: var(--hand);
  font-size: 15px;
  color: var(--ink-soft);
  pointer-events: none;
  transition: opacity 0.8s ease;
}
.hud-hint.gone { opacity: 0; }

/* ───────────────────────── drawer ───────────────────────── */
.drawer {
  position: fixed;
  z-index: 10;
  top: 0;
  right: 0;
  width: min(460px, 100vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--hud-line);
  box-shadow: var(--shadow);
  transform: translateX(104%);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-body {
  flex: 1;
  min-height: 0;
  background: var(--glass-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 72px 32px 32px;
}

/* tour footer: ← previous · position · next → */
.drawer-foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  position: relative;
  border-top: 1px solid var(--ink);
  background: var(--glass-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding-bottom: env(safe-area-inset-bottom);
}
.tour-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 12px 16px 13px;
  background: transparent;
  backdrop-filter: none; /* the footer behind it is already frosted */
  -webkit-backdrop-filter: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.tour-btn.next { text-align: right; align-items: flex-end; }
.tour-btn small {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.tour-btn.prev small::before { content: '← '; }
.tour-btn.next small::after { content: ' →'; }
.tour-btn span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.1;
}
.tour-btn:hover:not(:disabled) span, .tour-btn:hover:not(:disabled) small { color: var(--accent); }
.tour-btn.next:not(:disabled) { background: color-mix(in srgb, var(--ink) 84%, transparent); color: var(--paper); }
.tour-btn.next:not(:disabled) small { color: color-mix(in srgb, var(--paper) 70%, transparent); }
.tour-btn.next:hover:not(:disabled) span, .tour-btn.next:hover:not(:disabled) small { color: var(--accent); }
.tour-btn:disabled { cursor: default; opacity: 0.35; }
/* autoplay: the top rule fills with accent, left to right, then the tour advances */
.tour-progress {
  position: absolute;
  left: 0;
  right: 0;
  top: -2px;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.tour-progress.paused { opacity: 0.45; }
.tour-pos {
  align-self: center;
  padding: 0 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--hud-line);
  border-right: 1px solid var(--hud-line);
  line-height: 46px;
}
.drawer-close {
  position: absolute;
  z-index: 1; /* above the frosted body, which is its own layer */
  top: 18px;
  right: 18px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--hud-line);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.drawer-close:hover { border-color: var(--accent); color: var(--accent); }

.d-kicker {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.d-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 44px;
  line-height: 1.02;
  text-wrap: balance;
}
.d-meta {
  margin: 10px 0 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.d-rule {
  height: 1px;
  margin: 22px 0;
  background: var(--ink);
  position: relative;
}
.d-rule::before, .d-rule::after {
  content: '';
  position: absolute;
  top: -4px;
  width: 1px;
  height: 9px;
  background: var(--ink);
}
.d-rule::before { left: 0; }
.d-rule::after { right: 0; }
.d-body p {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.32;
}
.d-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 6px 0 18px;
}
.d-stat {
  padding: 10px 12px;
  border: 1px solid var(--hud-line);
  background: var(--glass);
}
.d-stat b {
  display: block;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 34px;
  line-height: 1;
  color: var(--accent);
}
.d-stat span { font-size: 11px; color: var(--ink-soft); }
.d-bullets {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  line-height: 1.55;
}
.d-bullets li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 8px;
}
.d-bullets li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.8em;
  width: 12px;
  height: 1px;
  background: var(--accent);
}
.d-section h3 {
  margin: 26px 0 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.d-item { margin-bottom: 16px; }
.d-item h4 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 22px; }
.d-item .d-meta { margin: 2px 0 8px; }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.d-tags span {
  padding: 3px 8px;
  border: 1px solid var(--hud-line);
  font-size: 11px;
  background: var(--glass);
}
.d-links { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.d-links a {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--ink);
  background: var(--glass);
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-decoration: none;
  text-transform: uppercase;
}
.d-links a:hover { background: var(--ink); color: var(--paper); }

.noscript { padding: 48px 24px; max-width: 640px; font-family: var(--serif); font-size: 20px; }
.noscript a { color: var(--accent); }

/* ───────────────────────── small screens ───────────────────────── */
@media (max-width: 640px) {
  .scene-dial {
    display: block;
    z-index: 4;
    left: 0;
    right: 0;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 20px);
    height: 20px;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
    transition: none;
  }
  .scene-dial-label {
    position: absolute;
    left: 50%;
    top: 0;
    white-space: nowrap;
    font-family: var(--hand);
    font-size: 13px;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    will-change: transform;
  }
  body.drawer-open .scene-dial { opacity: 0; }
  body.drawer-open .hud-top, body.drawer-open .hud-hint {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
  .hud-top { transition: opacity 0.35s ease, visibility 0.35s; }
  .brand { padding: 6px 10px 7px; gap: 9px; }
  .brand-mark { width: 26px; height: 26px; }
  .brand-kicker { font-size: 8.5px; letter-spacing: 0.1em; white-space: nowrap; }
  .brand-name { font-size: 21px; }
  .tool { min-width: 36px; height: 34px; padding: 0 9px; white-space: nowrap; }
  .hud-readout { display: none; }
  .hud-hint { left: 16px; right: 16px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 72px); text-align: center; }
  .drawer {
    top: auto;
    bottom: 0;
    width: 100%;
    height: 58vh;
    border-left: 0;
    border-top: 1px solid var(--ink);
    transform: translateY(104%);
  }
  .drawer.open { transform: none; }
  .drawer-close { top: 12px; right: 12px; }
  .d-title { font-size: 34px; }
  .drawer-body { padding: 24px 20px 24px; }
  .tour-btn { padding: 10px 12px 11px; }
  .tour-btn span { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer, .fab, .hud-hint, .tour-progress { transition: none; }
  button::after { animation: none; display: none; }
}

/* Personal details open from accent-colored, underlined words in the story. */
.d-ref-link {
  display: inline;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  text-transform: none;
  text-align: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}
.d-ref-link::after { display: none; }
.d-reference {
  margin: 0 0 22px;
  padding: 14px 16px;
  border-left: 1px solid var(--accent);
  background: var(--glass-strong);
}
.d-reference[hidden] { display: none; }
.d-reference h3 { margin: 0 0 10px; font: 12px var(--mono); color: var(--ink-soft); }
.d-reference p { font-size: 16px; }
.d-ref-close { padding: 8px 0; border: 0; background: transparent; color: var(--accent); font: 11px var(--mono); cursor: pointer; }
.d-ref-link:focus-visible, .d-ref-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
