:root {
  --parchment: #F3E7D0;
  --paper: #FFF7E8;
  --leather: #7A4A2A;
  --ink: #2F2118;
  --terracotta: #B96542;
  --olive: #667255;
  --moss: #A8B68A;
  --pencil: #8B8173;
  --hand: "Caveat", "Comic Sans MS", cursive;
  --display: "Fraunces", Georgia, serif;
  --body: "Nunito Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--parchment);
  font-family: var(--body);
  overflow-x: hidden;
}

.desk-field {
  position: fixed;
  inset: 0;
  z-index: -5;
  background:
    radial-gradient(circle at 16% 14%, rgba(255, 247, 232, .95) 0 16%, transparent 34%),
    radial-gradient(ellipse at 82% 22%, rgba(168, 182, 138, .28), transparent 34%),
    radial-gradient(ellipse at 70% 82%, rgba(185, 101, 66, .18), transparent 38%),
    linear-gradient(105deg, #F3E7D0, #FFF7E8 52%, #EAD7B9);
}

.grain,
.leather-tab::before,
.stitched-rail::before,
.paper-band::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(47, 33, 24, .16) .6px, transparent .8px),
    linear-gradient(90deg, rgba(122, 74, 42, .05) 1px, transparent 1px),
    linear-gradient(rgba(255, 247, 232, .16) 1px, transparent 1px);
  background-size: 13px 13px, 31px 100%, 100% 19px;
  opacity: .28;
  mix-blend-mode: multiply;
}

.cup-ring {
  position: fixed;
  width: 190px;
  height: 138px;
  border: 4px double rgba(122, 74, 42, .18);
  border-radius: 48% 52% 47% 53%;
  transform: rotate(-13deg);
}

.ring-one { right: 8vw; top: 24vh; }
.ring-two { left: 24vw; bottom: 10vh; transform: rotate(18deg) scale(.72); opacity: .7; }

.corner-protector {
  position: fixed;
  width: 180px;
  height: 180px;
  background: var(--leather);
  opacity: .86;
  box-shadow: inset 0 0 35px rgba(47, 33, 24, .5), 0 16px 32px rgba(47, 33, 24, .18);
}

.protector-top { right: -82px; top: -82px; border-radius: 0 0 0 95%; }
.protector-bottom { left: -100px; bottom: -105px; border-radius: 0 95% 0 0; }

.leather-tab {
  position: fixed;
  top: clamp(18px, 3vw, 34px);
  left: clamp(18px, 3vw, 38px);
  right: clamp(18px, 3vw, 42px);
  height: clamp(92px, 12vh, 132px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: clamp(22px, 5vw, 72px);
  padding: 16px clamp(22px, 4vw, 54px);
  color: var(--paper);
  background: var(--leather);
  border-radius: 30px 20px 34px 18px;
  box-shadow: inset 0 0 28px rgba(47, 33, 24, .48), 0 22px 40px rgba(47, 33, 24, .22);
  transform: translateX(-110%);
  animation: tabSettle 1.2s cubic-bezier(.2,.8,.16,1) forwards .12s;
  overflow: hidden;
}

.brand-wrap { position: relative; flex: 0 0 auto; }

h1 {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(46px, 7vw, 82px);
  font-weight: 700;
  letter-spacing: .01em;
  line-height: .78;
  text-shadow: 0 2px 0 rgba(47, 33, 24, .22);
}

h1 span { display: inline-block; transform: rotate(-1.5deg) translateY(2px); }

.gack-underline {
  position: absolute;
  width: 47%;
  left: 37%;
  bottom: -26px;
  overflow: visible;
}

.gack-underline path,
.loop-arrow path,
.stitch-card path {
  fill: none;
  stroke: currentColor;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 260;
  stroke-dashoffset: 260;
  animation: drawLine 1.1s ease forwards 1.1s;
}

.top-thoughts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  padding-top: 9px;
}

.margin-note {
  position: relative;
  display: inline-block;
  margin: 0;
  color: var(--olive);
  font-family: var(--hand);
  font-size: clamp(21px, 2.2vw, 32px);
  line-height: 1;
  transform: rotate(-1deg);
}

