:root {
  --ink: #111;
  --ink-soft: #2a2a2a;
  --paper: #f7f3ea;
  --paper-edge: #ece5d2;
  --shadow: rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper-edge);
  color: var(--ink);
  font-family: "Kalam", "Architects Daughter", system-ui, sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

a { color: var(--ink); }

/* ---------- VIEWPORT + WORLD ---------- */
.viewport {
  position: fixed;
  inset: 0;
  cursor: grab;
  touch-action: none;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,.025) 0 1px, transparent 2px),
    radial-gradient(circle at 70% 80%, rgba(0,0,0,.022) 0 1px, transparent 2px),
    radial-gradient(circle at 40% 60%, rgba(0,0,0,.02)  0 1px, transparent 2px);
  background-size: 7px 7px, 11px 11px, 13px 13px;
}
.viewport.dragging { cursor: grabbing; }

.world {
  position: absolute;
  width: 3000px;
  height: 2000px;
  transform-origin: 0 0;
  will-change: transform;
}

/* faint sketch frame around the giant page so panners feel an edge */
.world::before {
  content: "";
  position: absolute;
  inset: 28px;
  border: 1.5px dashed rgba(0,0,0,.18);
  pointer-events: none;
}

/* ---------- COVER ---------- */
.cover {
  position: absolute;
  left: 1500px;
  top: 1000px;
  width: 380px;
  height: auto;
  transform: translate(-50%, -50%) rotate(-1.5deg);
  background: #fff;
  border: 1px solid #e6dfca;
  filter: drop-shadow(2px 4px 0 rgba(0,0,0,.08))
          drop-shadow(0 18px 30px rgba(0,0,0,.18));
  user-select: none;
  -webkit-user-drag: none;
}

/* tape strips at two corners (decorative, no text) */
.cover-caption {
  position: absolute;
  left: 1500px;
  top: 1230px;
  transform: translate(-50%, 0) rotate(-1.5deg);
  font-family: "Caveat", cursive;
  font-size: 28px;
  color: var(--ink-soft);
  white-space: nowrap;
  pointer-events: none;
}

.cover.complete { animation: wobble 1.6s ease-in-out 1; }

.reward-frame {
  position: absolute;
  left: 1500px;
  top: 1000px;
  width: 480px;
  height: 480px;
  transform: translate(-50%, -50%) rotate(-1.5deg);
  pointer-events: none;
  opacity: 0;
}
.reward-frame path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
}
.reward-frame.show {
  opacity: 1;
}
.reward-frame.show path {
  animation: drawFrame 2.2s ease-out forwards;
}

@keyframes drawFrame {
  to { stroke-dashoffset: 0; }
}
@keyframes wobble {
  0%   { transform: translate(-50%, -50%) rotate(-1.5deg); }
  25%  { transform: translate(-50%, -50%) rotate(1deg) scale(1.02); }
  50%  { transform: translate(-50%, -50%) rotate(-2deg); }
  75%  { transform: translate(-50%, -50%) rotate(0.5deg) scale(1.01); }
  100% { transform: translate(-50%, -50%) rotate(-1.5deg); }
}

/* ---------- SCRIBBLES (track buttons) ---------- */
.scribble {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 78px;
  height: 78px;
  margin-left: -39px;
  margin-top: -39px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 32px;
  line-height: 1;
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 0;
  transform: rotate(var(--rot, 0deg));
  transform-origin: 50% 50%;
  transition: transform .18s ease;
  /* hand-drawn ink circle as background */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 78 78'><path d='M 39 6 C 18 8 6 22 7 41 C 8 62 24 73 41 72 C 62 71 73 56 72 38 C 71 19 58 6 39 6 Z' fill='%23fff' stroke='%23111' stroke-width='2.4' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-size: contain;
  user-select: none;
}

.scribble:hover,
.scribble:focus-visible {
  outline: none;
  transform: rotate(var(--rot, 0deg)) scale(1.18);
  z-index: 5;
}

.scribble .num {
  position: relative;
  transform: translateY(2px);
}

