/* ================================================================
   app.css — 统一棋类对战平台 全局样式表
   移动端优先 · 暗色主题 · 底部三 Tab 导航
   ================================================================ */

/* ── CSS 变量 ──────────────────────────────────── */
:root {
  --bg:        #1a1a2e;
  --bg2:       #16213e;
  --card-bg:   #1e2a45;
  --card-hover:#253256;
  --text:      #e0e0e0;
  --text2:     #a0a0b8;
  --text3:     #6a6a80;
  --accent:    #e8b44b;
  --accent2:   #f5af19;
  --green:     #4caf84;
  --red:       #e0556a;
  --blue:      #5b9bd5;
  --border:    rgba(255,255,255,0.08);
  --radius:    12px;
  --shadow:    0 2px 12px rgba(0,0,0,0.3);
  --btn-primary-text: #1a1a2e;
  --font:      'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  --header-h:  52px;
  --tab-h:     60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── 亮色主题 ──────────────────────────────────── */
[data-theme="light"] {
  --bg:        #f0f2f5;
  --bg2:       #ffffff;
  --card-bg:   #ffffff;
  --card-hover:#e8ecf1;
  --text:      #1a1a2e;
  --text2:     #5a5a72;
  --text3:     #9999aa;
  --accent:    #c8870b;
  --accent2:   #dda015;
  --green:     #2e9a64;
  --red:       #d14052;
  --blue:      #4a8cc7;
  --border:    rgba(0,0,0,0.08);
  --shadow:    0 2px 12px rgba(0,0,0,0.08);
  --btn-primary-text: #ffffff;
}

/* ── 全局重置 ──────────────────────────────────── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
a { color:inherit; text-decoration:none; }
button { font-family:inherit; cursor:pointer; border:none; outline:none; }
input { font-family:inherit; outline:none; }

/* ── App Shell 布局 ────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ── 顶部 Header ───────────────────────────────── */
.app-header {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.app-header .logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.app-header .status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  margin-left: 10px;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── 主内容区 ──────────────────────────────────── */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
}

/* ── 底部 Tab 导航栏 ────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--tab-h);
  padding-bottom: var(--safe-bottom);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text3);
  font-size: 11px;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.tab-item .tab-icon { font-size: 22px; line-height: 1; }
.tab-item.active { color: var(--accent); font-weight: 600; }

/* ── 面板切换 ──────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── 游戏卡片 ──────────────────────────────────── */
.game-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}
.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.2s, background 0.2s;
  cursor: pointer;
}
.game-card:active { transform: scale(0.96); background: var(--card-hover); }
.game-card .game-icon { font-size: 44px; }
.game-card .game-name { font-size: 16px; font-weight: 600; }
.game-card .game-desc { font-size: 11px; color: var(--text2); text-align: center; }

.section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

/* ── 表单 ──────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--btn-primary-text); }
.btn-outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; }

.form-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text2);
  margin-top: 12px;
}
.form-switch a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.form-error { color: var(--red); font-size: 13px; margin-top: 4px; display: none; }

/* ── 用户信息卡片 ──────────────────────────────── */
.profile-card {
  text-align: center;
  padding: 24px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.profile-name { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.profile-email { font-size: 13px; color: var(--text2); margin-bottom: 14px; }

.stats-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 16px;
}
.stat-item { text-align: center; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text2); margin-top: 2px; }
.stat-value.win { color: var(--green); }
.stat-value.loss { color: var(--red); }
.stat-value.draw { color: var(--text2); }

.profile-actions { display: flex; flex-direction: column; gap: 10px; }

/* ── 好友列表 ──────────────────────────────────── */
.search-box {
  position: relative;
  margin-bottom: 14px;
}
.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
}
.search-box input:focus { border-color: var(--accent); }
.search-box .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  font-size: 16px;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.friend-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text3);
  flex-shrink: 0;
}
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-size: 14px; font-weight: 600; }
.friend-meta { font-size: 12px; color: var(--text2); }
.friend-status {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.friend-status.online { background: var(--green); }
.friend-status.offline { background: var(--text3); }
.friend-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── 好友请求 ──────────────────────────────────── */
.request-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  padding: 0 6px;
  margin-left: 6px;
}
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text3);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .empty-text { font-size: 14px; }

/* ── Toast 通知 ────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 400px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  animation: toastIn 0.3s ease;
  pointer-events: auto;
}
.toast.success { background: var(--green); color: #fff; }
.toast.error { background: var(--red); color: #fff; }
.toast.info { background: var(--blue); color: #fff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Modal 弹窗 ────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}
.modal-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  width: calc(100% - 48px);
  max-width: 360px;
  box-shadow: var(--shadow);
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.modal-body { font-size: 14px; color: var(--text2); margin-bottom: 20px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── 返回按钮 ──────────────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  color: var(--text2);
  font-size: 14px;
  background: none;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}
.back-btn:hover, .back-btn:active { color: var(--text); background: var(--card-bg); }

/* ── 响应式 ────────────────────────────────────── */
@media (min-width: 769px) {
  .app-shell {
    max-width: none;
    overflow: visible;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
  }
  .app-content {
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    padding: 24px 32px;
    padding-bottom: calc(var(--tab-h) + 24px);
    scrollbar-width: none;
  }
  .app-content::-webkit-scrollbar { display: none; }
  .tab-bar {
    max-width: none;
    left: 0;
    transform: none;
    justify-content: center;
    gap: 0;
  }
  .tab-bar .tab-item {
    max-width: 200px;
    font-size: 13px;
  }
  .tab-item .tab-icon { font-size: 24px; }

  /* 游戏卡片横排 */
  .game-cards {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
  .game-card {
    padding: 36px 20px;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
  }
  .game-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  }
  .game-card .game-icon { font-size: 56px; }
  .game-card .game-name { font-size: 18px; }
  .game-card .game-desc { font-size: 12px; }

  /* 房间列表网格 */
  #activeRoomsList {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  #activeRoomsList .friend-item { margin-bottom: 0; }

  /* 按钮不撑满 */
  .btn { width: auto; min-width: 120px; }
  .btn-sm { min-width: auto; }

  /* 表单居中收窄 */
  #formLogin, #formRegister {
    max-width: 400px;
    margin: 0 auto;
  }

  /* 个人页横排 */
  .profile-card {
    display: flex;
    align-items: center;
    gap: 32px;
    text-align: left;
    padding: 32px;
  }
  .profile-avatar { margin: 0; flex-shrink: 0; }
  .profile-info-area { flex: 1; }
  .stats-row { justify-content: flex-start; gap: 32px; }
  .profile-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
  }
  .profile-actions .btn { min-width: auto; }

  /* 好友列表网格 */
  #friendsList {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  #friendsList .friend-item { margin-bottom: 0; }
  #friendsList .empty-state { grid-column: 1 / -1; }

  .search-results {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .search-results .friend-item { margin-bottom: 0; }

  /* 登录表单 */
  .section-title { font-size: 17px; }

  body {
    background: var(--bg);
  }
}

@media (max-width: 380px) {
  .game-cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .game-card { padding: 20px 12px; }
  .game-card .game-icon { font-size: 36px; }
}
