@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
:root {
  --tq: #1fa3a8; --tq2: #13777d; --cobalt: #1d3f8f; --ochre: #e3b448; --ochre2: #b88a22;
  --cream: #fbf5e8; --cream2: #efe4cc; --ink: #22303a; --muted: #5f6a72; --red: #c8414b; --red2: #932830;
  --glass: rgba(251, 245, 232, .93);
  --lift: 0 3px 0 rgba(60, 40, 20, .14), 0 8px 20px rgba(60, 40, 20, .16);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #c8dcea; color: var(--ink);
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
#view, #view canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#layer { position: fixed; inset: 0; z-index: 1; touch-action: none; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.snd-off { display: none; }
body.muted .snd-on { display: none; }
body.muted .snd-off { display: inline-block; }
.spacer { flex: 1; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#topbar {
  position: absolute; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  left: max(12px, env(safe-area-inset-left, 0px));
}
.chip {
  background: var(--glass); border-radius: 14px; padding: 6px 12px; font-weight: 800;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: var(--lift); color: var(--ink);
}
.chip .ic { width: 18px; height: 18px; color: var(--tq2); }
.coin {
  width: 22px; height: 22px; border-radius: 50%; display: inline-block; flex: 0 0 auto;
  background: radial-gradient(circle at 35% 32%, #fff4bd 0 12%, #f0c548 40%, #b8861e 100%);
  box-shadow: inset 0 0 0 2px #a8761a, inset 0 0 0 4px rgba(255, 236, 160, .6);
}
.coinchip { padding: 6px 12px 6px 14px; transform-origin: center; }
.coinchip #coin-n { font-size: 22px; min-width: 1.6em; text-align: center; line-height: 1; }
.coinchip .goal { display: inline-flex; flex-direction: column; gap: 3px; }
.coinchip .goal small { font-size: 11px; color: var(--muted); font-weight: 700; line-height: 1; }
.bar { width: 110px; height: 10px; background: rgba(34, 48, 58, .14); border-radius: 6px; overflow: hidden; display: inline-block; position: relative; }
.bar i {
  position: absolute; inset: 0 0 0 auto; width: 0; border-radius: 6px; transition: width .5s cubic-bezier(.2, .9, .3, 1.2);
  background: linear-gradient(270deg, var(--tq), var(--ochre));
}
.bar.big { flex: 1; width: auto; height: 14px; border-radius: 8px; }
.coinchip.bump { animation: bump .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.16); } 70% { transform: scale(.97); } 100% { transform: scale(1); } }
.ibtn {
  pointer-events: auto; font: inherit; font-weight: 800; font-size: 15px; height: 44px; min-width: 44px; padding: 0 14px;
  border: none; border-radius: 14px; background: var(--glass); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; box-shadow: var(--lift);
}
.ibtn.round { padding: 0; width: 44px; }
.ibtn.primary { background: var(--tq); color: #fff; box-shadow: 0 3px 0 var(--tq2), 0 8px 20px rgba(19, 119, 125, .3); }
.ibtn:active { transform: translateY(2px); }

#crosshair { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; }
#crosshair::before, #crosshair::after {
  content: ''; position: absolute; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}
