/* heartsake.app: a black sugar-paper album. */

@font-face { font-family: 'Homemade Apple'; src: url('/fonts/HomemadeApple-normal.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Alegreya'; src: url('/fonts/Alegreya-normal.woff2') format('woff2'); font-weight: 400 700; font-display: swap; }
@font-face { font-family: 'Alegreya'; src: url('/fonts/Alegreya-italic.woff2') format('woff2'); font-style: italic; font-display: swap; }
@font-face { font-family: 'Courier Prime'; src: url('/fonts/CourierPrime-normal.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Alegreya SC'; src: url('/fonts/AlegreyaSC-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }

:root {
  --paper: #141416;
  --gutter-shade: #08080a;
  --ink: #f5f0e6;
  --ink-soft: #cfc8ba;
  --foil: #b89a5e;
  --foil-deep: #8f7746;
  --print: #efe9dc;
  --label: #f2ead8;
  --label-ink: #17171a;
  --label-line: #b9a77e;
  --error: #f3b3a3;

  --hand: 'Homemade Apple', 'Segoe Script', cursive;
  --read: 'Alegreya', Georgia, 'Times New Roman', serif;
  --stamp: 'Alegreya SC', 'Alegreya', Georgia, serif;
  --typed: 'Courier Prime', 'Courier New', monospace;

  --gutter: clamp(64px, 8vw, 128px);
  --side: clamp(20px, 5vw, 72px);
  --ease: cubic-bezier(.16, 1, .3, 1);
}

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

/* Lifting a print grows the page; the browser mustn't scroll to compensate. */
html { overflow-anchor: none; background: var(--paper); color-scheme: dark; scroll-behavior: smooth; scrollbar-color: var(--foil-deep) var(--gutter-shade); }

body {
  margin: 0;
  background: var(--paper) url('/img/sugar-paper.png') 0 0 / 512px 512px;
  color: var(--ink);
  font: 400 clamp(20px, 1.05vw + 15px, 23px) / 1.55 var(--read);
  font-kerning: normal;
  caret-color: var(--foil);
  -webkit-text-size-adjust: 100%;
}

::selection { background: var(--foil); color: var(--label-ink); }
:focus-visible { outline: 3px solid var(--foil); outline-offset: 3px; border-radius: 3px; }

a { color: var(--ink); text-decoration-color: var(--foil); text-decoration-thickness: 1.5px; text-underline-offset: .2em; }
a:hover { color: var(--foil); }

p { margin: 0 0 1em; max-width: 34em; }
img { display: block; width: 100%; height: 100%; object-fit: cover; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--label); color: var(--label-ink); padding: 12px 18px; z-index: 10; border-radius: 3px; }
.skip:focus { left: 8px; }

/* Handwriting in white ink. */
.ink { font-family: var(--hand); font-weight: 400; color: var(--ink); }
.ink-xl { margin: 0 0 .75em; font-size: clamp(34px, 3.5vw, 58px); line-height: 1.42; text-wrap: balance; }
.ink-l { margin: 0 0 1em; font-size: clamp(30px, 2.9vw, 46px); line-height: 1.4; text-wrap: balance; }

/* Foil, stamped into the page. */
.foil { font-family: var(--stamp); font-weight: 500; font-size: 26px; letter-spacing: .08em; color: var(--foil); }

.locket {
  display: inline-block; width: 40px; height: 40px; flex: none;
  background: var(--foil);
  -webkit-mask: url('/img/locket.svg') center / contain no-repeat;
  mask: url('/img/locket.svg') center / contain no-repeat;
}

.cover-line, .foil-line { display: flex; align-items: center; gap: 12px; }
.cover-line { margin-bottom: clamp(40px, 7vh, 88px); }

/* The album: pairs of facing pages with a shadowed fold between them. */
.album { display: block; }

.spread {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: var(--gutter);
  align-items: center;
  max-width: 1480px;
  margin: 0 auto;
  padding: clamp(48px, 8vh, 112px) var(--side);
  min-height: min(100vh, 980px);
}

.spread::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: calc(50% - var(--gutter) / 2); width: var(--gutter); pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .55) 38%, var(--gutter-shade) 50%, rgba(0, 0, 0, .55) 62%, transparent);
}
.spread + .spread { border-top: 1px solid #000; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05); }

.page { position: relative; z-index: 1; min-width: 0; }
.page-words { max-width: 36em; }
.page-photo { display: flex; flex-direction: column; }

.lede { font-size: 1.12em; color: var(--ink); }

/* Prints, and the black paper corners that hold them. */
.mount { position: relative; aspect-ratio: var(--ratio); }

.print {
  position: absolute; inset: 0;
  padding: clamp(8px, 1vw, 14px);
  background: var(--print);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .8), 0 14px 28px rgba(0, 0, 0, .6);
  transform-origin: 50% 0;
  transition: transform 1s var(--ease), box-shadow 1s var(--ease), opacity .4s linear;
  backface-visibility: hidden;
}

