/* ---------- fonts (self-hosted, latin subset, OFL) ---------- */
@font-face {
  font-family: 'IM Fell English';
  src: url(../fonts/im-fell-english-latin.woff2) format('woff2');
  font-style: normal; font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url(../fonts/im-fell-english-italic-latin.woff2) format('woff2');
  font-style: italic; font-weight: 400; font-display: swap;
}
/* IM Fell only has old-style figures (1 looks like I): digits come from a lining serif */
@font-face {
  font-family: 'Fell Digits';
  src: local('Times New Roman'), local('TimesNewRomanPSMT'), local('Liberation Serif'),
       local('Tinos'), local('Noto Serif'), local('DejaVu Serif');
  unicode-range: U+0030-0039;
}
@font-face {
  font-family: 'Caveat';
  src: url(../fonts/caveat-latin.woff2) format('woff2');
  font-style: normal; font-weight: 400 700; font-display: swap;
}

:root {
  --paper: #f4ecd6;
  --paper-light: #fbf6e8;
  --cork: #8c6b47;
  --ink: #1d2b4a;
  --pencil: #5e5e5e;
  --red: #b3261e;
  --postit: #fbe77c;
  --tape: rgba(236, 229, 205, 0.78);
  --fell: 'Fell Digits', 'IM Fell English', Georgia, 'Times New Roman', serif;
  --hand: 'Caveat', 'Segoe Print', 'Comic Sans MS', cursive;
  --world-font: 28px;
  --halo: 0 0 3px var(--paper), 0 0 6px var(--paper), 0 0 10px var(--paper), 0 0 14px var(--paper);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--cork);
  color: var(--ink);
  font-family: var(--fell);
  -webkit-text-size-adjust: 100%;
}

/* ---------- camera ---------- */
.viewport {
  position: fixed;
  inset: 0;
  overflow: clip;            /* focus never scrolls the map behind the camera */
  touch-action: pinch-zoom;  /* horizontal swipes come to us, pinch zoom stays */
  background-color: var(--cork);
  background-image: url(../assets/paper-grain.png);
  background-size: 180px;
}
.world {
  position: absolute;
  left: 0;
  top: 0;
  width: 4800px;
  height: 4500px;
  transform-origin: 0 0;
  background-color: var(--paper);
  background-image: url(../assets/paper-grain.png);
  background-size: 256px;
  box-shadow: 0 30px 80px rgba(30, 20, 5, 0.55), 0 4px 12px rgba(30, 20, 5, 0.35);
}
.world.moving { will-change: transform; }
.world.fade { transition: opacity 220ms ease; }
.world.faded { opacity: 0; }

.chart {
  position: absolute;
  left: 0;
  top: 0;
  width: 4800px;
  height: 4500px;
  display: block;
}

/* Mindelo: the wind moves a little, only while you're there */
.gust { transform-box: fill-box; }
body[data-step="mindelo"] .gust { animation: gust 2.6s ease-in-out infinite alternate; }
body[data-step="mindelo"] .gust-1 { animation-delay: -0.8s; }
body[data-step="mindelo"] .gust-2 { animation-delay: -1.5s; }
body[data-step="mindelo"] .gust-3 { animation-delay: -2.1s; }
@keyframes gust { from { transform: translateX(-18px); } to { transform: translateX(22px); } }

#route { transition: stroke-dasharray 0.6s; }
body.route-done #route { stroke-dasharray: none; }

/* ---------- world content (sizes in world units) ---------- */
.stop {
  position: absolute;
  font-size: var(--world-font);
  line-height: 1.38;
}
.stop p { margin: 0 0 12px; }
.stop p:last-child { margin-bottom: 0; }

