/* ═══════════════════════════════════════════════════════════════
   waveit — a reading room that watches your hands
   candlelit literary: umber dark, aged paper, antique gold
   fonts: Cormorant (display/body) · Courier Prime (labels/HUD)
   motion rule: transform + opacity only on animated elements
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #0c0806;
  --bg-2: #160e08;
  --paper: #e9dcc3;
  --paper-dim: #cdbb97;
  --ink: #241a12;
  --gold: #c9a25e;
  --gold-bright: #ecd096;
  --gold-dim: #7d6438;
  --text: #d9caac;
  --text-dim: #8d7c60;
  --leather: #3b2013;
  --leather-2: #24120a;
  --ember: #b0602f;
  --serif: 'Cormorant', 'Iowan Old Style', Georgia, serif;
  --mono: 'Courier Prime', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html { height: 100%; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
body.reading { overflow: hidden; height: 100dvh; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
u { text-underline-offset: 3px; }

/* ═══════════════ THE ROOM (ambient) ═══════════════ */
.room { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

.candleglow {
  position: absolute; inset: 0;
  background:
    radial-gradient(120vmax 90vmax at 50% -20%, rgba(196, 128, 54, 0.16), transparent 55%),
    radial-gradient(70vmax 60vmax at 82% 108%, rgba(140, 78, 30, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 46%);
  animation: breathe 7s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 0.85; } 50% { opacity: 1; } }

.vignette {
  position: absolute; inset: 0;
  background: radial-gradient(130% 100% at 50% 44%, transparent 52%, rgba(4, 2, 1, 0.72) 100%);
}

#dust { position: absolute; inset: 0; width: 100%; height: 100%; }

.grain {
  position: absolute; inset: 0; opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

/* ═══════════════ LANDING ═══════════════ */
.landing {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: clamp(18px, 3vh, 34px) clamp(20px, 5vw, 64px);
}

.masthead { display: flex; justify-content: space-between; align-items: center; }

.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 15px; letter-spacing: 0.34em;
  color: var(--gold); text-decoration: none;
}
.wm-wave { width: 34px; height: 12px; }
.wm-wave path { stroke: var(--gold); stroke-width: 1.6; stroke-linecap: round; }

.mast-kin {
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.4em;
  color: var(--text-dim); text-decoration: none; transition: color 0.3s;
}
.mast-kin:hover { color: var(--gold); }

.hero {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  gap: clamp(14px, 2.4vh, 26px);
  padding: clamp(16px, 3vh, 40px) 0;
}

.overline {
  font-family: var(--mono); font-size: clamp(9px, 1.1vw, 11px);
  letter-spacing: 0.42em; color: var(--text-dim);
}

.headline {
  font-weight: 300; line-height: 0.98;
  font-size: clamp(52px, 9.2vw, 118px);
  letter-spacing: -0.015em; color: var(--text);
}
.hl-line { display: block; }
.hl-wave { position: relative; font-style: italic; font-weight: 400; color: var(--gold-bright); }
.swash {
  position: absolute; left: -4%; bottom: -0.28em; width: 108%; height: 0.32em;
  overflow: visible;
}
.swash path {
  stroke: var(--gold); stroke-width: 2.4; stroke-linecap: round;
  stroke-dasharray: 240; stroke-dashoffset: 240;
  animation: swash-draw 1.4s cubic-bezier(0.6, 0, 0.2, 1) 1.15s forwards;
}
@keyframes swash-draw { to { stroke-dashoffset: 0; } }

.lede {
  max-width: 500px;
  font-size: clamp(17px, 2vw, 20px); font-weight: 400;
  line-height: 1.55; color: var(--text-dim); font-style: italic;
}

/* ── the self-turning book ── */
.hero-book { perspective: 1400px; margin-top: clamp(2px, 1vh, 12px); }
.hb-tilt { position: relative; animation: hb-float 6s ease-in-out infinite; }
@keyframes hb-float { 0%, 100% { transform: rotateX(48deg) translateY(0); } 50% { transform: rotateX(48deg) translateY(-6px); } }
.hb-tilt { transform-style: preserve-3d; }

.hb-book {
  position: relative; width: clamp(240px, 30vw, 330px); aspect-ratio: 2 / 1.28;
  transform-style: preserve-3d;
}
.hb-page {
  position: absolute; top: 0; bottom: 0; width: 50%;
  background: linear-gradient(105deg, var(--paper) 0%, #ddcda9 88%, #c9b78f 100%);
  display: flex; flex-direction: column; gap: 9%; padding: 8% 9%;
}
.hb-left  { left: 0;  border-radius: 4px 0 0 4px; background: linear-gradient(255deg, var(--paper) 0%, #ddcda9 88%, #c9b78f 100%); }
.hb-right { right: 0; border-radius: 0 4px 4px 0; }
.hb-page i {
  display: block; height: 5%; border-radius: 2px;
  background: rgba(64, 46, 28, 0.24);
}
.hb-page i:nth-child(2) { width: 86%; } .hb-page i:nth-child(3) { width: 92%; }
.hb-page i:nth-child(4) { width: 70%; } .hb-page i:nth-child(5) { width: 40%; }

.hb-leaf {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 50%;
  transform-origin: left center; transform-style: preserve-3d;
}
.hb-leaf span {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 0 4px 4px 0;
}
.hb-leaf .f { background: linear-gradient(105deg, #f0e4cd 0%, #e0d1ae 90%); }
.hb-leaf .b { background: linear-gradient(255deg, #e6d9be 0%, #d5c49e 90%); transform: rotateY(180deg); border-radius: 4px 0 0 4px; }
.hb-l1 { animation: hb-flip 5.6s cubic-bezier(0.45, 0.05, 0.2, 1) infinite; }
.hb-l2 { animation: hb-flip 5.6s cubic-bezier(0.45, 0.05, 0.2, 1) 2.8s infinite; }
@keyframes hb-flip {
  0%, 12%  { transform: rotateY(0); }
  46%, 100% { transform: rotateY(-180deg); }
}

.hb-spine {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 12%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(40, 24, 10, 0.4) 50%, transparent);
}
.hb-shadow {
  position: absolute; left: 4%; right: 4%; bottom: -16%; height: 18%;
  background: radial-gradient(50% 100% at 50% 50%, rgba(0, 0, 0, 0.55), transparent 70%);
  transform: translateZ(-40px);
}

.steps {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 16px;
  font-family: var(--mono); font-size: clamp(8px, 1vw, 10px);
  letter-spacing: 0.3em; color: var(--text-dim);
}
.steps span { white-space: nowrap; }
.steps i { width: clamp(20px, 4vw, 54px); height: 1px; background: var(--gold-dim); }

/* ── landing footer ── */
.landing-foot { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.open-btn {
  position: relative;
  padding: 18px 58px 16px;
  background: linear-gradient(160deg, var(--leather), var(--leather-2));
  border-radius: 3px;
  transition: transform 0.35s cubic-bezier(0.2, 0.6, 0.2, 1);
}
.ob-ring {
  position: absolute; inset: 5px;
  border: 1px solid var(--gold-dim); border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(201, 162, 94, 0.16) inset;
  transition: border-color 0.35s, box-shadow 0.35s;
}
.open-btn:hover { transform: translateY(-2px); }
.open-btn:hover .ob-ring { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(236, 208, 150, 0.35) inset; }
.ob-label { display: block; font-size: 24px; font-weight: 500; color: var(--gold-bright); font-variant: small-caps; letter-spacing: 0.06em; }
.ob-sub { display: block; margin-top: 2px; font-family: var(--mono); font-size: 9px; letter-spacing: 0.34em; color: var(--text-dim); }

.demo-link {
  font-family: var(--serif); font-style: italic; font-size: 16px;
  color: var(--text-dim); transition: color 0.3s;
}
.demo-link:hover { color: var(--gold-bright); }
.demo-link u { color: var(--gold); }

.privacy {
  margin-top: 6px;
  font-family: var(--mono); font-size: 8.5px; letter-spacing: 0.3em;
  color: rgba(141, 124, 96, 0.65); text-align: center;
}

/* ── entrance reveals ── */
.reveal {
  opacity: 0; transform: translateY(18px);
  animation: reveal 0.9s cubic-bezier(0.2, 0.6, 0.2, 1) forwards;
  animation-delay: calc(var(--d) * 130ms + 150ms);
}
@keyframes reveal { to { opacity: 1; transform: translateY(0); } }

/* ═══════════════ READER ═══════════════ */
.reader {
  position: relative; z-index: 1;
  height: 100dvh; display: flex; flex-direction: column;
}

.hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 3vw, 30px);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.22em;
  color: var(--text-dim);
}
.hud-top { gap: 12px; }
.hud-right { display: flex; align-items: center; gap: 10px; }

.hud-btn {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.22em;
  color: var(--text-dim); padding: 6px 8px;
  transition: color 0.3s;
}
.hud-btn:hover { color: var(--gold-bright); }

.hud-title {
  flex: 1; text-align: center;
  font-family: var(--serif); font-style: italic; font-size: 15px; letter-spacing: 0.04em;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.eye-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border: 1px solid rgba(125, 100, 56, 0.4); border-radius: 999px;
  font-size: 8.5px; letter-spacing: 0.24em; text-transform: uppercase;
}
.eye-dot { width: 5px; height: 5px; border-radius: 50%; background: #574a35; }
.eye-pill[data-state="wake"] .eye-dot { background: var(--ember); animation: pulse 1.1s ease-in-out infinite; }
.eye-pill[data-state="watching"] .eye-dot { background: var(--gold-dim); }
.eye-pill[data-state="hand"] .eye-dot { background: var(--gold-bright); animation: pulse 2s ease-in-out infinite; }
.eye-pill[data-state="hand"] { border-color: var(--gold-dim); color: var(--gold); }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: 0.6; } }

/* ── the stage & the book ── */
.stage {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  perspective: 2400px;
  min-height: 0;
}

.book {
  position: relative;
  transform-style: preserve-3d;
  opacity: 0; transform: scale(0.94) translateY(10px);
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.2, 0.6, 0.2, 1);
}
.book.open { opacity: 1; transform: scale(1) translateY(0); }

/* leather binding behind the pages */
.book::before {
  content: ''; position: absolute; z-index: -1;
  inset: -12px -14px -17px -14px; border-radius: 6px;
  background: linear-gradient(150deg, #4a2a17 0%, var(--leather) 30%, var(--leather-2) 100%);
  box-shadow:
    0 0 0 1px rgba(201, 162, 94, 0.22) inset,
    0 0 0 5px rgba(0, 0, 0, 0.18) inset,
    0 30px 70px -18px rgba(0, 0, 0, 0.85),
    0 6px 22px rgba(0, 0, 0, 0.5);
}

.page { position: absolute; top: 0; bottom: 0; width: 50%; overflow: hidden; }
.pg-left  { left: 0; }
.pg-right { right: 0; }
.book.single .pg-left { display: none; }
.book.single .pg-right { width: 100%; }

.page canvas, .leaf-face canvas { display: block; width: 100%; height: 100%; }

/* leather board shown where there is no page (cover position) */
.board {
  display: none; position: absolute; inset: 0;
  background: linear-gradient(150deg, #46271539, transparent 40%), linear-gradient(160deg, var(--leather), var(--leather-2));
}
.page.empty canvas { visibility: hidden; }
.page.empty .board { display: block; }

/* stacked page edges */
.pg-right::after, .pg-left::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 5px; pointer-events: none;
}
.pg-right::after {
  right: 0;
  background: repeating-linear-gradient(90deg, rgba(120, 96, 60, 0.35) 0 1px, rgba(240, 228, 200, 0.5) 1px 2px);
}
.pg-left::after {
  left: 0;
  background: repeating-linear-gradient(90deg, rgba(240, 228, 200, 0.5) 0 1px, rgba(120, 96, 60, 0.35) 1px 2px);
}
.book.single .pg-right::after { display: none; }

.spine-shade {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 12%;
  transform: translateX(-50%); z-index: 2; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(36, 20, 8, 0.28) 48%, rgba(36, 20, 8, 0.34) 52%, transparent);
}
.book.single .spine-shade { display: none; }

/* ── the turning leaf ── */
.leaf {
  position: absolute; top: 0; bottom: 0; right: 0; width: 50%;
  transform-origin: left center; transform-style: preserve-3d;
  z-index: 3; display: none;
}
.book.single .leaf { width: 100%; }
.leaf.show { display: block; }
.leaf.from-left { left: 0; right: auto; transform-origin: right center; }

.leaf-face {
  position: absolute; inset: 0; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.lf-back { transform: rotateY(180deg); }

.leaf-face .shade { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.lf-front .shade { background: linear-gradient(90deg, rgba(30, 18, 8, 0.42), transparent 55%); }
.lf-back  .shade { background: linear-gradient(270deg, rgba(30, 18, 8, 0.42), transparent 55%); }
.leaf.turning .lf-front .shade { animation: shade-in-out var(--flip-ms, 850ms) ease-in-out; }
.leaf.turning .lf-back  .shade { animation: shade-out-in var(--flip-ms, 850ms) ease-in-out; }
@keyframes shade-in-out { 0% { opacity: 0; } 45% { opacity: 1; } 100% { opacity: 0; } }
@keyframes shade-out-in { 0% { opacity: 1; } 55% { opacity: 1; } 100% { opacity: 0; } }

/* ── wave streak feedback ── */
.wave-streak {
  position: absolute; top: 50%; left: 50%; z-index: 5;
  width: min(46vw, 560px); height: 2px; border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--gold-bright) 45%, var(--gold) 55%, transparent);
  opacity: 0; transform: translate(-50%, -50%);
  pointer-events: none;
}
.wave-streak.go-left  { animation: streak-left 0.7s cubic-bezier(0.2, 0.6, 0.2, 1); }
.wave-streak.go-right { animation: streak-right 0.7s cubic-bezier(0.2, 0.6, 0.2, 1); }
@keyframes streak-left {
  0%   { opacity: 0; transform: translate(10%, -50%) scaleX(0.4); }
  30%  { opacity: 0.9; }
  100% { opacity: 0; transform: translate(-110%, -50%) scaleX(1); }
}
@keyframes streak-right {
  0%   { opacity: 0; transform: translate(-110%, -50%) scaleX(0.4); }
  30%  { opacity: 0.9; }
  100% { opacity: 0; transform: translate(10%, -50%) scaleX(1); }
}

/* ── loading ── */
.loading {
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column; gap: 18px;
  align-items: center; justify-content: center;
}
.loading p { font-family: var(--mono); font-size: 10px; letter-spacing: 0.3em; color: var(--text-dim); text-transform: uppercase; }
.load-leaf {
  width: 26px; height: 36px; border-radius: 2px 6px 6px 2px;
  background: linear-gradient(105deg, var(--paper), #d5c49e);
  transform-origin: left center;
  animation: load-flip 1.1s cubic-bezier(0.45, 0.05, 0.2, 1) infinite;
}
@keyframes load-flip { 0% { transform: rotateY(0); } 55%, 100% { transform: rotateY(-180deg); } }

.hud-bottom { justify-content: center; flex-direction: column; gap: 4px; padding-top: 6px; }
.page-count { font-size: 11px; letter-spacing: 0.3em; color: var(--gold); cursor: pointer; }
.pc-input {
  width: 76px; background: none; border: 0; border-bottom: 1px solid var(--gold-dim);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em; color: var(--gold-bright);
  text-align: center; outline: none; -moz-appearance: textfield; appearance: textfield;
}
.pc-input::-webkit-outer-spin-button, .pc-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* returning from the reader: no second entrance ceremony */
.landing.settled .reveal { animation: none; opacity: 1; transform: none; }
.landing.settled .swash path { animation: none; stroke-dashoffset: 0; }
.hud-hint { font-size: 8.5px; letter-spacing: 0.26em; color: rgba(141, 124, 96, 0.7); text-transform: uppercase; }

/* ── the eye (camera preview) ── */
.eye {
  position: fixed; right: 18px; bottom: 64px; z-index: 10;
  width: 150px; aspect-ratio: 4 / 3;
  border-radius: 8px; overflow: hidden;
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.eye.on { opacity: 1; transform: translateY(0); }
.eye video, .eye canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1); /* mirror = selfie view, matches user's POV */
}
.eye video { filter: sepia(0.35) brightness(0.75) contrast(1.05); }
.eye-frame {
  position: absolute; inset: 0; border-radius: 8px; pointer-events: none;
  box-shadow: 0 0 0 1px rgba(201, 162, 94, 0.5) inset, 0 0 0 4px rgba(12, 8, 6, 0.55) inset;
}

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 20;
  transform: translateX(-50%);
  padding: 12px 22px; border-radius: 3px;
  background: rgba(22, 13, 8, 0.92);
  box-shadow: 0 0 0 1px rgba(201, 162, 94, 0.3) inset, 0 12px 30px rgba(0, 0, 0, 0.5);
  font-family: var(--serif); font-style: italic; font-size: 15.5px; color: var(--text);
  text-align: center; max-width: min(84vw, 480px);
  opacity: 0; transition: opacity 0.45s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 720px) {
  .headline { line-height: 1.02; }
  .lede { font-size: 15.5px; max-width: 320px; }
  .steps { gap: 9px; } .steps i { width: 14px; }
  .ob-label { font-size: 20px; }
  .open-btn { padding: 15px 44px 13px; }
  .hero-book { display: none; } /* small screens: keep the hero airy */
  .hud-title { display: none; }
  .eye { width: 108px; right: 12px; bottom: 76px; }
  .hud-hint { max-width: 86vw; }
}
@media (max-height: 640px) and (min-width: 721px) {
  .hero-book { display: none; }
}

/* ═══════════════ REDUCED MOTION ═══════════════ */
@media (prefers-reduced-motion: reduce) {
  .candleglow, .hb-tilt, .hb-l1, .hb-l2, .load-leaf { animation: none; }
  .reveal { animation-duration: 0.01s; animation-delay: 0s; }
  .swash path { animation: none; stroke-dashoffset: 0; }
  #dust { display: none; }
}
