:root {
  --ink: #241b2e;
  --ink-soft: #3b2d44;
  --cream: #f6e7c8;
  --cream-hi: #fff4d8;
  --cream-lo: #d8bb8a;
  --cream-mid: #ecd6ac;
  --green-deep: #24473a;
  --green: #3f7a4e;
  --green-live: #6fbe5a;
  --orange: #e3a857;
  --orange-deep: #b8563c;
  --sky: #86c0e8;
  --shadow: 0 5px 0 var(--ink), inset 0 3px 0 var(--cream-hi), inset 0 -5px 0 #c9a878;
  --shadow-sm: 0 3px 0 var(--ink), inset 0 2px 0 var(--cream-hi), inset 0 -3px 0 #c9a878;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #6fa9d2;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
}

button {
  border-radius: 0;
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

img {
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 640px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--sky);
  isolation: isolate;
  touch-action: auto;
}

@media (min-width: 700px) {
  body { background: #1a141f; }
  #app {
    border-left: 4px solid var(--ink);
    border-right: 4px solid var(--ink);
    box-shadow: 0 0 0 2px #4d3b5a;
  }
}

.sky {
  position: absolute;
  inset: 0 0 auto 0;
  height: 34%;
  background: var(--sky) url("assets/sky_band.webp") center top / cover no-repeat;
  z-index: 0;
}

#world {
  touch-action: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 16%;
  bottom: 0;
  z-index: 2;
  background: #6fa9d2;
  overflow: hidden;
}

#world canvas {
  display: block;
}

#world::before,
#world::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--cream-mid);
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  z-index: 4;
  pointer-events: none;
}
#world::before { top: 0; }
#world::after { display: none; }

.world-edge { display: none; }

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  display: none;
}

body.playing #hud { display: block; }

#hud > * { pointer-events: auto; }

.slab,
.portrait-slab,
.quest-slab,
.modal-panel,
.start-panel {
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  border-radius: 0;
  background-image:
    repeating-linear-gradient(90deg, rgba(36, 27, 46, .07) 0 1px, transparent 1px 22px),
    repeating-linear-gradient(0deg, rgba(36, 27, 46, .05) 0 1px, transparent 1px 22px);
}

.portrait-slab {
  position: absolute;
  left: calc(8px + var(--safe-left));
  top: calc(8px + var(--safe-top));
  width: 56px;
  height: 68px;
  padding: 2px;
  background-color: var(--cream);
  overflow: hidden;
}

.portrait-slab canvas {
  width: 100%;
  height: 100%;
  image-rendering: auto;
  background: #e9c98d;
}

.level-pill,
.coin-pill {
  position: absolute;
  top: calc(8px + var(--safe-top));
  width: 88px;
  height: 46px;
  border: 0;
  box-shadow: none;
  background: none;
  background-image: none;
}

.level-pill { left: calc(70px + var(--safe-left)); }
.coin-pill { right: calc(8px + var(--safe-right)); }

.level-pill img,
.coin-pill img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.level-pill .num,
.coin-pill .num {
  position: absolute;
  top: 50%;
  transform: translateY(-46%);
  font-size: 19px;
  color: var(--cream-hi);
  letter-spacing: .02em;
  text-shadow: 0 2px 0 var(--ink);
}

.level-pill .num { right: 13px; }
.coin-pill .num { right: 10px; font-size: 15px; color: var(--green-deep); text-shadow: 0 1px 0 rgba(255, 244, 216, .7); }

.hearts {
  position: absolute;
  right: calc(10px + var(--safe-right));
  top: calc(58px + var(--safe-top));
  display: flex;
  gap: 3px;
  align-items: center;
  pointer-events: none;
}

.hearts img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  filter: drop-shadow(0 1px 0 var(--ink));
  transition: transform .1s steps(2);
}

.hearts img.gone { opacity: .28; transform: translateY(3px); }

.xp-wrap {
  position: absolute;
  left: calc(70px + var(--safe-left));
  top: calc(60px + var(--safe-top));
  width: clamp(96px, 28vw, 146px);
  height: 17px;
  pointer-events: none;
}

