/* ---------- Setup ---------- */
:root {
  --glide: .6s cubic-bezier(.3, .7, .2, 1);
  --cork: #b98a55;
  --wood: #5a3a1e;
  --paper: #fbf7ee;
  --ink: #2b2118;
  --pin: #c8322b;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

/* the page itself never scrolls (also on phones) */
html {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  /* Wallpaper behind the board.
    To use your own wallpaper image, replace the second url(...) below
    with url("images/wallpaper.jpg") and drop the background-size line. */
  background-color: #2f4a3f;
  background-image:
    radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(0,0,0,.5) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='160'><rect width='120' height='160' fill='%232f4a3f'/><rect x='0' width='5' height='160' fill='%23385a4c'/><rect x='60' width='5' height='160' fill='%23385a4c'/><g fill='none' stroke='%23d9c48a' stroke-opacity='.35' stroke-width='1.5'><path d='M62.5 20 L77.5 40 L62.5 60 L47.5 40 Z'/><path d='M62.5 28 L69.5 40 L62.5 52 L55.5 40 Z'/><path d='M-12.5 120 L2.5 100 L17.5 120 L2.5 140 Z'/><path d='M107.5 120 L122.5 100 L137.5 120 L122.5 140 Z'/><circle cx='62.5' cy='40' r='3' fill='%23d9c48a' fill-opacity='.35'/><circle cx='2.5' cy='120' r='3' fill='%23d9c48a' fill-opacity='.35'/><circle cx='122.5' cy='120' r='3' fill='%23d9c48a' fill-opacity='.35'/></g></svg>");
  background-attachment: fixed, scroll;
  background-size: auto, 120px 160px;
  color: var(--ink);
  font-family: "Handlee", "Courier New", monospace;
  /* locks the page so it can't scroll on phones; centres the board */
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
}


/* ---------- Corkboard ---------- */
.frame {
  /* max 1400px wide, never wider than the window, and never taller than the
    window (the board is 16:10, so 145vh of width is about 90vh of height) */
  width: min(1400px, 94vw, 145vh);
  margin: 0;
  padding: clamp(8px, 1vw, 16px);
  border-radius: 10px;
  background: linear-gradient(145deg, #7a5230, var(--wood) 50%, #46290f);
  box-shadow: 0 20px 50px rgba(0,0,0,.6), inset 0 2px 3px rgba(255,255,255,.18);
}

.board {
  position: relative;
  aspect-ratio: 16 / 10;
  container-type: inline-size;   /* lets everything on the board scale with it */
  border-radius: 4px;
  box-shadow: inset 0 0 40px rgba(0,0,0,.45), inset 0 0 6px rgba(0,0,0,.6);

  /* To use your own cork image, uncomment the first line and set the path,
    then remove the background-color / background-image lines below it. */
  /* background: #b98a55 url("images/corkboard.jpg") center / cover; */
  background-color: var(--cork);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .25  0 0 0 0 .14  0 0 0 0 .05  0 0 0 .9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='m'><feTurbulence type='turbulence' baseFrequency='.03' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 .85  0 0 0 0 .6  0 0 0 .35 0'/></filter><rect width='100%' height='100%' filter='url(%23m)'/></svg>");
}

/* ---------- Everything pinned to the board ----------
  --x / --y / --w are percentages of the board, --z is stacking order,
  --r is the (random) tilt. Font size scales with the item's width,
  so all padding and text below is in em. */
.item {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  font-size: calc(var(--w) * .1cqw);
  z-index: var(--z, 1);
  transform: rotate(var(--r, 0deg));
  transition: transform .25s ease, box-shadow .25s ease;
}

/* ---------- Photos (click to flip, like the back of a polaroid) ---------- */
.photo-card {
  cursor: pointer;
  perspective: 70em;
  transition: transform var(--glide), left var(--glide), top var(--glide), width var(--glide), font-size var(--glide);
  -webkit-tap-highlight-color: transparent;
}

.photo-card:hover:not(.is-focused),
.photo-card:focus-visible:not(.is-focused) {
  transform: rotate(0deg) scale(1.05);
  z-index: 30;
  outline: none;
}
.photo-card:focus-visible .front { outline: 3px solid rgba(255, 255, 255, .45); outline-offset: 4px; }

.photo-flip {
  position: relative;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.3, .7, .2, 1);
}
.is-focused .photo-flip { transform: rotateY(180deg); }

.face {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background: var(--paper);
  box-shadow: 2px 6px 12px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .4);
}

