* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #05060f;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  font-family: 'Tahoma', 'Sarabun', sans-serif;
}
@supports (height: 100dvh) {
  html, body { height: 100dvh; } /* fill the real screen behind mobile browser chrome */
}
#gameCanvas {
  width: 100%; height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 40%, #10122b 0%, #04040c 70%);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  transition: opacity 1.2s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.load-inner { text-align: center; }
.load-title {
  font-size: clamp(34px, 8vw, 64px);
  font-weight: bold;
  color: #ffd98a;
  text-shadow: 0 0 18px rgba(255, 170, 60, .8), 0 0 60px rgba(255, 120, 30, .4);
  animation: flick 3.1s infinite;
}
.load-sub {
  margin-top: 6px;
  letter-spacing: .5em;
  font-size: clamp(10px, 2.4vw, 14px);
  color: #7f86b8;
}
.load-bar {
  width: min(320px, 70vw); height: 4px;
  margin: 28px auto 12px;
  background: #1b1e38;
  border-radius: 2px; overflow: hidden;
}
#loadFill {
  width: 0%; height: 100%;
  background: linear-gradient(90deg, #ff9d3c, #ffd98a);
  box-shadow: 0 0 12px rgba(255,170,60,.9);
  transition: width .3s ease;
}
.load-hint { color: #5b6191; font-size: 13px; }
@keyframes flick {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: .35; }
  94% { opacity: 1; }
  96% { opacity: .5; }
  97% { opacity: 1; }
}

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; pointer-events: none; z-index: 10; }
#parkName {
  position: absolute; top: 12px; left: 16px;
  color: rgba(255, 217, 138, .85);
  font-weight: bold; font-size: 18px;
  text-shadow: 0 0 10px rgba(255,150,40,.6);
}
.hint {
  position: absolute; top: 14px; right: 16px;
  color: rgba(160,168,210,.75); font-size: 12px;
  text-shadow: 0 1px 3px #000;
}

/* ---------- Online badge ---------- */
#online {
  position: absolute; top: 38px; left: 16px;
  color: rgba(180,220,190,.9); font-size: 13px;
  text-shadow: 0 1px 3px #000;
}

/* ---------- Monster event HUD ---------- */
#monster-alert {
  position: fixed; left: 50%; top: 74px;
  transform: translate(-50%, -18px);
  z-index: 55; pointer-events: none;
  display: flex; align-items: center; gap: 13px;
  min-width: min(430px, 88vw); padding: 13px 20px;
  border: 1px solid rgba(255, 65, 45, .75);
  border-radius: 9px;
  background: rgba(45, 4, 4, .9);
  color: #ffe3d5;
  box-shadow: 0 0 28px rgba(255, 25, 10, .35);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
}
#monster-alert.show { opacity: 1; transform: translate(-50%, 0); }
#monster-alert strong, #monster-alert span { display: block; }
#monster-alert strong { color: #ff765f; font-size: 18px; }
#monster-alert span { margin-top: 2px; color: #f3b6a8; font-size: 13px; }
.alert-siren { font-size: 30px; animation: alarmPulse .55s infinite alternate; }
#monster-status {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 35; pointer-events: none;
  display: none; padding: 7px 13px;
  border-radius: 16px;
  background: rgba(35, 4, 5, .76);
  color: #ff9b87; font-size: 12px; font-weight: bold;
  text-shadow: 0 1px 3px #000;
}
#monster-status.active { display: block; }
#death-screen {
  position: fixed; inset: 0; z-index: 120;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
  background: radial-gradient(circle, rgba(80, 0, 0, .45), rgba(0, 0, 0, .96));
  opacity: 0; transition: opacity .18s ease;
}
#death-screen.show { opacity: 1; }
.death-title { color: #d51f18; font-size: clamp(38px, 9vw, 76px); font-weight: bold; text-shadow: 0 0 25px #600; }
.death-sub { margin-top: 10px; color: #cab6b0; font-size: 15px; }
@keyframes alarmPulse { from { opacity: .45; transform: scale(.92); } to { opacity: 1; transform: scale(1.1); } }
body.is-mobile #monster-alert { top: 102px; min-width: 78vw; padding: 10px 14px; }
body.is-mobile #monster-alert strong { font-size: 15px; }
body.is-mobile #monster-alert span { font-size: 11px; }

/* ---------- Audio control ---------- */
#btn-audio {
  position: fixed; left: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 35;
  display: flex; align-items: center; gap: 7px;
  min-height: 42px; padding: 8px 13px;
  border: 1px solid rgba(255, 217, 138, .42);
  border-radius: 22px;
  background: rgba(9, 11, 27, .76);
  color: #ffe0a3;
  font: 700 13px 'Tahoma', 'Sarabun', sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 16px rgba(0, 0, 0, .48), inset 0 0 12px rgba(255, 170, 60, .05);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
  transition: background .2s ease, border-color .2s ease, opacity .2s ease;
}
#btn-audio:hover { background: rgba(35, 29, 28, .88); border-color: rgba(255, 217, 138, .72); }
#btn-audio:focus-visible { outline: 2px solid #ffd98a; outline-offset: 3px; }
#btn-audio.muted { color: #9da2bd; border-color: rgba(157, 162, 189, .3); }
.audio-icon { width: 20px; font-size: 17px; line-height: 1; }
body.is-mobile #btn-audio {
  left: auto; right: 14px; bottom: max(14px, env(safe-area-inset-bottom));
  width: 48px; min-height: 48px; padding: 0;
  justify-content: center;
}
body.is-mobile .audio-label { display: none; }