.xp-track,
.xp-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.xp-clip {
  position: absolute;
  left: 3px;
  right: 3px;
  top: 3px;
  bottom: 3px;
  overflow: hidden;
  width: 0;
  transition: width .35s steps(6);
}

.xp-clip .xp-fill { position: absolute; left: 0; top: 0; height: 100%; }

.xp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  letter-spacing: .03em;
  color: #f6e7c8;
  text-shadow: 0 1px 0 var(--ink);
  padding-top: 1px;
}

.sound-btn {
  position: absolute;
  right: calc(10px + var(--safe-right));
  top: calc(88px + var(--safe-top));
  width: 30px;
  height: 30px;
  background: var(--cream);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 46;
}

.sound-btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 var(--cream-hi); }

.speaker { display: flex; align-items: flex-end; gap: 2px; height: 13px; }
.speaker i {
  display: block;
  width: 3px;
  background: var(--green-deep);
  border: 1px solid var(--ink);
}
.speaker i:nth-child(1) { height: 6px; }
.speaker i:nth-child(2) { height: 10px; }
.speaker i:nth-child(3) { height: 13px; }
.sound-btn[aria-pressed="false"] .speaker i { background: #b9a98d; }
.sound-btn[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 13px;
  height: 3px;
  background: var(--orange-deep);
  transform: rotate(-38deg);
  border: 1px solid var(--ink);
}

.start-sound {
  position: absolute;
  top: calc(8px + var(--safe-top));
  right: calc(8px + var(--safe-right));
  z-index: 95;
}

.quest-slab {
  position: absolute;
  left: calc(8px + var(--safe-left));
  top: calc(82px + var(--safe-top));
  width: clamp(184px, 50vw, 214px);
  min-height: 122px;
  padding: 0;
  overflow: hidden;
  z-index: 44;
}

.quest-card-bg {
  position: absolute;
  inset: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  object-fit: fill;
  z-index: 0;
  opacity: .92;
}

.quest-body {
  position: absolute;
  left: 53px;
  right: 7px;
  top: 14px;
  bottom: 7px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(36, 27, 46, .08);
  padding: 7px 6px 5px;
  overflow: hidden;
}

.q-kicker {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 7px;
  letter-spacing: .1em;
  color: var(--orange-deep);
}

.q-title {
  font-family: "Pixelify Sans", "DM Sans", sans-serif;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.02;
  color: var(--green-deep);
}

.q-desc {
  font-size: 9.5px;
  line-height: 1.22;
  font-weight: 500;
  color: #3b3a2d;
  max-width: 150px;
}

.q-progress {
  margin-top: 2px;
  align-self: flex-start;
  font-size: 9px;
  padding: 2px 6px;
  background: var(--green-deep);
  color: var(--cream);
  border: 2px solid var(--ink);
  letter-spacing: .04em;
}

.friend-chip {
  pointer-events: auto;
  position: absolute;
  right: calc(8px + var(--safe-right));
  top: calc(124px + var(--safe-top));
  width: 116px;
  height: 42px;
  border: 0;
  background: none;
  pointer-events: none;
}

.friend-chip img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.friend-chip span {
  position: absolute;
  left: 50px;
  right: 14px;
  top: 50%;
  transform: translateY(-46%);
  font-family: "Silkscreen", monospace;
  font-size: 9px;
  color: #f3e6c4;
  text-shadow: 1px 1px 0 #17121f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Controls ---------- */

#controls {
  touch-action: none;
  position: absolute;
  inset: auto 0 0 0;
  height: 23%;
  z-index: 50;
  pointer-events: none;
  display: none;
}

body.playing #controls { display: block; }

#movePad {
  position: absolute;
  left: calc(5% + var(--safe-left));
  bottom: calc(22px + var(--safe-bottom));
  width: clamp(120px, 43vw, 176px);
  aspect-ratio: 400 / 332;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

#movePad > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform .06s steps(2);
}