.corner {
  position: absolute; width: clamp(34px, 3.4vw, 54px); aspect-ratio: 1; z-index: 2;
  background: center / 100% 100% no-repeat;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .7));
  transition: opacity .35s linear;
}
.corner.tl { top: -3px; left: -3px; background-image: url('/img/corner-tl.png'); }
.corner.tr { top: -3px; right: -3px; background-image: url('/img/corner-tr.png'); }
.corner.br { bottom: -3px; right: -3px; background-image: url('/img/corner-br.png'); }
.corner.bl { bottom: -3px; left: -3px; background-image: url('/img/corner-bl.png'); }

/* Lifting a print on its top corners shows what's written beneath it. */
.lift { display: grid; transform: rotate(var(--tilt, 0deg)); perspective: 1500px; min-height: var(--room, 0); }
.lift > * { grid-area: 1 / 1; min-width: 0; }
.lift .mount { align-self: start; z-index: 1; pointer-events: none; }
.lift .print { pointer-events: auto; }
.js [data-lift] .print { cursor: pointer; }

.under { display: grid; grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows .7s var(--ease), visibility 0s linear .7s; }
.under-inner { overflow: hidden; min-height: 0; }

[data-lift] .print { padding: 0; background: none; box-shadow: none; transform-style: preserve-3d; }
.face, .print-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face { padding: clamp(8px, 1vw, 14px); background: var(--print); box-shadow: 0 1px 2px rgba(0, 0, 0, .8), 0 14px 28px rgba(0, 0, 0, .6); }
.print-back {
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 8%;
  background: #e6d9bf url('/img/print-back.jpg') center / cover;
  transform: rotateX(180deg);
  box-shadow: 0 -10px 26px rgba(0, 0, 0, .7);
  font: 400 clamp(21px, 2vw, 30px)/1.5 var(--hand); color: #3a3226;
}
.lift.is-up .print { transform: rotateX(112deg); }
.lift.is-up .corner.bl, .lift.is-up .corner.br { opacity: 0; }
.lift.is-up .under { grid-template-rows: 1fr; visibility: visible; transition: grid-template-rows .7s var(--ease), visibility 0s; }

/* Once on arrival, the first print rises a little to show it can. */
.hero .lift:not(.is-up):not(.touched) .print { animation: peek 1.8s var(--ease) 1.1s 1 both; }
@keyframes peek {
  0%, 100% { transform: rotateX(0); }
  38% { transform: rotateX(16deg); box-shadow: 0 22px 34px rgba(0, 0, 0, .7); }
}

blockquote { margin: 0; padding-bottom: .75em; }
blockquote:first-child { padding-top: clamp(38px, 3.2vw, 46px); }
blockquote p { margin: 0 0 .2em; font-family: var(--hand); font-size: clamp(22px, 1.45vw, 25px); line-height: 1.5; max-width: none; }
cite { font-style: normal; color: var(--foil); font-size: .92em; }
.asked p::before { content: 'A question: '; font-family: var(--read); color: var(--foil); }

.nb { white-space: nowrap; }
.caption { margin: clamp(18px, 2vw, 28px) 0 0; font-size: clamp(20px, 1.4vw, 24px); line-height: 1.65; max-width: none; }

.lift-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 22px; margin-top: 20px; }
.sample-note { margin: 0; font-size: 18px; color: var(--ink-soft); }

/* Gummed labels: every action on the site. */
.label-button {
  appearance: none; border: 0; cursor: pointer;
  min-height: 54px; padding: 0 26px;
  background: var(--label); color: var(--label-ink);
  font: 700 20px/1 var(--read);
  border-radius: 4px;
  box-shadow: inset 0 0 0 3px var(--label), inset 0 0 0 4px var(--label-line), 0 3px 6px rgba(0, 0, 0, .6);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), background-color .2s linear;
  white-space: nowrap;
}
.label-button:hover { background: #fff8e8; transform: translateY(-1px) rotate(-.4deg); box-shadow: inset 0 0 0 3px #fff8e8, inset 0 0 0 4px var(--label-line), 0 7px 12px rgba(0, 0, 0, .7); }
.label-button:active { transform: translateY(1px); }
.label-button[disabled] { opacity: .65; cursor: progress; transform: none; }
.label-button.quiet { min-height: 46px; padding: 0 20px; font-size: 18px; }

/* The waiting list. */
.list-form { margin-top: 28px; max-width: 34em; }
.list-form label { display: block; margin-bottom: 4px; font-size: .95em; color: var(--ink); }
.list-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 18px; }
.list-row input {
  flex: 1 1 15em; min-width: 0; min-height: 54px; padding: 8px 2px;
  background: transparent; color: var(--ink);
  border: 0; border-bottom: 2px solid var(--ink-soft); border-radius: 0;
  font: 400 1.05em/1.3 var(--read);
}
.list-row input:hover { border-bottom-color: var(--ink); }
.list-row input:focus { outline: 0; border-bottom-color: var(--foil); box-shadow: 0 2px 0 var(--foil); }
.list-row input[aria-invalid='true'] { border-bottom-color: var(--error); }
.hp { position: absolute; left: -9999px; height: 0; overflow: hidden; }
.form-note { margin: 14px 0 0; font-size: 18px; color: var(--ink-soft); min-height: 1.5em; }
.form-note.is-error { color: var(--error); }
.form-note.is-done { font-family: var(--hand); font-size: 22px; color: var(--ink); line-height: 1.7; }