/* headings are written straight on the chart, with a paper halo over the lines */
.stop h2 {
  margin: 0 0 16px;
  font-weight: 400;
  font-size: 46px;
  line-height: 1.1;
  text-shadow: var(--halo);
}
.num {
  display: inline-grid;
  place-items: center;
  width: 1.3em;
  height: 1.3em;
  margin-right: 10px;
  border: 3px solid var(--red);
  border-radius: 52% 48% 55% 45% / 47% 55% 45% 53%;
  color: var(--red);
  font-size: 0.75em;
  vertical-align: 0.1em;
  text-shadow: none;
  background: var(--paper);
}

/* pencil notes in the margin */
.pencil {
  font-family: var(--hand);
  font-size: 40px;
  line-height: 1.15;
  color: var(--pencil);
  transform: rotate(-2deg);
  text-shadow: var(--halo);
  padding-left: 18px;
  margin-top: 14px !important;
}

/* post-it */
.postit {
  position: relative;
  background: var(--postit);
  background-image: linear-gradient(170deg, rgba(255,255,255,.35), rgba(255,255,255,0) 40%, rgba(0,0,0,.05));
  padding: 26px 28px 30px;
  font-family: var(--hand);
  font-size: 37px;
  line-height: 1.18;
  transform: rotate(-1.2deg);
  box-shadow: 0 14px 18px -10px rgba(60, 40, 0, .45), 0 2px 3px rgba(60, 40, 0, .2);
  border-bottom-right-radius: 30px 8px;
}
.postit p { margin-bottom: 10px; }
.postit-small { font-size: 34px; transform: rotate(1.6deg); margin-top: 22px; }
.postit-title { font-weight: 700; }

/* index card: ruled, with a red top line */
.index-card {
  position: relative;
  background-color: var(--paper-light);
  background-image:
    linear-gradient(var(--red), var(--red)),
    repeating-linear-gradient(transparent 0 37px, rgba(80, 120, 170, .28) 37px 39px);
  background-size: 100% 2px, 100% 100%;
  background-position: 0 40px, 0 56px;
  background-repeat: no-repeat, repeat;
  padding: 58px 30px 26px;
  transform: rotate(0.8deg);
  box-shadow: 0 10px 16px -8px rgba(60, 40, 0, .45), 0 1px 2px rgba(60, 40, 0, .25);
}

/* field notebook page with spiral holes */
.notebook {
  position: relative;
  background-color: var(--paper-light);
  background-image:
    radial-gradient(circle at 50% 50%, #3a3226 0 7px, transparent 8px),
    linear-gradient(90deg, transparent 54px, rgba(179, 38, 30, .5) 54px 57px, transparent 57px),
    repeating-linear-gradient(transparent 0 37px, rgba(80, 120, 170, .3) 37px 39px);
  background-size: 44px 34px, 100% 100%, 100% 100%;
  background-repeat: repeat-x, no-repeat, repeat;
  background-position: 6px 6px, 0 0, 0 22px;
  padding: 48px 28px 24px 76px;
  font-family: var(--hand);
  font-size: 37px;
  line-height: 1.05;
  transform: rotate(-0.8deg);
  box-shadow: 0 10px 18px -8px rgba(60, 40, 0, .5);
}
.notebook p { margin-bottom: 12px; }

/* a scrap of paper for ink text that sits on the chart */
.scrap {
  background: rgba(251, 246, 232, .93);
  padding: 22px 28px;
  box-shadow: 0 6px 12px -6px rgba(60, 40, 0, .4);
  clip-path: polygon(0 2%, 4% 0, 30% 1.5%, 62% 0, 100% 1%, 99% 40%, 100% 98%, 70% 100%, 35% 98.5%, 0 100%, 1% 60%);
}
.ink .big {
  font-family: var(--hand);
  font-weight: 700;
  font-size: 50px;
  line-height: 1.15;
  display: inline;
  text-decoration: underline double var(--red);
  text-decoration-thickness: 3px;
  text-underline-offset: 8px;
}
.ink .big + p { margin-top: 22px; }
.last-line {
  margin-top: 26px !important;
  font-size: 36px;
  text-shadow: var(--halo);
}

/* tape and pins */
.taped::before {
  content: "";
  position: absolute;
  top: -20px;
  left: 50%;
  width: 150px;
  height: 40px;
  margin-left: -75px;
  background: var(--tape);
  transform: rotate(-3deg);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
  z-index: 1;
}
.pinned::before {
  content: "";
  position: absolute;
  top: -14px;
  left: 50%;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f6a39d 0 18%, var(--red) 22%);
  box-shadow: 4px 6px 4px rgba(0,0,0,.25);
  z-index: 1;
}

