:root {
  --night: #141d4a;
  --panel: rgba(16, 22, 62, 0.78);
  --panel-solid: #1b2560;
  --sun: #ffd23f;
  --coral: #ff6b4a;
  --mint: #6ee7a8;
  --sky: #7cc8ff;
  --ui: clamp(14px, min(2.4vh, 3.4vw), 26px);
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: #fff; }
body {
  background:
    radial-gradient(ellipse at 50% 120%, #3a5bbf 0%, transparent 60%),
    linear-gradient(#070b24, #141d4a 60%, #24357e);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; touch-action: manipulation; color: inherit; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #eef1ff;
  border: 1px solid #c3c9ee;
  color: #1b2560;
}

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; }
#scene, #scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

.label {
  position: absolute; left: 0; top: 0;
  white-space: nowrap;
  font-weight: 700;
  pointer-events: none;
  will-change: transform;
}
.label.country {
  font-size: clamp(11px, 1.7vh, 17px);
  color: rgba(30, 30, 50, 0.85);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9), 0 0 6px rgba(255, 255, 255, 0.6);
  letter-spacing: 0.02em;
}
.label.continent {
  font-size: clamp(16px, 3.2vh, 34px);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 0 6px rgba(20, 30, 80, 0.75), 0 2px 0 rgba(20, 30, 80, 0.5);
}
.label.sea {
  font-size: clamp(12px, 2vh, 20px);
  font-style: italic;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(225, 245, 255, 0.85);
  text-shadow: 0 0 4px rgba(10, 50, 100, 0.8);
}
.label.line {
  font-size: clamp(10px, 1.5vh, 14px);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 0 3px rgba(10, 50, 100, 0.8);
}
.label.pin {
  font-size: clamp(15px, 2.6vh, 28px);
  font-weight: 800;
  background: var(--coral);
  color: #fff;
  padding: 0.1em 0.6em 0;
  border-radius: 1em;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  margin-top: -2.6em;
  z-index: 2;
}

/* ---------- Top bar ---------- */
#hud, #minimap { transition: opacity 0.3s; }
body.menu #hud #stats, body.menu #minimap { opacity: 0; pointer-events: none; }
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(1.6vh, env(safe-area-inset-top)) 1.6vw 0;
  z-index: 10;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#stats { display: flex; flex-direction: column; gap: 0.8vh; }
#fuel-box, #score-box {
  display: flex; align-items: center; gap: 0.6em;
  background: var(--panel);
  border-radius: 999px;
  padding: 0.3em 0.9em 0.3em 0.6em;
  font-size: var(--ui);
  font-weight: 800;
  backdrop-filter: blur(4px);
}
#fuel {
  width: clamp(110px, 22vw, 300px); height: 0.8em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
#fuel-fill {
  height: 100%; width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9f43, var(--sun));
  transition: width 0.2s linear;
}
#fuel-box.low #fuel-fill { background: var(--coral); animation: blink 0.6s steps(2) infinite; }
#fuel-box.gain #fuel-fill { background: var(--mint); }
@keyframes blink { 50% { opacity: 0.35; } }
#score-box { align-self: flex-start; font-size: calc(var(--ui) * 1.25); line-height: 1.2; }
#score { color: var(--sun); font-variant-numeric: tabular-nums; }
#streak { color: var(--mint); font-size: 0.8em; }

#toolbar { display: flex; gap: 0.6vh; }
#toolbar button {
  width: clamp(40px, min(6vh, 7.5vw), 60px); height: clamp(40px, min(6vh, 7.5vw), 60px);
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: clamp(20px, min(3vh, 3.75vw), 30px);
  cursor: pointer;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(16, 22, 62, 0.95); }

