/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #667eea;
  --primary-dark: #764ba2;
  --accent: #f093fb;
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --bg: #f0f2ff;
  --card: #ffffff;
  --text: #1e1b4b;
  --muted: #6b7280;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(102,126,234,0.15);
  --shadow-lg: 0 8px 32px rgba(102,126,234,0.25);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: var(--card);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

/* ===== Header ===== */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 20px 20px 28px;
  text-align: center;
  position: relative;
}

.app-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.app-header p {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 4px;
}

/* ===== Game Nav Bar (for game pages) ===== */
.game-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 16px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.btn-back {
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 10px;
  color: #fff;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s;
}
.btn-back:hover { background: rgba(255,255,255,0.3); }

.game-header-title {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
}

.score-badge {
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  padding: 0 0 80px; /* space for bottom nav */
  overflow-y: auto;
}

/* ===== Bottom Tab Nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  display: flex;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 12px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.2s;
}

.nav-tab .tab-icon { font-size: 22px; line-height: 1; }
.nav-tab.active { color: var(--primary); }

/* ===== Panels ===== */
.panel { display: none; }
.panel.active { display: block; }

/* ===== Game Cards ===== */
.games-grid {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
}

.game-card:hover, .game-card:active {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.game-card-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.game-card-body { flex: 1; min-width: 0; }

.game-card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 3px;
}

.game-card-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.game-card-record {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  margin-top: 5px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 28px;
  border-radius: 14px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

/* ===== Game Area ===== */
.game-area {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-intro-card, .game-play-card, .game-result-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  text-align: center;
}

.game-intro-card h2 { font-size: 20px; margin-bottom: 12px; }
.game-intro-card p  { font-size: 14px; color: var(--muted); line-height: 1.7; }

.game-result-card .result-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.game-result-card .result-score {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
  margin: 8px 0;
}
.game-result-card .result-record {
  color: var(--warning);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ===== Input ===== */
.input-group {
  display: flex;
  gap: 8px;
}
.game-input {
  flex: 1;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.game-input:focus { border-color: var(--primary); }
.game-input.correct { border-color: var(--success); background: #f0fdf4; }
.game-input.wrong   { border-color: var(--danger);  background: #fef2f2; }

/* ===== Timer Bar ===== */
.timer-bar-wrap {
  background: #e5e7eb;
  border-radius: 99px;
  height: 10px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 1s linear;
}

.timer-text {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
}

/* ===== Cards (24 points) ===== */
.cards-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.playing-card {
  width: 62px;
  height: 86px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: var(--primary-dark);
  box-shadow: var(--shadow);
  user-select: none;
  cursor: pointer;
  transition: transform 0.1s;
}
.playing-card:active { transform: scale(0.94); }
.playing-card.selected {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: var(--primary-dark);
}

/* ===== Feedback / Donate ===== */
.section-panel {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-panel h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary-dark);
}

.feedback-input {
  width: 100%;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  resize: none;
  height: 80px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
  margin-bottom: 10px;
}
.feedback-input:focus { border-color: var(--primary); }

.feedback-list { margin-top: 16px; }
.feedback-item {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 13px;
}
.feedback-item .fb-text { color: var(--text); line-height: 1.5; }
.feedback-item .fb-date { color: var(--muted); font-size: 11px; margin-top: 3px; }
.feedback-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 16px 0; }

.donate-qr {
  width: 200px;
  height: 200px;
  margin: 0 auto 12px;
  display: block;
  border-radius: 12px;
  border: 2px dashed var(--primary);
  object-fit: cover;
}
.donate-desc { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.7; }

/* ===== Number grid (prime blitz) ===== */
.number-display {
  font-size: 72px;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  margin: 8px 0;
}

.answer-row {
  display: flex;
  gap: 10px;
}
.answer-row .btn { flex: 1; padding: 16px; font-size: 18px; }

/* ===== Streak badge ===== */
.streak-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--warning), #f97316);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 99px;
}

/* ===== Stats row ===== */
.stats-row {
  display: flex;
  gap: 8px;
}
.stat-box {
  flex: 1;
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.stat-box .stat-val {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}
.stat-box .stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* ===== Guess bar ===== */
.guess-history {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.guess-chip {
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
}
.guess-chip.high  { background: #fef2f2; color: var(--danger); }
.guess-chip.low   { background: #f0fdf4; color: #16a34a; }
.guess-chip.hit   { background: var(--primary); color: #fff; }

/* ===== Multiply flash ===== */
.equation-display {
  font-size: 42px;
  font-weight: 800;
  text-align: center;
  color: var(--primary-dark);
  letter-spacing: 2px;
  margin: 8px 0;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Animations ===== */
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.pop { animation: pop 0.25s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-8px); }
  75%       { transform: translateX(8px); }
}
.shake { animation: shake 0.3s ease; }

/* ===== Modal ===== */
.modal-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal-mask.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}
.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 0 0 env(safe-area-inset-bottom, 16px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 99px;
  margin: 12px auto 0;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid #f3f4f6;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: #f3f4f6;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 20px;
}
.modal-empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 32px 0;
}
.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 12px;
  margin-bottom: 8px;
}
.history-row .h-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}
.history-row .h-date {
  font-size: 12px;
  color: var(--muted);
}
.history-row .h-rank {
  font-size: 18px;
  margin-right: 6px;
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== View Toggle (index) ===== */
.view-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 16px 0;
  background: #f0f2ff;
  gap: 6px;
}
.view-btn {
  width: 36px;
  height: 36px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--muted);
}
.view-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #ede9fe;
}

/* Icon grid view */
.games-grid.icon-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.games-grid.icon-view .game-card {
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px 12px 16px;
  gap: 10px;
}
.games-grid.icon-view .game-card-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  font-size: 32px;
}
.games-grid.icon-view .game-card-body {
  min-width: 0;
  width: 100%;
}
.games-grid.icon-view .game-card-desc { display: none; }
.games-grid.icon-view .game-card > span:last-child { display: none; }

/* ===== Utility ===== */
.hidden { display: none !important; }
.text-muted { color: var(--muted); font-size: 13px; }
.mt8  { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.bold { font-weight: 700; }