/* stop 2 */
.stop-site .site-grid {
  display: grid;
  grid-template-columns: 560px 1fr;
  grid-template-areas: "a b" "c b";
  gap: 34px 46px;
  align-items: start;
}
#site-a { grid-area: a; }
#site-b { grid-area: b; margin: 0; }
#site-c { grid-area: c; }

.screen {
  position: relative;
  border: 4px solid var(--ink);
  border-radius: 14px 10px 16px 9px;
  background: #fbf7ea;
  padding: 16px;
  transform: rotate(1deg);
  box-shadow: 0 12px 20px -8px rgba(30, 20, 5, .5);
}
.screen-stage {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #12222f;
  border-radius: 6px;
  color: #e9f2ff;
}
.counter {
  position: absolute;
  right: 18px;
  bottom: 10px;
  margin: 0;
  font-family: var(--hand);
  font-size: 54px;
}
.screen figcaption { margin: 14px 0; font-size: 24px; line-height: 1.35; }
.screen-actions { display: flex; gap: 14px; }
.screen .btn { font-size: 26px; }

/* stop 6 */
.old-title {
  font-size: 92px !important;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1 !important;
}
.old-title .num { font-size: 0.42em; vertical-align: 0.6em; }
.fog-objects {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  font-family: var(--hand);
  font-size: 34px;
  line-height: 1.15;
  text-shadow: var(--halo);
}
.fog-objects li { margin-bottom: 6px; }

.stars { list-style: none; margin: 0; padding: 0; }
.stars span { color: var(--red); letter-spacing: 2px; font-family: var(--fell); font-size: 0.8em; }

.hand-link {
  color: var(--red);
  font-family: var(--hand);
  font-size: 42px;
  font-weight: 700;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

/* polaroids: 6 personal photos, stops 4 and 5 only */
.polaroids {
  display: grid;
  grid-template-columns: 230px 230px;
  gap: 30px 24px;
  justify-content: center;
  margin-top: 40px;
}
.polaroid {
  position: relative;
  width: 230px;
  margin: 0;
  padding: 12px 12px 0;
  background: #fbf8ef;
  box-shadow: 0 10px 16px -6px rgba(40, 25, 5, .45), 0 1px 2px rgba(40, 25, 5, .25);
  transform: rotate(var(--tilt, 0deg));
}
.polaroid.wide { grid-column: 1 / -1; justify-self: center; width: 420px; }
.polaroids-right .polaroid:last-child { grid-column: 1 / -1; justify-self: center; }
.polaroid .photo {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #d8d0bf;
}
.polaroid.wide .photo { aspect-ratio: 16 / 9; }
.polaroid img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(.72) sepia(.14) contrast(.96);
  opacity: 0;
  transition: opacity .6s ease;
}
.polaroid img.loaded { opacity: 1; }
/* a touch of paper grain over the photo */
.polaroid .photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url(../assets/paper-grain.png) 0 0 / 128px;
  opacity: .7;
  pointer-events: none;
}
.polaroid figcaption {
  min-height: 64px;
  padding: 10px 6px 12px;
  font-family: var(--hand);
  font-size: 29px;
  line-height: 1.05;
  text-align: center;
  color: var(--ink);
}
/* photos sit beside the card; on phones the camera visits them in a step of their own */
.polaroids-right { position: absolute; left: calc(100% + 50px); top: 10px; margin: 0; }
.polaroids-left { position: absolute; right: calc(100% + 40px); top: -250px; margin: 0; }

