:root {
  --bg: #000000;
  --bg2: #0a0a0a;
  --panel: #141414;
  --panel-border: #2a2a2a;
  --text: #f0f0f0;
  --muted: #888888;
  --accent: #5c7cfa;
  --accent2: #7c5cfa;
  --highlight: #1e1e1e;
  --transition-base: 0.5s cubic-bezier(0.22, 0.61, 0.36, 1);
}

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

html,
body {
  width: 100%;
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: opacity var(--transition-base);
}

.hidden {
  display: none !important;
}

/* ============ 主菜单：1:3 左右分栏 ============ */
#menu {
  flex-direction: row;
  gap: 0;
  padding: 0;
}

.menu-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 60px;
  padding: 60px 24px;
  height: 100%;
  z-index: 5;
}

.menu-right {
  flex: 3;
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 模式按钮：大圆角方形 */
.mode-btn {
  width: 90%;
  max-width: 330px;
  height: 180px;
  border-radius: 42px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 33px;
  font-weight: 700;
  letter-spacing: 6px;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.mode-btn:hover {
  background: var(--highlight);
  border-color: var(--accent);
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  box-shadow: 0 0 45px rgba(92, 124, 250, 0.5);
  color: #fff;
}

/* ============ 对局实况 ============ */
.demo-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-base), opacity var(--transition-base);
  will-change: transform, opacity;
}

#demo-canvas {
  width: min(80vmin, 80vw);
  height: min(80vmin, 80vw);
  max-width: 960px;
  max-height: 960px;
  display: block;
  border-radius: 50%;
}

.demo-label {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 21px;
  letter-spacing: 6px;
  pointer-events: none;
}

/* 实况右移淡出（点击模式按钮后）*/
.demo-stage.slide-out {
  transform: translateX(120%);
  opacity: 0;
}

/* ============ 二级表单 ============ */
.sub-form {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 27px;
  padding: 60px;
  opacity: 0;
  transform: translateX(-120%);
  transition: transform var(--transition-base), opacity var(--transition-base);
  pointer-events: none;
  will-change: transform, opacity;
}

.sub-form.slide-in {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.form-tabs {
  display: flex;
  width: 100%;
  max-width: 540px;
  border-radius: 21px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.form-tabs .tab {
  flex: 1;
  padding: 21px;
  border: none;
  background: var(--bg2);
  color: var(--muted);
  font-size: 22.5px;
  font-weight: 600;
  letter-spacing: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.form-tabs .tab.active {
  background: var(--highlight);
  color: var(--text);
}

.input {
  width: 100%;
  max-width: 540px;
  padding: 21px 24px;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: var(--bg2);
  color: var(--text);
  font-size: 22.5px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s;
}

.input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  max-width: 540px;
  padding: 21px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 6px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn-primary:active {
  transform: scale(0.97);
}

.error {
  color: #ff6b6b;
  font-size: 19.5px;
  min-height: 27px;
  text-align: center;
}

/* ============ 房间大厅 ============ */
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 30px;
  padding: 42px 39px;
  width: 100%;
  max-width: 510px;
  text-align: center;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.8);
}

.room-code {
  color: var(--muted);
  font-size: 21px;
  margin: 12px 0 24px;
}

.room-code strong {
  color: var(--accent);
  font-size: 33px;
  letter-spacing: 4.5px;
}

.player-list {
  list-style: none;
  margin-bottom: 12px;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px 21px;
  border-radius: 15px;
  background: var(--bg2);
  margin-bottom: 12px;
}

.dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
}

.player-list .pname {
  flex: 1;
  text-align: left;
}

.player-list .pstatus {
  font-size: 18px;
  color: var(--muted);
}

.tip {
  color: var(--muted);
  font-size: 19.5px;
  margin: 6px 0 15px;
}

.btn {
  width: 100%;
  padding: 19.5px;
  margin-top: 18px;
  border: none;
  border-radius: 18px;
  font-size: 22.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  transition: transform 0.1s, opacity 0.2s;
  letter-spacing: 1.5px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary.btn {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border: none;
}

.btn-ghost {
  background: transparent;
}

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

.row .btn {
  flex: 1;
  margin-top: 18px;
}

/* ============ 游戏画面 ============ */
#game {
  flex-direction: column;
  opacity: 0;
  transition: opacity var(--transition-base);
}

#game.show {
  opacity: 1;
}

#canvas {
  width: min(92vmin, 92vw);
  height: min(92vmin, 92vw);
  max-width: 840px;
  max-height: 840px;
  touch-action: none;
  display: block;
}

#hud {
  position: absolute;
  top: 24px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  font-size: 21px;
}

