@font-face {
  font-family: "Caveat";
  src: url("fonts/caveat.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --desk: #e5dfd3;
  --desk-shade: #d6cfc0;

  --cloth: #2c4538;
  --cloth-deep: #1f3229;
  --label: #f5efdf;
  --label-key: #8b806b;

  --paper: #fbf8f0;
  --paper-edge: #ece4d2;
  --rule: #c9d7e4;
  --margin: #e4aaa3;
  --hole: rgba(74, 62, 46, 0.5);

  --ink: #1f2d4d;
  --ink-soft: #56607a;
  --pencil: #8b857a;
  --red-pen: #b0443a;
  --green-pen: #2f6b4f;
  --ribbon: #9b3a32;

  --tab-1: #f0d68f;
  --tab-2: #b4cfdc;
  --tab-3: #e8b9ad;
  --tab-4: #bcd5b3;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --hand: "Caveat", "Bradley Hand", "Segoe Print", cursive;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --pw: min(460px, 42vw, calc((100svh - 112px) * 0.74));
  --ph: calc(var(--pw) / 0.74);
  --line: calc(var(--pw) / 15);
  --ease: cubic-bezier(0.55, 0.05, 0.2, 1);
  --noise-desk: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .3  0 0 0 0 .25  0 0 0 0 .18  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --noise-paper: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .3  0 0 0 0 .2  0 0 0 .05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --noise-cloth: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background:
    var(--noise-desk),
    radial-gradient(ellipse at 50% 40%, var(--desk) 40%, var(--desk-shade) 100%);
  background-color: var(--desk);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--ink-soft);
  outline-offset: 3px;
  border-radius: 3px;
}

.hand { font-family: var(--hand); }

/* ---------- desk ---------- */

.desk {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 48px 0 64px;
}

.prop {
  position: absolute;
  filter: drop-shadow(6px 10px 8px rgba(60, 45, 25, 0.22));
  transition: opacity 0.7s ease, transform 0.9s var(--ease);
}
.pencil { width: clamp(220px, 24vw, 340px); left: 4vw; top: 62%; transform: rotate(-58deg); }
.glasses { width: clamp(160px, 17vw, 240px); right: 6vw; top: 8%; transform: rotate(14deg); }

.desk:not([data-state="closed"]) .prop { opacity: 0; }
.desk:not([data-state="closed"]) .pencil { transform: translate(-12vw, 6vh) rotate(-58deg); }
.desk:not([data-state="closed"]) .glasses { transform: translate(10vw, -8vh) rotate(14deg); }

.hint {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 22px;
  color: var(--ink-soft);
  transition: opacity 0.4s ease;
}
.hint::before { content: "↑ "; }
.desk:not([data-state="closed"]) .hint { opacity: 0; }

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

.book {
  position: relative;
  width: calc(var(--pw) * 2);
  height: var(--ph);
  font-size: calc(var(--pw) / 26.25);
  perspective: calc(var(--pw) * 6);
  transition: transform 0.9s var(--ease);
}
.book[data-current="0"] { transform: translateX(-25%) rotate(-4deg) scale(0.86); }
.book[data-current="5"] { transform: translateX(25%) rotate(3deg) scale(0.86); }
/* Closing: the cover shuts first, then the book slides back. */
.book[data-current="0"],
.book[data-current="5"] { transition-delay: 0.35s; }

.book::before {
  content: "";
  position: absolute;
  inset: 0 0 0 0;
  border-radius: 8px;
  box-shadow: 0 30px 60px -24px rgba(50, 38, 20, 0.55), 0 4px 10px rgba(50, 38, 20, 0.12);
  /* Opening: the shadow only reaches the other half as the cover lands there. */
  transition: left 0.4s ease-out 0.6s, right 0.4s ease-out 0.6s;
}
.book[data-current="0"]::before { left: 50%; }
.book[data-current="5"]::before { right: 50%; }
.book[data-current="0"]::before,
.book[data-current="5"]::before { transition: left 0.35s ease-in, right 0.35s ease-in; }

