/* ==========================================================================
   息壤 — 3D 场景漫游与角色动作控制样式 (支持桌面端 & 移动端无感自动横屏双摇杆模式)
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #0a1428;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #eef6ff;
}

/* ==========================================================================
   Auto-Landscape Stage Container (#game-stage)
   Automatically displays in landscape on portrait mobile screens without prompts
   ========================================================================== */
#game-stage {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
}

@media screen and (max-width: 960px) and (orientation: portrait) {
  #game-stage {
    top: 50%;
    left: 50%;
    width: 100vh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }
}

body.auto-rotated-landscape #game-stage {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
}

#webgl-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

#webgl-container canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#webgl-container canvas:active {
  cursor: grabbing;
}

/* ==========================================================================
   Loading Overlay (Auto-hides after GLB load)
   ========================================================================== */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(12, 28, 58, 0.82), rgba(5, 11, 24, 0.94));
  backdrop-filter: blur(8px);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  width: min(560px, 88%);
  padding: 24px 28px;
  border-radius: 18px;
  background: rgba(11, 25, 52, 0.88);
  border: 1px solid rgba(0, 229, 255, 0.35);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65), 0 0 30px rgba(0, 229, 255, 0.15);
}

.loading-logo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}

.loading-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loading-brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.loading-brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #ffffff;
  text-shadow: 0 0 12px rgba(0, 229, 255, 0.55);
}

.loading-tag {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 229, 255, 0.14);
  border: 1px solid rgba(0, 229, 255, 0.4);
  color: #64f4ff;
  font-weight: 600;
  white-space: nowrap;
}

.loading-title {
  font-size: 14.5px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 12px;
}

.loading-bar-bg {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-bottom: 12px;
}

.loading-bar-fill {
  width: 8%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #00c6ff, #00e676);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.7);
  transition: width 0.2s ease;
}

.loading-sub {
  font-size: 12px;
  color: #9ec0e6;
}

.loading-sub code {
  color: #70f0ff;
  background: rgba(0, 229, 255, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ==========================================================================
   HUD Layer
   ========================================================================== */
#hud-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.hud-panel {
  pointer-events: auto;
  background: rgba(9, 20, 42, 0.76);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 229, 255, 0.28);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

/* Top-Left Panel */
.hud-top-left {
  position: absolute;
  top: 14px;
  left: 16px;
  padding: 14px 16px;
  width: 416px;
  max-width: calc(100% - 32px);
  z-index: 25;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #00e676;
  box-shadow: 0 0 8px #00e676;
  flex-shrink: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
}

.scale-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 230, 118, 0.15);
  border: 1px solid rgba(0, 230, 118, 0.45);
  color: #69f0ae;
  font-weight: 600;
  white-space: nowrap;
}

.hud-collapse-btn {
  display: none;
  margin-left: auto;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: #00e5ff;
  background: rgba(0, 229, 255, 0.16);
  border: 1px solid rgba(0, 229, 255, 0.4);
  border-radius: 999px;
  cursor: pointer;
}

.mobile-mini-status {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #bfe3ff;
}

.mobile-mini-status .mini-zone {
  color: #ffffff;
  font-weight: 600;
}

.mobile-mini-status .mini-fps {
  color: #69f0ae;
  font-family: "JetBrains Mono", Consolas, monospace;
}

.info-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.info-label {
  color: #8ab0d8;
}

.info-val {
  color: #eef6ff;
  font-weight: 600;
}

.info-val.mono {
  font-family: "JetBrains Mono", Consolas, monospace;
  color: #bfe3ff;
}

.info-val.accent {
  color: #00e5ff;
}

.info-val.ok {
  color: #69f0ae;
  font-size: 11.5px;
}

.teleport-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tp-label {
  font-size: 11.5px;
  color: #8ab0d8;
  font-weight: 600;
}

.teleport-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.tp-btn {
  padding: 5px 6px;
  font-size: 11.5px;
  border-radius: 6px;
  border: 1px solid rgba(0, 229, 255, 0.25);
  background: rgba(18, 38, 76, 0.75);
  color: #d6ecff;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s ease;
}

.tp-btn:hover,
.tp-btn.active {
  background: rgba(0, 229, 255, 0.24);
  border-color: #00e5ff;
  color: #ffffff;
}

/* Top-Right Tool Buttons */
.hud-top-right {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  z-index: 20;
}

.tool-btn {
  padding: 8px 14px;
  font-size: 12.5px;
  color: #e2f1ff;
  background: rgba(9, 20, 42, 0.78);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 229, 255, 0.28);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tool-btn:hover {
  background: rgba(0, 229, 255, 0.2);
  border-color: #00e5ff;
}