/* ---------- The parcel's ticket ---------- */
#ticket {
  position: fixed; left: 50%; top: max(1.6vh, env(safe-area-inset-top));
  transform: translateX(-50%) rotate(-1.5deg);
  z-index: 9;
  min-width: min(380px, 50vw);
  max-width: min(640px, 52vw);
  text-align: center;
  background: #fff8e8;
  color: #1b2560;
  border-radius: 1.2vh;
  padding: 0.5em 1.2em 0.6em;
  font-size: var(--ui);
  box-shadow: 0 0.6vh 0 #c99a4b, 0 1.4vh 3vh rgba(0, 0, 0, 0.35);
  border: 0.35vh dashed #d9b36a;
}
#ticket.fresh { animation: stamp 0.5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes stamp {
  from { transform: translateX(-50%) rotate(-8deg) scale(1.6); opacity: 0; }
}
#ticket-top { display: flex; justify-content: space-between; gap: 1em; font-weight: 700; font-size: 0.75em; color: #8a6a2e; text-transform: uppercase; letter-spacing: 0.06em; }
#dest { font-weight: 800; font-size: 2em; line-height: 1.05; margin-top: 0.1em; }
#dest-note { font-size: 0.9em; color: #4a5488; line-height: 1.2; }
#compass-note { margin-top: 0.3em; font-size: 0.8em; font-weight: 700; color: #b06b00; }

#where {
  position: fixed; left: 50%; bottom: calc(14vh + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 8;
  display: flex; align-items: center; gap: 0.5em;
  font-size: var(--ui);
  background: rgba(16, 22, 62, 0.7);
  backdrop-filter: blur(4px);
  padding: 0.25em 1em 0.25em 0.3em;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}
#over { font-weight: 800; line-height: 1.15; }
#heading { font-size: 0.75em; opacity: 0.85; line-height: 1.1; }
#dial {
  width: 2.3em; height: 2.3em; flex: none;
  border-radius: 50%;
  background: #fff8e8;
  box-shadow: inset 0 0 0 2px #d9b36a;
  position: relative;
}
#needle { position: absolute; inset: 0; }
#needle::before {
  content: ''; position: absolute; left: 50%; top: 8%;
  border: 0.32em solid transparent; border-bottom: 0.8em solid #e5402f;
  border-top-width: 0;
  transform: translateX(-50%);
}
#needle::after {
  content: ''; position: absolute; left: 50%; bottom: 8%;
  border: 0.32em solid transparent; border-top: 0.8em solid #8a93c4;
  border-bottom-width: 0;
  transform: translateX(-50%);
}
#needle span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 0.55em; font-weight: 800; color: #1b2560;
}

/* ---------- Result toast ---------- */
#toast {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 12;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-radius: 2.4vh;
  padding: 1.2vh 3vh 1.6vh;
  max-width: min(720px, 92vw);
  pointer-events: none;
  font-size: var(--ui);
  animation: pop 0.45s cubic-bezier(.2, 1.5, .4, 1);
}
#toast.reveal { top: auto; bottom: calc(15vh + env(safe-area-inset-bottom)); transform: translateX(-50%); animation: rise 0.4s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } }
@keyframes rise { from { transform: translate(-50%, 30%); opacity: 0; } }
#toast-stars { font-size: 2.6em; line-height: 1; letter-spacing: 0.08em; color: var(--sun); text-shadow: 0 3px 0 #b27b00; }
#toast-stars .dim { color: rgba(255, 255, 255, 0.25); text-shadow: none; }
#toast-title { font-weight: 800; font-size: 2em; line-height: 1.1; }
#toast-line { font-size: 1.05em; line-height: 1.3; opacity: 0.95; }
#toast-points { margin-top: 0.3em; font-weight: 800; color: var(--mint); }

#pickup {
  position: fixed; left: 50%; top: 38%;
  transform: translateX(-50%);
  z-index: 11;
  font-weight: 800;
  font-size: calc(var(--ui) * 1.3);
  color: var(--mint);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  pointer-events: none;
  animation: float-up 1.2s ease-out forwards;
}
@keyframes float-up { to { transform: translate(-50%, -8vh); opacity: 0; } }