.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.9s var(--ease);
}
.leaf.flipped { transform: rotateY(-180deg); }

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

/* ---------- cover ---------- */

.cover {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 4px 12px 12px 4px;
  background:
    var(--noise-cloth),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 28% 18%, rgba(255, 255, 255, 0.09), transparent 60%),
    var(--cloth);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.25),
    inset 0 2px 0 rgba(255, 255, 255, 0.06),
    inset -6px 0 12px -6px rgba(0, 0, 0, 0.35);
}
.back-cover { border-radius: 12px 4px 4px 12px; }

.elastic {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 2.2em;
  width: 0.85em;
  background: linear-gradient(90deg, #15221b, #22362c 45%, #15221b);
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3), -1px 0 2px rgba(0, 0, 0, 0.25);
}

.label {
  position: absolute;
  top: 21%;
  left: 18%;
  right: 22%;
  display: grid;
  gap: 0.35em;
  padding: 1em 1.2em 1.1em;
  background: var(--noise-paper), var(--label);
  border-radius: 7px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 0 0 0.3em var(--label), inset 0 0 0 calc(0.3em + 1px) #cfc4ab;
  color: var(--ink);
}
.field { display: grid; grid-template-columns: 4.4em 1fr; align-items: end; }
.field .key {
  font-family: var(--serif);
  font-size: 0.62em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--label-key);
  padding-bottom: 0.55em;
}
.field .hand {
  font-size: 1.45em;
  line-height: 1.3;
  border-bottom: 1px solid #cdbfa3;
  white-space: nowrap;
}

.cover-sticker {
  position: absolute;
  height: auto;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)) drop-shadow(0 3px 6px rgba(0, 0, 0, 0.18));
}
.cover-sticker text {
  font-family: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-weight: 800;
}
.cover-sticker.plane { width: 34%; left: 46%; top: 5%; transform: rotate(-5deg); }
.cover-sticker.sky { width: 25%; left: 9%; top: 50%; transform: rotate(-9deg); }
.cover-sticker.found { width: 22%; left: 37%; top: 49%; transform: rotate(8deg); }
.cover-sticker.users { width: 21%; left: 62%; top: 52%; transform: rotate(-6deg); }
.cover-sticker.build { width: 44%; left: 12%; top: 75%; transform: rotate(-4deg); }
.cover-sticker.rocket { width: 15%; left: 63%; top: 66%; transform: rotate(14deg); }

.deboss {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2.4em;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.75em;
  letter-spacing: 0.2em;
  color: rgba(0, 0, 0, 0.32);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.07);
}

/* ---------- pages ---------- */

.page {
  padding: var(--line) 2.5em 0 3.9em;
  line-height: var(--line);
  color: var(--ink);
  background:
    var(--noise-paper),
    radial-gradient(circle, var(--hole) 0 0.26em, transparent 0.29em) 0.15em 0 / 1em var(--line) repeat-y,
    linear-gradient(to right, rgba(70, 52, 28, 0.13), rgba(70, 52, 28, 0) 10%),
    var(--paper);
}
.page.left {
  border-radius: 6px 2px 2px 6px;
  background:
    var(--noise-paper),
    radial-gradient(circle, var(--hole) 0 0.26em, transparent 0.29em) calc(100% - 0.15em) 0 / 1em var(--line) repeat-y,
    linear-gradient(to left, rgba(70, 52, 28, 0.13), rgba(70, 52, 28, 0) 10%),
    var(--paper);
}
.page.right { border-radius: 2px 6px 6px 2px; }

.page::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--line) * 2 - 0.42em);
  bottom: calc(var(--line) * 0.6);
  background: linear-gradient(var(--rule) 1px, transparent 1px) 0 0 / 100% var(--line);
  pointer-events: none;
}
.page::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3.1em;
  width: 1px;
  background: var(--margin);
  pointer-events: none;
}
.page.left::before { right: 1.2em; }
.page.right::before { left: 1.2em; }