.scribble .label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 6px) rotate(-1deg);
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 26px;
  white-space: nowrap;
  background: var(--paper);
  padding: 2px 10px 0;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .14s ease;
  box-shadow: 2px 2px 0 var(--ink);
}
.scribble:hover .label,
.scribble:focus-visible .label { opacity: 1; }

.scribble[data-found="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 78 78'><path d='M 14 42 Q 22 50 32 60 Q 44 38 70 14' fill='none' stroke='%23111' stroke-width='5' stroke-linecap='round' stroke-linejoin='round' opacity='0.85'/></svg>");
  background-repeat: no-repeat;
  background-size: contain;
  pointer-events: none;
}

.scribble[data-found="true"] {
  opacity: .92;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 16px));
  right: max(16px, env(safe-area-inset-right, 16px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 20;
}

.counter {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 42px;
  line-height: 1;
  background: var(--paper);
  padding: 6px 14px 2px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(2deg);
  pointer-events: auto;
}
.counter .slash { margin: 0 4px; color: var(--ink-soft); }
.counter .total { color: var(--ink-soft); }

.minimap {
  width: 144px;
  height: 96px;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-1.5deg);
  pointer-events: none;
}

.yt-link {
  font-family: "Caveat", cursive;
  font-size: 30px;
  line-height: 1;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  text-decoration: none;
  transform: rotate(3deg);
  pointer-events: auto;
}
.yt-link:hover { transform: rotate(0deg) scale(1.06); }

/* ---------- HINT ---------- */
.hint {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, 30%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .35s ease;
  z-index: 15;
  animation: hintBob 1.4s ease-in-out infinite;
}
.hint.show { opacity: .9; }
.hint.gone { opacity: 0 !important; animation: none; }

@keyframes hintBob {
  0%, 100% { transform: translate(-50%, 30%) rotate(-6deg); }
  50%      { transform: translate(-32%, 32%) rotate(8deg); }
}

/* ---------- PLAYER OVERLAY ---------- */
.player {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(247, 243, 234, .92);
  z-index: 50;
  padding: 20px;
}
.player[hidden] { display: none; }

.player-card {
  width: min(960px, 96vw);
  background: #fff;
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 18px 18px 22px;
  transform: rotate(-.4deg);
}

.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--ink);
  overflow: hidden;
}
.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.track-title {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1;
  margin: 4px 4px 14px;
  letter-spacing: .005em;
}

.close {
  position: fixed;
  top: max(14px, env(safe-area-inset-top, 14px));
  right: max(16px, env(safe-area-inset-right, 16px));
  width: 48px;
  height: 48px;
  font-size: 28px;
  line-height: 1;
  font-family: "Caveat", cursive;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  z-index: 60;
  transform: rotate(4deg);
}
.close:hover { transform: rotate(0deg) scale(1.06); }

/* ---------- TOUCH DEVICES ---------- */
/* On touch there's no :hover, so reveal labels by default. */
@media (hover: none) {
  .scribble .label {
    opacity: .92;
    transition: none;
  }
}

/* ---------- MOBILE ---------- */
/* Cover, scribbles, and label sizes inside the world are handled
   by the world's scale transform (set in app.js for touch viewports),
   so we only restyle elements OUTSIDE the world here. */
@media (max-width: 720px) {
  .counter { font-size: 32px; padding: 4px 10px 0; }
  .minimap { width: 108px; height: 72px; }
  .yt-link { width: 38px; height: 38px; font-size: 24px; }

  .player { padding: 0; }
  .player-card {
    width: 100vw;
    max-width: 100vw;
    padding: 14px 12px 16px;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    transform: rotate(0);
  }
  .track-title {
    margin: 0 4px 10px;
    font-size: 34px;
  }

  .close {
    width: 52px;
    height: 52px;
    font-size: 30px;
  }

  .hint { width: 80px; height: 80px; }
}

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .cover, .cover-caption, .counter, .minimap, .yt-link,
  .player-card, .close, .scribble {
    transform: none !important;
  }
  .cover { transform: translate(-50%, -50%) !important; }
  .cover-caption { transform: translate(-50%, 0) !important; }
  .reward-frame { transform: translate(-50%, -50%) !important; }
}