/* A contents page, handwritten. */
.contents-title { display: block; margin: 0 0 14px; font-size: 24px; }
.contents { list-style: none; margin: 0 0 clamp(32px, 4vw, 52px); padding: 0; }
.contents li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 18px; padding: 12px 0; border-bottom: 1px solid rgba(245, 240, 230, .16); }
.contents .ink { font-size: clamp(20px, 1.5vw, 24px); line-height: 1.6; }
.contents .when { color: var(--foil); font-variant-numeric: lining-nums; text-align: right; }
.contents em { display: block; font-size: 18px; color: var(--ink-soft); }

.pair { display: grid; grid-template-columns: 1.15fr 1fr; gap: clamp(20px, 3vw, 40px); align-items: start; }
.small-print { margin: 0; transform: rotate(var(--tilt, 0deg)); }
.small-print .caption { font-size: 20px; }

/* An index card, typed. */
.index-card {
  position: relative; margin: 0; padding: clamp(22px, 2.6vw, 38px);
  background: var(--label); color: var(--label-ink);
  transform: rotate(var(--tilt, 0deg));
  box-shadow: 0 1px 2px rgba(0, 0, 0, .8), 0 14px 28px rgba(0, 0, 0, .6);
}
.index-card figcaption { font: 700 1.05em/1.3 var(--read); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--label-line); }
.tree { list-style: none; margin: 0; padding: 0; font: 400 18px/1.35 var(--typed); }
.tree li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 18px; padding: 4px 0; }
.tree .d1 { padding-left: 1.2em; }
.tree .d2 { padding-left: 2.4em; }
.tree code { font: inherit; overflow-wrap: anywhere; }
.tree span { color: #5f5030; font-family: var(--read); font-size: 1.05em; }

.gifts { list-style: none; margin: 0 0 1em; padding: 0; }
.gifts li { padding-bottom: 1em; }
.gifts .ink { display: block; font-size: clamp(20px, 1.6vw, 27px); line-height: 1.6; }

.endpaper { background: var(--gutter-shade); border-top: 1px solid #000; }
.endpaper-inner { max-width: 62em; margin: 0 auto; padding: clamp(48px, 7vw, 88px) var(--side); font-size: 19px; }
.endpaper h2 { margin: 1.6em 0 .5em; font: 700 1.25em/1.3 var(--read); }
.endpaper p { max-width: 42em; color: var(--ink-soft); }
.credits { margin: 0 0 1.5em; padding: 0; list-style: none; columns: 2 20em; column-gap: 40px; }
.credits li { padding: 8px 0; break-inside: avoid; }
.fine { font-size: 18px; }

@media (max-width: 880px) {
  .spread { grid-template-columns: minmax(0, 1fr); row-gap: 40px; min-height: 0; padding-left: 20px; padding-right: 20px; }
  .spread::before { display: none; }
  .cover-line { margin-bottom: 30px; }
  /* The story reads in order on a phone: words before their picture, and the
     first photo before anyone is asked for an email. */
  .spread > .page-words { order: -1; }
  .hero { row-gap: 0; }
  .hero > .page:first-child { display: contents; }
  .cover-line { order: 1; }
  .hero h1 { order: 2; margin-bottom: 1em; }
  .hero .page-photo { order: 3; margin-bottom: 36px; }
  .hero .lede { order: 4; }
  .hero .list-form { order: 5; }
  /* The label sits above the print, so nothing moves under the thumb. */
  .page-photo .lift-foot { order: -2; margin: 0 0 16px; }
  /* The caption fills the room the raised print swings into. */
  .caption-first .caption { order: -1; margin: 0 0 18px; }
  .hero .lift-foot { flex-direction: column; align-items: flex-start; margin-bottom: 24px; }
  blockquote p { font-size: 24px; }
  .list-row input { flex-basis: 100%; }
  .label-button { width: 100%; }
  .label-button.quiet { width: auto; }
  .pair { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .lift.is-up .print { transform: none; opacity: 0; }
}

/* Without scripts, the words simply sit under the photo. */
html:not(.js) .lift > * { grid-area: auto; }
html:not(.js) .under { grid-template-rows: 1fr; visibility: visible; margin-top: 24px; }
html:not(.js) blockquote:first-child { padding-top: 0; }
html:not(.js) [data-lift-toggle] { display: none; }