.leather-tab .margin-note { color: #F3E7D0; opacity: .92; }
.margin-note.tilt { transform: rotate(2deg) translateY(4px); }

.margin-note span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -8px;
  height: 8px;
  transform-origin: left;
  transform: scaleX(0);
  border-bottom: 3px solid currentColor;
  border-radius: 50%;
  transition: transform .42s ease;
}

.margin-note.draw span,
.margin-note:hover span { transform: scaleX(1); }

.stitched-rail {
  position: fixed;
  z-index: 18;
  top: clamp(138px, 19vh, 178px);
  bottom: clamp(22px, 4vh, 42px);
  left: clamp(24px, 4vw, 62px);
  width: 112px;
  padding: 28px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  background: rgba(122, 74, 42, .93);
  border-radius: 999px;
  box-shadow: inset 0 0 24px rgba(47, 33, 24, .48), 0 16px 36px rgba(47, 33, 24, .18);
  transform: translateY(24px);
  opacity: 0;
  animation: railArrive .9s ease forwards .9s;
  overflow: hidden;
}

.stitched-rail::after {
  content: "";
  position: absolute;
  top: 22px;
  bottom: 22px;
  left: 50%;
  border-left: 2px dashed rgba(255, 247, 232, .55);
}

.knot {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--paper);
  font-family: var(--hand);
  font-size: 22px;
  cursor: pointer;
}

.knot i {
  width: 25px;
  height: 25px;
  border-radius: 46% 54% 52% 48%;
  background: var(--parchment);
  border: 4px solid rgba(47, 33, 24, .35);
  box-shadow: 0 0 0 4px rgba(255, 247, 232, .13);
  transition: transform .25s ease, background .25s ease;
}

