/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #FF6B6B;
  --primary-dark: #E05555;
  --accent: #4ECDC4;
  --gold: #FFD93D;
  --bg-dark: #0a0a1a;
  --bg-card: rgba(255,255,255,0.08);
  --bg-panel: rgba(10,10,30,0.92);
  --text: #FFFFFF;
  --text-dim: rgba(255,255,255,0.5);
  --border: rgba(255,255,255,0.12);
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
}

html, body {
  width: 100%; height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-dark);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ===== 屏幕容器 ===== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ===== 主菜单 ===== */
#menuScreen {
  background: linear-gradient(135deg, #0a0a2e 0%, #1a0a3e 30%, #2d1b4e 60%, #1a1a3e 100%);
}

.menu-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(255,107,107,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(78,205,196,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 0%, rgba(255,217,61,0.08) 0%, transparent 40%);
}

.menu-content {
  position: relative;
  z-index: 1;
  text-align: center;
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.logo-area { margin-bottom: 32px; }

.game-title {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #FF6B6B, #FFD93D, #4ECDC4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  margin-bottom: 8px;
}

.title-icon { -webkit-text-fill-color: initial; }

.subtitle {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 4px;
  text-transform: uppercase;
}

.menu-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.input-group {
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(78,205,196,0.15);
}

.input-group input::placeholder { color: var(--text-dim); }

.room-info {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.room-info-item {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.room-info-item .label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.room-info-item .value {
  font-size: 16px;
  font-weight: 700;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #FF8E53);
  color: white;
  box-shadow: 0 4px 16px rgba(255,107,107,0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(255,107,107,0.4);
}

.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: rgba(255,255,255,0.14); }

.btn-icon { font-size: 20px; }

.menu-hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ===== 游戏 HUD ===== */
#gameHUD {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  z-index: 20;
  pointer-events: none;
}

#gameHUD > * { pointer-events: auto; }

.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-left { gap: 16px; }

.hud-time {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255,217,61,0.3);
}

.hud-players { font-size: 14px; color: var(--text-dim); }

.hud-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.8);
}

.hud-score {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
}

.hud-btn {
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: white;
  font-size: 16px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.hud-btn:hover { background: rgba(255,255,255,0.15); }

/* ===== 排行榜 ===== */
#scoreboard {
  position: fixed;
  top: 64px;
  right: 12px;
  width: 220px;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 20;
  overflow: hidden;
}

.scoreboard-header {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  color: var(--gold);
}

#scoreList {
  padding: 6px 0;
  max-height: 300px;
  overflow-y: auto;
}

.score-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 13px;
  transition: background 0.15s;
}

.score-item:hover { background: rgba(255,255,255,0.04); }
.score-item.me { background: rgba(78,205,196,0.1); }

.score-rank {
  width: 20px;
  font-weight: 700;
  color: var(--text-dim);
  font-size: 11px;
}

.score-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

/* ===== 聊天 ===== */
#chatContainer {
  position: fixed;
  bottom: 60px;
  left: 12px;
  width: 320px;
  max-height: 260px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.chat-msg {
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg .sender {
  font-weight: 700;
  margin-right: 4px;
}

.chat-msg .text { color: rgba(255,255,255,0.85); }
.chat-msg.system .text { color: var(--accent); font-style: italic; }

.chat-input-row {
  display: flex;
  gap: 6px;
}

#chatInput {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

#chatInput:focus { border-color: var(--accent); }
#chatInput::placeholder { color: var(--text-dim); }

#chatSendBtn {
  padding: 8px 14px;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}

/* ===== 结算界面 ===== */
#resultScreen {
  background: var(--bg-panel);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 30;
}

.result-content {
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.result-title {
  font-size: 36px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--gold), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.result-item:last-child { border-bottom: none; }

.result-rank {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255,255,255,0.08);
}

.result-rank.gold { background: linear-gradient(135deg, #FFD93D, #FFB800); color: #333; }
.result-rank.silver { background: linear-gradient(135deg, #C0C0C0, #A0A0A0); color: #333; }
.result-rank.bronze { background: linear-gradient(135deg, #CD7F32, #B86C2E); color: white; }

.result-name { flex: 1; font-weight: 600; }
.result-score { font-weight: 700; color: var(--gold); }
.result-me { color: var(--accent); font-size: 11px; }

.result-buttons { display: flex; flex-direction: column; gap: 10px; }

/* ===== 设置面板 ===== */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 320px;
}

.panel h3 {
  font-size: 20px;
  margin-bottom: 20px;
  text-align: center;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row label { font-size: 14px; }

.setting-row:last-of-type { border-bottom: none; }
.panel .btn { margin-top: 16px; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 24px;
  transition: 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

input[type="color"] {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: none;
  padding: 2px;
}

/* ===== 移动端触控 ===== */
#mobileControls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
}

.mobile-dpad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left down right";
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(2, 60px);
  gap: 4px;
}

.ctrl-btn {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: white;
  font-size: 20px;
  cursor: pointer;
  touch-action: none;
}

.ctrl-btn:active { background: rgba(255,255,255,0.25); }

/* ===== 响应式 ===== */
@media (max-width: 640px) {
  .game-title { font-size: 32px; }
  .menu-card { padding: 20px; }
  #scoreboard { right: 8px; width: 180px; }
  #chatContainer { left: 8px; width: 240px; }
  .hud-title { display: none; }
  #mobileControls:not(.hidden) { display: block; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
