/* ---------- Walkable world ---------- */
body.is-world {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: none;
}

.is-world .top {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 20;
}

/* The ground scrolls with the camera on its own composited layer. */
.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  background-color: #0f0c0a;
}
.ground {
  position: absolute;
  inset: 0 -256px -256px 0;
  will-change: transform;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255, 240, 220, 0.075) 1.4px, transparent 1.6px),
    linear-gradient(rgba(255, 240, 220, 0.03) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 240, 220, 0.03) 2px, transparent 2px);
  background-size: 25px 25px, 300px 330px, 300px 330px;
}

/* soft vignette so the edges feel like the end of a lamp's light */
.viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, transparent 45%, rgba(10, 7, 5, 0.65) 100%);
}

.world {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

/* Cards lying on the ground */
.world .card {
  position: absolute;
  width: 250px;
  min-height: 0;
  height: auto;
  cursor: pointer;
  transform: rotate(var(--rot, 0deg));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.28),
    inset 0 -4px 0 rgba(0, 0, 0, 0.22),
    0 2px 0 rgba(0, 0, 0, 0.55),
    0 8px 14px -8px rgba(0, 0, 0, 0.7);
  transition:
    transform 260ms var(--ease-out),
    box-shadow 260ms var(--ease-out),
    filter 300ms ease,
    opacity 300ms ease;
}

/* On the ground only the headline is readable: the text is a blurred, two-line tease.
   Step up and it unfolds. --text-h (full text height) and --grow (how much taller the
   card gets) are measured in world.js. */
.world .card { transform-origin: 50% 100%; }
/* Keep room for the discovery check from the start, so a heading doesn't rewrap
   (and the card change height) the moment you step on it. */
.world .card:not(.is-fav) .card__heading { padding-right: 24px; }
.world .card__text {
  max-height: 2lh;
  overflow: hidden;
  /* The blur spreads ~10px past the glyphs. Without room on the sides, overflow and
     the mask cut it off in a hard edge, so widen the box into the card's padding. */
  padding-inline: 10px;
  margin-inline: -10px;
  filter: blur(3.5px);
  opacity: 0.75;
  -webkit-mask-image: linear-gradient(#000 25%, transparent 95%);
  mask-image: linear-gradient(#000 25%, transparent 95%);
  user-select: none;
  transition:
    max-height 260ms var(--ease-out),
    filter 260ms ease,
    opacity 260ms ease;
}
.world .card.is-active .card__text {
  max-height: var(--text-h, 20em);
  filter: none;
  opacity: 1;
  -webkit-mask-image: none;
  mask-image: none;
  user-select: auto;
}

/* The card you stand on lifts up to meet you. It unfolds upwards (the translate matches
   the height it gains, on the same curve), so its bottom edge stays put and the walker
   can stand just below it without covering anything. */
.world .card.is-active {
  transform: rotate(0deg) translateY(calc(-8px - var(--grow, 0px))) scale(1.04);
  z-index: 2;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.32),
    inset 0 -5px 0 rgba(0, 0, 0, 0.22),
    0 0 0 3px rgba(255, 255, 255, 0.85),
    0 26px 30px -14px rgba(0, 0, 0, 0.8);
}

/* Topic highlight: other topics fade into the ground.
   Already-read cards get the same gray; the one you stand on stays lit. */
.world .card.is-dim,
.world .card.is-read:not(.is-active) {
  filter: grayscale(1) brightness(0.45);
  opacity: 0.55;
}


/* Lure: unread cards from the book you just read pulse for a moment.
   An outline, because the card clips anything drawn outside it. */
.world .card.is-lure {
  outline: 3px solid #FFCA0A;
  outline-offset: 4px;
  animation: lure 900ms var(--ease-out) 3;
}
@keyframes lure {
  0%   { outline-offset: 2px;  outline-color: rgba(255, 202, 10, 1); }
  100% { outline-offset: 16px; outline-color: rgba(255, 202, 10, 0); }
}

/* ---------- The walker ---------- */
.walker {
  position: absolute;
  left: 0;
  top: 0;
  width: 64px;
  height: 64px;
  margin: -60px 0 0 -32px; /* anchor at the feet */
  z-index: 10;
  pointer-events: none;
}

.walker__sprite {
  position: relative;
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
}
.walker.is-left .walker__sprite { transform: scaleX(-1); }

.walker__shadow {
  position: absolute;
  left: 10px;
  bottom: -4px;
  width: 44px;
  height: 10px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
}

.target-marker {
  position: absolute;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  border: 3px solid #FFCA0A;
  opacity: 0;
  pointer-events: none;
  z-index: 9;
}
.target-marker.is-on { animation: ping 700ms var(--ease-out) forwards; }
@keyframes ping {
  from { opacity: 1; transform: scale(0.4); }
  to   { opacity: 0; transform: scale(1.5); }
}

/* ---------- Pitch: one line about what this is, on the ground at the start ---------- */
.pitch {
  position: absolute;
  z-index: 1;
  transform: translate(-50%, -50%);
  width: max-content;
  text-align: center;
  pointer-events: none;
}
.pitch p { margin: 0; }
.pitch__title {
  font-family: var(--font-label);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(255, 240, 220, 0.85);
}
.pitch .pitch__sub {
  margin-top: 4px;
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 240, 220, 0.5);
}

