/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252540;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eaeaea;
  --text2: #8888aa;
  --gold: #ffd700;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }

/* ── Layout ── */
.app-shell {
  display: flex; flex-direction: column; min-height: 100vh;
  max-width: 1200px; margin: 0 auto; padding: 0 20px;
}

/* ── Header ── */
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 0; flex-wrap: wrap; gap: 12px;
}
header h1 {
  font-size: 1.6rem; background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
header h1 span { font-size: 1.4rem; }
nav { display: flex; gap: 8px; flex-wrap: wrap; }
nav button {
  background: var(--surface); color: var(--text); border: 1px solid transparent;
  padding: 8px 18px; border-radius: 8px; cursor: pointer; font-size: .9rem;
  transition: .2s;
}
nav button:hover, nav button.active { border-color: var(--accent); background: var(--surface2); }
nav button.online { border-color: #2ecc71; }

/* ── Main Content ── */
main { flex: 1; padding: 10px 0 30px; }
.page { display: none; }
.page.active { display: block; }

/* ── Game Cards ── */
.game-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px,1fr));
  gap: 20px;
}
.game-card {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  cursor: pointer; transition: .25s; box-shadow: var(--shadow);
  border: 1px solid transparent; position: relative; overflow: hidden;
}
.game-card:hover { transform: translateY(-4px); border-color: var(--accent); }
.game-card .emoji { font-size: 2.8rem; display: block; margin-bottom: 10px; }
.game-card h3 { font-size: 1.2rem; margin-bottom: 6px; }
.game-card p { color: var(--text2); font-size: .85rem; }
.game-card .high { position: absolute; top: 12px; right: 12px;
  background: var(--accent); color: #fff; padding: 2px 10px; border-radius: 6px;
  font-size: .75rem; font-weight: 600; display: none;
}
.game-card .high.show { display: block; }

/* ── Game Frame ── */
.game-frame {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  min-height: 500px; box-shadow: var(--shadow);
}
.game-frame iframe {
  width: 100%; height: 600px; border: none; border-radius: 8px; background: #fff;
}
.game-frame .back-btn {
  background: var(--surface2); color: var(--text); border: none;
  padding: 8px 20px; border-radius: 8px; cursor: pointer; margin-bottom: 12px;
  font-size: .9rem; display: inline-flex; align-items: center; gap: 6px;
}
.game-frame .back-btn:hover { background: var(--accent); }

/* ── Leaderboard ── */
.leaderboard {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}
.ldb-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.ldb-tabs button {
  background: var(--surface2); color: var(--text2); border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer; font-size: .85rem;
}
.ldb-tabs button.active { background: var(--accent); color: #fff; }
.ldb-table { width: 100%; border-collapse: collapse; }
.ldb-table th { text-align: left; color: var(--text2); font-size: .8rem;
  padding: 8px 12px; border-bottom: 1px solid var(--surface2); }
.ldb-table td { padding: 8px 12px; border-bottom: 1px solid var(--surface2); }
.ldb-table .rank { font-weight: 700; width: 40px; }
.ldb-table .rank-1 { color: var(--gold); }
.ldb-table .rank-2 { color: #c0c0c0; }
.ldb-table .rank-3 { color: #cd7f32; }
.empty-state { color: var(--text2); text-align: center; padding: 40px 20px; }

/* ── Personal history ── */
.history-chart {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-top: 20px;
}
.history-chart h3 { margin-bottom: 12px; font-size: 1rem; }
.history-list { max-height: 300px; overflow-y: auto; }
.history-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--surface2);
  font-size: .85rem;
}
.history-item .h-date { color: var(--text2); }
.history-item .h-score { font-weight: 600; color: var(--accent); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 600px) {
  header { flex-direction: column; align-items: flex-start; }
  .game-grid { grid-template-columns: 1fr; }
  .game-frame iframe { height: 400px; }
  .app-shell { padding: 0 12px; }
}
