:root {
  --primary: #5ac8fa;
  --primary-dark: #007aff;
  --primary-gradient: linear-gradient(135deg, #5ac8fa, #007aff);
  --bg: #f2f2f7;
  --card: #fff;
  --text: #1c1c1e;
  --text-sub: #86868b;
  --border: #e5e5ea;
  --danger: #ff3b30;
  --success: #34c759;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 15px;
}

#app { height: 100vh; display: flex; flex-direction: column; }

.view { display: none; height: 100vh; box-sizing: border-box; padding-top: 5px; }
.view.active { display: flex; flex-direction: column; }

.btn-primary {
  background: var(--primary-gradient); color: #fff; border: none; border-radius: 12px;
  padding: 0 20px; height: 48px; font-size: 16px; font-weight: 600; cursor: pointer; min-width: 80px;
}
.btn-primary:active { transform: scale(0.96); }
.btn-large { width: 100%; height: 52px; font-size: 17px; }
.btn-small { height: 34px; min-width: 60px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-outline {
  background: #fff; color: var(--primary-dark); border: 1.5px solid var(--border);
  border-radius: 12px; padding: 0 20px; height: 48px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-outline.btn-small { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-danger {
  background: #fff; color: var(--danger); border: 1.5px solid #ffcccb;
  border-radius: 12px; padding: 0 20px; height: 48px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-danger.btn-small { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }

.auth-container { max-width: 400px; margin: auto; padding: 40px 24px; width: 100%; }
.auth-logo { font-size: 64px; text-align: center; margin-bottom: 12px; }
.auth-title { text-align: center; font-size: 28px; font-weight: 800; }
.auth-subtitle { text-align: center; color: var(--text-sub); margin: 8px 0 32px; }
.auth-tabs { display: flex; background: #fff; border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; height: 40px; border: none; background: transparent; border-radius: 10px; font-size: 15px; font-weight: 600; color: var(--text-sub); cursor: pointer; }
.auth-tab.active { background: var(--primary-gradient); color: #fff; }
.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form input, .form-item input, .form-item select, .form-item textarea {
  width: 100%; height: 48px; padding: 0 16px; border: 1.5px solid var(--border);
  border-radius: 12px; font-size: 15px; outline: none; box-sizing: border-box; background: #fff;
}
.form-item textarea { height: auto; padding: 12px 16px; resize: vertical; }
.form-item { margin-bottom: 14px; }
.form-item label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 6px; font-weight: 500; }

.page { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.page.active { display: flex; }
.page-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: #fff;
  border-bottom: 1px solid var(--border); padding-top: calc(14px + env(safe-area-inset-top));
}
.header-back { width: 32px; height: 32px; font-size: 26px; color: var(--primary-dark); cursor: pointer; font-weight: 700; line-height: 1; flex-shrink: 0; }
.header-title { flex: 1; font-size: 18px; font-weight: 700; }
.icon-btn { width: 36px; height: 36px; border: none; background: #e6f7ff; border-radius: 10px; font-size: 18px; cursor: pointer; }

.platform-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 16px; overflow-y: auto; overflow-x: hidden; flex: 1; }
@media (min-width: 768px) { .platform-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .platform-grid { grid-template-columns: repeat(4, 1fr); } }
.platform-card {
  background: #fff; border-radius: var(--radius); padding: 12px 8px; text-align: center; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04); transition: transform .1s;
  aspect-ratio: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
}
.platform-card:active { transform: scale(0.95); }
.platform-icon { font-size: 40px; margin-bottom: 8px; }
.platform-name { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.platform-count { font-size: 11px; color: var(--text-sub); }

.search-wrap { padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-wrap input { width: 100%; height: 40px; padding: 0 16px; border: 1.5px solid var(--border); border-radius: 20px; font-size: 14px; outline: none; background: #f5f5f7; }
.game-list { flex: 1; overflow-y: auto; padding: 12px 16px; }
.game-item {
  display: flex; align-items: center; gap: 12px; background: #fff; border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); cursor: pointer;
}
.game-item:active { transform: scale(0.98); }
.game-cover { width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: #f0f0f0; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.game-cover img { width: 100%; height: 100%; object-fit: cover; }
.game-no-cover { font-size: 28px; }
.game-info { flex: 1; min-width: 0; }
.game-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.game-desc { font-size: 12px; color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-arrow { color: var(--text-sub); font-size: 20px; }

.game-detail { flex: 1; overflow-y: auto; }
.detail-cover { width: 100%; max-height: 280px; overflow: hidden; background: #000; }
.detail-cover img { width: 100%; height: auto; object-fit: contain; }
.detail-body { padding: 20px; }
.detail-title { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.detail-meta { font-size: 13px; color: var(--text-sub); margin-bottom: 16px; }
.detail-desc { font-size: 15px; line-height: 1.6; margin-bottom: 24px; white-space: pre-wrap; }
.rom-btn { display: block; text-align: center; text-decoration: none; line-height: 52px; }
.no-rom { text-align: center; color: var(--text-sub); padding: 20px; }

.admin-tabs { display: flex; background: #fff; border-bottom: 1px solid var(--border); padding: 0 16px; }
.admin-tab { padding: 12px 16px; border: none; background: transparent; font-size: 14px; font-weight: 600; color: var(--text-sub); cursor: pointer; border-bottom: 2px solid transparent; }
.admin-tab.active { color: var(--primary-dark); border-bottom-color: var(--primary-dark); }
.admin-content { flex: 1; overflow-y: auto; padding: 16px; }
.admin-toolbar { margin-bottom: 16px; }
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-item { display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.admin-item-info { flex: 1; min-width: 0; }
.admin-item-name { font-size: 15px; font-weight: 600; }
.admin-item-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.admin-item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.push-hint { color: var(--text-sub); font-size: 14px; margin-bottom: 16px; line-height: 1.6; }

.me-container { flex: 1; overflow-y: auto; padding: 16px; }
.me-user { background: #fff; border-radius: var(--radius); padding: 24px; text-align: center; margin-bottom: 16px; }
.me-nickname { font-size: 20px; font-weight: 700; }
.me-username { font-size: 13px; color: var(--text-sub); margin-top: 4px; }
.me-section { background: #fff; border-radius: var(--radius); overflow: hidden; }
.me-item { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.me-item:last-child { border-bottom: none; }
.me-item:active { background: #f5f5f7; }
.me-arrow { color: var(--text-sub); }

.bottom-nav { display: flex; background: #fff; border-top: 1px solid var(--border); padding: 6px 0 calc(3px + env(safe-area-inset-bottom)); }
.nav-item { flex: 1; text-align: center; padding: 6px 0; cursor: pointer; }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; color: var(--text-sub); margin-top: 2px; }
.nav-item.active .nav-label { color: var(--primary-dark); }

.modal-mask { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; align-items: flex-end; justify-content: center; }
.modal-mask.active { display: flex; }
.modal { background: #fff; width: 100%; max-width: 500px; border-radius: 20px 20px 0 0; padding: 20px; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header span { font-size: 17px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border: none; background: #f5f5f7; border-radius: 50%; font-size: 20px; cursor: pointer; }
.modal-footer { display: flex; gap: 12px; margin-top: 20px; }
.modal-footer button { flex: 1; }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 48px; opacity: 0.5; margin-bottom: 12px; }
.empty-text { color: var(--text-sub); font-size: 14px; }

.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.8); color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 14px; z-index: 9999; opacity: 0; transition: opacity .3s; pointer-events: none; }
.toast.show { opacity: 1; }

@media (min-width: 500px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: 20px; }
  .platform-grid { grid-template-columns: repeat(4, 1fr); }
}