/* ---------- Minimap ---------- */
#minimap {
  position: fixed;
  right: 1.6vw; top: calc(max(1.6vh, env(safe-area-inset-top)) + clamp(48px, 7.5vh, 72px));
  width: clamp(170px, 24vw, 320px);
  aspect-ratio: 2 / 1;
  border-radius: 1.2vh;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 1vh 2vh rgba(0, 0, 0, 0.35);
  z-index: 9;
  cursor: zoom-in;
  background: #2f8fd0;
}
#minimap.big { width: min(64vw, 720px); cursor: zoom-out; }

/* ---------- Flying controls ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 1.6vw max(1.8vh, env(safe-area-inset-bottom));
  z-index: 10;
  pointer-events: none;
}
#controls .pad { display: flex; gap: 1.2vh; align-items: flex-end; pointer-events: auto; }
#controls .pad.middle { gap: 0.8vh; }
#controls button {
  width: clamp(64px, min(12vh, 17vw), 120px); height: clamp(64px, min(12vh, 17vw), 120px);
  border-radius: 50%;
  border: none;
  background: var(--panel);
  backdrop-filter: blur(4px);
  font-size: clamp(24px, min(5vh, 7vw), 48px);
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 -0.6vh 0 rgba(0, 0, 0, 0.25);
  touch-action: none;
}
#controls .pad.steer { display: flex; gap: 1.2vh; }
#controls button.small {
  width: clamp(44px, min(7vh, 11vw), 70px); height: clamp(44px, min(7vh, 11vw), 70px);
  font-size: clamp(18px, min(3.4vh, 5vw), 32px);
}
#controls button.held, #controls button:active { background: rgba(124, 200, 255, 0.55); }
#controls #compass.on { background: var(--sun); color: #1b2560; }
#controls #drop {
  width: clamp(88px, min(17vh, 24vw), 170px); height: clamp(88px, min(17vh, 24vw), 170px);
  background: var(--coral);
  font-size: clamp(22px, min(4.6vh, 6.2vw), 46px);
  box-shadow: inset 0 -0.9vh 0 rgba(0, 0, 0, 0.25), 0 0.8vh 2vh rgba(0, 0, 0, 0.35);
}
#controls #drop:disabled { opacity: 0.45; cursor: default; }
#controls #drop.ready { animation: throb 1.2s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.05); } }

/* ---------- Menu and end panels ---------- */
#setup, #end {
  position: fixed; inset: 0;
  z-index: 20;
  display: grid;
  padding: 2vh 2vw;
  background: rgba(7, 11, 36, 0.55);
  overflow: auto;
}
.panel {
  margin: auto; /* centred, but scrolls from the top when taller than the screen */
  width: min(780px, 100%);
  background: var(--panel-solid);
  border-radius: 3vh;
  padding: 2.4vh clamp(16px, 3vw, 40px) 2.8vh;
  box-shadow: 0 2vh 6vh rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.08);
}
.logo {
  margin: 0;
  font-size: clamp(36px, 7vh, 72px);
  font-weight: 800;
  line-height: 1;
  color: var(--sun);
  text-shadow: 0 0.5vh 0 #b27b00;
}
.logo span { display: inline-block; transform: rotate(-12deg); }
.tagline { margin: 0.8vh 0 0; font-size: clamp(15px, 2.3vh, 22px); line-height: 1.35; opacity: 0.92; }
.kicker { margin: 0; font-weight: 800; color: var(--sky); font-size: clamp(16px, 2.6vh, 26px); }
.panel h2 { margin: 2vh 0 0.8vh; font-size: clamp(14px, 2.1vh, 20px); text-transform: uppercase; letter-spacing: 0.08em; color: var(--sky); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.8vh; }
.cards.wide { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cards button {
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 1.4vh;
  padding: 0.7vh 1vh 0.5vh;
  cursor: pointer;
  font-weight: 700;
  font-size: clamp(14px, 2.1vh, 20px);
  line-height: 1.2;
}
.cards button small { display: block; font-weight: 400; opacity: 0.8; font-size: 0.8em; }
.cards button:hover { background: rgba(255, 255, 255, 0.12); }
.cards button[aria-pressed="true"] { background: var(--sun); color: #1b2560; border-color: var(--sun); }
.buttons { display: flex; gap: 1vh; margin-top: 2.4vh; flex-wrap: wrap; }
.buttons button {
  border: none;
  border-radius: 1.6vh;
  padding: 0.8vh 2.4vh 0.5vh;
  font-weight: 800;
  font-size: clamp(18px, 3vh, 30px);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.12);
}
.buttons button.primary { background: var(--coral); box-shadow: inset 0 -0.6vh 0 rgba(0, 0, 0, 0.2); }
.buttons button:disabled { opacity: 0.6; cursor: wait; }
#best-line { margin: 1vh 0 0; opacity: 0.85; min-height: 1.2em; }
#offline-status { margin: 0.6vh 0 0; font-size: 0.85em; opacity: 0.7; }
.help { margin-top: 1.6vh; font-size: clamp(14px, 2vh, 18px); }
.help summary { cursor: pointer; font-weight: 700; color: var(--sky); }
.help ul { margin: 0.8vh 0 0; padding-left: 1.2em; line-height: 1.45; }

#end h1 { margin: 0.2vh 0 0; font-size: clamp(40px, 8vh, 80px); line-height: 1; color: var(--sun); }
#end-list {
  list-style: none; margin: 1.6vh 0 0; padding: 0;
  max-height: 40vh; overflow: auto;
  display: grid; gap: 0.4vh;
}
#end-list li {
  display: flex; gap: 0.8em; align-items: baseline;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 1vh;
  padding: 0.4vh 1vh 0.2vh;
  font-size: clamp(14px, 2.1vh, 20px);
}
#end-list .s { color: var(--sun); letter-spacing: 0.05em; flex: none; }
#end-list .s .dim { color: rgba(255, 255, 255, 0.25); }
#end-list b { flex: none; }
#end-list span.d { opacity: 0.75; }

