:root {
  --ink: #3b2a1a;
  --cream: #fff8e8;
  --gold: #ffc531;
  --gold-dark: #d99a00;
  --panel: rgba(255, 250, 235, 0.94);
  --shadow: 0 6px 18px rgba(30, 40, 10, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fd6ff;
  font-family: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#scene { display: block; width: 100vw; height: 100vh; height: 100dvh; }

[hidden] { display: none !important; }

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

.profile {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  width: 104px;
  text-align: center;
}
.profile img {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto;
  border-radius: 50%;
  border: 5px solid #ff8a65;
  background: radial-gradient(circle at 50% 35%, #fff 0%, #e9f6ff 70%);
  box-shadow: var(--shadow);
}
.profile-name {
  display: inline-block;
  margin-top: -16px;
  position: relative;
  padding: 2px 14px;
  border-radius: 999px;
  background: #ff8a65;
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  box-shadow: var(--shadow);
}

.pills {
  position: fixed;
  top: max(20px, env(safe-area-inset-top));
  left: calc(max(12px, env(safe-area-inset-left)) + 116px);
  display: flex;
  gap: 10px;
}
.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 20px 0 12px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 30px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.pill-friends { font-size: 22px; }
.coin-icon {
  --coin: var(--gold);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff8 0%, var(--coin) 55%, color-mix(in srgb, var(--coin) 70%, #000));
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--coin) 80%, #000);
}


.pill.bump { animation: bump 0.3s; }
@keyframes bump { 50% { transform: scale(1.15); } }

.quest {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(640px, calc(100vw - 32px));
  padding: 10px 12px 10px 18px;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.quest-icon { font-size: 34px; }
.quest-title { color: #b8641a; font-weight: 600; font-size: 20px; line-height: 1.1; }
.quest-objective { font-weight: 700; font-size: 30px; line-height: 1.15; }
.quest-arrow {
  flex: none;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 -4px 0 var(--gold-dark);
  display: grid;
  place-items: center;
}
.quest-arrow svg { width: 40px; height: 40px; fill: #fff; stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; transition: transform 0.1s linear; }
.quest.flash { animation: flash 0.6s; }
@keyframes flash { 30% { transform: translateX(-50%) scale(1.06); } }

.minimap {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 180px;
  text-align: center;
}
.minimap canvas {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 6px solid #fff;
  box-shadow: var(--shadow);
  background: #7cc35a;
}
.map-label {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--panel);
  font-weight: 600;
  font-size: 17px;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  top: 210px;
  left: max(12px, env(safe-area-inset-left));
  padding: 10px 18px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 18px;
  opacity: 0;
  transform: translateX(-120%);
  transition: transform 0.35s, opacity 0.35s;
}
.toast b { display: block; font-size: 24px; }
.toast.show { opacity: 1; transform: none; }

.caption {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 32px));
  padding: 16px 26px;
  border-radius: 22px;
  background: rgba(40, 40, 40, 0.78);
  color: #fff;
  text-align: center;
  font-weight: 600;
  font-size: clamp(20px, 3vw, 32px);
  line-height: 1.25;
}

.corner-buttons {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  top: 250px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.round-btn {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 22px;
  cursor: pointer;
}

.hint {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 15px;
  box-shadow: var(--shadow);
}

/* ---------- camp: build a little house ---------- */

.camp-panel {
  position: fixed;
  top: 50%;
  right: max(16px, env(safe-area-inset-right));
  transform: translateY(-50%);
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 18px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 8px 0 #c99b4a, 0 20px 40px rgba(0, 0, 0, 0.3);
  touch-action: pan-y;
}
.camp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.camp-title { font-size: 26px; font-weight: 700; color: #3f8f3a; line-height: 1.1; }
.camp-coins { display: flex; align-items: center; gap: 8px; padding: 6px 16px 6px 8px; border-radius: 999px; background: #fff; font-size: 30px; box-shadow: 0 3px 0 #e6d6b4; }
.camp-status { margin: 8px 2px 12px; font-size: 18px; font-weight: 600; }
.camp-parts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.part {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  padding: 8px 10px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #fff;
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 0 #e6d6b4;
}
.part:not([disabled]):hover { border-color: var(--gold); }
.part:not([disabled]):active { transform: translateY(2px); box-shadow: 0 2px 0 #e6d6b4; }
.part-icon { grid-row: span 2; font-size: 30px; }
.part-name { font-size: 17px; font-weight: 700; line-height: 1.1; }
.part-name small { display: block; font-size: 12px; font-weight: 500; opacity: 0.6; }
.part-cost { display: flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 600; }
.part-cost .coin-icon { width: 18px; height: 18px; }
.part.built { background: #e3f2d9; box-shadow: 0 4px 0 #9fc78a; }
.part.built .part-cost { color: #3f8f3a; }
.part.locked, .part.poor { opacity: 0.55; }
.part.poor .part-cost { color: #c0392b; }
.part[disabled] { cursor: default; }
.camp-actions { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.camp-actions .btn { font-size: 20px; padding: 10px 20px; }

.done-parts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 12px; margin: -8px 0 18px; font-size: 17px; font-weight: 600; }

/* ---------- touch controls: left thumb moves, right thumb jumps and looks ---------- */

.touch { position: fixed; inset: 0; pointer-events: none; }
.stick-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 50%;
  height: 72%;
  pointer-events: auto;
  touch-action: none;
}
.stick {
  position: fixed;
  left: max(28px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 3px solid rgba(255, 255, 255, 0.55);
  opacity: 0.75;
  transition: opacity 0.15s;
  pointer-events: none;
}
.stick.active { opacity: 1; background: rgba(255, 255, 255, 0.28); transition: none; }
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 66px;
  height: 66px;
  margin: -33px 0 0 -33px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}
.jump-btn {
  position: absolute;
  right: max(28px, env(safe-area-inset-right));
  bottom: max(36px, env(safe-area-inset-bottom));
  width: 110px;
  height: 110px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 -6px 0 var(--gold-dark), var(--shadow);
  font: inherit;
  font-size: 40px;
  line-height: 1;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.jump-btn small { font-size: 13px; font-weight: 700; letter-spacing: 1px; }
.jump-btn.active { transform: scale(0.92); box-shadow: inset 0 -2px 0 var(--gold-dark), var(--shadow); }
.look-hint {
  position: absolute;
  right: max(150px, calc(env(safe-area-inset-right) + 150px));
  bottom: max(70px, env(safe-area-inset-bottom));
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 14px;
  pointer-events: none;
}
/* Phones in portrait: tuck the quest card and caption above the thumbs. */
body.touching .hint { display: none; }

/* ---------- overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(30, 60, 30, 0.35);
}
.card {
  width: min(480px, 100%);
  padding: 30px 26px;
  border-radius: 30px;
  background: var(--cream);
  text-align: center;
  box-shadow: 0 10px 0 #c99b4a, 0 24px 50px rgba(0, 0, 0, 0.3);
}
.card h1 { margin: 0 0 6px; font-size: 48px; color: #3f8f3a; }
.card h2 { margin: 0 0 8px; font-size: 36px; color: #3f8f3a; }
.card p { margin: 8px 0 18px; font-size: 20px; }
.card .stats { font-size: 26px; font-weight: 700; margin-bottom: 18px; }
.btn {
  display: inline-block;
  margin: 6px;
  padding: 14px 34px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font: inherit;
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--gold-dark);
  text-decoration: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--gold-dark); }
.btn.secondary { background: #e3f2d9; box-shadow: 0 6px 0 #9fc78a; font-size: 18px; padding: 10px 22px; }

/* ---------- explorer picker ---------- */

.picking .card { width: min(600px, 100%); }
.hero-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 4px 0 20px;
}
.hero-grid .hero-pick { flex: 0 0 calc((100% - 24px) / 3); }
.hero-pick {
  padding: 8px 4px 6px;
  border: 4px solid transparent;
  border-radius: 22px;
  background: #fff;
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 #e6d6b4;
  transition: transform 0.12s;
}
.hero-pick img {
  display: block;
  width: 100%;
  max-width: 120px;
  aspect-ratio: 1;
  margin: 0 auto 2px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #fff 0%, #e9f6ff 70%);
}
.hero-pick:hover { transform: translateY(-2px); }
.hero-pick.selected {
  border-color: var(--gold);
  background: #fff6d6;
  transform: scale(1.04);
  box-shadow: 0 4px 0 var(--gold-dark);
}

/* ---------- dress up ---------- */

.dressing .card.dressup { width: min(940px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; padding: 20px; }
.dressup h2 { margin-bottom: 10px; }
.dressup-body { display: flex; gap: 18px; min-height: 0; flex: 1; }
.dressup-stage { flex: 0 0 300px; display: flex; flex-direction: column; align-items: center; }
.dressup-preview {
  width: 100%;
  flex: 1;
  min-height: 300px;
  border-radius: 24px;
  background: radial-gradient(circle at 50% 40%, #ffffff 0%, #dff2ff 75%);
  overflow: hidden;
}
.dressup-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.dressup-name { margin-top: 10px; font-weight: 700; font-size: 18px; }
.dressup-name input {
  width: 170px;
  margin-left: 6px;
  padding: 8px 12px;
  border: 3px solid #e6d6b4;
  border-radius: 14px;
  font: inherit;
  font-size: 18px;
  color: var(--ink);
}
.dressup-name input:focus { outline: none; border-color: var(--gold); }
.dressup-hint { font-size: 13px; opacity: 0.6; margin-top: 4px; }
.dressup-options { flex: 1; overflow-y: auto; text-align: left; padding-right: 4px; touch-action: pan-y; }
.dress-row { margin-bottom: 10px; }
.dress-label { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.dress-items { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 34px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: 0 0 0 2px #e6d6b4;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  color: #b9a37a;
}
.swatch.none { background: #fff; }
.swatch.on { box-shadow: 0 0 0 3px var(--gold-dark); transform: scale(1.12); }
.chip {
  padding: 6px 12px;
  border: 2px solid #e6d6b4;
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.chip.on { border-color: var(--gold-dark); background: #fff3c4; }
.dressup-actions { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.dressup-actions .btn { font-size: 20px; padding: 10px 22px; }

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  .profile { width: 72px; }
  .profile img { width: 64px; height: 64px; border-width: 4px; }
  .profile-name { font-size: 14px; margin-top: -12px; padding: 1px 8px; }
  .pills { left: calc(max(12px, env(safe-area-inset-left)) + 80px); top: max(12px, env(safe-area-inset-top)); flex-direction: column; gap: 6px; }
  .pill { height: 40px; font-size: 22px; padding: 0 14px 0 8px; }
  .pill-friends { font-size: 16px; }
  .coin-icon { width: 26px; height: 26px; }
  .quest { top: auto; bottom: calc(max(28px, env(safe-area-inset-bottom)) + 190px); padding: 6px 8px 6px 12px; gap: 8px; }
  .quest-icon { display: none; }
  .quest-title { font-size: 14px; }
  .quest-objective { font-size: 20px; }
  .quest-arrow { width: 48px; height: 48px; }
  .quest-arrow svg { width: 28px; height: 28px; }
  .minimap, .minimap canvas { width: 110px; }
  .minimap canvas { height: 110px; border-width: 4px; }
  .map-label { font-size: 12px; }
  .toast { top: 130px; }
  .corner-buttons { top: 160px; }
  .caption { bottom: calc(max(28px, env(safe-area-inset-bottom)) + 150px); font-size: 18px; padding: 10px 16px; }
  .hint { display: none; }
  .dressup-body { flex-direction: column; }
  .dressup-stage { flex: 0 0 auto; }
  .dressup-preview { min-height: 200px; height: 200px; }
  .dressup-options { overflow: visible; }
  .dressing .card.dressup { overflow-y: auto; }
  .look-hint { display: none; }
  .camp-panel { top: auto; bottom: max(10px, env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%); max-height: 55dvh; padding: 12px; border-radius: 22px; }
  .camp-title { font-size: 20px; }
  .camp-coins { font-size: 22px; }
  .camp-status { font-size: 15px; margin: 6px 2px 8px; }
  .part { padding: 6px 8px; }
  .part-icon { font-size: 24px; }
  .part-name { font-size: 15px; }
  .card { padding: 20px 16px; }
  .card h1 { font-size: 34px; }
  .card p { font-size: 17px; margin-bottom: 12px; }
  .hero-grid { gap: 8px; margin-bottom: 14px; }
  .hero-pick { font-size: 16px; border-width: 3px; border-radius: 16px; }
}

@media (max-height: 640px) {
  .overlay { align-items: flex-start; overflow-y: auto; touch-action: pan-y; }
  .picking .card { width: min(720px, 100%); }
  .picking .hero-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (max-height: 480px) {
  .stick { width: 120px; height: 120px; }
  .knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
  .jump-btn { width: 90px; height: 90px; font-size: 32px; }
}