.page > * { position: relative; z-index: 1; }

.page p,
.page ul,
.page ol,
.page h2,
.page pre,
.page figure { margin: 0; }

.page p + p { margin-top: var(--line); }

.title {
  font-size: 2.1em;
  font-weight: 600;
  line-height: calc(var(--line) * 1);
  height: var(--line);
  color: var(--ink);
  letter-spacing: 0.01em;
}
.title + * { margin-top: var(--line) !important; }

.lede { font-weight: 600; }

.note {
  font-size: 1.45em;
  line-height: var(--line);
  color: var(--red-pen);
  margin-top: var(--line) !important;
}

.page a {
  text-decoration-color: rgba(31, 45, 77, 0.35);
  text-underline-offset: 0.18em;
}
.page a:hover { text-decoration-color: currentColor; }

.folio {
  position: absolute;
  top: calc(var(--line) * 0.35);
  font-family: var(--hand);
  font-size: 1.15em;
  line-height: 1;
  color: var(--pencil);
}
.page.left .folio { left: 1.1em; }
.page.right .folio { right: 1.2em; }

.turn {
  position: absolute;
  bottom: calc(var(--line) * 0.55);
  font-size: 1.35em;
  line-height: 1;
  color: var(--ink-soft);
  padding: 0.2em 0.1em;
}
.turn:hover { color: var(--ink); text-decoration: underline wavy rgba(31, 45, 77, 0.4) 1px; text-underline-offset: 0.25em; }
.page.right .turn { right: 2.3em; }
.page.left .turn { left: 3.9em; }

/* polaroid */
.polaroid {
  float: right;
  width: 7.4em;
  margin: -0.3em -0.8em 0.8em 1.2em !important;
  padding: 0.45em 0.45em 0;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), 0 6px 14px -6px rgba(60, 45, 25, 0.35);
  transform: rotate(3.5deg);
}
.polaroid::before {
  content: "";
  position: absolute;
  top: -0.7em;
  left: 50%;
  width: 3.4em;
  height: 1.3em;
  transform: translateX(-50%) rotate(-5deg);
  background: rgba(232, 220, 186, 0.78);
  box-shadow: 0 0 0 1px rgba(160, 140, 100, 0.12);
}
.polaroid img { display: block; width: 100%; height: auto; filter: saturate(0.92) contrast(1.02); }
.polaroid figcaption {
  font-size: 1.15em;
  line-height: 1.7;
  text-align: center;
  color: var(--ink-soft);
}

