:root {
  --gold: #ffd97a;
  --teal: #35c2a9;
  --ink: #f4f7f2;
  --ink-dim: #c2cfc4;
  --panel: rgba(10, 26, 24, 0.6);
  --panel-line: rgba(255, 217, 122, 0.3);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #07131a;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font-family: inherit; border: none; cursor: pointer; user-select: none; -webkit-user-select: none; }

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

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud[hidden] { display: none; }
#hud button, #joyZone { pointer-events: auto; }

#topbar {
  position: absolute;
  top: calc(var(--safe-t) + 12px);
  left: calc(var(--safe-l) + 14px);
  right: calc(var(--safe-r) + 14px);
  display: flex; justify-content: space-between; align-items: center;
}

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 15px; font-weight: 800;
}
.chip.subtle { border-color: rgba(255,255,255,0.1); color: var(--ink-dim); font-weight: 700; }

#compass {
  position: absolute;
  top: calc(var(--safe-t) + 64px);
  left: 50%;
  transform: translateX(-50%);
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
}
#compassArrow {
  font-size: 20px;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 217, 122, 0.6);
  transition: transform 0.1s linear;
}
#compass.near {
  animation: compass-hot 0.7s ease-in-out infinite;
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(255, 217, 122, 0.45);
}
@keyframes compass-hot { 0%, 100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.12); } }

#hint {
  position: absolute;
  bottom: calc(var(--safe-b) + 130px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px; font-weight: 700;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  padding: 8px 16px;
  white-space: nowrap;
  animation: hint-in 0.3s ease;
}
#hint[hidden] { display: none; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

#joyZone {
  position: absolute;
  left: calc(var(--safe-l) + 22px);
  bottom: calc(var(--safe-b) + 24px);
  width: 116px; height: 116px;
  border-radius: 50%;
  background: rgba(10, 26, 24, 0.42);
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}
#joyStick {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.5), rgba(210,225,215,0.25));
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

#jumpBtn {
  position: absolute;
  right: calc(var(--safe-r) + 24px);
  bottom: calc(var(--safe-b) + 34px);
  width: 84px; height: 84px;
  border-radius: 50%;
  background: rgba(10, 26, 24, 0.5);
  border: 1.5px solid var(--panel-line);
  color: var(--gold);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s ease;
  touch-action: none;
}
#jumpBtn:active { transform: scale(0.92); }

.icon-btn {
  position: absolute;
  right: calc(var(--safe-r) + 14px);
  top: calc(var(--safe-t) + 64px);
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--ink);
  font-size: 17px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ---------- overlays ---------- */

#menu, #win {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 20px calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
  background: radial-gradient(90% 70% at 50% 30%, rgba(6, 16, 20, 0.1), rgba(4, 10, 14, 0.72));
}
#menu[hidden], #win[hidden] { display: none; }

.menu-card {
  width: min(92vw, 390px);
  background: rgba(9, 22, 26, 0.78);
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 30px 26px 24px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.menu-badge { filter: drop-shadow(0 6px 18px rgba(53, 194, 169, 0.35)); }

.menu-title {
  font-size: 46px; font-weight: 900;
  margin-top: 10px;
  background: linear-gradient(165deg, #fdf3d0 5%, var(--gold) 45%, #d9a13f 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.menu-sub { font-size: 15.5px; color: var(--ink-dim); margin-top: 6px; font-weight: 700; }

.primary {
  margin-top: 20px;
  width: 100%;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(160deg, #ffe9ae, var(--gold) 55%, #cfa04a);
  color: #23180a;
  font-size: 20px; font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 28px rgba(255, 217, 122, 0.3);
  transition: transform 0.12s ease;
}
.primary:active { transform: scale(0.97); }

.menu-hints {
  margin-top: 18px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; color: var(--ink-dim); font-weight: 700;
}

/* ---------- loader ---------- */

#loader {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background:
    linear-gradient(180deg, #0e2f42 0%, #14514f 55%, #0a2a33 100%);
  transition: opacity 0.45s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 13px; }
.loader-badge { animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.loader-title {
  font-size: 40px; font-weight: 900;
  background: linear-gradient(165deg, #fdf3d0 5%, var(--gold) 45%, #d9a13f 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.loader-bar {
  width: min(60vw, 240px); height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}
.loader-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 0.25s ease;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { 0% { filter: brightness(0.92); } 50% { filter: brightness(1.2); } 100% { filter: brightness(0.92); } }
.loader-sub { font-size: 13.5px; color: #cfe3d6; font-weight: 700; }

@media (max-width: 700px) {
  .menu-title { font-size: 40px; }
}
