/* Layout for the 52 Emotions site: the book, and a few quiet lines under it.
   Colors, type, spacing and components come from graphite.css. */

* { box-sizing: border-box; }

html { height: 100%; }

:root {
  /* How far the 3D canvas reaches below the book's area, under the text, so
     the book's soft shadow fades out instead of meeting an edge. Above, it
     reaches the top of the page (--top-bleed, set by book.js). */
  --bleed: clamp(56px, 12vh, 160px);
  /* The even gap between the branding, the book and what's under it. */
  --gap: clamp(16px, 3.5vh, 40px);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

body {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background: var(--background);
  color: var(--foreground);
  font: 400 14px/20px var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }
button { font: inherit; color: inherit; }
h2, p { margin: 0; }

/* ------------------------------------------------------- floating masthead */

.masthead {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 var(--space-5);
  pointer-events: none;
}

.site-actions { position: absolute; top: 9px; right: var(--space-5); z-index: 2; display: grid; justify-items: end; gap: 14px; }
.site-actions > * { pointer-events: auto; }

.brand {
  position: relative;
  z-index: 2;
  pointer-events: auto;
  padding-top: 2px; /* Bebas sits a touch high in its line box */
  font: 400 24px/1 var(--font-display);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity var(--duration-fast) var(--ease-standard);
}

.brand:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

/* The waitlist control. Closed, it's a "Waitlist" button. Opening it grows the
   outline leftward into an email field while the button shrinks into a white
   "Join" pill at its right end; the labels crossfade on the way. One element
   does both jobs, so nothing invisible can sit on top of anything clickable.
   The button's sizes are in px rather than %, so it shrinks straight into the
   pill instead of first stretching along with the growing field. */
.tw {
  position: relative;
  width: 96px;
  height: var(--control-md);
  margin: 0;
  border: 1px solid var(--gray-alpha-200);
  border-radius: var(--radius-base);
  background: var(--background);
  transition:
    width 380ms var(--ease-snap),
    border-color var(--duration-base) var(--ease-standard),
    box-shadow var(--duration-base) var(--ease-standard);
}

.tw:not(.is-open):not(.is-joined):hover { border-color: var(--gray-alpha-300); }
.tw.is-open { width: min(340px, calc(100vw - 2 * var(--space-5))); }
.tw.is-joined { width: 124px; }
.tw.is-open:focus-within { border-color: var(--foreground); box-shadow: 0 0 0 0.5px var(--foreground); }
.tw.is-invalid,
.tw.is-invalid:focus-within { border-color: var(--destructive); box-shadow: 0 0 0 0.5px var(--destructive); animation: gr-shake 420ms ease-in-out; }

/* The field fills the bar, under the Join pill, so a click anywhere in the
   open bar lands in it. */
.tw-input {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  padding: 0 64px 0 var(--space-3);
  border: 0;
  border-radius: calc(var(--radius-base) - 1px);
  outline: none;
  background: transparent;
  color: var(--foreground);
  font: 400 13px/20px var(--font-sans);
  opacity: 0;
  visibility: hidden;
  transform: translateX(10px);
  transition:
    opacity 120ms var(--ease-standard),
    transform 380ms var(--ease-snap),
    visibility 0s linear 120ms;
}

.tw-input::placeholder { color: var(--subtle); }

/* Keep Chrome's autofill tint from painting a box inside the bar. */
.tw-input:-webkit-autofill,
.tw-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--foreground);
  -webkit-box-shadow: 0 0 0 40px var(--background) inset;
  caret-color: var(--foreground);
}

.tw.is-open .tw-input {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 240ms var(--ease-out) 120ms,
    transform 420ms var(--ease-snap) 60ms,
    visibility 0s;
}

.tw-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 94px; /* the closed bar, inside its border */
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: calc(var(--radius-base) - 1px);
  background: transparent;
  color: var(--foreground);
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  cursor: pointer;
  transition:
    top 380ms var(--ease-snap),
    right 380ms var(--ease-snap),
    width 380ms var(--ease-snap),
    height 380ms var(--ease-snap),
    border-radius 380ms var(--ease-snap),
    background-color 240ms var(--ease-standard),
    color 240ms var(--ease-standard);
}

.tw-btn:hover { background: var(--gray-alpha-50); }
.tw-btn:focus-visible { outline: none; background: var(--gray-alpha-100); }

.tw.is-open .tw-btn {
  top: 3px;
  right: 3px;
  width: 54px;
  height: 24px;
  border-radius: var(--radius-md);
  background: var(--foreground);
  color: var(--background);
}