/* map pins (number badges) */
.pin {
  position: absolute;
  width: 66px;
  height: 66px;
  margin: -33px 0 0 -33px;
  border: 4px solid var(--paper-light);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a5d86 0 12%, var(--ink) 45%);
  color: #fff;
  font: 400 36px/1 var(--fell);
  cursor: pointer;
  z-index: 2;
  box-shadow: 3px 6px 6px rgba(0,0,0,.3);
}
.pin-red { background: radial-gradient(circle at 35% 30%, #e4625a 0 12%, var(--red) 45%); }

/* ---------- screen-space UI ---------- */
.btn {
  font: inherit;
  font-size: 17px;
  min-height: 44px;
  padding: 8px 18px;
  border: 2px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: var(--paper-light);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 3px 0 rgba(29, 43, 74, .35);
}
.btn:hover { background: #fff3cf; }
.btn:active { transform: translate(1px, 2px); box-shadow: 1px 1px 0 rgba(29, 43, 74, .35); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #2c3e66; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.controls > * { pointer-events: auto; }
.where {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  padding: 6px 14px;
  background: var(--paper-light);
  border-radius: 4px;
  font-size: 16px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.btn-nav { white-space: nowrap; flex: none; }

.card {
  position: fixed;
  z-index: 9;
  background-color: var(--paper-light);
  background-image: url(../assets/paper-grain.png);
  background-size: 256px;
  padding: 22px 22px 20px;
  left: 12px;
  right: 12px;
  bottom: 74px;
  max-height: 55vh;
  overflow: auto;
  box-shadow: 0 14px 28px rgba(0,0,0,.4);
  transform: rotate(-0.6deg);
}
.card[hidden] { display: none; }
.card h1, .card h2 { margin: 0; font-weight: 400; font-size: 32px; line-height: 1.05; }
.card .subtitle { margin: 4px 0 12px; font-style: italic; color: var(--pencil); }
.card p { margin: 0 0 14px; font-size: 17px; line-height: 1.4; }
.card a { color: var(--ink); }
.signature { font-size: 16px !important; }

.legend ol {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  counter-reset: stop;
}
.legend li { counter-increment: stop; }
.legend button {
  font: inherit;
  font-size: 15px;
  min-height: 36px;
  padding: 4px 11px;
  border: 1.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.legend button:hover { background: #fff3cf; }
.legend button::before { content: counter(stop) " · "; color: var(--red); }

/* Narrow phones: arrows only, the label stays for screen readers */
@media (max-width: 479px) {
  .btn-nav { min-width: 52px; font-size: 20px; padding: 6px 12px; }
  .btn-nav .lbl {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (min-width: 760px) {
  .card {
    left: 22px;
    right: auto;
    top: 72px;
    bottom: auto;
    width: 350px;
    max-height: calc(100vh - 160px);
  }
  .card h1 { font-size: 44px; }
}

/* Short windows (laptops, landscape phones, small panes): a tighter card */
@media (max-height: 760px) {
  .card { padding: 14px 16px 12px; }
  .card h1, .card h2 { font-size: 28px !important; }
  .card .subtitle { margin-bottom: 6px; font-size: 15px; }
  .card p { font-size: 15px; margin-bottom: 10px; }
  .card .btn { min-height: 40px; padding: 6px 14px; font-size: 16px; }
  .legend ol { margin-top: 10px; gap: 5px; }
  .legend button { font-size: 13px; min-height: 30px; padding: 2px 9px; }
}
@media (max-height: 760px) and (max-width: 759px) {
  .card { bottom: 66px; max-height: 50vh; }
}
/* Narrow and short (small panes, split screens): stops on one scrollable row */
@media (max-height: 600px) and (max-width: 759px) {
  .card { max-height: 46vh; }
  .card .subtitle { display: none; }
  .legend ol { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .legend li { flex: none; }
}
@media (max-height: 520px) {
  .card .subtitle { display: none; }
  .card h1, .card h2 { font-size: 24px !important; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-step="mindelo"] .gust { animation: none; }
  #route { transition: none; }
}
