/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --accent: #e94560;
  --accent2: #ff6b6b;
  --green: #00c853;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --text: #f0f0f0;
  --text2: #a0a0b0;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ad-height: 60px;
  --font-display: 'Fredoka One', cursive;
  --font-body: 'Inter', sans-serif;
}
html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
}
.safe-area-top { min-height: var(--safe-top); background: var(--bg); flex-shrink: 0; }
.safe-area-bottom { min-height: var(--safe-bottom); background: var(--bg); flex-shrink: 0; }

/* ===== SCREENS ===== */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

/* ===== AD DOCK ===== */
.ad-dock {
  min-height: var(--ad-height);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  flex-shrink: 0;
  overflow: visible;
  z-index: 10;
  width: 100%;
}
.ad-dock.hidden { display: none; }

/* ===== INSTALL BANNER ===== */
.install-banner {
  position: fixed;
  top: var(--safe-top);
  left: 0; right: 0;
  z-index: 1000;
  background: linear-gradient(135deg, var(--bg3), var(--bg2));
  border-bottom: 2px solid var(--accent);
  padding: 10px 16px;
  animation: slideDown 0.3s ease;
}
.install-banner.hidden { display: none; }
.install-content { display: flex; align-items: center; gap: 10px; }
.install-icon { width: 40px; height: 40px; border-radius: 8px; }
.install-text { flex: 1; display: flex; flex-direction: column; font-size: 13px; }
.install-text strong { font-size: 15px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  text-decoration: none;
  color: #fff;
}
.btn:active { transform: scale(0.96); }
.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.btn-green { background: linear-gradient(135deg, #00c853, #00e676); }
.btn-outline { background: transparent; border: 2px solid var(--text2); color: var(--text); }
.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: 8px; }
.btn-close { background: none; border: none; color: var(--text2); font-size: 24px; cursor: pointer; padding: 4px; }
.btn-icon {
  width: 48px; height: 48px; border-radius: 50%; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px;
}

/* ===== TYPOGRAPHY ===== */
.title-xl { font-family: var(--font-display); font-size: 42px; letter-spacing: 2px; }
.title-lg { font-family: var(--font-display); font-size: 28px; }
.title-md { font-family: var(--font-display); font-size: 22px; }
.subtitle { color: var(--text2); font-size: 14px; }

/* ===== HOME SCREEN ===== */
.home-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 20px;
}
.home-logo { width: 120px; height: 120px; border-radius: 24px; box-shadow: 0 8px 32px rgba(233,69,96,0.3); }
.home-title {
  background: linear-gradient(135deg, var(--accent), var(--gold), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.home-nav { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }
.home-footer { display: flex; gap: 16px; margin-top: 12px; }
.home-footer a { color: var(--text2); font-size: 12px; text-decoration: underline; cursor: pointer; }

/* ===== CATEGORY SCREEN ===== */
.category-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.back-btn { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; padding: 8px; }
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cat-card {
  background: linear-gradient(135deg, var(--bg2), var(--bg3));
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}
.cat-card:active { transform: scale(0.97); }
.cat-card.locked { opacity: 0.5; pointer-events: none; }
.cat-card .cat-emoji { font-size: 36px; margin-bottom: 8px; }
.cat-card .cat-name { font-family: var(--font-display); font-size: 14px; }
.cat-card .cat-progress { font-size: 11px; color: var(--text2); margin-top: 4px; }
.cat-card .lock-icon { position: absolute; top: 8px; right: 8px; font-size: 16px; }

/* ===== LEVEL SELECT ===== */
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 16px; }
.level-btn {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid var(--bg3);
  background: var(--bg2);
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.level-btn.completed { border-color: var(--green); background: rgba(0,200,83,0.15); }
.level-btn.current { border-color: var(--accent); background: rgba(233,69,96,0.15); animation: pulse 1.5s infinite; }
.level-btn.locked { opacity: 0.3; pointer-events: none; }
.level-btn:active { transform: scale(0.92); }

/* ===== GAME SCREEN ===== */
.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  margin-bottom: 12px;
}
.hud-item { text-align: center; }
.hud-label { font-size: 11px; color: var(--text2); text-transform: uppercase; }
.hud-value { font-family: var(--font-display); font-size: 22px; }
.timer-bar {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 20px;
}
.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--accent));
  border-radius: 3px;
  transition: width 0.1s linear;
}
.timer-fill.warning { background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.timer-fill.danger { background: var(--accent2); animation: flashRed 0.5s infinite; }

.question-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.question-text {
  font-family: var(--font-display);
  font-size: 38px;
  text-align: center;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.answer-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.answer-display {
  font-family: var(--font-display);
  font-size: 36px;
  min-width: 120px;
  text-align: center;
  padding: 8px 16px;
  border-bottom: 3px solid var(--accent);
  min-height: 52px;
}
.feedback {
  font-family: var(--font-display);
  font-size: 20px;
  min-height: 30px;
  text-align: center;
  transition: opacity 0.2s;
}
.feedback.correct { color: var(--green); }
.feedback.wrong { color: var(--accent2); }

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 300px;
  width: 100%;
  margin: 0 auto;
}
.numpad-btn {
  padding: 16px;
  border-radius: 10px;
  border: none;
  background: var(--bg2);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  font-family: var(--font-body);
}
.numpad-btn:active { transform: scale(0.93); background: var(--bg3); }
.numpad-btn.negative { background: var(--bg3); color: var(--accent2); }
.numpad-btn.submit-key { background: linear-gradient(135deg, var(--green), #00e676); color: #fff; }
.numpad-btn.backspace { background: var(--bg3); }

/* ===== RESULTS SCREEN ===== */
.results-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 20px;
}
.results-score {
  font-family: var(--font-display);
  font-size: 64px;
  background: linear-gradient(135deg, var(--gold), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.results-stars { font-size: 36px; margin: 8px 0; }
.results-stats { display: flex; gap: 24px; margin: 12px 0; }
.stat-item { text-align: center; }
.stat-val { font-family: var(--font-display); font-size: 24px; }
.stat-label { font-size: 11px; color: var(--text2); }
.results-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 300px; }
.share-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.share-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer; transition: transform 0.15s;
  color: #fff;
}
.share-btn:active { transform: scale(0.9); }
.share-btn.facebook { background: #1877f2; }
.share-btn.twitter { background: #000; }
.share-btn.whatsapp { background: #25d366; }
.share-btn.telegram { background: #0088cc; }
.share-btn.reddit { background: #ff4500; }
.share-btn.copy-link { background: var(--bg3); }

/* ===== BADGES ===== */
.badges-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.badge-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
  position: relative;
}
.badge-card.earned { border: 2px solid var(--gold); }
.badge-card.unearned { opacity: 0.4; filter: grayscale(1); }
.badge-emoji { font-size: 36px; }
.badge-name { font-size: 11px; font-weight: 700; margin-top: 6px; }
.badge-share-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent);
  border: none;
  color: #fff;
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  display: none;
}
.badge-card.earned .badge-share-btn { display: flex; align-items: center; justify-content: center; }

/* ===== LEADERBOARD ===== */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.lb-tab {
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid var(--bg3);
  background: transparent;
  color: var(--text2);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.lb-tab.active { border-color: var(--accent); color: var(--text); background: rgba(233,69,96,0.15); }
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg2);
  border-radius: var(--radius);
}
.lb-rank { font-family: var(--font-display); font-size: 18px; min-width: 32px; text-align: center; }
.lb-rank.gold { color: var(--gold); }
.lb-rank.silver { color: var(--silver); }
.lb-rank.bronze { color: var(--bronze); }
.lb-name { flex: 1; font-weight: 600; }
.lb-score { font-family: var(--font-display); color: var(--accent); }

/* ===== TOURNAMENTS ===== */
.tournament-card {
  background: linear-gradient(135deg, var(--bg2), var(--bg3));
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  border-left: 4px solid var(--accent);
}
.tournament-card .t-name { font-family: var(--font-display); font-size: 18px; }
.tournament-card .t-desc { font-size: 13px; color: var(--text2); margin: 6px 0; }
.tournament-card .t-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text2); margin-bottom: 12px; }

/* ===== SETTINGS ===== */
.settings-group { margin-bottom: 24px; }
.settings-group-title { font-family: var(--font-display); font-size: 16px; margin-bottom: 12px; color: var(--text2); }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.setting-label { font-weight: 600; }
.toggle {
  width: 48px; height: 26px;
  background: var(--bg3);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}
.toggle.on { background: var(--green); }
.toggle::after {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: transform 0.2s;
}
.toggle.on::after { transform: translateX(22px); }

/* ===== LEGAL PAGES ===== */
.legal-content {
  line-height: 1.7;
  font-size: 14px;
  color: var(--text2);
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}
.legal-content h2 { font-family: var(--font-display); font-size: 18px; color: var(--text); margin: 20px 0 8px; }
.legal-content p { margin-bottom: 12px; }
.legal-content ul { padding-left: 20px; margin-bottom: 12px; }
.legal-content li { margin-bottom: 6px; }
.legal-return-top { margin-bottom: 16px; }
.legal-return-bottom { margin-top: 24px; text-align: center; padding-bottom: 16px; }

/* ===== INSTITUTION ===== */
.inst-card {
  background: linear-gradient(135deg, var(--bg3), var(--bg2));
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  border: 2px solid var(--gold);
  margin-top: 16px;
}
.inst-price { font-family: var(--font-display); font-size: 36px; color: var(--gold); margin: 12px 0; }
.inst-features { text-align: left; margin: 16px 0; }
.inst-features li { margin-bottom: 8px; font-size: 14px; }

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 8px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}
.progress-fill.green { background: var(--green); }
.progress-fill.accent { background: var(--accent); }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(var(--ad-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 14px;
  z-index: 999;
  animation: fadeUp 0.3s ease;
  white-space: nowrap;
}
.toast.hidden { display: none; }

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 20px;
}
.modal-box {
  background: var(--bg2);
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(233,69,96,0.4); } 50% { box-shadow: 0 0 0 8px rgba(233,69,96,0); } }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes flashRed { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pop-in { animation: popIn 0.3s ease; }
.shake { animation: shake 0.3s ease; }

/* ===== SCROLLBAR ===== */
.screen::-webkit-scrollbar { width: 4px; }
.screen::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
  .question-text { font-size: 48px; }
  .numpad { max-width: 340px; }
  .numpad-btn { padding: 20px; font-size: 24px; }
}

@media (max-width: 360px) {
  .title-xl { font-size: 32px; }
  .home-logo { width: 90px; height: 90px; }
  .category-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .level-grid { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .badges-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .question-text { font-size: 28px; }
  .numpad-btn { padding: 12px; font-size: 18px; }
  .results-stats { gap: 12px; flex-wrap: wrap; }
}

@media (min-width: 768px) {
  .category-grid { grid-template-columns: repeat(4, 1fr); }
  .badges-grid { grid-template-columns: repeat(4, 1fr); }
  .legal-content { max-width: 640px; margin: 0 auto; }
}
