/* WALD'S ART — online magazine mockup */

:root {
  --cream: #FFFDF1;
  --butter: #FFF09A;
  --peach: #F5E3D9;
  --brown: #572C21;
  --brown-deep: #46231a;
  --orange: #D45E1B;
  --orange-dark: #C0511A;
  --paper: #FBFAF5;
  --muted: rgba(87, 44, 33, 0.62);
  --line: rgba(87, 44, 33, 0.18);

  --font-text: "STIX Two Text", Georgia, serif;
  --font-display: "Playfair Display", Georgia, serif;
  --font-mono: "DM Mono", ui-monospace, monospace;
  --font-hand: "Caveat", "Segoe Print", cursive;

  --flip-ms: 900ms;
  --ease-flip: cubic-bezier(0.35, 0.1, 0.3, 1);

  /* Paper grain: brown speckles on transparent, tiled */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .34 0 0 0 0 .17 0 0 0 0 .13 1.3 0 0 0 -.52'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  /* Light speckles for dark surfaces */
  --grain-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .97 0 0 0 0 .9 1.3 0 0 0 -.55'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
}

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

html { background: var(--cream); }

body {
  margin: 0;
  background: var(--cream);
  color: var(--brown);
  font-family: var(--font-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ */
/* First screen: masthead + magazine                                   */
/* ------------------------------------------------------------------ */

.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 520px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  padding: 10px clamp(16px, 3vw, 40px) 14px;
  overflow: hidden;
  background:
    radial-gradient(140% 75% at 50% 118%, rgba(255, 240, 154, 0.85) 0%, rgba(255, 240, 154, 0.32) 42%, rgba(255, 240, 154, 0) 68%),
    var(--grain),
    var(--cream);
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
  font: 500 10px/1 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand {
  margin: clamp(4px, 0.8vh, 8px) 0 0;
  display: flex;
  justify-content: center;
  line-height: 0;
}

.brand img {
  display: block;
  height: clamp(40px, 7.5vh, 84px);
  width: auto;
}

/* ---------------- Stage & book ---------------- */

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1.8vh, 20px) 0 clamp(8px, 1.4vh, 14px);
}

.book-size {
  --corner: 6px; /* rounding of the pages' outer corners */
  /* The blocks' edges and the book's sink change together, and as slowly as the book
     slides to and from the centre, so the sink is part of that slide */
  --restack: var(--shift-ms, var(--flip-ms)) var(--ease-flip);
  position: relative;
  width: min(760px, 100%); /* set from app.js to fit the screen */
  translate: var(--sink, 0px) 0; /* pages sit lower on a thinner block, see sink() in app.js */
  transition:
    transform var(--shift-ms, var(--flip-ms)) var(--ease-flip),
    translate var(--restack),
    opacity 0.35s ease;
}

/* A closed magazine is centred: shift by half a page */
.book-size[data-state="front"] { transform: translateX(-25%); }
.book-size[data-state="back"]  { transform: translateX(25%); }
.book-size.is-portrait { transform: none; }
/* While a cover turns, app.js moves the book along with it, frame by frame */
.book-size.is-sliding { transition: translate var(--restack), opacity 0.35s ease; }
.book-size.no-shift-anim { transition: opacity 0.35s ease; }
.book-size.is-fading { opacity: 0; }

