/* ===== 三炮十五兵 - 中国风样式 ===== */

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

:root {
  --primary: #8B1A1A;
  --primary-light: #C0392B;
  --gold: #D4A017;
  --gold-light: #F5D76E;
  --bg-dark: #1A0F0A;
  --bg-card: #2C1810;
  --bg-page: #0D0806;
  --text-primary: #FFF8E7;
  --text-secondary: #C4A882;
  --text-muted: #8B7355;
  --accent-green: #27AE60;
  --accent-red: #E74C3C;
  --accent-blue: #2E86C1;
  --border-color: #5C3D2E;
  --shadow: rgba(0, 0, 0, 0.5);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
}

/* ===== 容器 ===== */
#app {
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  background: linear-gradient(180deg, #1A0F0A 0%, #0D0806 100%);
}

/* ===== 页面容器 ===== */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 70px; /* 底部导航高度 */
}
.page.active {
  display: flex;
  flex-direction: column;
}

.page::-webkit-scrollbar {
  width: 0;
}

/* ===== 底部导航 ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 60px;
  display: flex;
  background: rgba(26, 15, 10, 0.95);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-btn .nav-icon {
  font-size: 22px;
  line-height: 1;
}
.nav-btn.active {
  color: var(--gold);
}
.nav-btn:active {
  opacity: 0.7;
}

/* ===== 首页 ===== */
#page-home {
  align-items: center;
  justify-content: flex-start;
  padding-top: 30px;
}

.game-title {
  text-align: center;
  margin-bottom: 8px;
}

.game-title h1 {
  font-size: 36px;
  font-weight: 900;
  background: linear-gradient(135deg, #D4A017, #F5D76E, #D4A017);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 6px;
  text-shadow: none;
  font-family: "STKaiti", "KaiTi", serif;
}

.game-title .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 4px;
}

.user-info-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  padding: 10px 16px;
  margin: 8px 0 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

.user-info-bar .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  color: var(--text-primary);
  flex-shrink: 0;
}

.user-info-bar .user-details {
  flex: 1;
  min-width: 0;
}
.user-info-bar .user-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.user-info-bar .user-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}
.user-info-bar .user-vitality {
  font-size: 13px;
  color: var(--accent-green);
  font-weight: 600;
  text-align: right;
}

#btn-watch-ad {
  background: linear-gradient(135deg, #E67E22, #D35400);
  border: none;
  color: white;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}

/* ===== 主菜单按钮 ===== */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  padding: 0 16px;
  margin-top: 8px;
}

.menu-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-primary);
  text-decoration: none;
}
.menu-btn:active {
  transform: scale(0.96);
  border-color: var(--gold);
}

.menu-btn .btn-icon {
  font-size: 36px;
}
.menu-btn .btn-label {
  font-size: 15px;
  font-weight: 600;
}
.menu-btn .btn-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: -4px;
}

.menu-btn.gold {
  border-color: rgba(212, 160, 23, 0.3);
  background: linear-gradient(135deg, rgba(212,160,23,0.08), var(--bg-card));
}
.menu-btn.gold:active {
  border-color: var(--gold);
}

/* 全宽按钮 */
.menu-btn.full {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: flex-start;
  padding: 16px 20px;
  gap: 14px;
}
.menu-btn.full .btn-icon {
  font-size: 28px;
}

/* ===== AI 模式选择 ===== */
#page-ai-select {
  padding: 24px 16px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  text-align: center;
  font-family: "STKaiti", "KaiTi", serif;
  letter-spacing: 2px;
}

.select-section {
  margin-bottom: 20px;
}
.select-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  font-weight: 500;
}

.diff-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.diff-grid .diff-btn {
  padding: 14px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  color: var(--text-primary);
}
.diff-btn .diff-name {
  font-size: 15px;
  font-weight: 600;
}
.diff-btn .diff-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.diff-btn.selected {
  border-color: var(--gold);
  background: rgba(212,160,23,0.1);
}
.diff-btn.master {
  border-color: rgba(231, 76, 60, 0.3);
}
.diff-btn.master.selected {
  border-color: #E74C3C;
  background: rgba(231,76,60,0.1);
}

.side-grid {
  display: flex;
  gap: 10px;
}
.side-btn {
  flex: 1;
  padding: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
}
.side-btn.selected {
  border-color: var(--gold);
  background: rgba(212,160,23,0.1);
}
.side-btn .side-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
}

/* AI描述 */
.ai-desc-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 20px;
}
.ai-desc-box .desc-title {
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 4px;
}
.ai-desc-box .desc-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  border: none;
  border-radius: 14px;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 2px;
}
.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* ===== 游戏页面 ===== */
#page-game, #page-room-game {
  padding: 0;
  align-items: center;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.game-header {
  width: 100%;
  padding: 12px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(26, 15, 10, 0.9);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  min-height: 48px;
}

.header-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-back:active { color: var(--gold); }