#movePad.pressing > img { transform: scale(.975); }

.pad-hit {
  position: absolute;
  display: block;
}

.pad-up { left: 27%; top: 0%; width: 46%; height: 44%; }
.pad-left { left: 0%; top: 26%; width: 40%; height: 48%; }
.pad-right { right: 0%; top: 26%; width: 40%; height: 48%; }
.pad-down { left: 27%; bottom: 0%; width: 46%; height: 44%; }

.pad-press {
  position: absolute;
  opacity: 0;
  background: rgba(255, 244, 216, .26);
  border: 2px solid rgba(36, 27, 46, .5);
  pointer-events: none;
  transition: opacity .04s steps(1);
}

.pad-press-up { left: 29%; top: 3%; width: 42%; height: 38%; }
.pad-press-left { left: 3%; top: 29%; width: 35%; height: 42%; }
.pad-press-right { right: 3%; top: 29%; width: 35%; height: 42%; }
.pad-press-down { left: 27%; bottom: 2%; width: 46%; height: 40%; }

#movePad[data-dir="up"] .pad-press-up,
#movePad[data-dir="left"] .pad-press-left,
#movePad[data-dir="right"] .pad-press-right,
#movePad[data-dir="down"] .pad-press-down { opacity: 1; transform: translateY(2px); }

.action-stack {
  position: absolute;
  right: calc(6% + var(--safe-right));
  bottom: calc(22px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  pointer-events: none;
}

.small-buttons {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.mini-cube {
  width: clamp(44px, 13vw, 58px);
  aspect-ratio: 1;
  position: relative;
  transition: transform .06s steps(2);
}

.mini-cube img { width: 100%; height: 100%; object-fit: contain; }
.mini-cube:active, .mini-cube.pressed { transform: translateY(4px) scale(.97); }

.action-slab {
  position: relative;
  width: clamp(118px, 40vw, 156px);
  aspect-ratio: 371 / 326;
  pointer-events: auto;
  transition: transform .07s steps(2);
  touch-action: none;
}

.action-slab img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity .1s steps(2);
}

.action-slab.dim img { opacity: 1; filter: saturate(.62) brightness(.9); }
.action-slab:active, .action-slab.pressed { transform: translateY(6px) scale(.97); }

.action-tag {
  position: absolute;
  left: 50%;
  bottom: 13%;
  transform: translateX(-50%);
  font-size: 8px;
  letter-spacing: .08em;
  color: var(--cream);
  background: var(--ink);
  border: 2px solid var(--cream);
  padding: 1px 6px 0;
  white-space: nowrap;
}

.ready-ring {
  position: absolute;
  inset: -7px;
  border: 3px solid var(--cream-hi);
  box-shadow: 0 0 0 3px var(--ink);
  opacity: 0;
  pointer-events: none;
}

.action-slab.ready .ready-ring {
  opacity: 1;
  animation: readyPulse .9s steps(2, end) infinite;
}

@keyframes readyPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}

/* ---------- Toasts, hint, bubble ---------- */

.toast-stack {
  position: absolute;
  right: calc(8px + var(--safe-right));
  top: calc(212px + var(--safe-top));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  width: min(48%, 220px);
  pointer-events: none;
}

.toast {
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 7px 12px 8px;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.15;
  text-align: center;
  color: var(--green-deep);
  animation: toastIn .16s steps(2) both;
}

.toast.gold { background: #f2cd82; }
.toast.big {
  font-family: "Pixelify Sans", sans-serif;
  font-size: 17px;
  letter-spacing: .02em;
  padding: 10px 16px;
}
.toast.out { animation: toastOut .2s steps(2) both; }

@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(-8px); opacity: 0; } }

.hint-slab {
  position: absolute;
  left: 7%;
  right: 7%;
  top: calc(210px + var(--safe-top));
  width: auto;
  max-width: 330px;
  margin: 0 auto;
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 10px 14px 12px;
  z-index: 55;
  display: none;
  pointer-events: none;
}