.front {
  position: relative;
  padding: .5em .5em 1.9em;
  text-align: center;
}

.front img {
  display: block;
  width: 100%;
  aspect-ratio: var(--ratio, 1);
  object-fit: cover;
  background: #ddd;
}

.front .caption {
  /* sits in the white strip under the photo (1.9em tall, see .front padding),
    centred in it: the line height is that strip height, measured in caption-sized units */
  --cap: .6;
  position: absolute;
  left: .4em; right: .4em; bottom: 0;
  font-family: "Handlee", cursive;
  font-size: calc(var(--cap) * 1em);
  line-height: calc(1.9 / var(--cap));
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* the back: slightly yellowed card with pen handwriting */
.back {
  position: absolute;
  inset: 0;
  display: flex;
  transform: rotateY(180deg);
  background-color: #f1ead6;
  background-image: linear-gradient(160deg, rgba(255, 255, 255, .35), rgba(120, 90, 30, .12));
}
.back-inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: .9em .8em .8em;
  font-size: calc(var(--bk, .5) * 1em);
  font-family: "Handlee", cursive;
  line-height: 1.3;
  color: #2a3350;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, .25) transparent;
}
.back-date {
  margin: 0 0 .35em;
  font-family: "Special Elite", "Courier New", monospace;
  font-size: .6em;
  letter-spacing: .1em;
  text-transform: uppercase;
  opacity: .6;
}
.back-inner h3 {
  margin: 0 0 .25em;
  font-size: 1.3em;
  font-weight: normal;
  line-height: 1.15;
}
.back-text {
  margin: 0;
  font-size: 1em;
  white-space: pre-line;
}