.tw.is-open .tw-btn:hover { background: var(--gray-800); }
.tw.is-open .tw-btn:active { background: var(--gray-700); }
.tw.is-open .tw-btn:focus-visible { box-shadow: 0 0 0 2px var(--background), 0 0 0 3.5px var(--foreground); }
.tw.is-joined .tw-btn { width: 122px; color: var(--secondary); cursor: default; }
.tw.is-joined .tw-btn:hover { background: transparent; }

/* The outgoing label blurs and shrinks away quickly; the incoming one waits
   a beat, then sharpens into place as the button settles. */
.tw-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  white-space: nowrap;
  opacity: 0;
  filter: blur(2px);
  transform: scale(0.9);
  transition:
    opacity 140ms var(--ease-standard),
    filter 140ms var(--ease-standard),
    transform 320ms var(--ease-snap);
}

.tw-label[data-for="open"] { font-size: 12px; }

.tw:not(.is-open):not(.is-joined) .tw-label[data-for="closed"],
.tw.is-open .tw-label[data-for="open"],
.tw.is-joined:not(.is-open) .tw-label[data-for="joined"] {
  opacity: 1;
  filter: none;
  transform: none;
  transition:
    opacity 220ms var(--ease-out) 110ms,
    filter 220ms var(--ease-out) 110ms,
    transform 380ms var(--ease-snap) 60ms;
}

.tw-btn[data-loading] { pointer-events: none; }
.tw-btn[data-loading] .tw-label { opacity: 0; transition: none; }
.tw-btn[data-loading]::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 12px;
  height: 12px;
  margin: auto;
  border: 1.5px solid var(--gray-500);
  border-top-color: var(--background);
  border-radius: var(--radius-full);
  animation: gr-spin 1s linear infinite;
}

/* -------------------------------------------------------------------- book */

.book-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  margin: var(--gap) 0;
  padding: 0 clamp(24px, 4vw, 72px);
}

.stage { position: relative; min-width: 0; min-height: 0; touch-action: pan-y; user-select: none; -webkit-user-select: none; }

.book-nav { display: grid; width: 96px; gap: 2px; opacity: 0; }
.is-ready .book-nav { opacity: 1; }
.book-nav .book-button { justify-content: center; }
.book-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--secondary);
  font-size: 13px;
  line-height: 20px;
  text-align: left;
  cursor: pointer;
  transition: color var(--duration-base) var(--ease-standard), background-color var(--duration-base) var(--ease-standard), transform 160ms var(--ease-out);
}
.book-button svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.book-button[aria-current="page"] { color: var(--foreground); }
.book-button:focus-visible { outline: 1px solid var(--foreground); outline-offset: 3px; }
.book-button:active:not(:disabled) { transform: scale(0.97); }
.book-button:disabled { opacity: 0.28; cursor: default; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* This overlay follows the rendered cover edge; it never intercepts a turn. */
.book-hint {
  position: absolute;
  z-index: 4;
  display: grid;
  justify-items: center;
  gap: 2px;
  width: 116px;
  color: rgb(245 242 236 / .8);
  pointer-events: none;
  transform: translate(-88%, -32%);
}
.book-hint[hidden] { display: none; }
.book-hint span { font: 400 10px/16px var(--font-mono); letter-spacing: .04em; white-space: nowrap; }
.hint-gesture { width: 108px; height: 72px; overflow: visible; stroke: currentColor; stroke-width: .9; stroke-linecap: round; stroke-linejoin: round; }
.hint-trace { opacity: .35; transform-origin: 87px 48px; }
.hint-touch { transform: translate(87px, 48px); opacity: .7; }
.hint-ring { fill: rgb(245 242 236 / .03); stroke-width: .7; }
.hint-dot { fill: currentColor; stroke: none; }
.is-ready .book-hint:not([hidden]) .hint-touch { animation: open-book-gesture 2800ms var(--ease-in-out) 1000ms 2 both; }
.is-ready .book-hint:not([hidden]) .hint-trace { animation: opening-trace 2800ms var(--ease-in-out) 1000ms 2 both; }
@keyframes open-book-gesture {
  0%, 12%, 100% { transform: translate(87px, 48px) scale(1); opacity: .7; }
  22% { transform: translate(87px, 48px) scale(.8); opacity: .9; }
  42% { transform: translate(70px, 29px) scale(.8); opacity: .9; }
  58% { transform: translate(46px, 22px) scale(.8); opacity: .8; }
  68% { transform: translate(24px, 24px) scale(.8); opacity: .6; }
  78% { transform: translate(24px, 24px); opacity: 0; }
  84% { transform: translate(87px, 48px); opacity: 0; }
}
@keyframes opening-trace {
  0%, 12%, 100% { transform: scaleX(1); opacity: .35; }
  24% { transform: scaleX(.8); opacity: .15; }
  62% { transform: scaleX(1); opacity: .65; }
  80%, 84% { transform: scaleX(1); opacity: 0; }
}
body.is-page-hidden .book-hint * { animation-play-state: paused !important; }
@media (hover: hover) and (pointer: fine) {
  .book-button:hover:not(:disabled) { color: var(--foreground); background: var(--gray-alpha-100); }
}

.stage canvas {
  position: absolute;
  z-index: 3; /* Turning pages pass in front of the floating masthead. */
  top: calc(-1 * var(--top-bleed, var(--bleed)));
  left: 0;
  width: 100%;
  height: calc(100% + var(--top-bleed, var(--bleed)) + var(--bleed));
  display: block;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.9s var(--ease-out);
}

.is-ready .stage canvas { opacity: 1; }
.stage canvas[hidden] { display: none; }

.loading, .kicker {
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--subtle);
  font-size: 11px;
  letter-spacing: 0.18em;
  pointer-events: none;
  transition: opacity var(--duration-slow);
}