.hint-slab.show { display: block; animation: toastIn .18s steps(2) both; }
.hint-slab.hide { animation: toastOut .2s steps(2) both; }

.hint-title {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: .09em;
  color: var(--orange-deep);
  margin-top: 4px;
}
.hint-title:first-child { margin-top: 0; }
.hint-text { font-size: 11px; line-height: 1.25; font-weight: 500; margin: 1px 0 5px; }

.bubble-slab {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: calc(41% + 8px);
  width: auto;
  max-width: 360px;
  margin: 0 auto;
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 9px 13px 11px;
  z-index: 62;
  animation: toastIn .15s steps(2) both;
}

.bubble-name {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 9px;
  color: var(--orange-deep);
  letter-spacing: .06em;
}
.bubble-text { font-size: 12px; line-height: 1.28; font-weight: 500; margin-top: 3px; }

/* ---------- Start screen ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(8px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  background: rgba(30, 22, 40, .16);
  transition: opacity .25s steps(3), transform .25s steps(3);
}

.screen.gone {
  opacity: 0;
  transform: translateY(-14px);
  pointer-events: none;
}

.title-wrap {
  flex: 0 0 auto;
  width: min(64vw, 296px);
  margin-top: 1.2vh;
  pointer-events: none;
}

.title-img {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 0 rgba(36, 27, 46, .65));
}

.start-panel {
  touch-action: pan-y;
  position: relative;
  margin-top: 1.8vh;
  width: min(94%, 380px);
  padding: 12px 13px 12px;
  max-height: calc(100dvh - 190px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.start-panel::-webkit-scrollbar { display: none; }

.panel-kicker {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: .12em;
  color: var(--orange-deep);
  text-align: center;
}

.panel-title {
  margin: 2px 0 9px;
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: clamp(20px, 6vw, 26px);
  line-height: .98;
  text-align: center;
  color: var(--green-deep);
  letter-spacing: .01em;
}

.hero-studio {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.hero-stage {
  position: relative;
  flex: 0 0 40%;
  min-width: 102px;
  background: #bfe2f2;
  border: 3px solid var(--ink);
  box-shadow: inset 0 -4px 0 rgba(36, 27, 46, .18);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.hero-stage canvas {
  position: relative;
  z-index: 1;
  width: 92%;
  height: auto;
  margin-bottom: 12px;
  image-rendering: auto;
}

.stage-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  background:
    repeating-linear-gradient(90deg, #5aa04f 0 12px, #4c8d44 12px 24px);
  border-top: 3px solid var(--ink);
  z-index: 0;
}

.hero-picks {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.pick-label {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 7px;
  letter-spacing: .09em;
  color: var(--green-deep);
  margin: 2px 0 4px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 7px;
}

.swatch {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), inset 0 -3px 0 rgba(0, 0, 0, .22);
  transition: transform .06s steps(2);
}

.swatch:active { transform: translateY(2px); }
.swatch.on { outline: 3px solid var(--orange); outline-offset: 1px; }
.swatch.on::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  transform: translate(-50%, -50%);
  background: var(--cream-hi);
  border: 2px solid var(--ink);
}

.shuffle-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  padding: 5px 8px 6px;
  background: var(--cream-mid);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-sm);
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 7px;
  letter-spacing: .06em;
  color: var(--green-deep);
}
.shuffle-btn:active { transform: translateY(2px); box-shadow: inset 0 2px 0 var(--cream-hi); }
.dice {
  width: 10px;
  height: 10px;
  background: var(--orange);
  border: 2px solid var(--ink);
  box-shadow: inset 0 2px 0 #f7d79f;
}

.start-note {
  margin: 8px 0 9px;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.25;
  font-weight: 500;
  color: #4a4334;
}

.start-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  background: var(--orange);
  border: 3px solid var(--ink);
  box-shadow: 0 5px 0 var(--ink), inset 0 3px 0 #f7d79f, inset 0 -5px 0 #b9762c;
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: clamp(16px, 4.6vw, 20px);
  letter-spacing: .02em;
  color: var(--ink);
  padding: 10px 8px 12px;
  transition: transform .06s steps(2);
}

.start-btn:active { transform: translateY(5px); box-shadow: inset 0 3px 0 #f7d79f; }
.start-btn[disabled] { opacity: .55; }

.start-foot {
  margin-top: 8px;
  text-align: center;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  letter-spacing: .05em;
  line-height: 1.4;
  color: #6a5a45;
}

.loading {
  position: absolute;
  left: 50%;
  bottom: calc(24% + 12px);
  transform: translateX(-50%);
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: .12em;
  color: var(--cream-hi);
  text-shadow: 0 2px 0 var(--ink);
  white-space: nowrap;
}

.loading.done { display: none; }
.dots { display: inline-block; width: 12px; text-align: left; }

.poster-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(8px + var(--safe-bottom));
  height: 23%;
  pointer-events: none;
  z-index: 1;
}

.poster-pad {
  position: absolute;
  left: calc(5% + var(--safe-left));
  bottom: 14px;
  width: clamp(120px, 43vw, 176px);
}

.poster-action-wrap {
  position: absolute;
  right: calc(6% + var(--safe-right));
  bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.poster-minis { display: flex; gap: 8px; }
.poster-mini { width: clamp(44px, 13vw, 58px); }
.poster-action { width: clamp(122px, 42vw, 164px); }

@media (orientation: landscape) and (max-height: 540px) {
  .poster-pad { width: clamp(104px, 18vw, 132px); }
  .poster-action { width: clamp(106px, 19vw, 136px); }
  .poster-mini { width: clamp(38px, 7vw, 48px); }
  .poster-controls { height: 20%; }
}

@media (max-height: 760px) {
  .poster-minis { display: none; }
}

@media (max-height: 620px), (max-width: 340px) {
  .poster-controls { display: none; }
}

/* ---------- Modals ---------- */