.tool-btn strong {
  color: #00e5ff;
}

/* ==========================================================================
   Mobile Dual-Thumb Controls (Left Virtual Joystick + Right Jump/Wave Buttons)
   ========================================================================== */
#mobile-joystick-zone {
  position: absolute;
  bottom: 18px;
  left: 22px;
  width: 124px;
  height: 138px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
  z-index: 18;
}

.joystick-base {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(12, 30, 62, 0.45) 0%, rgba(8, 20, 44, 0.78) 100%);
  border: 2px solid rgba(0, 229, 255, 0.42);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45), inset 0 0 18px rgba(0, 229, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.joystick-base.active {
  border-color: rgba(0, 229, 255, 0.85);
  box-shadow: 0 4px 24px rgba(0, 229, 255, 0.32), inset 0 0 22px rgba(0, 229, 255, 0.25);
}

.joystick-base.sprinting {
  border-color: #00e676;
  box-shadow: 0 4px 26px rgba(0, 230, 118, 0.45), inset 0 0 22px rgba(0, 230, 118, 0.28);
}

.joystick-dir-arrows {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: rgba(0, 229, 255, 0.35);
  font-size: 9px;
}

.joystick-dir-arrows span {
  position: absolute;
}

.joystick-dir-arrows .arr-up {
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
}

.joystick-dir-arrows .arr-down {
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
}

.joystick-dir-arrows .arr-left {
  left: 7px;
  top: 50%;
  transform: translateY(-50%);
}

.joystick-dir-arrows .arr-right {
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
}

.joystick-stick {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #80f8ff, #00b8d4 70%, #0078a8 100%);
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 12px rgba(0, 229, 255, 0.65);
  pointer-events: none;
  transform: translate3d(0, 0, 0);
}

.joystick-base.sprinting .joystick-stick {
  background: radial-gradient(circle at 35% 35%, #b9f6ca, #00e676 70%, #00a152 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 14px rgba(0, 230, 118, 0.8);
}

.joystick-hint {
  margin-top: 5px;
  font-size: 10px;
  color: rgba(191, 227, 255, 0.75);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

/* Mobile Right Action Buttons */
#mobile-right-controls {
  position: absolute;
  bottom: 22px;
  right: 22px;
  display: none;
  align-items: flex-end;
  gap: 12px;
  pointer-events: auto;
  touch-action: none;
  z-index: 18;
}

.mobile-action-circle {
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #ffffff;
  backdrop-filter: blur(8px);
  transition: transform 0.1s ease, background 0.15s ease;
}

.mobile-action-circle.primary {
  width: 66px;
  height: 66px;
  background: radial-gradient(circle, rgba(0, 229, 255, 0.35), rgba(10, 28, 60, 0.85));
  border: 2px solid rgba(0, 229, 255, 0.75);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 16px rgba(0, 229, 255, 0.3);
}

.mobile-action-circle.sub {
  width: 48px;
  height: 48px;
  background: radial-gradient(circle, rgba(0, 230, 118, 0.28), rgba(10, 28, 60, 0.82));
  border: 1.5px solid rgba(0, 230, 118, 0.65);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

.mobile-action-circle:active {
  transform: scale(0.91);
  background: rgba(0, 229, 255, 0.48);
}

.mobile-action-circle .mac-icon {
  font-size: 17px;
  line-height: 1.1;
}

.mobile-action-circle.sub .mac-icon {
  font-size: 14px;
}

.mobile-action-circle .mac-text {
  font-size: 11px;
  font-weight: 700;
  margin-top: 2px;
}

.mobile-action-circle.sub .mac-text {
  font-size: 10px;
}

/* Bottom-Center Action Bar */
.hud-bottom-center {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px 12px;
  width: min(980px, calc(100% - 24px));
  z-index: 15;
}

.controls-hint-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 12px;
  color: #a9caec;
  margin-bottom: 10px;
}

.controls-hint-row code {
  color: #00e5ff;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-weight: 700;
  color: #06152d;
  background: #00e5ff;
  border-radius: 4px;
  margin: 0 2px;
}

.action-buttons-row {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 7px;
}

.anim-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 7px 4px;
  border-radius: 9px;
  border: 1px solid rgba(0, 229, 255, 0.25);
  background: rgba(16, 34, 68, 0.82);
  color: #e6f4ff;
  cursor: pointer;
  transition: all 0.16s ease;
}

.anim-btn:hover {
  background: rgba(0, 229, 255, 0.22);
  border-color: #00e5ff;
  transform: translateY(-2px);
}

.anim-btn.active {
  background: linear-gradient(180deg, rgba(0, 229, 255, 0.35), rgba(0, 150, 255, 0.25));
  border-color: #00e5ff;
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.35);
}