.is-ready .loading { opacity: 0; }

/* flat pages when WebGL isn't available */
.flat { position: absolute; inset: 6%; display: flex; justify-content: center; align-items: center; cursor: pointer; }
.flat canvas { position: static; width: auto; height: auto; max-width: 50%; max-height: 100%; opacity: 1; }
.flat[hidden] { display: none; }

/* Flat phone pages, only for browsers without WebGL; phones otherwise get the
   3D book a page at a time (page-book.js), styled with the other canvases. */
.mobile-reader { position: absolute; inset: 0; z-index: 3; display: none; place-items: center; touch-action: pan-y; }
body[data-reader="page"] .mobile-reader { display: grid; }
.mobile-reader[hidden] { display: none !important; }
.reader-page { position: relative; overflow: hidden; border-radius: 2px; background: #ece6db; box-shadow: 0 20px 44px #0007, 2px 1px 0 #bdb5a4; transition: transform 180ms var(--ease-out); }
.reader-page[data-kind="cover"], .reader-page[data-kind="backCover"], .reader-page[data-kind="endpaper"] { border-radius: 10px; }
.reader-page.is-dragging { transition: none; cursor: grabbing; }
.stage .reader-canvas { position: static; display: block; width: 100%; height: 100%; opacity: 1; pointer-events: auto; transition: none; }
.stage .reader-canvas[hidden], .reader-story[hidden] { display: none; }
.reader-story { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 16px; padding: 24px 22px 14px; color: #2a2a2a; background: linear-gradient(#465a6e13 1px, transparent 1px), linear-gradient(90deg, #465a6e13 1px, transparent 1px), #ece6db; background-size: 10px 10px; box-shadow: inset 8px 0 18px #322d2813; }
.reader-week { color: #5c5c5c; font: 400 9px/15px var(--font-mono); letter-spacing: .04em; text-transform: uppercase; }
.reader-story-heading h2 { margin: 10px 0 0; color: #161616; font: 400 clamp(26px, 9.5vw, 44px)/.95 var(--font-display); text-transform: uppercase; overflow-wrap: anywhere; }
.reader-story-body { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #8885 transparent; font: 400 13px/21px var(--font-mono); }
.reader-story-body p { margin: 0 0 12px; white-space: pre-line; overflow-wrap: anywhere; }
.reader-story-body:focus-visible { outline: 1px solid #5c5c5c; outline-offset: 4px; }
.reader-folio { color: #5c5c5c; font: 400 9px/12px var(--font-mono); }
.reader-thumbnails { display: flex; gap: 12px; margin: 18px 0 12px; }
.reader-thumbnail { width: calc(50% - 6px); height: 90px; padding: 3px; border: 0; background: #f7f6f3; cursor: zoom-in; }
.reader-thumbnail img { width: 100%; height: 100%; object-fit: contain; }
.reader-thumbnail:focus-visible { outline: 2px solid #161616; outline-offset: 3px; }
.reader-story-links { display: flex; gap: 18px; margin-top: 18px; font-size: 10px; }
.reader-story-links a { min-height: 28px; text-underline-offset: 3px; }

/* ------------------------------------------------- the spread, as text */

/* Spread descriptions for assistive technology; the mobile page has its own text. */
.now {
  position: absolute;
  z-index: 5;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.kicker { margin-bottom: var(--space-2); color: var(--secondary); font-size: 11px; line-height: 16px; letter-spacing: 0.16em; }
.title { margin-bottom: var(--space-3); font: 400 60px/0.88 var(--font-display); letter-spacing: 0.005em; text-transform: uppercase; }
.story p { margin-bottom: var(--space-3); color: var(--gray-900); font-size: 16px; line-height: 24px; white-space: pre-line; }
.links { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1); }
.links:empty { display: none; }

/* ---------------------------------------------------------- under the book */

.about {
  position: relative;
  z-index: 5; /* Keep text and signup controls above the book's shadow. */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5) var(--space-8);
  text-align: center;
}

.waitlist-form { display: flex; gap: var(--space-2); width: min(380px, 100%); }
.waitlist-form .gr-input { flex: 1; min-width: 0; }
.waitlist-form[hidden] { display: none; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.gr-error { max-width: 380px; }
.gr-error a { color: inherit; text-underline-offset: 2px; }
.gr-error[hidden], .waitlist-done[hidden] { display: none; }
.waitlist-done { max-width: 380px; color: var(--secondary); }
.waitlist-done strong { color: var(--foreground); font-weight: 500; }

.latest-post { color: var(--secondary); }
.latest-post:hover { color: var(--foreground); }
.latest-post[hidden] { display: none; }

/* ------------------------------------------------------------------ toasts */

/* Native dialog supplies focus containment, Escape, and an inert background. */
.photo-viewer {
  width: min(1120px, calc(100vw - 48px));
  height: min(900px, calc(100svh - 64px));
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--foreground);
}
.photo-viewer::backdrop { background: rgb(0 0 0 / .88); }
body:has(.photo-viewer[open]) { overflow: hidden; }
.photo-viewer figure { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100%; margin: 0; }
.photo-frame { position: relative; display: grid; place-items: center; min-height: 0; padding: 48px 28px 16px; }
.photo-frame img { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; opacity: 0; }
.photo-viewer.is-loaded img { opacity: 1; }
.photo-close { position: absolute; top: 8px; right: 8px; z-index: 1; width: 44px; padding: 0; justify-content: center; }
.photo-status { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; color: var(--secondary); text-align: center; pointer-events: none; }
.photo-status[hidden] { display: none; }
.photo-viewer figcaption { padding: 8px 28px 24px; color: var(--secondary); font-size: 12px; line-height: 18px; text-align: center; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(360px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toasts .gr-toast { width: 100%; transition: opacity 300ms var(--ease-standard); }

.noscript { padding: var(--space-6); }

/* ------------------------------------------------------------------- small */

@media (max-width: 760px) {
  /* The book fills the screen under the header; no shadow needs room below it. */
  :root { --bleed: 8px; }
  html, body { overscroll-behavior: none; }
  body { grid-template-rows: 84px minmax(0, 1fr); height: 100svh; min-height: 0; overflow: hidden; }
  /* Horizontal swipes turn pages; a double tap shouldn't zoom between them. */
  .stage { touch-action: pan-y pinch-zoom; }

  .masthead { padding: 0 var(--space-4); }
  .brand { font-size: 20px; }
  .site-actions { right: var(--space-4); gap: 4px; }
  .book-nav { display: flex; width: auto; gap: 0; }
  .book-nav .book-button { min-height: 36px; padding: 0 10px; font-size: 11px; }
  .tw.is-open { width: calc(100vw - 2 * var(--space-4)); }
  .masthead.is-open .brand { opacity: 0; pointer-events: none; }
  /* 16px or more, or iOS zooms the page in when the field takes focus. */
  .tw-input, .waitlist-form .gr-input { font-size: 16px; }
  /* Edge to edge: a page turning over runs off the side of the screen. */
  .book-layout { margin: 0; padding: 0 0 calc(8px + env(safe-area-inset-bottom)); }
  .stage { height: auto; max-height: none; }
  .book-hint span { display: none; }
  .photo-viewer { width: calc(100vw - 24px); height: calc(100svh - 32px); }
  .photo-frame { padding: 52px 12px 12px; }
  .photo-viewer figcaption { padding: 8px 16px 20px; }

  .about { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .tw { animation: none !important; }
  .is-ready .book-hint:not([hidden]) .hint-touch,
  .is-ready .book-hint:not([hidden]) .hint-trace { animation: none; }
  .book-button:active:not(:disabled) { transform: none; }
}