.knot span { max-width: 82px; line-height: .9; }
.knot.active i { background: var(--terracotta); transform: scale(1.18) rotate(15deg); }
.knot.active span { color: #FFF7E8; }

.notebook {
  position: relative;
  min-height: 100vh;
  padding-left: clamp(154px, 17vw, 236px);
}

.spread {
  position: absolute;
  inset: 0;
  min-height: 100vh;
  padding: clamp(178px, 21vh, 220px) clamp(28px, 7vw, 94px) clamp(42px, 7vh, 84px) 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(210px, 330px);
  gap: clamp(24px, 4vw, 62px);
  align-items: center;
  opacity: 0;
  transform: translateX(70px) rotate(.7deg);
  pointer-events: none;
  transition: opacity .55s ease, transform .65s cubic-bezier(.2,.78,.18,1);
}

.spread.active {
  position: relative;
  opacity: 1;
  transform: translateX(0) rotate(0deg);
  pointer-events: auto;
}

.spread.turning { animation: pageFlip .62s ease; }

.paper-band {
  position: absolute;
  z-index: -2;
  width: min(78vw, 1060px);
  height: min(58vh, 550px);
  top: 25vh;
  background: rgba(255, 247, 232, .8);
  border-radius: 28% 6% 35% 8% / 12% 28% 10% 34%;
  box-shadow: inset 0 0 62px rgba(122, 74, 42, .09), 0 22px 60px rgba(47, 33, 24, .12);
  mask-image: radial-gradient(circle at 0 50%, transparent 0 16px, #000 17px), linear-gradient(#000, #000);
}

.band-left { left: clamp(126px, 16vw, 220px); transform: rotate(-1.4deg); }
.band-right { right: clamp(8px, 5vw, 86px); transform: rotate(1.2deg); border-radius: 7% 30% 9% 28% / 30% 14% 34% 11%; }
.torn { mask-image: radial-gradient(circle at 100% 34%, transparent 0 22px, #000 23px), linear-gradient(#000, #000); }
.final-band { background: rgba(243, 231, 208, .88); }

.spread-copy {
  position: relative;
  max-width: 860px;
  padding: clamp(20px, 4vw, 42px);
}

.spread-copy.narrow { max-width: 760px; }
.chapter-label {
  margin: 0 0 16px;
  color: var(--terracotta);
  font-family: var(--hand);
  font-size: clamp(34px, 5vw, 58px);
  line-height: .8;
}

h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(48px, 7vw, 112px);
  font-weight: 650;
  font-variation-settings: "SOFT" 80, "WONK" 1;
  line-height: .98;
  letter-spacing: -.045em;
}

.spread-copy > p:last-child {
  max-width: 650px;
  margin: 28px 0 0;
  color: rgba(47, 33, 24, .76);
  font-size: clamp(17px, 1.45vw, 23px);
  line-height: 1.72;
}

.marginalia {
  position: relative;
  display: grid;
  gap: 30px;
  align-content: center;
  padding: 30px 16px;
}

.right-notes { transform: translateY(28px); }
.loop-arrow, .stitch-card { width: 160px; color: var(--terracotta); opacity: .82; }
.stitch-card { color: var(--olive); }

.check-flower {
  position: relative;
  width: 86px;
  height: 86px;
  transform: rotate(-12deg);
}

.check-flower b {
  position: absolute;
  width: 38px;
  height: 38px;
  border: 3px solid var(--olive);
  border-radius: 48% 52% 46% 54%;
}

.check-flower b:nth-child(1) { left: 22px; top: 0; }
.check-flower b:nth-child(2) { right: 0; top: 24px; }
.check-flower b:nth-child(3) { left: 22px; bottom: 0; }
.check-flower b:nth-child(4) { left: 0; top: 24px; }

.blob {
  position: absolute;
  z-index: -1;
  display: grid;
  place-items: center;
  width: clamp(150px, 18vw, 260px);
  height: clamp(130px, 16vw, 230px);
  color: rgba(47, 33, 24, .62);
  font-family: var(--hand);
  font-size: clamp(36px, 5vw, 64px);
  opacity: .72;
  filter: saturate(.9);
  box-shadow: inset 12px -18px 42px rgba(255, 247, 232, .32);
  transition: border-radius .5s ease, transform .5s ease, opacity .5s ease;
  animation: blobBreath 7s ease-in-out infinite alternate;
}

.blob.relaxed { opacity: .9; transform: translate(var(--blob-x, 0), var(--blob-y, 0)) scale(1.05) rotate(-2deg); }
.moss { background: rgba(168, 182, 138, .68); }
.terracotta { background: rgba(185, 101, 66, .38); }
.olive { background: rgba(102, 114, 85, .32); }
.blob-a { right: 16vw; top: 31vh; border-radius: 56% 44% 62% 38% / 42% 61% 39% 58%; }
.blob-b { left: 23vw; bottom: 13vh; border-radius: 39% 61% 43% 57% / 58% 40% 60% 42%; }
.blob-c { right: 18vw; bottom: 12vh; border-radius: 65% 35% 47% 53% / 39% 54% 46% 61%; }
.blob-d { left: 25vw; top: 30vh; border-radius: 42% 58% 34% 66% / 53% 38% 62% 47%; }

.reset-tab {
  width: max-content;
  border: 0;
  border-radius: 999px 999px 999px 18px;
  padding: 12px 20px;
  color: var(--paper);
  background: var(--leather);
  font-family: var(--hand);
  font-size: 26px;
  box-shadow: inset 0 0 14px rgba(47, 33, 24, .42), 0 12px 22px rgba(47, 33, 24, .16);
  cursor: pointer;
}

@keyframes tabSettle { 0% { transform: translateX(-110%) rotate(-2deg); } 74% { transform: translateX(10px) rotate(.5deg); } 100% { transform: translateX(0) rotate(0); } }
@keyframes railArrive { to { opacity: 1; transform: translateY(0); } }
@keyframes drawLine { to { stroke-dashoffset: 0; } }
@keyframes pageFlip { 0% { filter: brightness(.98); } 45% { transform: translateX(-32px) rotate(-1.2deg); filter: brightness(1.05); } 100% { filter: brightness(1); } }
@keyframes blobBreath { to { transform: translate(8px, -10px) rotate(2deg); } }

body.restarting .leather-tab { animation: tabSettle .8s cubic-bezier(.2,.8,.16,1) both; }
body.restarting .stitched-rail { animation: railArrive .7s ease both .15s; }

@media (max-width: 820px) {
  .leather-tab { height: auto; align-items: flex-start; flex-direction: column; gap: 12px; }
  .top-thoughts { display: none; }
  .stitched-rail { width: 76px; left: 12px; top: 132px; }
  .knot span { font-size: 18px; }
  .notebook { padding-left: 92px; }
  .spread { grid-template-columns: 1fr; padding-top: 178px; }
  .marginalia { grid-template-columns: 1fr 1fr; padding-top: 0; }
  .paper-band { top: 27vh; width: 86vw; }
}