/* markdown on the back of a photo */
.back-inner h1 { margin: .6em 0 .2em; font-size: 1.6em; font-weight: normal; line-height: 1.15; }
.back-inner h2 { margin: .4em 0 .2em; font-size: 1.25em; font-weight: normal; line-height: 1.15; }
.back-inner > :first-child { margin-top: 0; }
.back-inner p,
.back-inner li,
.back-inner blockquote { font-size: 1em; margin: .5em 0; }
.back-inner ul,
.back-inner ol { margin: .2em 0; padding-left: 1.1em; }
.back-inner blockquote { padding-left: .6em; border-left: 2px solid rgba(42, 51, 80, .4); }
.back-inner a { color: #1d4f91; }
.back-inner img { max-width: 100%; }
.back-inner code { font-family: "Special Elite", "Courier New", monospace; font-size: .8em; }

/* ---------- Pins ---------- */
.pinned::before {
  content: "";
  position: absolute;
  top: -.4em;
  left: calc(50% + var(--px, 0px));
  width: .85em; height: .85em;
  margin-left: -.42em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9a90 0 12%, var(--pin) 45%, #6b110d 100%);
  box-shadow: .15em .25em .25em rgba(0,0,0,.5);
  z-index: 3;
  transition: opacity .25s ease, transform .4s ease;
}
.pin-blue::before   { background: radial-gradient(circle at 35% 30%, #a7d4ff 0 12%, #2f6fb8 45%, #123560 100%); }
.pin-yellow::before { background: radial-gradient(circle at 35% 30%, #fff1a0 0 12%, #d9a91c 45%, #765407 100%); }
.pin-green::before  { background: radial-gradient(circle at 35% 30%, #b7f0b0 0 12%, #3a9a3a 45%, #17501a 100%); }

/* the pin pops out when the item is taken off the board */
.unpinned::before {
  opacity: 0;
  transform: translateY(-1.2em) scale(1.5);
}

/* ---------- Slip of paper ---------- */
.slip {
  filter: drop-shadow(.1em .25em .25em rgba(0, 0, 0, .4));
}
.slip-paper {
  aspect-ratio: 2 / 1;
  display: grid;
  place-items: center;
  padding: .55em .45em .3em;
  background-color: #f8f2de;
  background-image: linear-gradient(170deg, rgba(255, 255, 255, .5), rgba(130, 100, 40, .1));
  /* torn along the top edge, cut a little crooked along the bottom */
  clip-path: polygon(
    0% 9%, 4% 3%, 9% 10%, 14% 2%, 20% 9%, 27% 3%, 33% 10%, 40% 2%, 47% 9%, 54% 3%,
    61% 10%, 68% 2%, 75% 9%, 82% 3%, 89% 10%, 95% 3%, 100% 8%,
    100% 100%, 0% 96%
  );
  text-align: center;
  color: #26304d;
  font-family: "Handlee", cursive;
  font-size: 1.3em;
  line-height: 1.2;
}
.slip-text {
  display: block;
  transform: rotate(-1.5deg);
}

/* ---------- Sticky notes ---------- */
.note {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  padding: .5em;
  background-color: var(--note, #fff176);
  background-image: linear-gradient(170deg, rgba(255,255,255,.4), rgba(0,0,0,.07));
  box-shadow:
    inset 0 .7em .6em -.5em rgba(0,0,0,.14),
    .1em .3em .4em rgba(0,0,0,.4);
  color: var(--ink);
  text-decoration: none;
  text-align: center;
  font-family: "Handlee", cursive;
  font-size: calc(var(--w) * .1cqw * var(--ts, 2.2) * .65);
  line-height: 1;
  overflow-wrap: anywhere;
}
a.note { cursor: pointer; }
a.note:hover,
a.note:focus-visible {
  transform: rotate(0deg) scale(1.08);
  box-shadow: inset 0 .7em .6em -.5em rgba(0,0,0,.14), .15em .6em .9em rgba(0,0,0,.45);
  z-index: 30;
  outline: none;
}

/* ---------- Pinned page (its contents scroll) ---------- */
.page {
  display: flex;
  aspect-ratio: var(--ratio, .72);
  background-color: #fbf8ef;
  background-image: linear-gradient(175deg, rgba(255, 255, 255, .5), rgba(120, 90, 30, .08));
  box-shadow: 2px 7px 14px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .4);
  color: var(--ink);
  transition: transform var(--glide), left var(--glide), top var(--glide), width var(--glide), font-size var(--glide);
}
.page:hover:not(.is-focused),
.page:focus-within:not(.is-focused) {
  transform: rotate(0deg) scale(1.03);
  z-index: 30;
}

.page-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2.2em 2em 5em;
  font-size: calc(var(--bk, .5) * var(--pts, .5) * 2em);
  line-height: 1.55;
  scrollbar-width: 0;
  scrollbar-color: rgba(60, 40, 20, .35) transparent;
}
.page-scroll:focus-visible { outline: 2px solid rgba(60, 40, 20, .35); outline-offset: -2px; }

/* soft fade at the bottom to hint that there is more to scroll */
.page::after {
  content: "";
  position: absolute;
  left: 0; right: .7em; bottom: 0;
  height: 3em;
  background: linear-gradient(rgba(251, 248, 239, 0), #fbf8ef 85%);
  pointer-events: none;
}

.page-scroll h1,
.fold-content h1 {
  margin: 0;
  font-family: "Handlee", "Courier New", cursive;
  font-size: 2.2em;
  font-weight: normal;
  line-height: 1.05;
}
.page-scroll h2,
.fold-content h2 {
  margin: 1em 0 .25em;
  padding-bottom: .05em;
  border-bottom: 1px solid rgba(0, 0, 0, .25);
  font-family: "Handlee", cursive;
  font-size: 1.5em;
  font-weight: normal;
  line-height: 1.15;
}
/* h3 and h4 are plain bold titles that sit tight against each other:
  h3 has space above and none below, h4 has none above and space below */
.page-scroll h3,
.fold-content h3 {
  margin: 1em 0 0;
  font-size: 1em;
  font-weight: bold;
  line-height: 1.3;
}
.page-scroll h4,
.fold-content h4 {
  margin: 0 0 .5em;
  font-size: 1em;
  font-weight: bold;
  line-height: 1.3;
}
.page-scroll p,
.fold-content p { margin: .5em 0; }
.page-scroll .sub,
.page-scroll .meta { margin: 0; opacity: .65; }
.page-scroll ul,
.fold-content ul { margin: .4em 0; padding-left: 1.3em; }
.page-scroll a,
.fold-content a { color: #1d4f91; }

/* ---------- Folded letter (a sheet folded in thirds) ----------
  The box is the full sheet; the folded packet sits in its middle third.
  The top flap folds forward over the middle, the bottom flap folds up
  over that. Each panel shows its own third of one shared content block. */
.fold {
  aspect-ratio: var(--ratio, .72);
  perspective: 45em;
  pointer-events: none;
  --glide: calc(.8s * var(--ft, 1)) cubic-bezier(.3, .7, .2, 1);
  transition: transform var(--glide), left var(--glide), top var(--glide), width var(--glide), font-size var(--glide);
}
.fold:hover:not(.is-focused),
.fold:focus-visible:not(.is-focused) {
  transform: rotate(0deg) scale(1.05);
  z-index: 30;
  outline: none;
}
.fold:focus-visible .fold-a .fold-back { outline: 3px solid rgba(255, 255, 255, .45); }

.fold.pinned::before { top: calc(33.333% - .4em); }

.fold-sheet {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transition: box-shadow calc(.3s * var(--ft, 1)) ease;
}

.fold-panel {
  position: absolute;
  left: 0;
  width: 100%;
  height: 33.34%;
  transform-style: preserve-3d;
  pointer-events: auto;
  cursor: pointer;
  transition: transform calc(.7s * var(--ft, 1)) ease-in-out;
}
.fold-a { top: 0;      transform-origin: 50% 100%; transform: translateZ(.1em) rotateX(-180deg); transition-delay: calc(.4s * var(--ft, 1)); }
.fold-b { top: 33.33%; }
.fold-c { top: 66.66%; transform-origin: 50% 0;    transform: translateZ(.05em) rotateX(180deg); }

/* folding: bottom flap first, then the top. unfolding: top flap first. */
.is-focused .fold-a { transform: translateZ(0) rotateX(0deg); transition-delay: 0s; }
.is-focused .fold-c { transform: translateZ(0) rotateX(0deg); transition-delay: calc(.3s * var(--ft, 1)); }

.fold-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background-color: #fbf8ef;
  box-shadow: 0 .1em .3em rgba(0, 0, 0, .3);
  transition: box-shadow calc(1s * var(--ft, 1)) linear;
}
.fold-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, .1), inset 0 -1px 0 rgba(0, 0, 0, .1);
  transition: opacity calc(1s * var(--ft, 1)) linear;
}

/* once open, the creases and the per-panel shadows fade away, and the whole sheet gets one shadow */
.is-focused .fold-face { box-shadow: 0 0 0 rgba(0, 0, 0, 0); }
.is-focused .fold-face::after { opacity: 0; }
.is-focused .fold-sheet {
  box-shadow: 2px 7px 14px rgba(0, 0, 0, .45);
  transition-duration: calc(.5s * var(--ft, 1));
  transition-delay: calc(.5s * var(--ft, 1));
}

/* outside of the paper: slightly darker, with a handwritten title on the top flap */
.fold-back {
  transform: rotateX(180deg);
  display: grid;
  place-items: center;
  background-color: #f1ead6;
  background-image: linear-gradient(160deg, rgba(255, 255, 255, .35), rgba(120, 90, 30, .12));
  color: #26304d;
  font-family: "Handlee", cursive;
  font-size: 1.5em;
  line-height: 1.15;
  text-align: center;
}

/* one content block per panel, shifted so each shows its own third */
.fold-content {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 300%;
  padding: 2.2em 2em;
  background-image: linear-gradient(175deg, rgba(255, 255, 255, .5), rgba(120, 90, 30, .08));
  color: var(--ink);
  /* normal reading size on screen once the sheet is up front */
  font-size: calc(var(--bk, .5) * 1em);
  line-height: 1.55;
}
.fold-b .fold-content { top: -100%; }
.fold-c .fold-content { top: -200%; }

/* ---------- Brought to the front ----------
  --fx / --fy / --fw / --ffs / --bk are set by layoutFocus() in script.js */
.board .item.is-focused {
  left: var(--fx);
  top: var(--fy);
  width: var(--fw);
  font-size: var(--ffs);
  z-index: 50;
  cursor: default;
  transform: rotate(0deg);
}
.item.lift { z-index: 40; }


.dim {
  position: absolute;
  inset: 0;
  z-index: 35;
  border-radius: 4px;
  background: rgba(0, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s ease;
}
.has-focus .dim {
  opacity: 1;
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; transition-delay: 0s !important; }
}

/* ---------- Option slip ---------- */
.option .slip-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3em;
  cursor: pointer;
}
.option input {
  width: .8em;
  height: .8em;
  margin: 0;
  accent-color: #26304d;
  cursor: pointer;
}

/* ---------- Readable font ---------- */
body.readable,
body.readable * { font-family: "Courier New", Courier, monospace !important; }

body.readable h1,
body.readable h2,
body.readable h3,
body.readable h4 { font-weight: bold; }

/* Courier is much wider than the handwriting fonts, so sizes come down */
body.readable .slip-paper { font-size: 1em; }
body.readable .note { font-size: calc(var(--w) * .1cqw * var(--ts, 2.2) * .55); }
body.readable .front .caption { font-size: calc(var(--cap) * 1em); }
body.readable .back-inner { font-size: calc(var(--bk, .5) * 1em); line-height: 1.3; }
body.readable .fold-back { font-size: 1.3em; }
body.readable .slip-text { transform: rotate(1.5deg); }

/* ---------- Phones ----------
  Keep the 700px in step with MOBILE_MAX in script.js */
@media (max-width: 700px) {
  /* a tall, narrow board on phones (never taller than the screen) */
  .frame { width: min(94vw, 56vh); width: min(94vw, 56dvh); }
  .board { aspect-ratio: 10 / 16; }

  /* taller photo (and back of the photo) when brought forward */
  .photo-card.tall .front img { aspect-ratio: 3 / 4; }

  /* the board is small on a phone, so the dim layer must cover the whole screen */
  .dim { inset: -200vh -200vw; border-radius: 0; }
}

/* ---------- Phone notice (script.js adds it on phones) ---------- */
.phone-notice {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 14, 8, .88);
}
.phone-notice-card {
  max-width: 340px;
  padding: 1.4em 1.3em 1.2em;
  background-color: #f8f2de;
  background-image: linear-gradient(170deg, rgba(255, 255, 255, .5), rgba(130, 100, 40, .1));
  border-radius: 4px;
  box-shadow: 2px 8px 20px rgba(0, 0, 0, .6);
  color: #26304d;
  font-family: "Handlee", cursive;
  text-align: center;
}
.phone-notice-card h2 { margin: 0 0 .5em; font-size: 1.4em; font-weight: normal; line-height: 1.2; }
.phone-notice-card p { margin: 0 0 1.1em; font-size: 1em; line-height: 1.45; }
.phone-notice-card button {
  padding: .7em 1em;
  border: 0;
  border-radius: 4px;
  background: #26304d;
  color: #f8f2de;
  font: inherit;
  cursor: pointer;
}
body.readable .phone-notice-card { font-family: "Courier New", Courier, monospace !important; }

/* photos with flip: false stay facing front when brought forward */
.photo-card.noflip.is-focused .photo-flip {
  transform: none;
}

/* pdf items: the pdf fills the paper exactly, and only takes clicks once brought forward */
.pdf .pdf-view {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.pdf .pdf-view object {
  display: block;
  width: calc(100% + 20px);   /* pushes the scrollbar out of view */
  height: 100%;
  border: 0;
  pointer-events: none;
}

.pdf.is-focused .pdf-view object {
  pointer-events: auto;
}
/* the scroll-fade that pages have would cover the bottom of the pdf */
.pdf::after {
  display: none;
}

/* a pdf keeps its own shape on the board and grows into a tall page when brought forward */
.pdf {
  transition: transform var(--glide), left var(--glide), top var(--glide), width var(--glide), font-size var(--glide), aspect-ratio var(--glide);
}
.pdf.is-focused {
  aspect-ratio: var(--focus-ratio, .72);
}

/* ---------- Videos ---------- */
.front video {
  display: block;
  width: 100%;
  aspect-ratio: var(--ratio, 1.778);
  object-fit: cover;
  background: #000;
  pointer-events: none;            /* clicks go to the card until it is brought forward */
}
.video-card.is-focused .front video {
  pointer-events: auto;
  object-fit: contain;             /* never crop a video once it is up front */
}

/* a small play button on the board, hidden once the video is brought forward */
.video-card .front::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(50% - .7em);
  width: 2.2em;
  height: 2.2em;
  margin: -1.1em 0 0 -1.1em;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  pointer-events: none;
  transition: opacity .25s ease;
}
.video-card .front::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(50% - .7em);
  margin: -.55em 0 0 -.3em;
  border-style: solid;
  border-width: .55em 0 .55em .95em;
  border-color: transparent transparent transparent #fff;
  z-index: 1;
  pointer-events: none;
  transition: opacity .25s ease;
}
.video-card.is-focused .front::before,
.video-card.is-focused .front::after { opacity: 0; }

/* ---------- Titles on photos that don't flip ----------
  The caption stays hidden on the board and fades in once the photo is brought
  forward; it fades out again as soon as the photo goes back. */
.photo-card.noflip .front .caption {
  opacity: 0;
  transition: opacity .2s ease;
}
.photo-card.noflip.is-focused .front .caption {
  opacity: 1;
  transition: opacity .35s ease .25s;
}