/* self-hosted variable fonts: weights 400–700, only the latin glyphs the site uses */
@font-face {
  font-family: "Pixelify Sans";
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/pixelify-sans.v2.woff2) format("woff2");
  unicode-range: U+0020-007E, U+00A0-00FF, U+2013-2014, U+2018-201E, U+2022, U+2026, U+2190-2199, U+20AC, U+2122;
}
@font-face {
  font-family: "Nunito";
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/nunito.v2.woff2) format("woff2");
  unicode-range: U+0020-007E, U+00A0-00FF, U+2013-2014, U+2018-201E, U+2022, U+2026, U+2190-2199, U+20AC, U+2122;
}

:root {
  --ink: #3d1f0a;
  --ink-soft: #7a4a24;
  --paper: #fcd9a0;
  --paper-2: #f3c57e;
  --edge: #5b2a12;
  --edge-2: #d8843a;
  --edge-3: #a85a24;
  --wood: #3b2416;
  --wood-2: #2f1c10;
  --orange: #ff9a2e;
  --green: #4f9e3b;
  --red: #d63c3c;
  --font: "Pixelify Sans", ui-monospace, Menlo, monospace;
  --text: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

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

/* iOS 26 Safari ignores theme-color and tints the status bar / camera island from body's background-color.
   So body's colour is the sky while its opaque wood stripes are a background image on top of it;
   JS switches the colours to wood once the scene is scrolled away. */
html { -webkit-text-size-adjust: 100%; background-color: var(--top, #4aa8e8); }
html.below, html.below body { background-color: var(--wood); }

body {
  margin: 0;
  color: var(--ink);
  font: 400 16px/1.4 var(--text);
  background: var(--top, #4aa8e8) repeating-linear-gradient(180deg, var(--wood) 0 30px, var(--wood-2) 30px 33px);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

a { color: #2a5fb0; }
ul { list-style: none; margin: 0; padding: 0; }
h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }

/* pixel font for headings, names and labels; running text stays in --text */
.hud, .dlg-text, .name, .plaque, .tabs button, .page h2, .page h3,
.sname, .skill b, .slots > li, .quest b, .quest em, .detail b,
.ava, .who b, .school b, .btn, .sign {
  font-family: var(--font);
  -webkit-font-smoothing: none;
}

/* the wooden menu frame used everywhere */
.panel {
  background: var(--paper);
  border: 4px solid var(--edge);
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 3px var(--edge-2),
    inset 0 0 0 5px var(--edge-3),
    0 5px 0 rgba(0, 0, 0, .35);
}

/* ---------- stage ---------- */
.stage {
  position: relative;
  height: clamp(320px, 58svh, 560px);
  overflow: hidden;
  border-bottom: 4px solid var(--edge);
}
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  animation: fadein 1s var(--ease) both;
}
@keyframes fadein { from { opacity: 0; } }

.hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: 8px;
  padding: 8px 12px 6px;
  text-align: right;
  font-size: 14px;
  line-height: 1.25;
  animation: drop .7s .3s var(--ease) both;
}
@keyframes drop { from { opacity: 0; transform: translateY(-20px); } }
.hud-date { font-weight: 700; font-size: 16px; }
.hud-gold {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 2px solid var(--edge-2);
}
.hud-gold img { width: 16px; height: 16px; }

/* ---------- dialog ---------- */
.dialog {
  position: absolute;
  left: 8px; right: 8px;
  bottom: 10px;
  max-width: 680px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  opacity: 0;
  transform: translateY(24px) scale(.97);
  pointer-events: none;
  transition: opacity .35s var(--ease), transform .45s var(--ease);
}
.dialog.open { opacity: 1; transform: none; pointer-events: auto; }
.dlg-text {
  position: relative;
  min-height: 92px;
  padding: 14px 16px 18px;
  font-size: 16px;
}
.more {
  position: absolute;
  right: 12px; bottom: 6px;
  font-style: normal;
  font-size: 12px;
  color: var(--edge-3);
  opacity: 0;
}
.dialog.done .more { opacity: 1; animation: bob .8s steps(2) infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
.dlg-who {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  gap: 4px;
}
#portrait { width: 60px; height: 50px; background: #9fd8ff; border: 2px solid var(--edge-3); }
.name { font-size: 13px; font-weight: 700; }

/* ---------- menu ---------- */
.menu {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 12px 8px;
}

.plaque {
  margin: 0 auto 18px;
  width: fit-content;
  max-width: 100%;
  padding: 8px 18px;
  text-align: center;
  font-size: 22px;
  line-height: 1.15;
  color: #fff3d6;
  background: #8a4a1e;
  border: 4px solid var(--edge);
  border-radius: 4px;
  box-shadow: inset 0 3px 0 #b5642a, inset 0 -3px 0 #6b3613, 0 5px 0 rgba(0, 0, 0, .35);
  text-shadow: 2px 2px 0 #4a220c;
}
.plaque small { display: block; font-size: 13px; font-weight: 400; color: #ffd9a0; }

.tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: -4px;
  position: relative;
  z-index: 1;
}
.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 64px;
  padding: 8px 4px 8px;
  font-size: 12px;
  background: var(--paper-2);
  border: 4px solid var(--edge);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  transform: translateY(6px);
  transition: transform .25s var(--ease), background .2s;
}
.tabs button:hover { transform: translateY(2px); }
.tabs button[aria-selected="true"] { background: var(--paper); transform: none; }
.tabs img { width: 24px; height: 24px; }
.tabs button:hover img { animation: wiggle .4s steps(3); }
@keyframes wiggle { 33% { transform: rotate(-10deg); } 66% { transform: rotate(10deg); } }

.page { padding: 18px 16px 20px; min-height: 360px; }
.page[hidden] { display: none; }
.page.enter { animation: page .45s var(--ease) both; }
@keyframes page { from { opacity: 0; transform: translateY(10px); } }

.page h2 {
  font-size: 22px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--edge-2);
}
.page h3 { font-size: 17px; margin: 20px 0 10px; color: var(--ink-soft); }
.sub { margin: -4px 0 14px; color: var(--ink-soft); font-size: 14px; }

/* skills */
.skills { display: grid; gap: 10px; }
.skill { display: grid; grid-template-columns: 112px 1fr 40px; align-items: center; gap: 10px; }
.sname { font-weight: 600; }
.skill b { font-size: 13px; color: var(--ink-soft); text-align: right; white-space: nowrap; }
.pips { display: flex; gap: 3px; }
.pip {
  flex: 1;
  max-width: 18px;
  height: 16px;
  background: #e2a961;
  box-shadow: inset 0 0 0 2px #b97a3a;
  transition: background .2s, box-shadow .2s, transform .3s var(--ease);
  transition-delay: calc(var(--i) * 70ms);
}
.skills.on .pip.f {
  background: var(--orange);
  box-shadow: inset 0 0 0 2px #c4601a, inset 0 3px 0 #ffd27a;
  transform: scaleY(1.12);
}

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.slots > li {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px;
  text-align: center;
  font-size: 13px;
  background: var(--paper-2);
  box-shadow: inset 2px 2px 0 #b97a3a, inset -2px -2px 0 #ffe6b8;
  transition: transform .2s var(--ease);
}
.slots > li:hover { transform: translateY(-3px); }

/* quests */
.quests { display: grid; gap: 10px; }
.quest {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  background: #fff0cf;
  box-shadow: inset 0 0 0 2px var(--edge-2);
  transition: transform .25s var(--ease);
}
.quest:hover { transform: translateX(4px); }
.quest b { font-size: 17px; padding-right: 90px; }
.quest b a { color: inherit; }
.quest.has-ico { padding-left: 70px; }
.quest-ico { position: absolute; top: 12px; left: 14px; width: 44px; height: 44px; border-radius: 8px; image-rendering: auto; }
.giver { font-size: 13px; color: var(--ink-soft); }
.quest p { font-size: 14px; margin: 4px 0; }
.parts { display: grid; gap: 4px; margin: 0 0 6px; font-size: 14px; }
.parts li { padding-left: 14px; position: relative; }
.parts li::before { content: "▸"; position: absolute; left: 0; color: var(--edge-2); }
.parts a { font-weight: 600; margin-right: 4px; }

.reward { font-size: 13px; color: #2f7a2a; font-weight: 600; }
.quest em {
  position: absolute;
  top: 10px; right: 10px;
  font-style: normal;
  font-size: 12px;
  padding: 2px 8px;
  color: #fff;
  background: #b97a3a;
  border: 2px solid var(--edge);
}
.quest em.done { background: var(--green); }
.quest em.merged { background: #8250df; }
.quest em.silver { background: #8a96a3; }
.quest em.live { background: var(--red); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* app screenshots: horizontal strip */
.shots {
  display: flex;
  gap: 8px;
  margin: 6px 0 8px;
  padding-bottom: 6px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  min-width: 0;
}
.shots li { flex: none; scroll-snap-align: start; }
.shots img {
  display: block;
  width: 110px;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 0 0 2px var(--edge-2);
  image-rendering: auto;
}

/* items */
.items { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
.items > li { padding: 0; min-height: 0; }
.item {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 6px;
  background: none;
  border: 0;
  cursor: pointer;
}
.item img { width: 44px; height: 44px; border-radius: 8px; transition: transform .3s var(--ease); image-rendering: auto; }
.item:hover img { transform: scale(1.1) rotate(-5deg); }
.item span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.items > li:has([aria-pressed="true"]) { box-shadow: inset 0 0 0 3px var(--red), inset 2px 2px 0 #b97a3a; }

.detail {
  display: flex;
  gap: 14px;
  margin-top: 14px;
  padding: 14px;
  background: #fff0cf;
  box-shadow: inset 0 0 0 2px var(--edge-2);
  animation: page .35s var(--ease) both;
}
.detail img { flex: none; width: 56px; height: 56px; border-radius: 10px; image-rendering: auto; }
.detail b { display: block; font-size: 17px; }
.detail p { font-size: 14px; margin: 6px 0 10px; }

/* friends */
.friends { display: grid; gap: 8px; }
.friends li {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 4px 10px;
  align-items: center;
  padding: 8px 10px;
  background: #fff0cf;
  box-shadow: inset 0 0 0 2px var(--edge-2);
}
.ava {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  background: var(--c);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .3), inset 0 3px 0 rgba(255, 255, 255, .25);
}
.who { display: grid; }
.who span { font-size: 13px; color: var(--ink-soft); }
.hearts { display: flex; gap: 2px; }
.hearts i {
  width: 14px; height: 14px;
  background: var(--heart-empty) center / contain no-repeat;
  image-rendering: pixelated;
}
.hearts i.on { background-image: var(--heart-full); animation: beat .5s var(--ease) both; animation-delay: calc(var(--i) * 80ms); }
@keyframes beat { from { transform: scale(0); } 60% { transform: scale(1.3); } }
.school { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.school img { flex: none; mix-blend-mode: multiply; image-rendering: auto; }

/* mail */
/* ruled paper: line-height equals the rule step; --base puts each rule just under the text baseline */
.letter {
  --line: 26px;
  --base: calc(var(--line) / 2 + .33em + 1px);
  display: grid;
  padding: 18px;
  line-height: var(--line);
  background: #fffaf0 repeating-linear-gradient(180deg, transparent 0 var(--base), #e8d3b0 var(--base) calc(var(--base) + 1px), transparent calc(var(--base) + 1px) var(--line));
  background-origin: content-box;
  box-shadow: inset 0 0 0 2px #e0c08f, 3px 3px 0 rgba(0, 0, 0, .15);
  transform: rotate(-.6deg);
}
.sign { text-align: right; font-weight: 600; }
.attach { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }

.btn {
  display: inline-block;
  padding: 7px 14px;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  text-decoration: none;
  background: #e07a2a;
  border: 3px solid var(--edge);
  box-shadow: inset 0 3px 0 #ffb36b, inset 0 -3px 0 #a8501a, 0 3px 0 rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); }

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 8px;
  padding: 16px 12px calc(24px + env(safe-area-inset-bottom));
  color: #d9b48a;
  font-size: 14px;
}
footer a { color: #ffd9a0; }
footer small { flex-basis: 100%; text-align: center; color: #a07a55; }

@media (min-width: 640px) {
  .menu { padding-top: 28px; }
  .page { padding: 22px 24px 26px; }
  .tabs button { width: 76px; font-size: 13px; }
  .tabs img { width: 28px; height: 28px; }
  .plaque { font-size: 26px; }
}

/* desktop: a taller scene, a wider menu and everything a size up */
@media (min-width: 1024px) {
  body { font-size: 17px; }
  .stage { height: clamp(420px, 66svh, 760px); }

  .hud { top: 16px; right: 20px; padding: 12px 18px 10px; font-size: 17px; }
  .hud-date { font-size: 20px; }
  .hud-gold img { width: 20px; height: 20px; }

  .dialog { bottom: 20px; max-width: 860px; gap: 8px; }
  .dlg-text { min-height: 120px; padding: 18px 22px 24px; font-size: 20px; }
  .more { font-size: 14px; right: 16px; bottom: 8px; }
  .dlg-who { padding: 10px 14px; }
  #portrait { width: 84px; height: 70px; }
  .name { font-size: 15px; }

  .menu { max-width: 1080px; padding: 40px 24px 16px; }
  .plaque { font-size: 34px; padding: 12px 28px; margin-bottom: 26px; }
  .plaque small { font-size: 16px; margin-top: 2px; }

  .tabs { gap: 10px; }
  .tabs button { width: 104px; padding: 10px 6px; font-size: 16px; gap: 4px; }
  .tabs img { width: 36px; height: 36px; }

  .page { padding: 30px 36px 36px; min-height: 460px; }
  .page h2 { font-size: 28px; margin-bottom: 16px; }
  .page h3 { font-size: 20px; margin: 28px 0 12px; }
  .sub { font-size: 16px; }

  .skills { gap: 14px; }
  .skill { grid-template-columns: 140px auto 1fr; gap: 18px; font-size: 18px; }
  .skill b { font-size: 15px; text-align: left; }
  .pips { gap: 5px; }
  .pip { flex: none; width: 30px; max-width: none; height: 22px; }

  .slots { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 8px; }
  .slots > li { min-height: 54px; font-size: 15px; }

  .quests { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; align-items: start; }
  .quests.even { align-items: stretch; }
  .quests.even > .quest { display: flex; flex-direction: column; }
  .quests.even .reward { margin-top: auto; }
  .quest { padding: 16px 18px; }
  .quest.has-ico { padding-left: 88px; }
  .quest-ico { top: 16px; left: 18px; width: 54px; height: 54px; border-radius: 10px; }
  .quest:hover { transform: translateY(-3px); }
  .quest b { font-size: 19px; }
  .giver, .reward { font-size: 14px; }
  .quest p, .parts { font-size: 15px; }
  .quest em { font-size: 13px; top: 14px; right: 14px; }
  .shots { gap: 12px; }
  .shots img { width: 140px; border-radius: 12px; }

  .items { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .item img { width: 64px; height: 64px; border-radius: 12px; }
  .detail { gap: 20px; padding: 20px; }
  .detail img { width: 80px; height: 80px; border-radius: 14px; }
  .detail b { font-size: 20px; }
  .detail p { font-size: 16px; }

  .friends { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
  .friends li { grid-template-columns: 52px 1fr; gap: 6px 14px; padding: 12px 14px; }
  .ava { width: 52px; height: 52px; font-size: 17px; }
  .who b { font-size: 17px; }
  .who span { font-size: 14px; }
  .hearts { gap: 3px; }
  .hearts i { width: 18px; height: 18px; }
  .school { font-size: 16px; gap: 14px; }
  .school img { width: 50px; height: 60px; }

  .letter { --line: 30px; max-width: 720px; margin: 0 auto; padding: 28px 32px; font-size: 18px; }
  .btn { font-size: 17px; padding: 9px 18px; }

  footer { font-size: 15px; padding-top: 24px; }
}

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