.hud-item {
  background: rgba(20, 20, 20, 0.85);
  padding: 12px 21px;
  border-radius: 30px;
  border: 1px solid var(--panel-border);
}

.hud-item span {
  color: var(--accent);
  font-weight: 700;
}

#shrink-tip {
  position: absolute;
  top: 105px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffb04d;
  font-size: 21px;
  font-weight: 600;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.8);
}

#local-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 24px;
  justify-content: center;
  pointer-events: none;
  font-size: 19.5px;
  color: var(--muted);
  background: rgba(20, 20, 20, 0.85);
  padding: 12px 24px;
  border-radius: 30px;
  border: 1px solid var(--panel-border);
  white-space: nowrap;
}

#announce {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 63px;
  font-weight: 800;
  pointer-events: none;
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.8);
  animation: pop 0.4s ease;
  text-align: center;
}

@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* 虚拟摇杆 */
#joystick {
  position: absolute;
  left: 42px;
  bottom: 42px;
  width: 195px;
  height: 195px;
}

#joystick-base {
  width: 195px;
  height: 195px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(40, 40, 40, 0.5), rgba(20, 20, 20, 0.7));
  border: 2px solid rgba(120, 120, 120, 0.5);
  position: relative;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7ca4ff, #5c7cfa);
  transform: translate(-50%, -50%);
  box-shadow: 0 6px 21px rgba(80, 120, 255, 0.5);
}

/* 结算 */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 24px;
  opacity: 0;
  transition: opacity var(--transition-base);
  pointer-events: none;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.result-card h2 {
  margin-bottom: 24px;
  letter-spacing: 3px;
}

.rank-list {
  list-style: none;
  text-align: left;
  margin-bottom: 12px;
  max-height: 390px;
  overflow-y: auto;
}

.rank-list li {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--bg2);
  margin-bottom: 9px;
}

.rank-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.rank-list li.me {
  outline: 2px solid var(--accent);
}

/* 首页淡出 */
#menu.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ============ 移动端适配（仅影响手机，不改变电脑端显示） ============ */
@media (max-width: 767px) {
  .screen {
    padding: 12px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  /* 主菜单改为上下布局：在线对战按钮位于对局实况上方 */
  #menu {
    flex-direction: column;
  }

  .menu-left {
    flex: none;
    width: 100%;
    height: auto;
    min-height: auto;
    flex-direction: row;
    gap: 15px;
    padding: 15px 18px;
    order: 0;
    z-index: 6;
  }

  /* 本地对战在手机上由 JS 隐藏；此处兜底也隐藏，保持单按钮顶部栏 */
  #btn-local {
    display: none;
  }

  .mode-btn {
    width: 100%;
    max-width: none;
    height: 78px;
    border-radius: 21px;
    font-size: 24px;
    letter-spacing: 4.5px;
  }

  .menu-right {
    flex: 1;
    width: 100%;
    height: auto;
    min-height: 0;
    order: 1;
  }

  /* 对局实况画布：在顶部按钮之下适配剩余高度 */
  #demo-canvas {
    width: min(88vw, 46vh);
    height: min(88vw, 46vh);
  }

  .demo-label {
    top: 18px;
    font-size: 18px;
  }

  /* 二级表单 */
  .sub-form {
    justify-content: flex-start;
    padding: 24px 24px 42px;
    gap: 18px;
    overflow-y: auto;
  }

  .form-tabs,
  .input,
  .btn-primary {
    max-width: none;
    width: 100%;
  }

  .form-tabs .tab {
    padding: 19.5px;
    font-size: 21px;
  }

  .btn-primary {
    padding: 22.5px;
    font-size: 22.5px;
  }

  /* 大厅 / 结算卡片 */
  .card {
    max-width: none;
    padding: 36px 30px;
    width: 100%;
  }

  .row {
    flex-direction: column;
  }

  .row .btn {
    margin-top: 15px;
    padding: 22.5px;
  }

  /* 游戏画布 */
  #canvas {
    width: min(94vw, 78vh);
    height: min(94vw, 78vh);
  }

  #hud {
    top: calc(15px + env(safe-area-inset-top));
    font-size: 18px;
  }

  .hud-item {
    padding: 9px 15px;
  }

  #shrink-tip {
    top: calc(78px + env(safe-area-inset-top));
    font-size: 18px;
  }

  #announce {
    font-size: 51px;
  }

  /* 虚拟摇杆：适当放大并贴近边角 */
  #joystick {
    left: 24px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: scale(1.05);
    transform-origin: bottom left;
  }

  #joystick-base {
    width: 180px;
    height: 180px;
  }
}