#crosshair::before { left: 8px; top: 2px; width: 2px; height: 14px; }
#crosshair::after { left: 2px; top: 8px; width: 14px; height: 2px; }
#ring { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; transform: translate(-50%, -50%) rotate(-90deg); opacity: 0; transition: opacity .15s; }
#ring circle { fill: none; stroke: var(--ochre); stroke-width: 4; stroke-dasharray: 100; stroke-dashoffset: 100; stroke-linecap: round; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .5)); }
#aimhint {
  position: absolute; left: 50%; top: calc(50% + 30px); transform: translate(-50%, 4px); opacity: 0;
  transition: opacity .2s, transform .2s; background: rgba(29, 63, 143, .85); color: #fff; font-weight: 800;
  font-size: 14px; padding: 4px 12px; border-radius: 10px; white-space: nowrap;
}
#aimhint.show { opacity: 1; transform: translate(-50%, 0); }
#aimhint .t-touch, body.touch #aimhint .t-pc { display: none; }
body.touch #aimhint .t-touch { display: inline; }
#hint {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  background: var(--ochre); color: var(--ink); font-weight: 800; padding: 7px 16px; border-radius: 14px;
  box-shadow: 0 3px 0 var(--ochre2), 0 8px 18px rgba(60, 40, 0, .25); display: flex; align-items: center; gap: 8px;
  white-space: nowrap; max-width: calc(100vw - 24px); animation: float 2.4s ease-in-out infinite;
}
body.touch #hint { bottom: auto; top: calc(62px + env(safe-area-inset-top, 0px)); }
#hint .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(200, 65, 75, .3); }
@keyframes float { 50% { transform: translate(-50%, -4px); } }
#hotbar {
  position: absolute; left: 50%; transform: translateX(-50%); display: flex; gap: 5px; direction: ltr;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px)); pointer-events: auto;
  max-width: calc(100vw - 20px); overflow-x: auto; padding: 6px 6px 5px; border-radius: 16px;
  background: rgba(34, 40, 46, .5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  scrollbar-width: none;
}
#hotbar::-webkit-scrollbar { display: none; }
.slot {
  position: relative; width: 54px; height: 54px; flex: 0 0 auto; padding: 0; cursor: pointer;
  border: 2px solid rgba(255, 255, 255, .22); border-radius: 12px; background: rgba(255, 255, 255, .08);
  transition: transform .12s, border-color .12s, background .12s;
}
.slot img { width: 42px; height: 42px; image-rendering: pixelated; display: block; margin: auto; pointer-events: none; }
.slot span { position: absolute; top: 1px; left: 5px; font-size: 11px; color: #fff; text-shadow: 0 1px 2px #000; font-weight: 700; }
.slot.sel { border-color: var(--ochre); background: rgba(227, 180, 72, .32); transform: translateY(-3px); box-shadow: 0 4px 10px rgba(0, 0, 0, .3); }
.slot.pulse { animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(227, 180, 72, .75), 0 0 18px rgba(227, 180, 72, .8); } }
#selname {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(132px + env(safe-area-inset-bottom, 0px));
  color: #fff; text-shadow: 0 1px 3px #000, 0 0 10px rgba(0, 0, 0, .4); font-weight: 800; font-size: 17px;
  opacity: 0; transition: opacity .3s; white-space: nowrap;
}
#selname.show { opacity: 1; }

/* tutorial card */
#coach {
  position: absolute; left: 50%; top: calc(70px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px)); background: var(--glass); border-radius: 18px; padding: 12px 16px 12px;
  box-shadow: var(--lift); border-top: 5px solid var(--tq); pointer-events: auto;
}
#coach.pop { animation: coach .45s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes coach { from { transform: translate(-50%, -12px) scale(.96); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
#coach.done { border-top-color: var(--ochre); }
#coach .coach-top { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 800; color: var(--tq2); }
#coach .dots { display: inline-flex; gap: 4px; direction: rtl; }
#coach .dots i { width: 18px; height: 5px; border-radius: 3px; background: rgba(34, 48, 58, .15); }
#coach .dots i.on { background: var(--tq); }
#coach.done .coach-top { display: none; }
#coach b { display: block; font-size: 18px; color: var(--cobalt); margin-top: 2px; }
#coach p { margin: 3px 0 0; line-height: 1.7; font-size: 15px; }
#coach small { display: block; color: var(--muted); font-size: 13px; }
#coach small:empty { display: none; }
#coach-skip {
  font: inherit; font-size: 12px; font-weight: 700; color: var(--muted); background: none; border: none; padding: 4px 0 0;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
#coach.done #coach-skip { display: none; }

/* demo time skip */
#ffwd {
  position: absolute; left: 50%; top: calc(118px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 8px 18px; border-radius: 16px; white-space: nowrap;
  background: rgba(29, 63, 143, .88); color: #fff; font-weight: 900; font-size: 20px;
  box-shadow: 0 3px 0 #142e6b, 0 10px 24px rgba(20, 30, 60, .3); animation: ffpulse 1s ease-in-out infinite;
}
#ffwd svg { width: 26px; height: 26px; fill: var(--ochre); }
@keyframes ffpulse { 50% { transform: translateX(-50%) scale(1.06); } }

/* film: no interface during the demo's opening flyover; it fades in when the camera lands */
#hud, #touch, #wpops { transition: opacity .8s ease; }
body.cine #hud, body.cine #touch, body.cine #wpops { opacity: 0; }

/* coin text over the counter */
#wpops { position: fixed; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.wpop {
  position: absolute; left: 0; top: 0; font-weight: 900; font-size: 34px; color: #ffd75e; white-space: nowrap;
  text-shadow: 0 2px 0 #8a5a00, 0 3px 0 #8a5a00, 0 0 14px rgba(60, 30, 0, .45); will-change: transform, opacity;
}