#btn-quality {
  position: fixed; right: 72px; bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 35;
  display: none; align-items: center; gap: 6px;
  min-height: 48px; padding: 0 14px;
  border: 1px solid rgba(118, 220, 255, .4);
  border-radius: 24px;
  background: rgba(9, 18, 29, .78);
  color: #bdeeff;
  font: 700 12px 'Tahoma', 'Sarabun', sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 16px rgba(0, 0, 0, .48);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
}
body.is-mobile #btn-quality { display: flex; }
#btn-quality.high {
  color: #ffe0a3;
  border-color: rgba(255, 217, 138, .42);
  background: rgba(29, 21, 9, .78);
}
#btn-quality:focus-visible { outline: 2px solid #bdeeff; outline-offset: 3px; }
@media (max-width: 520px) {
  #btn-quality { width: 48px; padding: 0; justify-content: center; }
  .quality-label { display: none; }
}

/* ---------- Join dialog ---------- */
#join {
  position: fixed; inset: 0;
  background: rgba(3, 4, 12, .78);
  display: none;
  align-items: center; justify-content: center;
  z-index: 90;
}
.join-card {
  width: min(340px, 86vw);
  padding: 28px 26px;
  border-radius: 14px;
  background: linear-gradient(180deg, #14162e, #0b0c1c);
  border: 1px solid rgba(255, 200, 120, .3);
  box-shadow: 0 8px 40px rgba(0,0,0,.7), 0 0 30px rgba(255,150,40,.08);
  text-align: center;
}
.join-title {
  font-size: 26px; font-weight: bold;
  color: #ffd98a;
  text-shadow: 0 0 14px rgba(255,170,60,.6);
}
.join-sub {
  margin: 8px 0 18px;
  font-size: 13px; color: #8a90bb;
}
#join-name {
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid rgba(160,170,230,.35);
  background: rgba(10, 12, 26, .9);
  color: #e8ecff; font-size: 16px;
  text-align: center;
  outline: none;
}
#join-name:focus { border-color: rgba(255,200,120,.6); }
#join-btn {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(180deg, #c96a1e, #a04e10);
  color: #fff2d8; font-size: 17px; font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#join-btn:active { filter: brightness(1.2); }

/* ---------- Fullscreen prompt ---------- */
#btn-fs {
  position: fixed; top: 64px; left: 50%;
  transform: translateX(-50%);
  z-index: 30; display: none;
  padding: 10px 22px;
  border-radius: 24px;
  border: 2px solid rgba(255,200,120,.6);
  background: rgba(40,28,10,.75);
  color: #ffd98a; font-size: 15px; font-weight: bold;
  box-shadow: 0 2px 14px rgba(0,0,0,.6);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Mobile joysticks (left = move, right = turn) ---------- */
#joystick-zone {
  position: fixed; left: 0; bottom: 0;
  width: 45%; height: 55%;
  z-index: 20; display: none;
  touch-action: none;
}
#joystick-zone-right {
  position: fixed; right: 0; bottom: 0;
  width: 45%; height: 55%;
  z-index: 20; display: none;
  touch-action: none;
}
#joystick-base, #joystick-base-r {
  position: absolute;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(140,150,220,.10);
  border: 2px solid rgba(160,170,230,.25);
  display: none;
}
#joystick-knob, #joystick-knob-r {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(190,200,255,.30);
  border: 2px solid rgba(200,210,255,.5);
}
#joystick-knob-r { background: rgba(255,205,140,.30); border-color: rgba(255,215,160,.5); }
#mobile-buttons {
  position: fixed; right: 14px; top: 44px;
  z-index: 25; display: none;
  flex-direction: column; gap: 12px;
}
.mbtn {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 2px solid rgba(200,210,255,.6);
  background: rgba(24,28,58,.6);
  color: #e6e9ff; font-size: 24px;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
}
.mbtn:active, .mbtn.active { background: rgba(255,170,60,.45); border-color: rgba(255,200,120,.7); }
body.is-mobile #joystick-zone, body.is-mobile #joystick-zone-right,
body.is-mobile #mobile-buttons { display: flex; }
body.is-mobile #hint-pc { display: none; }
body.is-mobile #hint-mobile { display: block !important; }
