* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #7cc8f5;
  color: #24324a;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
}

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

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* 注意：不用 backdrop-filter，它在 iPad 上疊在 WebGL 畫布上非常耗 GPU */
.panel {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 22px;
  box-shadow: 0 12px 34px rgba(20, 40, 80, 0.2);
  padding: 18px;
}

.side-left,
.side-right {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(420px, 46vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-left {
  left: max(16px, env(safe-area-inset-left));
}

.side-right {
  right: max(16px, env(safe-area-inset-right));
  width: min(400px, 44vw);
}

@media (orientation: portrait) {
  .side-left,
  .side-right {
    top: auto;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
    height: 54vh;
  }
}

.scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  min-height: 0;
}

h1,
h2 {
  margin: 0;
}

h2 {
  font-size: 18px;
}

h2 small {
  font-size: 12px;
  font-weight: 400;
  color: #6b7a90;
  margin-left: 6px;
}

.logo {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ff8a3d;
  text-shadow: 0 3px 0 #ffd66b;
}

.logo span {
  color: #3a7bd5;
  text-shadow: 0 3px 0 #bfe0ff;
  font-size: 22px;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.field input {
  flex: 1;
  font: inherit;
  font-size: 17px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid #d5e3f5;
  background: #f6faff;
  color: inherit;
  -webkit-user-select: text;
  user-select: text;
  outline: none;
}

.field input:focus {
  border-color: #3a7bd5;
}

.row {
  display: flex;
  gap: 10px;
}

.row .btn {
  flex: 1;
}

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(#ffb340, #ff8a3d);
  color: #fff;
  box-shadow: 0 4px 0 #d9682a;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #d9682a;
}

.btn.ghost {
  background: #eef4fc;
  color: #3a5a88;
  box-shadow: 0 4px 0 #cfdcee;
}

.btn.danger {
  background: linear-gradient(#ff6b6b, #e04848);
  box-shadow: 0 4px 0 #b23434;
}

.btn.small {
  padding: 8px 14px;
  font-size: 14px;
}

.btn.disabled,
.btn:disabled {
  background: #c9d2de;
  box-shadow: none;
  cursor: default;
}

.msg {
  margin: 0;
  min-height: 1.2em;
  color: #d9482f;
  font-weight: 700;
}

/* 伺服器列表 */
.server-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.server {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #f3f8ff;
}

.server-info {
  flex: 1;
  min-width: 0;
}

.server-name {
  font-weight: 800;
}

.server-meta {
  font-size: 12px;
  color: #6b7a90;
  margin: 2px 0 5px;
}

.server-bar {
  height: 6px;
  border-radius: 3px;
  background: #dce6f3;
  overflow: hidden;
}

.server-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5bd17a, #ffb340);
}

/* 捏臉 */
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modes {
  display: flex;
  padding: 4px;
  border-radius: 14px;
  background: #eef4fc;
}

.mode {
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  padding: 8px 20px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #3a5a88;
  cursor: pointer;
  touch-action: manipulation;
}

.mode.active {
  background: linear-gradient(#ffb340, #ff8a3d);
  color: #fff;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 0;
  background: #eef4fc;
  color: #3a5a88;
  cursor: pointer;
  touch-action: manipulation;
}

.tab.active {
  background: #3a7bd5;
  color: #fff;
}

.ed-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 2px;
}

.ed-label {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 12px;
  border: 2px solid #d5e3f5;
  background: #fff;
  color: #3a5a88;
  cursor: pointer;
  touch-action: manipulation;
}

.chip.active {
  border-color: #ff8a3d;
  background: #fff3e8;
  color: #d9682a;
  font-weight: 800;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #d5e3f5;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
}

.swatch.active {
  box-shadow: 0 0 0 3px #ff8a3d;
}

.swatch.custom {
  background: conic-gradient(#f55, #fd4, #5d5, #4cf, #55f, #f5f, #f55);
}

.swatch.custom input {
  position: absolute;
  inset: -10px;
  width: 60px;
  height: 60px;
  opacity: 0;
  cursor: pointer;
}

.slider {
  width: 100%;
  height: 32px;
  accent-color: #ff8a3d;
  touch-action: pan-x;
}

/* HUD */
.hud-top-left,
.hud-event,
.score-board,
.detector,
.toast {
  background: rgba(20, 30, 50, 0.6);
  color: #fff;
}

.hud-top-left {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 13px;
}

.hud-server {
  font-weight: 800;
  font-size: 15px;
}

.hud-event {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
}

.hud-event.hunting {
  background: rgba(230, 120, 20, 0.9);
}

.hud-event.results {
  background: rgba(58, 123, 213, 0.9);
}

.hud-top-right {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.hud-buttons {
  display: flex;
  gap: 8px;
}

.icon-btn.wide {
  width: auto;
  padding: 0 14px;
  font: inherit;
  font-weight: 800;
  font-size: 15px;
}

.icon-btn {
  pointer-events: auto;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 0;
  background: rgba(20, 30, 50, 0.6);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  touch-action: manipulation;
}

.score-board {
  min-width: 170px;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
}

.sb-title {
  font-weight: 800;
  margin-bottom: 4px;
  opacity: 0.8;
}

.sb-row,
.res-row {
  display: flex;
  gap: 8px;
  padding: 2px 0;
}

.sb-row.me {
  color: #ffd66b;
  font-weight: 800;
}

.sb-rank {
  width: 16px;
  opacity: 0.7;
}

.sb-name,
.res-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

.toasts {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 52px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.toast {
  padding: 7px 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: nowrap;
  transition: opacity 0.4s;
}

.toast.mine {
  background: rgba(240, 160, 20, 0.95);
  font-weight: 800;
}

.toast.big {
  background: rgba(58, 123, 213, 0.92);
  font-weight: 800;
  font-size: 16px;
}

.toast.out {
  opacity: 0;
}

.detector {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 20px;
}

.bars i {
  width: 6px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
}

.bars i:nth-child(1) { height: 20%; }
.bars i:nth-child(2) { height: 40%; }
.bars i:nth-child(3) { height: 60%; }
.bars i:nth-child(4) { height: 80%; }
.bars i:nth-child(5) { height: 100%; }

.bars i.on {
  background: #ffd23f;
}

.detector[data-level="5"] .bars i.on {
  background: #ff6b3d;
}

.joystick {
  position: absolute;
  width: 130px;
  height: 130px;
  margin: -65px 0 0 -65px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.55);
}

.joystick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  transform: translate(-50%, -50%);
}

.hud-actions {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

.act {
  pointer-events: auto;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.8);
  background: rgba(20, 30, 50, 0.5);
  color: #fff;
  font: inherit;
  font-weight: 900;
  font-size: 20px;
  cursor: pointer;
  touch-action: manipulation;
}

.act:active {
  transform: scale(0.94);
}

.act.dig {
  width: 96px;
  height: 96px;
  font-size: 22px;
  background: linear-gradient(#ffcf4a, #ff9a1f);
  border-color: #fff4c2;
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.08);
  }
}

.results {
  pointer-events: none; /* 結算面板只是顯示，不能擋住轉視角的手指 */
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, 86vw);
  text-align: left;
}

.results h2 {
  text-align: center;
  margin-bottom: 12px;
}

.results p {
  text-align: center;
  color: #6b7a90;
}

.res-row {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 15px;
}

.res-row.me {
  background: #fff3e8;
  font-weight: 800;
}

.res-row.top1 .res-rank { color: #e6a700; }
.res-row.top2 .res-rank { color: #8b9bb0; }
.res-row.top3 .res-rank { color: #c27a3d; }

.res-rank {
  width: 22px;
  font-weight: 900;
}

.menu {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  background: rgba(10, 20, 40, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-panel {
  width: min(380px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tip {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: #6b7a90;
}

.boot-error {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 40, 0.55);
  -webkit-user-select: text;
  user-select: text;
}

.boot-error .panel {
  width: min(560px, 90vw);
  font-size: 16px;
  line-height: 1.7;
}

.boot-error h2 {
  color: #d9482f;
  margin-bottom: 8px;
}

.boot-error code {
  background: #eef4fc;
  padding: 1px 6px;
  border-radius: 6px;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 40, 0.45);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
}

.fatal {
  padding: 40px;
  font-size: 18px;
}

@media (max-width: 700px) {
  .score-board {
    min-width: 0;
    font-size: 12px;
  }
  .hud-event {
    font-size: 13px;
    top: calc(max(10px, env(safe-area-inset-top)) + 62px);
  }
}