@media (max-width: 700px) {
  #ticket { max-width: 58vw; min-width: 0; left: 50%; }
  #minimap { top: auto; bottom: calc(max(1.8vh, env(safe-area-inset-bottom)) + clamp(96px, min(19vh, 26vw), 180px)); right: 1.6vw; width: 34vw; }
  #controls .pad.middle { flex-direction: column; }
}
@media (max-width: 700px) and (orientation: portrait) {
  #hud { flex-direction: column; gap: 0.8vh; }
  #toolbar { position: fixed; right: 1.6vw; top: max(1.6vh, env(safe-area-inset-top)); flex-direction: column; }
  #ticket { top: calc(max(1.6vh, env(safe-area-inset-top)) + 11vh); max-width: 80vw; }
  #minimap { top: calc(max(1.6vh, env(safe-area-inset-top)) + 27vh); bottom: auto; right: 1.6vw; left: auto; width: 36vw; }
  #minimap.big { width: 92vw; }
  /* Zoom and compass in a column above the Drop button */
  #controls .pad.middle {
    position: absolute; flex-direction: column;
    right: 1.6vw; bottom: calc(max(1.8vh, env(safe-area-inset-bottom)) + clamp(88px, min(17vh, 24vw), 170px) + 1.5vh);
  }
  #where { bottom: calc(max(1.8vh, env(safe-area-inset-bottom)) + clamp(64px, min(12vh, 17vw), 120px) + 3vh); }
  #toast.reveal { bottom: calc(max(1.8vh, env(safe-area-inset-bottom)) + clamp(64px, min(12vh, 17vw), 120px) + 3vh); }
}
@media (prefers-reduced-motion: reduce) {
  #ticket.fresh, #toast, #controls #drop.ready { animation: none; }
}
