* {
      box-sizing: border-box;
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      user-select: none;
    }
    body {
      margin: 0;
      overflow: hidden;
      background-color: #050505;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      touch-action: none;
    }

    /* 載入畫面樣式 */
    #loading-screen {
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      background: radial-gradient(circle at center, #1e293b 0%, #0a0f1d 100%);
      z-index: 9999;
      display: flex;
      justify-content: center;
      align-items: center;
      transition: opacity 0.45s ease, visibility 0.45s ease;
    }
    #loading-screen.fade-out {
      opacity: 0;
      visibility: hidden;
    }
    .loader-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 16px;
    }
    .volleyball-spinner {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      background: conic-gradient(#004899 0% 25%, #f8cf00 25% 50%, #004899 50% 75%, #f8cf00 75% 100%);
      box-shadow: 0 0 20px rgba(0, 72, 153, 0.45);
      animation: spinBall 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    }
    @keyframes spinBall {
      0% { transform: rotate(0deg) scale(0.95); }
      50% { transform: rotate(180deg) scale(1.05); }
      100% { transform: rotate(360deg) scale(0.95); }
    }
    .loading-title {
      color: #e2e8f0;
      font-size: 15px;
      font-weight: 600;
      letter-spacing: 1px;
    }
    .progress-bar-container {
      width: 200px;
      height: 7px;
      background: rgba(255, 255, 255, 0.12);
      border-radius: 6px;
      overflow: hidden;
    }
    #progress-bar {
      width: 0%;
      height: 100%;
      background: linear-gradient(90deg, #38bdf8, #f8cf00);
      transition: width 0.18s ease-out;
      border-radius: 6px;
    }
    #loading-text {
      color: #94a3b8;
      font-size: 13px;
      font-weight: 500;
    }


    #joystick-container {
      position: absolute;
      bottom: calc(30px + env(safe-area-inset-bottom, 0px));
      left: calc(35px + env(safe-area-inset-left, 0px));
      width: 120px;
      height: 120px;
      background: rgba(255, 255, 255, 0.06);
      border: 2px solid rgba(255, 255, 255, 0.2);
      border-radius: 50%;
      display: block;
      z-index: 100;
      opacity: 0.7;
    }
    #joystick-knob {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 50px;
      height: 50px;
      background: rgba(255, 255, 255, 0.35);
      border-radius: 50%;
      transform: translate(-50%, -50%);
    }

    .action-btn {
      position: absolute;
      width: 68px;
      height: 68px;
      background: rgba(255, 255, 255, 0.12);
      border: 2px solid rgba(255, 255, 255, 0.35);
      border-radius: 50%;
      color: white;
      display: none;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      font-size: 13px;
      z-index: 100;
      user-select: none;
      -webkit-tap-highlight-color: transparent;
      pointer-events: auto;
      text-align: center;
      line-height: 1.2;
    }
    .action-btn:active {
      background: rgba(255, 255, 255, 0.45);
      transform: scale(0.9);
    }

    #jump-button {
      bottom: calc(25px + env(safe-area-inset-bottom, 0px));
      right: calc(35px + env(safe-area-inset-right, 0px));
      display: flex;
    }
    #spike-button {
      bottom: calc(25px + env(safe-area-inset-bottom, 0px));
      right: calc(115px + env(safe-area-inset-right, 0px));
      background: rgba(255, 50, 50, 0.3);
      border-color: rgba(255, 80, 80, 0.55);
      display: flex;
    }
    #dig-button {
      bottom: calc(105px + env(safe-area-inset-bottom, 0px));
      right: calc(115px + env(safe-area-inset-right, 0px));
      background: rgba(52, 152, 219, 0.3);
      border-color: rgba(52, 152, 219, 0.6);
      display: flex;
    }
    #pick-button {
      bottom: calc(105px + env(safe-area-inset-bottom, 0px));
      right: calc(35px + env(safe-area-inset-right, 0px));
      background: rgba(255, 204, 0, 0.25);
      border-color: rgba(255, 204, 0, 0.55);
    }
    #cart-take-button {
      bottom: calc(105px + env(safe-area-inset-bottom, 0px));
      right: calc(35px + env(safe-area-inset-right, 0px));
      background: rgba(46, 204, 113, 0.4);
      border-color: rgba(46, 204, 113, 0.8);
      font-size: 15px;
    }
    #float-button {
      bottom: calc(185px + env(safe-area-inset-bottom, 0px));
      right: calc(195px + env(safe-area-inset-right, 0px));
      background: rgba(0, 255, 255, 0.2);
      border-color: rgba(0, 255, 255, 0.5);
    }

    .machine-control-btn {
      width: 54px !important;
      height: 54px !important;
      font-size: 10.5px !important;
      border-width: 1.5px !important;
    }

    #machine-button {
      bottom: calc(185px + env(safe-area-inset-bottom, 0px));
      right: calc(35px + env(safe-area-inset-right, 0px));
      background: rgba(46, 204, 113, 0.35);
      border-color: rgba(46, 204, 113, 0.7);
      font-size: 13px !important;
    }
    #angle-button {
      bottom: calc(185px + env(safe-area-inset-bottom, 0px));
      right: calc(100px + env(safe-area-inset-right, 0px));
      background: rgba(52, 152, 219, 0.35);
      border-color: rgba(52, 152, 219, 0.7);
    }
    #horiz-angle-button {
      bottom: calc(248px + env(safe-area-inset-bottom, 0px));
      right: calc(100px + env(safe-area-inset-right, 0px));
      background: rgba(230, 126, 34, 0.35);
      border-color: rgba(230, 126, 34, 0.7);
    }
    #speed-button {
      bottom: calc(185px + env(safe-area-inset-bottom, 0px));
      right: calc(165px + env(safe-area-inset-right, 0px));
      background: rgba(155, 89, 182, 0.35);
      border-color: rgba(155, 89, 182, 0.7);
    }
    #mode-button {
      bottom: calc(248px + env(safe-area-inset-bottom, 0px));
      right: calc(35px + env(safe-area-inset-right, 0px));
      background: rgba(0, 206, 209, 0.35);
      border-color: rgba(0, 206, 209, 0.7);
      width: 60px !important;
    }

    /* 白色透明揮手動畫圖層 */
    .anim-overlay {
      position: absolute;
      pointer-events: none;
      z-index: 200;
      opacity: 0;
    }
    #spike-anim {
      right: 5%;
      bottom: 28%;
      width: 220px;
      height: 220px;
      transition: transform 0.12s ease-out, opacity 0.1s;
      transform: translateY(-100px) rotate(-40deg);
    }
    #float-anim {
      right: 15%;
      bottom: 32%;
      width: 220px;
      height: 220px;
      transform: translateY(120px) rotate(-10deg);
      transition: transform 0.1s cubic-bezier(0.1, 0.9, 0.2, 1), opacity 0.1s;
    }

    canvas { display: block; }

    #orientation-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      background: rgba(10, 14, 24, 0.94);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      z-index: 9999;
      display: none;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #fff;
      text-align: center;
      padding: 24px;
      transition: opacity 0.3s ease;
    }
    .rotate-phone-icon {
      width: 68px;
      height: 68px;
      margin-bottom: 20px;
      animation: rotatePhone 2.2s infinite ease-in-out;
    }
    @keyframes rotatePhone {
      0%, 20% { transform: rotate(0deg); }
      50%, 80% { transform: rotate(-90deg); }
      100% { transform: rotate(-90deg); }
    }
    #orientation-overlay h3 { margin: 0 0 10px 0; font-size: 20px; letter-spacing: 1px; }
    #orientation-overlay p { margin: 0 0 24px 0; font-size: 14px; color: #94a3b8; line-height: 1.5; }
    #ignore-orientation-btn {
      padding: 10px 24px;
      background: rgba(255, 255, 255, 0.12);
      border: 1px solid rgba(255, 255, 255, 0.3);
      border-radius: 20px;
      color: #e2e8f0;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
    }
  
    #game-canvas { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; touch-action: none; outline: none; }

    /* 錯誤訊息（手機看不到 console 時用） */
    #error-box {
      position: fixed; left: 8px; right: 8px; top: 8px; max-height: 60vh; overflow: auto;
      background: rgba(120, 0, 0, 0.92); color: #fff; font: 12px/1.45 monospace;
      padding: 10px 12px; border-radius: 8px; z-index: 20000; display: none;
      white-space: pre-wrap; word-break: break-all; -webkit-user-select: text; user-select: text;
    }
    #error-box button { float: right; margin-left: 8px; }