#toast {
  position: fixed; z-index: 30; left: 50%; transform: translate(-50%, -6px); pointer-events: none;
  top: calc(66px + env(safe-area-inset-top, 0px)); background: rgba(29, 40, 50, .9); color: #fff;
  padding: 9px 18px; border-radius: 14px; font-weight: 700; opacity: 0; transition: opacity .25s, transform .25s;
  max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 8px 20px rgba(0, 0, 0, .2);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.touch #toast { top: auto; bottom: calc(300px + env(safe-area-inset-bottom, 0px)); }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#stick {
  position: absolute; width: 150px; height: 150px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .1) 0 55%, rgba(255, 255, 255, .22) 56% 100%);
  border: 3px solid rgba(255, 255, 255, .55); box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
  left: max(24px, calc(env(safe-area-inset-left, 0px) + 12px)); bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  opacity: .8; transition: opacity .15s;
}
#stick.on { opacity: 1; }
#knob {
  position: absolute; left: 40px; top: 40px; width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff, rgba(255, 255, 255, .75)); box-shadow: 0 4px 10px rgba(0, 0, 0, .25);
}
.tbtn {
  position: absolute; pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; touch-action: none;
  border: 3px solid rgba(255, 255, 255, .85); background: rgba(19, 119, 125, .62); color: #fff;
  font: inherit; font-weight: 800; font-size: 13px; text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .2); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  transition: transform .08s, background .08s;
}
.tbtn .ic { width: 26px; height: 26px; stroke-width: 2.6; }
.tbtn.big { width: 96px; height: 96px; font-size: 15px; background: rgba(169, 42, 49, .62); }
.tbtn.big .ic { width: 32px; height: 32px; }
.tbtn.on { background: rgba(227, 180, 72, .92); color: var(--ink); text-shadow: none; transform: scale(.94); }
#b-dig { right: max(20px, calc(env(safe-area-inset-right, 0px) + 10px)); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
#b-place { right: max(128px, calc(env(safe-area-inset-right, 0px) + 118px)); bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
#b-jump { right: max(34px, calc(env(safe-area-inset-right, 0px) + 24px)); bottom: calc(206px + env(safe-area-inset-bottom, 0px)); }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: rgba(30, 36, 44, .42); overflow: auto; touch-action: pan-y;
}
.panel {
  background: var(--cream); border-radius: 22px; padding: 28px 22px 20px; max-width: 520px; width: 100%;
  box-shadow: 0 18px 50px rgba(40, 25, 10, .35); position: relative; overflow: hidden auto;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); margin: auto;
  animation: panel .3s cubic-bezier(.2, 1.2, .4, 1);
}
.panel.narrow { max-width: 400px; }
@keyframes panel { from { transform: translateY(14px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.band {
  position: absolute; top: 0; left: 0; right: 0; height: 12px;
  background:
    radial-gradient(circle at 50% 50%, var(--ochre) 0 2px, transparent 2.5px) 0 0 / 16px 12px,
    linear-gradient(45deg, transparent 0 40%, var(--cobalt) 40% 60%, transparent 60%) 0 0 / 16px 12px,
    linear-gradient(-45deg, transparent 0 40%, var(--cobalt) 40% 60%, transparent 60%) 0 0 / 16px 12px,
    var(--tq);
}
.panel h2 { margin: 4px 0 12px; color: var(--cobalt); font-weight: 900; font-size: 26px; }
.panel h3 { margin: 16px 0 8px; color: var(--tq2); font-size: 17px; font-weight: 900; }
.panel ul { margin: 4px 0; padding-inline-start: 22px; line-height: 1.9; }
.panel p { line-height: 1.9; margin: 8px 0; }
.small { font-size: 14px; color: var(--muted); }
.big { font-size: 30px; font-weight: 900; color: var(--tq2); direction: ltr; text-align: center; }
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.menu.row, .row { display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; }
.menu.row .btn, .row .btn { flex: 1; }
.btn {
  font: inherit; font-size: 18px; font-weight: 800; padding: 12px 18px; border-radius: 15px; border: none;
  background: var(--tq); color: #fff; cursor: pointer; box-shadow: 0 4px 0 var(--tq2); text-align: center;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--tq2); }
.btn.big { font-size: 24px; padding: 14px 18px; }
.btn.sm { font-size: 15px; padding: 9px 12px; border-radius: 13px; }
.btn.icon { flex: 0 0 auto !important; width: 48px; padding: 0; }
.btn.alt { background: var(--ochre); color: var(--ink); box-shadow: 0 4px 0 var(--ochre2); }
.btn.alt:active:not(:disabled) { box-shadow: 0 1px 0 var(--ochre2); }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #d8cbac; }
.btn.ghost:active:not(:disabled) { box-shadow: 0 1px 0 #d8cbac; }
.btn.red { background: var(--red); color: #fff; box-shadow: 0 4px 0 var(--red2); }
.btn:disabled { opacity: .45; cursor: default; }

/* start screen: big name over the turning world, small card at the bottom */
#scr-start {
  flex-direction: column; justify-content: space-between; align-items: center; touch-action: auto;
  background: linear-gradient(180deg, rgba(40, 60, 90, .18) 0%, rgba(40, 60, 90, 0) 32%, rgba(40, 60, 90, 0) 55%, rgba(50, 30, 15, .45) 100%);
  padding-block: calc(20px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-bottom, 0px));
}
.hero { text-align: center; margin-top: 5vh; animation: hero .9s cubic-bezier(.2, 1.2, .4, 1); }
@keyframes hero { from { transform: translateY(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
.hero .tiles {
  width: 200px; max-width: 60vw; height: 16px; margin: 0 auto 6px; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(30, 20, 10, .25);
  background:
    radial-gradient(circle, var(--ochre) 0 2.5px, transparent 3px) 0 0 / 20px 16px,
    linear-gradient(45deg, transparent 0 38%, var(--cobalt) 38% 62%, transparent 62%) 0 0 / 20px 16px,
    linear-gradient(-45deg, transparent 0 38%, var(--cobalt) 38% 62%, transparent 62%) 0 0 / 20px 16px,
    var(--tq);
}
h1.title {
  font-size: clamp(64px, 18vw, 136px); margin: 0; font-weight: 900; color: #fffaf0; line-height: 1.1;
  text-shadow: 0 4px 0 var(--cobalt), 0 8px 0 #142e6b, 0 16px 34px rgba(30, 20, 10, .45);
}
.tag {
  color: #fff; font-weight: 700; font-size: clamp(15px, 4vw, 20px); margin: 14px 0 0;
  text-shadow: 0 2px 10px rgba(30, 20, 10, .6), 0 1px 2px rgba(30, 20, 10, .5);
}
.startcard {
  width: min(360px, 100%); background: var(--glass); border-radius: 22px; padding: 14px;
  box-shadow: 0 16px 40px rgba(40, 25, 10, .35); display: flex; flex-direction: column; gap: 10px;
  animation: panel .5s .15s both cubic-bezier(.2, 1.2, .4, 1);
}
.startcard .by { text-align: center; font-weight: 800; color: var(--tq2); direction: ltr; font-size: 13px; letter-spacing: 1px; }
.note { background: #fff4cf; border: 1px solid var(--ochre); border-radius: 12px; padding: 6px 10px; margin: 0; font-size: 14px; }

/* shop */
.panel.shop { max-width: 680px; }
.shop-head { display: flex; align-items: center; gap: 10px; }
.shop-head h2 { margin: 4px 0; }
.shop-head .chip { box-shadow: none; background: #fff; font-size: 18px; }
.xbtn {
  font: inherit; font-size: 26px; line-height: 1; width: 40px; height: 40px; border-radius: 12px; border: none;
  background: #fff; color: var(--muted); cursor: pointer; box-shadow: 0 3px 0 #d8cbac;
}
.goalrow { display: flex; align-items: center; gap: 10px; margin: 12px 0 10px; font-weight: 800; font-size: 14px; color: var(--muted); }
.goalrow b { color: var(--ink); min-width: 3em; text-align: left; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: #fff; border-radius: 14px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat small { color: var(--muted); font-weight: 700; font-size: 12px; }
.stat b { font-size: 19px; color: var(--cobalt); }
.stars { color: var(--ochre); letter-spacing: 1px; font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 8px; }
.card {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 14px; background: #fff;
  border: 2px solid transparent; min-width: 0;
}
.card:hover { border-color: rgba(31, 163, 168, .35); }
.card.owned { background: rgba(255, 255, 255, .55); }
.card.locked { opacity: .62; }
.card.locked img { filter: grayscale(.8); }
.card img { width: 46px; height: 46px; image-rendering: pixelated; flex: 0 0 auto; }
.card .txt { flex: 1; min-width: 0; }
.card .txt b { display: block; font-size: 15px; }
.card .txt small { color: var(--muted); font-size: 12.5px; line-height: 1.6; display: block; }
.card .btn { white-space: nowrap; }
.card .btn .coin { width: 16px; height: 16px; }
.card.ready { border-color: rgba(227, 180, 72, .95); box-shadow: 0 0 0 3px rgba(227, 180, 72, .28); animation: ready 1.4s ease-in-out infinite; }
@keyframes ready { 50% { box-shadow: 0 0 0 6px rgba(227, 180, 72, .16); } }
.btn.press { transform: translateY(3px) scale(.95); box-shadow: 0 1px 0 var(--ochre2), 0 0 0 6px rgba(227, 180, 72, .5); filter: brightness(1.08); }

textarea {
  width: 100%; font: 13px/1.5 ui-monospace, Consolas, monospace; padding: 8px; border-radius: 12px;
  border: 2px solid var(--tq); background: #fff; color: var(--ink); resize: none; word-break: break-all;
  -webkit-user-select: text; user-select: text; touch-action: auto;
}

/* goal */
.goal { text-align: center; z-index: 1; }
.bigcoin {
  width: 84px; height: 84px; margin: 8px auto 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff4bd 0 12%, #f0c548 40%, #b8861e 100%);
  box-shadow: inset 0 0 0 4px #a8761a, inset 0 0 0 8px rgba(255, 236, 160, .6), 0 8px 20px rgba(120, 80, 0, .35);
  animation: spin 2.4s linear infinite;
}
@keyframes spin { from { transform: rotateY(0); } to { transform: rotateY(360deg); } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }

#nogl {
  position: fixed; z-index: 40; left: 50%; bottom: 16px; transform: translateX(-50%); background: #a92a31;
  color: #fff; padding: 8px 14px; border-radius: 10px; max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- round 5 ---------- */
/* MrMpAi's speech bubble, placed over his head every frame */
#npcbub {
  position: fixed; left: 0; top: 0; z-index: 3; max-width: min(320px, calc(100vw - 32px)); width: max-content;
  background: #fffaf0; color: var(--ink); border: 3px solid var(--ink); border-radius: 18px; padding: 8px 14px 9px;
  font-weight: 800; font-size: 15px; line-height: 1.75; box-shadow: 0 8px 20px rgba(0, 0, 0, .22);
  pointer-events: none; will-change: transform;
}
#npcbub::after {
  content: ''; position: absolute; bottom: -12px; left: 50%; margin-left: -9px; width: 0; height: 0;
  border: 9px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
#npcbub p { margin: 0; }
#npcbub small { display: block; margin-top: 4px; color: var(--tq2); font-weight: 900; font-size: 14px; }
#npcbub a { pointer-events: auto; margin-top: 6px; display: flex; font-size: 14px; }
#npcbub.pop { animation: bub .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bub { from { opacity: 0; } to { opacity: 1; } }
body.touch #npcbub a { padding: 10px 12px; }

/* riddle note */
.note-panel #riddle {
  background: #f3e6c4; border-radius: 12px; padding: 12px 16px; box-shadow: inset 0 0 0 2px rgba(120, 80, 30, .25);
  font-weight: 800; color: #4a3218;
}
.note-panel #riddle p { margin: 2px 0; line-height: 2; }

/* treasure */
.chest {
  width: 96px; height: 70px; margin: 6px auto 0; border-radius: 10px 10px 6px 6px; position: relative;
  background: linear-gradient(180deg, #6a4426 0 38%, #2a170c 38% 42%, #5e3a20 42% 100%);
  box-shadow: inset 12px 0 0 -6px #e3b448, inset -12px 0 0 -6px #e3b448, 0 10px 24px rgba(120, 80, 0, .35);
  animation: chest 1.6s ease-in-out infinite;
}
.chest::after {
  content: ''; position: absolute; left: 50%; top: 24px; width: 18px; height: 20px; margin-left: -9px;
  background: #e3b448; border-radius: 3px; box-shadow: inset 0 -6px 0 #b88a22;
}
@keyframes chest { 50% { transform: translateY(-4px) rotate(-1deg); } }
#tr-codebox { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
#tr-code {
  font: 900 26px/1.2 ui-monospace, Consolas, monospace; letter-spacing: 2px; color: var(--cobalt);
  background: #fff; border: 2px dashed var(--tq); border-radius: 12px; padding: 8px 14px;
  -webkit-user-select: text; user-select: text;
}
#tr-step:empty { display: none; }

/* small screens */
@media (max-width: 560px) {
  #topbar { gap: 6px; }
  .chip { padding: 5px 10px; }
  .coinchip #coin-n { font-size: 19px; }
  .bar { width: 72px; }
  .ibtn { height: 40px; min-width: 40px; font-size: 14px; padding: 0 10px; }
  .ibtn.round { width: 40px; }
  .ibtn#b-shop span { display: none; }
  .ibtn#b-shop { width: 40px; padding: 0; }
  .chip.lvl { display: none; }
  .slot { width: 48px; height: 48px; }
  .slot img { width: 36px; height: 36px; }
  #hint { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); font-size: 14px; }
  .stat b { font-size: 16px; }
}
@media (max-height: 520px) {
  .hero { margin-top: 0; }
  h1.title { font-size: clamp(44px, 14vh, 90px); }
  .tag { margin-top: 4px; }
}

/* the minimap (top left, under the bar) and the big map */
#minimap { position: absolute; left: max(12px, env(safe-area-inset-left, 0px)); top: calc(64px + env(safe-area-inset-top, 0px));
  width: 132px; height: 132px; border-radius: 50%; pointer-events: auto; cursor: pointer; box-shadow: var(--lift); background: rgba(11,15,20,.35); }
#minimap canvas { width: 100%; height: 100%; display: block; border-radius: 50%; }
.mappanel { max-width: min(92vw, 560px); }
#bigmap { width: 100%; height: auto; aspect-ratio: 1; border-radius: 14px; display: block; image-rendering: pixelated; }
.maplegend { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; margin: 10px 0; }
.maplegend .lg { display: inline-block; width: 16px; height: 16px; border-radius: 50%; }
.maplegend .lg.m { background: #0b0f14; border: 2px solid #00e5ce; color: #00e5ce; font-size: 10px; font-weight: 900; text-align: center; line-height: 13px; }
.maplegend .lg.s { background: #ffd166; }
.maplegend .lg.r { background: #b48cff; border: 1.5px solid #2a1a40; border-radius: 3px; }
.maplegend .lg.p { background: #fff; border: 2px solid #0b0f14; }
@media (max-width: 560px) { #minimap { width: 100px; height: 100px; top: calc(58px + env(safe-area-inset-top, 0px)); } }

#bigmap { width: min(100%, 52vh); margin: 0 auto; }
.mappanel .menu { margin-top: 6px; }


/* phone: the tutorial card covers the top-left corner, so the minimap waits until the card is gone */
@media (max-width: 560px) { #hud:has(#coach:not([hidden])) #minimap { visibility: hidden; } }


/* the treasure tracker (under the coin bar, right side) and the clue card */
#quest { position: absolute; right: max(12px, env(safe-area-inset-right, 0px)); top: calc(62px + env(safe-area-inset-top, 0px));
  width: min(330px, calc(100vw - 160px)); pointer-events: auto; cursor: pointer; background: rgba(11,15,20,.78); color: #e8f6f4;
  border: 1.5px solid #00e5ce; border-radius: 14px; padding: 8px 12px; box-shadow: var(--lift); font-size: 14px; line-height: 1.6; }
#quest b { display: block; color: #00e5ce; font-size: 13px; }
#quest p { margin: 2px 0 0; }
#quest small { display: block; color: #ffd166; font-weight: 800; }
#quest small:empty { display: none; }
#quest.closed p, #quest.closed small { display: none; }
#quest.tick { animation: qtick .6s ease; }
@keyframes qtick { 0% { transform: scale(1); } 40% { transform: scale(1.05); box-shadow: 0 0 0 4px rgba(0,229,206,.35); } 100% { transform: scale(1); } }
#cluecard { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); width: min(460px, calc(100vw - 32px)); pointer-events: auto;
  background: #f6eedc; color: #3a2a14; border-radius: 16px; padding: 14px 18px; box-shadow: 0 18px 50px rgba(0,0,0,.45); border-top: 6px solid #00e5ce; }
#cluecard b { display: block; font-size: 18px; margin-bottom: 6px; }
#cluecard p { margin: 0; font-size: 16px; line-height: 1.8; }
#cluecard small { display: block; margin-top: 8px; color: #8a7a5a; }
@media (max-width: 560px) { #quest { width: calc(100vw - 132px); font-size: 13px; top: calc(56px + env(safe-area-inset-top, 0px)); }
  #hud:has(#coach:not([hidden])) #quest { visibility: hidden; } }