/* ---------- First-visit walk hint (keycaps on the ground under the walker) ---------- */
.walk-hint {
  position: absolute;
  z-index: 9;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 10px;
  pointer-events: none;
  animation: walk-hint-in 400ms var(--ease-out) 300ms both;
  transition: opacity 400ms ease, transform 400ms var(--ease-out);
}
.walk-hint.is-gone { opacity: 0; transform: translateX(-50%) translateY(8px); }
.walk-hint__keys {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(2, 40px);
  gap: 6px;
}
.walk-hint__keys kbd {
  display: grid;
  place-items: center;
  min-width: 0;
  margin: 0;
  padding: 0;
  font-size: 16px;
  border-radius: 9px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.4), 0 6px 14px -8px rgba(0, 0, 0, 0.8);
  transition: transform 80ms ease, background-color 80ms ease, color 80ms ease, box-shadow 80ms ease;
}
.walk-hint__keys [data-k="w"] { grid-column: 2; grid-row: 1; }
.walk-hint__keys [data-k="a"] { grid-column: 1; grid-row: 2; }
.walk-hint__keys [data-k="s"] { grid-column: 2; grid-row: 2; }
.walk-hint__keys [data-k="d"] { grid-column: 3; grid-row: 2; }
.walk-hint__keys kbd.is-down {
  background: #FFCA0A;
  color: #2a1d06;
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
.walk-hint__text {
  margin: 0;
  text-align: center;
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.5;
  color: rgba(255, 240, 220, 0.6);
}
@keyframes walk-hint-in { from { opacity: 0; transform: translateX(-50%) translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  .walk-hint, .walk-hint__keys kbd { animation: none; transition: opacity 200ms ease; }
  .walk-hint.is-gone { transform: translateX(-50%); }
}

/* ---------- First-visit touch hint: a hand taps a card, then drags ---------- */
/* Positions come from world.js as --tap-*, --drag-*, --walker-* (screen px). One 5s loop:
   0-40% tap the card, 50-90% press below the walker and drag sideways. */
.touch-hint {
  position: fixed;
  inset: 0;
  z-index: 14;
  pointer-events: none;
  transition: opacity 300ms ease;
}
.touch-hint.is-gone { opacity: 0; }
.touch-hint__hand {
  position: absolute;
  left: 0;
  top: 0;
  margin: -4px 0 0 -16px; /* fingertip on the point */
  fill: #fff;
  stroke: #1c1815;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
  transform-origin: 16px 4px;
  animation: touch-hand 5s var(--ease-out) 600ms infinite both;
}
@keyframes touch-hand {
  0%   { opacity: 0; transform: translate(var(--tap-x), calc(var(--tap-y) + 24px)); }
  8%   { opacity: 1; transform: translate(var(--tap-x), var(--tap-y)); }
  14%  { transform: translate(var(--tap-x), var(--tap-y)) scale(0.86); }
  20%  { transform: translate(var(--tap-x), var(--tap-y)) scale(1); }
  38%  { opacity: 1; transform: translate(var(--tap-x), var(--tap-y)); }
  44%  { opacity: 0; transform: translate(var(--tap-x), var(--tap-y)); }
  46%  { opacity: 0; transform: translate(var(--drag-x), calc(var(--drag-y) + 24px)); }
  54%  { opacity: 1; transform: translate(var(--drag-x), var(--drag-y)); }
  60%  { transform: translate(var(--drag-x), var(--drag-y)) scale(0.86); }
  84%  { opacity: 1; transform: translate(var(--drag-to-x), var(--drag-y)) scale(0.86); }
  90%  { opacity: 0; transform: translate(var(--drag-to-x), var(--drag-y)) scale(1); }
  100% { opacity: 0; transform: translate(var(--drag-to-x), var(--drag-y)); }
}
.touch-hint__ripple,
.touch-hint__ring {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  opacity: 0;
}
.touch-hint__ripple {
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border: 3px solid #FFCA0A;
  translate: var(--tap-x) var(--tap-y);
  animation: touch-ripple 5s ease-out 600ms infinite both;
}
@keyframes touch-ripple {
  0%, 13% { opacity: 0; transform: scale(0.4); }
  14%     { opacity: 1; transform: scale(0.4); }
  30%     { opacity: 0; transform: scale(1.6); }
  100%    { opacity: 0; }
}
/* ghost of the real joystick, so the drag looks like what will happen */
.touch-hint__ring {
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border: 3px solid rgba(255, 240, 220, 0.28);
  background: rgba(255, 240, 220, 0.06);
  translate: var(--drag-x) var(--drag-y);
  animation: touch-ring 5s ease 600ms infinite both;
}
@keyframes touch-ring {
  0%, 58% { opacity: 0; }
  62%, 86% { opacity: 1; }
  92%, 100% { opacity: 0; }
}
.touch-hint__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: #FFCA0A;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  animation: touch-knob 5s var(--ease-out) 600ms infinite both;
}
@keyframes touch-knob {
  0%, 60% { transform: translateX(0); }
  84%, 100% { transform: translateX(var(--stick-r)); }
}
.touch-hint__text {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  translate: calc(var(--walker-x) - 50%) calc(var(--walker-y) + 28px);
  text-align: center;
  white-space: nowrap;
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.5;
  color: rgba(255, 240, 220, 0.7);
  animation: touch-text-in 400ms var(--ease-out) 300ms both;
}
@keyframes touch-text-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  /* no looping motion: the hand just points at the card */
  .touch-hint__hand { animation: none; transform: translate(var(--tap-x), var(--tap-y)); }
  .touch-hint__ripple, .touch-hint__ring { display: none; }
  .touch-hint__text { animation: none; }
}