.game-status-bar {
  width: 100%;
  text-align: center;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(26, 15, 10, 0.6);
  flex-shrink: 0;
}

.game-status-text {
  text-align: center;
  width: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

.game-header .turn-info {
  font-size: 15px;
  font-weight: 600;
}
.game-header .cannon-turn { color: var(--accent-red); }
.game-header .soldier-turn { color: var(--accent-blue); }
.game-header .game-over-text { color: var(--gold); }

.game-header .piece-count {
  font-size: 13px;
  color: var(--text-muted);
}

.canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  position: relative;
  min-height: 0;  /* 防止 flex 溢出 */
}

#game-canvas, #game-canvas-pvp {
  touch-action: none;
  display: block;
}

.game-controls {
  width: 100%;
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  background: rgba(26, 15, 10, 0.9);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.game-controls .ctrl-btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.game-controls .ctrl-btn:active {
  transform: scale(0.96);
}
.game-controls .ctrl-btn.primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  border-color: transparent;
}

/* ===== 匹配页面 ===== */
#page-matching {
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 40px;
}

.match-spinner {
  width: 80px;
  height: 80px;
  border: 4px solid var(--border-color);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.match-text {
  text-align: center;
}
.match-text .main {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}
.match-text .sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 8px;
}
.match-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  opacity: 0.8;
}

.btn-cancel {
  padding: 14px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
}

/* ===== 房间等待 ===== */
#page-room-waiting {
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px;
}

.room-code-display {
  text-align: center;
}
.room-code-display .label {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.room-code-display .code {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--gold);
  font-family: monospace;
}

.room-share-hint {
  text-align: center;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}
.room-share-hint .hint-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.room-waiting-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 8px auto;
}

/* ===== 加入房间 ===== */
#page-join-room {
  align-items: center;
  padding: 40px 24px;
  gap: 20px;
}

.room-input-group {
  width: 100%;
  max-width: 320px;
}

.room-input-group input {
  width: 100%;
  padding: 16px;
  font-size: 28px;
  letter-spacing: 8px;
  text-align: center;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  color: var(--gold);
  font-family: monospace;
  font-weight: 700;
  outline: none;
  caret-color: var(--gold);
}
.room-input-group input:focus {
  border-color: var(--gold);
}
.room-input-group input::placeholder {
  font-size: 16px;
  letter-spacing: 2px;
  color: var(--text-muted);
}

/* ===== PvP 游戏 ===== */
.pvp-header {
  width: 100%;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(26, 15, 10, 0.9);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.pvp-header .opponent-info {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== 排行榜 ===== */
#page-ranking {
  padding: 24px 16px;
}

.ranking-list {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-bottom: 8px;
  transition: all 0.2s;
}
.ranking-item.me {
  border-color: var(--gold);
  background: rgba(212, 160, 23, 0.06);
}

.rank-num {
  width: 36px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.rank-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}
.rank-elo {
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
}
.rank-record {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 80px;
  text-align: right;
}

.ranking-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 16px;
}

#page-ranking {
  padding-top: 50px;
  overflow-y: auto;
}
.ranking-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 60px;
}
.ranking-my {
  text-align: center;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  font-size: 14px;
  color: var(--gold);
  font-weight: 600;
}
.ranking-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== 共享工具 ===== */
.btn-back {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  z-index: 10;
}
.btn-back:active {
  opacity: 0.7;
}

/* ===== 响应式 ===== */
@media (max-height: 640px) {
  .game-title h1 { font-size: 28px; }
  .menu-btn { padding: 20px 12px; }
  .menu-btn .btn-icon { font-size: 28px; }
  .game-header { padding: 8px 12px; }
  .game-controls { padding: 8px 12px; }
  .game-header .turn-info { font-size: 13px; }
}

/* ===== 游戏结束遮罩 ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.overlay-box {
  background: var(--bg-card);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 32px 28px 24px;
  width: 300px;
  max-width: 85vw;
  text-align: center;
}

.overlay-title {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--gold);
}

.overlay-body {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.overlay-btns {
  display: flex;
  gap: 10px;
}
.overlay-btns .ctrl-btn {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.overlay-btns .ctrl-btn:active { transform: scale(0.96); }
.overlay-btns .ctrl-btn.primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  border-color: transparent;
}

/* ===== 房间大厅 ===== */
.room-player-slot {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.room-player-slot.active {
  border-color: var(--gold);
}
.room-player-slot.ready {
  border-color: var(--accent-green);
  background: rgba(39,174,96,0.06);
}

.room-player-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #FFF8E7;
  flex-shrink: 0;
}

.room-player-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.room-player-side {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.room-player-status {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.room-player-status.ready {
  color: var(--accent-green);
}

/* ===== 自己身份标记 ===== */
.room-player-slot.is-me {
  border-color: var(--gold);
  background: rgba(212, 160, 23, 0.08);
}
.room-player-slot.is-me .room-player-name::after {
  content: "（我）";
  color: var(--gold);
  font-weight: 700;
  margin-left: 4px;
}
