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

  /* 100dvh = dynamic viewport height — กัน Android Chrome address bar ดันปุ่มล่างตกขอบจอ
     (100vh รวมความสูง address bar ที่ซ่อน/แสดง ทำให้ bottom:0 หลุดใต้พื้นที่เห็นจริง)
     fallback 100vh ก่อนสำหรับ browser เก่าที่ยังไม่รองรับ dvh */
  #app { position: relative; width: 100vw; height: 100vh; height: 100dvh; }

  #camera-feed {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    pointer-events: none;
  }

  #three-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
  }

  #ui {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
  }

  /* ===== Top bar (nickname / score / timer) ===== */
  #topbar {
    position: absolute;
    top: 0; 
    left: 0; 
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* บวก safe-area บน กัน notch/status bar บังชื่อ player */
    padding: 3vw;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    color: #fff;
  }
  #topbar .player { display: flex; align-items: center; gap: 8px; font-weight: 600; }
  #topbar .player .avatar {
    width: 24px; height: 24px; border-radius: 50%;
    background: #fff; color: #000;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
  }
  #topbar .stats { display: flex; gap: 14px; align-items: center; }
  #topbar .pill {
      border-radius: 20px;
      font-variant-numeric: tabular-nums;
      display: flex; 
      align-items: center; 
      gap: 5px;
  }
  #topbar .pill.timer.warning { 
    /* background: rgba(226,54,54,0.8);  */
  }

  /* ===== Start Screen ===== */
  #start-screen {
    position: absolute; 
    inset: 0;
    display: flex; 
    flex-direction: column;
    align-items: center; 
    justify-content: center;
    z-index: 20; 
    pointer-events: all;
    gap: 16px; 
    padding: 24px;
  }

  /* ===== Error ===== */
  #error-msg {
    position: absolute; inset: 0;
    display: none; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.9); color: #ff6b6b;
    font-size: 16px; text-align: center; padding: 24px; gap: 12px; z-index: 30;
  }
  #error-msg small { }

  /* ===== Center hint (หมุนหาสิงโต) ===== */
  #search-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-align: center;
  color: rgba(255,255,255,0.85);
  width: 60vw;
  }
  #search-hint #icon_rotate {
    width: 45vw;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-touch-callout: none;
  }
  #search-hint .spin-icon { 
    font-size: 48px;
    animation: spin 2.5s linear infinite;
    display: inline-block;
  }
  #search-hint .spin-icon img {
    width: 30vw;
    opacity: 0.5;
  }
  #search-hint .label { margin-top: 8px; font-size: 14px; }

  #animation-pic-arrow2{
    width: 45vw;
    margin-left: auto;
    margin-right: auto;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ===== Bottom: Refresh Map ===== */
  #bottombar {
    position: absolute; bottom: 0; left: 0; right: 0;
    /* บวก safe-area-inset กัน notch / navigation bar ของ Android-iOS
       ดัน padding ล่างให้ปุ่มลอยพ้นขอบจอเสมอ */
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex; justify-content: center;
    pointer-events: none;
    /* padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); */
    padding-bottom: env(safe-area-inset-bottom);
  }
  #refresh-btn {
    pointer-events: all;
    background: rgba(0,0,0,0.7); color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 12px 28px; border-radius: 30px;
    font-size: 15px; cursor: pointer;
    backdrop-filter: blur(4px);
    display: flex; align-items: center; gap: 8px;
  }
  #refresh-btn:active { transform: scale(0.97); }

  /* ===== Modal (caught / time-up / refresh confirm) ===== */
  .modal-overlay {
    position: absolute; inset: 0;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.9);
    z-index: 40; pointer-events: all; padding: 24px;
  }
  .modal-overlay.show { display: flex; }
  .modal {
    /* background: #fff; 
    border-radius: 18px;
    padding: 28px 24px;
     width: 100%; 
     max-width: 300px;
    text-align: center; 
    display: flex; 
    flex-direction: column;
    align-items: center; 
    gap: 14px; */
  }
  .modal .big { font-size: 34px; font-weight: 800; color: #111; }
  .modal .lion-img { width: 90px; height: 90px; object-fit: contain; }
  .modal h2 { font-size: 18px; color: #111; font-weight: 700; }
  .modal p { font-size: 14px; color: #666; }
  .modal .btn {
    width: 100%; padding: 13px; border: none; border-radius: 10px;
    font-size: 15px; font-weight: 600; cursor: pointer;
  }
  .modal .btn-dark { background: #111; color: #fff; }
  .modal .btn-light { background: #f0f0f0; color: #111; }
  .modal .btn-row { display: flex; gap: 10px; width: 100%; }
  .modal .btn-row .btn { flex: 1; }