/* ===== XMini v4 — 布局修复 + 进度管理 ===== */
:root {
  --bg: #0f0f1a;
  --bg-surface: #1a1a2e;
  --bg-card: #16213e;
  --bg-elevated: #1f2b47;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --accent: #6c5ce7;
  --accent-glow: rgba(108,92,231,0.35);
  --accent2: #00cec9;
  --danger: #ff6b6b;
  --success: #51cf66;
  --gold: #ffd43b;
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 0.25s cubic-bezier(0.4,0,0.2,1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== 容器 ===== */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 480px) and (min-height: 700px) {
  html, body { display: flex; justify-content: center; align-items: center; }
  .app-container {
    max-width: 420px;
    max-height: 860px;
    border-radius: 28px;
    box-shadow: 0 0 80px rgba(108,92,231,0.12);
    overflow: hidden;
  }
}

/* ===== 屏幕切换 ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

/* ===== 顶部栏 ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: rgba(15,15,26,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  z-index: 10;
}

.brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.icon-btn:active {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  transform: scale(0.92);
}

/* ===== 加载页 ===== */
#screen-loading {
  justify-content: center;
  align-items: center;
  background: var(--bg);
}
.loading-wrap { text-align: center; }
.logo-ring {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  border-top-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
  animation: spin 0.9s linear infinite;
}
.logo-x {
  font-size: 30px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label {
  font-size: 10px;
  letter-spacing: 4px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 14px;
}
.progress-track {
  width: 150px; height: 3px;
  background: var(--bg-surface);
  border-radius: 3px;
  margin: 0 auto;
  overflow: hidden;
}
.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width 0.25s ease;
}

/* ===== 首页 ===== */
.home-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.home-content::-webkit-scrollbar { display: none; }

.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 18px 18px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

/* ===== 游戏网格 ===== */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 16px 16px;
}
.fav-grid { grid-template-columns: repeat(4, 1fr); }

.game-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.06);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.game-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--card-accent, var(--accent));
  opacity: 0;
  transition: opacity 0.25s;
}
.game-card:active {
  transform: scale(0.96);
  background: var(--bg-elevated);
}
.game-card:active::before { opacity: 1; }

.card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  background: var(--card-accent, var(--accent));
}

.card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tag {
  font-size: 10px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 20px;
  align-self: flex-start;
}

.fav-grid .game-card {
  padding: 10px 8px;
  align-items: center;
  text-align: center;
}
.fav-grid .card-icon {
  width: 38px; height: 38px;
  font-size: 18px;
  border-radius: 10px;
}
.fav-grid .card-name {
  font-size: 10px;
  text-align: center;
}
.fav-grid .card-tag { display: none; }

/* ===== 游戏视图 ===== */
#screen-game { background: #000; }

.game-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(15,15,26,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  z-index: 10;
}

.game-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.game-nav { color: var(--text); }
.game-nav:active { color: var(--accent); }
#btn-fav.active svg { fill: var(--gold); stroke: var(--gold); }

.game-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #000;
  overflow: hidden;
}
#game-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
  display: block;
}

/* ===== 设置页 ===== */
.settings-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.settings-list::-webkit-scrollbar { display: none; }

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,0.04);
  gap: 12px;
}

.setting-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.setting-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.setting-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.toggle {
  position: relative;
  width: 44px; height: 26px;
  background: var(--bg-elevated);
  border-radius: 13px;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  padding: 0;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: var(--transition);
}
.toggle.on::after { left: 21px; }

.theme-row {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.theme-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.theme-dot.active {
  border-color: var(--text);
  transform: scale(1.15);
}
.theme-dot.t-dark { background: #0f0f1a; }
.theme-dot.t-purple { background: linear-gradient(135deg, #6c5ce7, #a29bfe); }
.theme-dot.t-cyber { background: linear-gradient(135deg, #00cec9, #6c5ce7); }
.theme-dot.t-warm { background: linear-gradient(135deg, #ff6b6b, #ffd43b); }

.vol-slider {
  width: 100px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* ===== 账户页 ===== */
.account-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.account-panel::-webkit-scrollbar { display: none; }

.account-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 16px;
}

.avatar {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
}

.account-name { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.account-id { font-size: 11px; color: var(--text-dim); }

.account-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}
.stat-box {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
}
.stat-val { font-size: 18px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 10px; color: var(--text-dim); margin-top: 2px; }

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

/* ===== 进度管理区 ===== */
.progress-section {
  margin-bottom: 16px;
}

.progress-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.04);
  gap: 10px;
}

.progress-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.progress-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.progress-meta {
  flex: 1;
  min-width: 0;
}

.progress-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-detail {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.progress-clear {
  padding: 6px 12px;
  border: 1px solid rgba(255,107,107,0.3);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.progress-clear:active {
  background: rgba(255,107,107,0.15);
}

.progress-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ===== 按钮 ===== */
.btn-primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}
.btn-primary:active { transform: scale(0.97); opacity: 0.9; }

.btn-outline {
  width: 100%;
  padding: 13px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-outline:active { background: rgba(255,255,255,0.05); }

.btn-danger {
  width: 100%;
  padding: 13px;
  border: 1px solid rgba(255,107,107,0.3);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-danger:active { background: rgba(255,107,107,0.1); }

/* ===== 登录表单 ===== */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-input {
  width: 100%;
  padding: 13px 14px;
  background: var(--bg-elevated);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}
.login-input:focus { border-color: var(--accent); }
.login-input::placeholder { color: var(--text-dim); }

/* ===== 弹窗 ===== */
.modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.show { display: flex; }

.modal-card {
  background: var(--bg-surface);
  border-radius: 20px;
  padding: 28px 22px;
  max-width: 300px;
  width: 100%;
  text-align: center;
  position: relative;
  border: 1px solid rgba(255,255,255,0.08);
  animation: slideUp 0.25s ease;
}
.modal-card.small { max-width: 260px; }
@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 10px; right: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.modal-close:active { background: rgba(255,255,255,0.08); }

.modal-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 28px;
}

.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 8px; }
.modal-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 18px;
}

.diff-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.diff-btn {
  padding: 11px 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.diff-btn:active { background: var(--accent); border-color: var(--accent); }
.diff-btn.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.diff-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== 主题变体 ===== */
.theme-purple {
  --bg: #12101f;
  --bg-surface: #1e1a33;
  --bg-card: #252040;
  --bg-elevated: #2d2750;
  --accent: #a29bfe;
  --accent-glow: rgba(162,155,254,0.35);
  --accent2: #6c5ce7;
}
.theme-cyber {
  --bg: #0a0e1a;
  --bg-surface: #111827;
  --bg-card: #1a2332;
  --bg-elevated: #1f2d42;
  --accent: #00cec9;
  --accent-glow: rgba(0,206,201,0.35);
  --accent2: #6c5ce7;
}
.theme-warm {
  --bg: #1a1008;
  --bg-surface: #2a1e12;
  --bg-card: #332518;
  --bg-elevated: #3d2d1c;
  --accent: #ff6b6b;
  --accent-glow: rgba(255,107,107,0.35);
  --accent2: #ffd43b;
}

::-webkit-scrollbar { width: 0; height: 0; }