.anim-btn .anim-title {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.anim-btn small {
  font-size: 10px;
  color: #82b1de;
  font-family: "JetBrains Mono", Consolas, monospace;
  white-space: nowrap;
}

/* Toast Notification */
#toast-container {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.xr-toast {
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(7, 19, 42, 0.9);
  border: 1px solid #00e5ff;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  max-width: 85%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Mobile & Touch Landscape Game Mode Adaptation
   ========================================================================== */
body.is-touch-device #mobile-joystick-zone,
body.is-touch-device #mobile-right-controls {
  display: flex;
}

body.is-touch-device .controls-hint-row {
  display: none;
}

body.is-touch-device .hud-top-left {
  width: auto;
  min-width: 220px;
  max-width: min(350px, 50%);
  padding: 7px 11px;
}

body.is-touch-device .brand-header {
  margin-bottom: 3px;
}

body.is-touch-device .brand-title {
  font-size: 13px;
}

body.is-touch-device .scale-badge {
  display: none;
}

body.is-touch-device .hud-collapse-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

body.is-touch-device .mobile-mini-status {
  display: flex;
}

body.is-touch-device .hud-top-left:not(.expanded) .hud-collapsible-body {
  display: none;
}

body.is-touch-device .hud-top-left.expanded {
  width: min(380px, 80%);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: rgba(7, 17, 38, 0.94);
}

body.is-touch-device .hud-top-left.expanded .mobile-mini-status {
  display: none;
}

body.is-touch-device .hud-top-right {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  max-width: 46%;
}

body.is-touch-device .tool-btn {
  padding: 5px 9px;
  font-size: 11px;
  border-radius: 8px;
}

body.is-touch-device .tool-btn .tool-lbl {
  display: none;
}

body.is-touch-device .hud-bottom-center {
  width: min(460px, calc(100% - 290px));
  padding: 5px 7px;
  bottom: 10px;
  border-radius: 10px;
}

body.is-touch-device .action-buttons-row {
  display: flex;
  overflow-x: auto;
  gap: 5px;
  scrollbar-width: none;
}

body.is-touch-device .action-buttons-row::-webkit-scrollbar {
  display: none;
}

body.is-touch-device .anim-btn {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 5px 6px;
}

body.is-touch-device .anim-btn kbd,
body.is-touch-device .anim-btn small {
  display: none;
}

body.is-touch-device .anim-btn .anim-title {
  font-size: 11px;
}

@media (pointer: coarse), screen and (max-width: 1024px) {
  #mobile-joystick-zone,
  #mobile-right-controls {
    display: flex;
  }

  .controls-hint-row {
    display: none;
  }

  .hud-top-left {
    width: auto;
    min-width: 220px;
    max-width: min(350px, 50%);
    padding: 7px 11px;
  }

  .brand-header {
    margin-bottom: 3px;
  }

  .brand-title {
    font-size: 13px;
  }

  .scale-badge {
    display: none;
  }

  .hud-collapse-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
  }

  .mobile-mini-status {
    display: flex;
  }

  .hud-top-left:not(.expanded) .hud-collapsible-body {
    display: none;
  }

  .hud-top-left.expanded {
    width: min(380px, 80%);
    max-height: calc(100% - 24px);
    overflow-y: auto;
    background: rgba(7, 17, 38, 0.94);
  }

  .hud-top-left.expanded .mobile-mini-status {
    display: none;
  }

  .hud-top-right {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
    max-width: 46%;
  }

  .tool-btn {
    padding: 5px 9px;
    font-size: 11px;
    border-radius: 8px;
  }

  .tool-btn .tool-lbl {
    display: none;
  }

  .hud-bottom-center {
    width: min(460px, calc(100% - 290px));
    padding: 5px 7px;
    bottom: 10px;
    border-radius: 10px;
  }

  .action-buttons-row {
    display: flex;
    overflow-x: auto;
    gap: 5px;
    scrollbar-width: none;
  }

  .action-buttons-row::-webkit-scrollbar {
    display: none;
  }

  .anim-btn {
    flex: 0 0 auto;
    min-width: 52px;
    padding: 5px 6px;
  }

  .anim-btn kbd,
  .anim-btn small {
    display: none;
  }

  .anim-btn .anim-title {
    font-size: 11px;
  }
}