.modal-layer {
  touch-action: pan-y;
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(30, 22, 40, .55);
}

.modal-layer[hidden] { display: none; }

.modal-panel {
  touch-action: pan-y;
  position: relative;
  width: min(94%, 392px);
  max-height: 82dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 16px;
  scrollbar-width: none;
}
.modal-panel::-webkit-scrollbar { display: none; }

.modal-close {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 34px;
  height: 34px;
  background: var(--cream-mid);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-sm);
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 11px;
  z-index: 2;
}
.modal-close:active { transform: translateY(3px); box-shadow: inset 0 2px 0 var(--cream-hi); }

.modal-kicker {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: .12em;
  color: var(--orange-deep);
}

.modal-title {
  margin: 2px 36px 10px 0;
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: 23px;
  line-height: 1;
  color: var(--green-deep);
}

.modal-content { font-size: 12px; line-height: 1.32; }

.map-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--cream-mid);
  overflow: hidden;
  background: #9d8e72;
  margin-bottom: 10px;
}

.map-frame img.map-ground {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.map-pin {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: var(--orange);
  border: 2px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  z-index: 3;
}
.map-pin.done { background: var(--green-live); }
.map-pin.hero { background: var(--cream-hi); width: 14px; height: 14px; margin: -7px 0 0 -7px; }
.map-pin.beacon { background: #7fc6e0; }
.map-pin-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  letter-spacing: .04em;
  color: var(--cream-hi);
  background: var(--ink);
  border: 1px solid var(--cream);
  padding: 1px 3px;
  white-space: nowrap;
  z-index: 4;
}

.modal-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 2px solid rgba(36, 27, 46, .16);
}
.modal-row:last-child { border-bottom: 0; }

.modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 11px 9px;
  background: var(--orange);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-sm);
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: .05em;
  color: var(--ink);
  text-align: center;
}
.modal-btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 #f7d79f; }
.modal-btn.alt { background: var(--cream-mid); }
.modal-btn.green { background: var(--green); color: var(--cream-hi); }
.modal-btn.wide { width: 100%; margin-top: 9px; }
.modal-btn[disabled] { opacity: .5; }