.book {
  position: relative;
  z-index: 1;
  aspect-ratio: 1118 / 697;
  perspective: 5500px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
.book.is-dragging { cursor: grabbing; }
.book.is-portrait { aspect-ratio: 559 / 697; }

/* The pages lying open: one slot each side of the spine */
.slot {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 50%;
}
.slot--right { left: 50%; }
.book.is-portrait .slot--left { display: none; }
.book.is-portrait .slot--right { left: 0; width: 100%; }
.slot > .page { position: absolute; inset: 0; }

/* Shadow of a turning sheet on the page below it, drawn from flipbook.js */
.cast {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.slot.is-empty .cast { display: none; }
.slot--left > .cast  { border-radius: var(--corner) 0 0 var(--corner); }
.slot--right > .cast { border-radius: 0 var(--corner) var(--corner) 0; }

/* The turning sheet: vertical strips hinged at the spine, bent in 3D */
.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 100%;
  z-index: 4;
  transform-style: preserve-3d;
  pointer-events: none;
}
.book.is-portrait .leaf { left: 0; }
.leaf__face {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  overflow: hidden;
  transform-origin: 0 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.leaf__page {
  position: absolute;
  top: 0;
  height: 100%;
}
.leaf__page > .page { position: absolute; inset: 0; }
.leaf__shade {
  position: absolute;
  inset: 0;
  z-index: 5;
}
/* The cut edge of the sheet catches a hairline of shadow: it has some thickness */
.leaf__shade--front-edge { box-shadow: inset -1px 0 rgba(87, 44, 33, 0.22); }
.leaf__shade--back-edge  { box-shadow: inset 1px 0 rgba(87, 44, 33, 0.22); }

/* A sheet turns with its rounded corners, on its outer strip */
.leaf__face--front.is-outer { border-radius: 0 var(--corner) var(--corner) 0; }
.leaf__face--back.is-outer  { border-radius: var(--corner) 0 0 var(--corner); }
.leaf__shade { border-radius: inherit; }

/* The sheet's free edge, seen as it stands up: trimmed paper, or the board in the
   endpaper's dark brown. Pieces of it are placed from flipbook.js, which also reads
   --corner to round the corners with them. */
.leaf__edge {
  transform-origin: 0 0;
  background: #ece5d5;
}
.leaf.is-hard .leaf__edge {
  background: linear-gradient(to right, var(--brown-deep), #62332a 30%, #62332a 70%, var(--brown-deep));
}

/* Page block edges + cast shadow, drawn under each half of the book */
.stack {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  transition: opacity 0.35s ease, box-shadow var(--restack);
  pointer-events: none;
}
/* Anchored at the spine, so a cover's shadow can shrink in toward it; rounded off
   with the pages' outer corners */
.stack--left  { right: 50%; border-radius: var(--corner) 1px 1px var(--corner); }
.stack--right { left: 50%; border-radius: 1px var(--corner) var(--corner) 1px; }
.stack.is-following { transition: none; }
.is-portrait .stack--left { display: none; }
.is-portrait .stack--right { left: 0; width: 100%; }

/* Pages: thick matte stock */
.page {
  background: var(--paper);
  overflow: hidden;
  container-type: size;
}

.page > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  /* Ink on uncoated paper: a little softer and flatter than on screen */
  filter: saturate(0.94) contrast(0.95) brightness(1.015);
}

/* Paper tooth showing through the print */
.page:not([data-density="hard"])::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--grain);
  opacity: 0.32;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* Gutter shading: paper curving into the spine */
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.page.is-left::after {
  background:
    linear-gradient(to left, rgba(40, 20, 12, 0.26) 0%, rgba(40, 20, 12, 0.1) 2.2%, rgba(40, 20, 12, 0.03) 6%, rgba(40, 20, 12, 0) 11%),
    linear-gradient(to right, rgba(40, 20, 12, 0.06) 0%, rgba(40, 20, 12, 0) 1.6%);
}
.page.is-right::after {
  background:
    linear-gradient(to right, rgba(40, 20, 12, 0.24) 0%, rgba(40, 20, 12, 0.09) 2%, rgba(40, 20, 12, 0.03) 5%, rgba(40, 20, 12, 0) 10%),
    linear-gradient(to left, rgba(40, 20, 12, 0.05) 0%, rgba(40, 20, 12, 0) 1.6%);
}
.page[data-density="hard"]::after { display: none; }

/* Every page, paper and board alike, has rounded outer corners */
.page.is-right { border-radius: 0 var(--corner) var(--corner) 0; }
.page.is-left  { border-radius: var(--corner) 0 0 var(--corner); }

/* ---------------- Covers ---------------- */

.cover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 9% 9% 7.5%;
  background:
    var(--grain),
    radial-gradient(120% 90% at 30% 20%, #fffffb 0%, #fbf9f2 55%, #f3efe3 100%);
  color: var(--brown);
  text-align: center;
}

.cover__logo {
  width: 86%;
  height: auto;
  margin-top: auto;
}

.cover__title {
  margin: 5cqw 0 auto;
  font: italic 400 5.4cqw/1.2 var(--font-display);
  color: rgba(87, 44, 33, 0.78);
}

.cover__issue {
  width: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 3cqw;
  font: 500 2.5cqw/1 var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.cover__issue::before,
.cover__issue::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.cover__issue span + span::before {
  content: "·";
  margin-right: 3cqw;
}

/* Hinge groove of a hard cover */
.page--cover .cover::before,
.page--back .cover::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2.6%;
  background: linear-gradient(to right, rgba(87, 44, 33, 0.07), rgba(255, 255, 255, 0.75) 45%, rgba(87, 44, 33, 0.07));
}
.page--cover .cover::before { left: 3.4%; }
.page--back .cover::before { right: 3.4%; }

.cover--back .cover__logo {
  width: 44%;
  margin-top: auto;
  margin-bottom: 7cqw;
}

.cover__quote {
  margin: auto 0 0;
  font: italic 400 4.6cqw/1.35 var(--font-display);
  color: rgba(87, 44, 33, 0.72);
}

/* Endpapers */
.endpaper {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 9%;
  background:
    var(--grain-light),
    radial-gradient(130% 100% at 50% 0%, #62332a 0%, var(--brown) 55%, var(--brown-deep) 100%);
}
.endpaper span {
  font: italic 400 4.2cqw/1 var(--font-display);
  letter-spacing: 0.02em;
  color: rgba(255, 253, 241, 0.72);
}

/* ---------------- Handwritten notes ---------------- */

.note {
  position: absolute;
  top: 16%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border: 0;
  background: none;
  cursor: pointer;
  font: 500 clamp(19px, 1.7vw, 25px)/1 var(--font-hand);
  color: var(--brown);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, color 0.2s ease;
}
.note:hover { color: var(--orange); }
.note svg {
  width: 56px;
  height: 38px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.note--open {
  left: calc(100% + 10px);
  align-items: flex-start;
  transform: rotate(-5deg);
}
.note--again {
  right: calc(100% + 10px);
  align-items: flex-end;
  transform: rotate(5deg);
}
.book-size[data-state="front"] .note--open,
.book-size[data-state="back"] .note--again {
  opacity: 1;
  pointer-events: auto;
  transition-delay: var(--shift-ms, var(--flip-ms));
}

.is-portrait .note {
  top: auto;
  bottom: calc(100% + 4px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  font-size: 21px;
}
.is-portrait .note svg { display: none; }

/* ---------------- Controls ---------------- */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.ctrl {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(87, 44, 33, 0.28);
  border-radius: 50%;
  background: rgba(255, 253, 241, 0.65);
  color: var(--brown);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}
.ctrl:hover:not(:disabled) {
  background: var(--brown);
  border-color: var(--brown);
  color: var(--cream);
}
.ctrl:focus-visible,
.note:focus-visible,
.btn-download:focus-visible,
.scroll-hint:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 3px;
}
.ctrl:disabled { opacity: 0.32; cursor: default; }
.ctrl svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.counter {
  min-width: 108px;
  text-align: center;
  font: 500 11px/1 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.ctrl--sound { margin-left: 8px; }
.ctrl--sound .icon-off { display: none; }
.ctrl--sound[aria-pressed="false"] .icon-on { display: none; }
.ctrl--sound[aria-pressed="false"] .icon-off { display: block; }

/* ---------------- Scroll hint ---------------- */

/* Sits in the corner beside the controls, so it costs the magazine no height */
.scroll-hint {
  position: absolute;
  right: clamp(16px, 3vw, 40px);
  bottom: 25px;
  display: flex;
  align-items: center;
  gap: 6px;
  font: 500 10px/1 var(--font-mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  opacity: 0.75;
  transition: opacity 0.3s ease;
}
.scroll-hint svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: nudge 2.2s ease-in-out infinite;
}
.is-scrolled .scroll-hint { opacity: 0; pointer-events: none; }

@keyframes nudge {
  0%, 100% { transform: translateY(-1px); }
  50% { transform: translateY(3px); }
}

/* ------------------------------------------------------------------ */
/* Footer                                                              */
/* ------------------------------------------------------------------ */

.site-footer {
  padding: clamp(64px, 9vw, 128px) clamp(20px, 5vw, 72px) 28px;
  background:
    var(--grain-light),
    var(--brown);
  color: var(--cream);
}

.footer__inner {
  max-width: 1160px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: clamp(40px, 6vw, 96px);
  align-items: center;
}

.eyebrow {
  margin: 0 0 18px;
  font: 500 11px/1 var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #F2A877;
}

.footer__about h2 {
  margin: 0 0 22px;
  font: 400 clamp(26px, 3vw, 40px)/1.18 var(--font-display);
  text-wrap: balance;
}

.footer__about p {
  max-width: 52ch;
  margin: 0;
  font-size: 17px;
  line-height: 1.65;
  color: rgba(255, 253, 241, 0.78);
}

.issue-card {
  display: flex;
  align-items: center;
  gap: clamp(22px, 3vw, 36px);
  padding: clamp(22px, 3vw, 32px);
  border: 1px solid rgba(255, 253, 241, 0.14);
  border-radius: 8px;
  background: rgba(255, 253, 241, 0.05);
}

.issue-card__cover {
  flex: none;
  width: clamp(110px, 12vw, 150px);
  aspect-ratio: 559 / 697;
  display: grid;
  place-items: center;
  border-radius: 1px 3px 3px 1px;
  background:
    var(--grain),
    radial-gradient(120% 90% at 30% 20%, #fffffb 0%, #fbf9f2 55%, #f1ece0 100%);
  box-shadow:
    inset 4px 0 0 rgba(87, 44, 33, 0.06),
    inset 5px 0 0 rgba(255, 255, 255, 0.7),
    3px 3px 0 #e7e0cf,
    0 22px 36px -14px rgba(0, 0, 0, 0.6);
  transform: rotate(-3deg);
}
.issue-card__cover img { width: 80%; height: auto; }

.issue-card__body h3 {
  margin: 0 0 12px;
  font: 400 26px/1.2 var(--font-display);
}
.issue-card__body h3 em {
  display: block;
  font-size: 20px;
  color: rgba(255, 253, 241, 0.7);
}

.issue-card__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  font: 500 11px/1.4 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 253, 241, 0.6);
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px 14px 20px;
  border-radius: 999px;
  background: var(--orange-dark);
  color: #fff;
  font: 600 16px/1 var(--font-text);
  text-decoration: none;
  box-shadow: 0 10px 22px -10px rgba(0, 0, 0, 0.55);
  transition: background-color 0.2s ease, transform 0.2s ease;
}
.btn-download:hover { background: var(--orange); transform: translateY(-1px); }
.btn-download svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.footer__bottom {
  max-width: 1160px;
  margin: clamp(56px, 7vw, 96px) auto 0;
  padding-top: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 24px;
  border-top: 1px solid rgba(255, 253, 241, 0.16);
  font: 500 11px/1.4 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 253, 241, 0.55);
}

/* ------------------------------------------------------------------ */
/* Small screens                                                       */
/* ------------------------------------------------------------------ */

@media (max-width: 860px) {
  .footer__inner { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .hero { padding: 10px 16px 30px; }
  .meta { letter-spacing: 0.12em; }
  .brand img { height: clamp(36px, 6.5vh, 64px); }
  .stage { padding-top: 34px; }
  .counter { min-width: 92px; }
  /* No room beside the controls: back under them */
  .scroll-hint { right: auto; left: 50%; bottom: 9px; transform: translateX(-50%); }
}

@media (max-width: 480px) {
  .issue-card { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint svg { animation: none; }
}