/* ---------- Touch joystick (forms wherever the thumb lands) ---------- */
.joystick {
  position: fixed;
  z-index: 14;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  border: 3px solid rgba(255, 240, 220, 0.28);
  background: rgba(255, 240, 220, 0.06);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 120ms ease, transform 160ms var(--ease-out);
}
.joystick.is-on { opacity: 1; transform: scale(1); }
.joystick__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: #FFCA0A;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 8px 18px -8px rgba(0, 0, 0, 0.7);
}
@media (prefers-reduced-motion: reduce) { .joystick { transition: none; } }

/* ---------- HUD ----------
   Only the card prompt lives down here. It keeps its space while hidden,
   so the free area above it (and the active card) doesn't jump. */
.hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  pointer-events: none;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--ink-dim);
}

.hud p { margin: 0; }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  margin: 0 1px;
  text-align: center;
  font-family: var(--font-label);
  font-size: 11px;
  color: var(--ink);
  background: #3a322b;
  border-radius: 5px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.4);
}

.hud__prompt {
  display: block;
  line-height: 20px;
  color: var(--ink-dim);
  background: rgba(28, 24, 21, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 6px 14px;
  animation: prompt-in 200ms var(--ease-out);
  pointer-events: auto;
  cursor: pointer;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud__prompt[hidden] { visibility: hidden; pointer-events: none; animation: none; }
.hud__prompt kbd { margin-right: 5px; }
.hud__sep { margin: 0 8px; opacity: 0.5; }
@keyframes prompt-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  .world .card, .world .card.is-active, .world .card__text { transition: none; }
  .world .card.is-lure { animation: none; }
  .target-marker.is-on, .hud__prompt { animation: none; }
}

/* ---------- "+1" over the walker ---------- */
.plus {
  position: absolute;
  z-index: 12;
  translate: -50% 0;
  pointer-events: none;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 22px;
  color: #FFCA0A;
  text-shadow: 0 2px 0 #1a1410, 0 0 8px rgba(0, 0, 0, 0.6);
  animation: plus 900ms var(--ease-out) forwards;
}
@keyframes plus {
  0%   { opacity: 0; transform: translateY(8px) scale(0.6); }
  20%  { opacity: 1; transform: translateY(0) scale(1.1); }
  100% { opacity: 0; transform: translateY(-46px) scale(1); }
}

/* ---------- Toasts (first thought, book complete) ---------- */
.toasts {
  position: fixed;
  top: 76px;
  left: 50%;
  translate: -50% 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  --tc: #FFCA0A;
  --tf: #2a1d06;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 10px;
  border-radius: 18px;
  color: var(--tf);
  background: var(--tc);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 18px 34px -12px rgba(0, 0, 0, 0.8);
  animation: toast-in 420ms var(--ease-out) both;
}
.toast.is-out { animation: toast-out 260ms ease-in forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-16px) scale(0.9); }
  60%  { transform: translateY(2px) scale(1.02); }
}
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(0.96); } }

.toast__icon {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-size: 20px;
  background: rgba(0, 0, 0, 0.16);
}
.toast__title {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 18px;
  line-height: 1.05;
}
.toast__sub {
  margin: 2px 0 0;
  font-family: var(--font-label);
  font-size: 12px;
  opacity: 0.8;
}

/* ---------- Confetti ---------- */
.fx {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}
.fx i {
  position: absolute;
  width: 10px;
  height: 6px;
  border-radius: 3px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

@media (prefers-reduced-motion: reduce) {
  .plus, .toast, .toast.is-out { animation: none; }
}

/* A saved card, rolling up on its way into the walker's map tube (animated in world.js) */
.stash {
  position: absolute;
  width: 120px;
  height: 90px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--fg);
  background: var(--c);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), inset 0 -4px 0 rgba(0, 0, 0, 0.22), 0 10px 18px -8px rgba(0, 0, 0, 0.7);
  z-index: 11;
  pointer-events: none;
}
.stash svg { width: 40px; height: 40px; }