.quest-detail-title {
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--green-deep);
  margin: 0 0 4px;
}
.quest-detail-desc { margin: 0 0 9px; font-size: 12px; line-height: 1.35; }
.quest-bar {
  height: 15px;
  border: 2px solid var(--ink);
  background: #d5c39c;
  margin: 6px 0 10px;
  position: relative;
}
.quest-bar span {
  display: block;
  height: 100%;
  background: var(--green);
  border-right: 2px solid var(--ink);
  transition: width .3s steps(5);
}
.quest-steps { margin: 0; padding-left: 17px; font-size: 11.5px; line-height: 1.45; }
.quest-steps li { margin-bottom: 3px; }
.quest-steps li.done { color: #6b7f5a; text-decoration: line-through; }

.link-box {
  width: 100%;
  min-height: 42px;
  padding: 7px 8px;
  background: var(--cream-mid);
  border: 2px solid var(--ink);
  font-family: "Silkscreen", monospace;
  font-size: 8px;
  line-height: 1.4;
  color: var(--green-deep);
  overflow-wrap: anywhere;
  user-select: all;
}

.friend-state {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.friend-seat {
  padding: 4px 7px 5px;
  border: 2px solid var(--ink);
  background: var(--cream-mid);
  font-family: "Silkscreen", monospace;
  font-size: 8px;
  color: var(--green-deep);
}
.friend-seat.empty { opacity: .55; border-style: dashed; }
.friend-seat.mine { background: var(--orange); }

.small-note {
  font-size: 10.5px;
  line-height: 1.3;
  color: #574b3a;
  margin: 6px 0 0;
}

/* ---------- Level up ---------- */

.levelup {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 70;
  pointer-events: none;
}

.levelup-inner {
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 12px 26px 16px;
  text-align: center;
  animation: levelPop .5s steps(4) both;
}

.levelup-kicker {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: .1em;
  color: var(--orange-deep);
}
.levelup-num {
  font-size: 46px;
  line-height: 1;
  color: var(--green-deep);
  text-shadow: 0 3px 0 var(--orange);
}

@keyframes levelPop {
  0% { transform: scale(.6) translateY(20px); opacity: 0; }
  60% { transform: scale(1.06) translateY(0); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Small screens ---------- */

@media (max-width: 370px) {
  .quest-slab {
    width: 176px;
    min-height: 116px;
  }
  .quest-body { left: 47px; top: 12px; padding: 6px 5px 4px; }
  .q-title { font-size: 12px; }
  .q-desc { font-size: 9px; max-width: 118px; }
  .level-pill, .coin-pill { width: 78px; }
  .level-pill { left: 64px; }
  .xp-wrap { left: 64px; width: 90px; }
  .portrait-slab { width: 50px; height: 62px; }
  .hearts img { width: 16px; height: 16px; }
  .start-panel { padding: 10px; }
  .hero-stage { min-width: 92px; flex-basis: 36%; }
}

@media (max-height: 650px) {
  #world { top: 14%; bottom: 0; }
  .quest-slab { min-height: 104px; padding-top: 12px; }
  .q-desc { font-size: 9px; }
  .start-panel { max-height: calc(100dvh - 150px); }
  .title-wrap { width: min(52vw, 230px); }
  .hero-stage canvas { margin-bottom: 10px; }
  .stage-ground { height: 11px; }
}

@media (orientation: landscape) and (max-height: 540px) {
  #world { top: 8%; bottom: 0; }
  .quest-slab {
    width: 176px;
    min-height: 94px;
    top: 68px;
  }
  .quest-body { top: 12px; bottom: 6px; padding: 5px 5px 3px; }
  .q-title { font-size: 11px; }
  .q-desc { font-size: 8.5px; max-width: 116px; }
  .portrait-slab { width: 46px; height: 56px; }
  .level-pill { left: 58px; width: 76px; }
  .level-pill .num { font-size: 14px; }
  .coin-pill { width: 78px; }
  .coin-pill .num { font-size: 12px; }
  .xp-wrap { top: 54px; left: 58px; width: 84px; height: 14px; }
  .hearts { top: 52px; }
  .sound-btn { top: 78px; width: 26px; height: 26px; }
  #movePad { width: clamp(100px, 17vw, 126px); }
  .action-slab { width: clamp(100px, 18vw, 130px); }
  .mini-cube { width: clamp(38px, 7vw, 48px); }
  #controls { height: 20%; }
  .bubble-slab { bottom: calc(38% + 6px); }
  .toast-stack { top: 160px; right: 8px; width: min(34%, 210px); }
  .start-panel {
    width: min(90%, 430px);
    max-height: calc(100dvh - 84px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 6px 12px;
    padding: 8px 12px 10px;
  }
  .panel-kicker, .panel-title, .start-note, .start-foot { grid-column: 1 / -1; }
  .panel-title { margin-bottom: 0; font-size: 18px; }
  .hero-studio { grid-column: 1 / -1; }
  .hero-stage { min-width: 86px; flex-basis: 22%; }
  .hero-stage canvas { width: 82%; margin-bottom: 8px; }
  .start-note, .start-foot { display: none; }
  .start-btn { grid-column: 1 / -1; min-height: 38px; font-size: 15px; }
  .poster-controls { display: none; }
  .hint-slab { display: none !important; }
  .title-wrap { width: min(30vw, 180px); margin-top: 0; }
  .levelup { top: 50%; }
}

/* ---------- World light, quest arrow, place banner ---------- */

.world-light {
  position: absolute;
  left: 0; right: 0; top: 16%; bottom: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 8% 0%, rgba(255, 236, 190, .16), rgba(255, 236, 190, 0) 60%),
    radial-gradient(90% 70% at 100% 100%, rgba(40, 40, 80, .14), rgba(40, 40, 80, 0) 70%);
  display: none;
}
body.playing .world-light { display: block; }

.quest-arrow {
  position: absolute;
  left: 0; top: 0;
  width: 40px; height: 40px;
  z-index: 38;
  pointer-events: none;
}
.quest-arrow[hidden] { display: none; }
.quest-arrow .qa-cube {
  position: absolute; inset: 0;
  display: block;
}
.quest-arrow .qa-cube i {
  position: absolute;
  left: 4px; top: 9px;
  width: 0; height: 0;
  border-left: 30px solid #f2a33a;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  filter: drop-shadow(2px 0 0 #241b2e) drop-shadow(-2px 0 0 #241b2e) drop-shadow(0 2px 0 #241b2e) drop-shadow(0 -2px 0 #241b2e);
  animation: qaPulse 1s steps(2, end) infinite;
}
@keyframes qaPulse { 50% { transform: translateX(3px); } }
.quest-arrow .qa-dist {
  position: absolute;
  left: 50%; top: 40px;
  transform: translateX(-50%);
  font-family: "Silkscreen", monospace;
  font-size: 9px;
  color: var(--cream-hi);
  background: var(--ink);
  padding: 1px 4px;
  white-space: nowrap;
}

.place-banner {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: max-content;
  max-width: 86%;
  top: 34%;
  z-index: 58;
  pointer-events: none;
  background: var(--ink);
  border: 3px solid var(--cream);
  box-shadow: 0 4px 0 #120d18;
  padding: 8px 18px 9px;
  text-align: center;
  min-width: 190px;
}
.place-banner[hidden] { display: none; }
.place-banner.in { animation: toastIn .18s steps(2) both; }
.place-banner.out { animation: toastOut .22s steps(2) both; }
.place-name {
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: #f2cd82;
  letter-spacing: .02em;
  line-height: 1.05;
}
.place-job {
  font-size: 11px;
  font-weight: 500;
  color: var(--cream);
  margin-top: 3px;
}

.map-frame canvas.map-ground {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.quest-place {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: .08em;
  color: var(--orange-deep);
  margin: 10px 0 2px;
}