/* code */
.code {
  font-family: var(--mono);
  font-size: 0.82em;
  line-height: var(--line);
  white-space: pre;
  color: var(--ink);
  counter-reset: ln;
  min-height: calc(var(--line) * 6);
}
.code .ln { display: block; position: relative; height: var(--line); counter-increment: ln; }
.code .ln::before {
  content: counter(ln);
  position: absolute;
  left: -3.4em;
  width: 2.2em;
  text-align: right;
  font-family: var(--hand);
  font-size: 1.25em;
  color: var(--pencil);
}
.code .kw { color: var(--red-pen); }
.code .const { color: var(--green-pen); }
.code .fn { color: #2a4a8a; }

/* note to self */
.poem {
  font-size: 2.1em;
  line-height: var(--line);
  color: var(--ink);
}
.poem .word { white-space: nowrap; }
.poem .ch { opacity: 0; transition: opacity 0.18s ease-out; }
.poem .ch.on { opacity: 1; }
.signed { text-align: right; margin-top: 0 !important; }
.scribble {
  font-size: 1.2em;
  color: var(--pencil);
  margin-top: var(--line) !important;
  transform: rotate(-2deg);
  transform-origin: left center;
}
.margin-code { font-size: 0.72em; min-height: 0; }
[data-after-poem],
.margin-code .ln { transition: opacity 0.45s ease-out; }
.unwritten { opacity: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* entries */
.entries { list-style: none; padding: 0; }
.entries li + li { margin-top: var(--line); }
.entries p + p { margin-top: 0; }
.when {
  display: block;
  font-family: var(--hand);
  font-size: 1.3em;
  color: var(--pencil);
}
.what { font-weight: 600; }

/* projects */
.projects { list-style: none; padding: 0; }
.projects li {
  display: grid;
  grid-template-columns: 3.4em 1fr;
  grid-template-rows: var(--line) auto;
  min-height: calc(var(--line) * 3);
}
.sticker {
  grid-row: 1 / 3;
  width: 2.5em;
  height: 2.5em;
  margin-top: 0.3em;
  padding: 0.18em;
  object-fit: contain;
  background: #fff;
  border-radius: 0.7em;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16), 0 4px 8px -4px rgba(60, 45, 25, 0.3);
  transform: rotate(-3deg);
}
.projects li:nth-child(even) .sticker { transform: rotate(2.5deg); }
.projects .name {
  font-size: 1.4em;
  font-weight: 600;
  line-height: var(--line);
  color: var(--ink);
}
.projects a.name {
  justify-self: start;
  text-decoration: none;
  background: linear-gradient(transparent 62%, rgba(240, 214, 143, 0.55) 62% 92%, transparent 92%);
}
.projects a.name:hover { background: linear-gradient(transparent 62%, rgba(240, 214, 143, 0.95) 62% 92%, transparent 92%); }
.projects .soon { font-size: 0.7em; font-weight: 400; color: var(--red-pen); margin-left: 0.3em; }
.projects p { color: var(--ink-soft); font-size: 0.94em; }

/* snapshots */
.snapshots {
  display: flex;
  justify-content: center;
  gap: 1.2em;
  margin-top: calc(var(--line) * 1.5) !important;
}
.polaroid.snap {
  float: none;
  width: 44%;
  height: auto;
  margin: 0 !important;
  transform: rotate(-3deg);
}
.polaroid.snap + .polaroid.snap { transform: rotate(2.5deg) translateY(1.4em); }
.photo-slot {
  aspect-ratio: 4 / 5;
  display: grid;
  place-items: center;
  font-size: 1.2em;
  color: var(--pencil);
  background: repeating-linear-gradient(-45deg, #f1ede4 0 6px, #e9e4d8 6px 12px);
}
.snap img { aspect-ratio: 4 / 5; object-fit: cover; }

/* links */
.links { list-style: none; padding: 0; }
.links li { display: grid; grid-template-columns: 6.2em 1fr; align-items: baseline; }
.links li + li { margin-top: var(--line); }
.links .key {
  font-size: 0.72em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pencil);
}

/* last page */
.last { text-align: center; padding-left: 2.6em; }
.salam {
  margin-top: calc(var(--line) * 4) !important;
  font-family: "Kefa", "Abyssinica SIL", "Noto Serif Ethiopic", var(--serif);
  font-size: 3.2em;
  line-height: calc(var(--line) * 3);
  height: calc(var(--line) * 3);
}
.thanks { font-style: italic; margin-top: var(--line) !important; }

/* ---------- spiral, ribbon, tabs ---------- */

.spiral {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2.3em;
  transform: translateX(-50%);
  z-index: 500;
  pointer-events: none;
}
.spiral span {
  position: absolute;
  left: 0;
  right: 0;
  height: 0.5em;
  margin-top: -0.25em;
  border-radius: 999px;
  border: 0.17em solid #8f8d87;
  border-top-color: #d6d4cd;
  border-bottom-color: #6f6d68;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.22);
}

.ribbon {
  position: absolute;
  left: calc(50% + 2.4em);
  bottom: -3.4em;
  width: 0.6em;
  height: 5em;
  background: linear-gradient(90deg, #86302a, var(--ribbon) 40%, #86302a);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 86%, 0 100%);
  transform: rotate(-6deg);
  transform-origin: top center;
  transition: left 1s var(--ease);
}
.book[data-current="0"] .ribbon { left: calc(50% + 6em); }

.tabs {
  position: absolute;
  top: calc(var(--line) * 2);
  left: calc(100% - 0.8em);
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  transition: opacity 0.4s ease 0.8s;
}
.book[data-current="0"] .tabs,
.book[data-current="5"] .tabs { opacity: 0; pointer-events: none; transition-delay: 0s; }

.tab {
  padding: 0.2em 0.85em 0.25em 1.35em;
  font-size: 1.3em;
  line-height: 1.2;
  text-align: left;
  border-radius: 0 9px 9px 0;
  white-space: nowrap;
  color: var(--ink);
  box-shadow: 1px 2px 3px rgba(60, 45, 25, 0.18);
  transition: transform 0.25s ease, filter 0.25s ease;
}
.tab:nth-child(1) { background: var(--tab-1); }
.tab:nth-child(2) { background: var(--tab-2); }
.tab:nth-child(3) { background: var(--tab-3); }
.tab:nth-child(4) { background: var(--tab-4); }
.tab:not([aria-current]) { filter: saturate(0.6) brightness(0.97); }
.tab:hover,
.tab[aria-current] { transform: translateX(0.45em); filter: none; }

/* ---------- small screens: pages become a stack ---------- */

@media (max-width: 760px) {
  :root { --line: 28px; }
  .desk { display: block; padding: 20px 16px 48px; }
  .prop, .hint, .tabs, .spiral, .ribbon, .turn { display: none; }
  .book,
  .book[data-current="0"],
  .book[data-current="5"] {
    width: auto;
    height: auto;
    font-size: 16px;
    perspective: none;
    transform: none;
  }
  .book::before { display: none; }
  .leaf { display: contents; }
  .face,
  .face.back {
    position: relative;
    inset: auto;
    transform: none;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    margin-bottom: 16px;
    box-shadow: 0 10px 24px -14px rgba(50, 38, 20, 0.5), 0 1px 3px rgba(50, 38, 20, 0.12);
  }
  .cover { height: 62svh; border-radius: 6px 12px 12px 6px; }
  .back-cover { height: 120px; border-radius: 6px; }
  .page,
  .page.left {
    border-radius: 4px;
    padding: var(--line) 20px var(--line) 3.6em;
    min-height: 0;
    background: var(--noise-paper), var(--paper);
  }
  .page::before { left: 0 !important; right: 0 !important; bottom: 0; }
  .page::after { left: 2.8em; }
  .page.left .folio,
  .page.right .folio { left: auto; right: 16px; }
  .label { left: 12%; right: 20%; }
  .cover-sticker.plane { width: 30%; left: 50%; top: 5%; }
  .cover-sticker.sky { width: 20%; left: 8%; top: 60%; }
  .cover-sticker.found { width: 18%; left: 32%; top: 59%; }
  .cover-sticker.users { width: 19%; left: 56%; top: 61%; }
  .cover-sticker.build { width: 38%; left: 12%; top: 81%; }
  .cover-sticker.rocket { width: 11%; left: 62%; top: 74%; }
  .polaroid {
    float: none;
    display: block;
    width: 9.5em;
    height: calc(var(--line) * 8);
    margin: calc(var(--line) * 0.5) auto calc(var(--line) * 0.5) !important;
  }
  .polaroid + .title { margin-top: 0 !important; }
  .polaroid.snap { width: 44%; height: auto; margin: 0 !important; }
  .snapshots { padding-bottom: calc(var(--line) * 1.5); }
  .last { padding-bottom: calc(var(--line) * 2); }
  .salam { margin-top: var(--line) !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
