:root {
  --bg: #0b1026;
  --bg-2: #141b3d;
  --card: rgba(24, 32, 72, 0.72);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eef1ff;
  --muted: #9aa3c7;
  --gold: #ffd166;
  --gold-2: #f4a261;
  --silver: #cfd8e3;
  --bronze: #d49a6a;
  --accent: #7c8cff;
  --ok: #43d17a;
  --bad: #ff6b6b;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Night-sky gradient on a fixed layer (background-attachment: fixed is unreliable on mobile) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(1200px 800px at 70% -10%, #2a2f6e 0%, transparent 60%),
              radial-gradient(900px 600px at -10% 30%, #1b2a5a 0%, transparent 55%),
              linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

/* Twinkling star field, pure CSS */
.sky, .sky::before, .sky::after {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-repeat: repeat;
}
.sky {
  background-image:
    radial-gradient(1px 1px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 120px 80px, #cfd6ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 200px 150px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 280px 40px, #fff 50%, transparent 51%);
  background-size: 320px 220px;
  opacity: 0.55;
}
.sky::before {
  content: "";
  background-image:
    radial-gradient(1.5px 1.5px at 60px 120px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 170px 20px, #ffe8a3 50%, transparent 51%),
    radial-gradient(2px 2px at 330px 190px, #fff 50%, transparent 51%);
  background-size: 400px 260px;
  animation: twinkle 4s ease-in-out infinite alternate;
}
.sky::after {
  content: "";
  background-image:
    radial-gradient(1px 1px at 90px 60px, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 240px 210px, #cfe3ff 50%, transparent 51%);
  background-size: 290px 300px;
  animation: twinkle 6s ease-in-out 1s infinite alternate;
}
@keyframes twinkle { from { opacity: 0.2; } to { opacity: 0.9; } }
@media (prefers-reduced-motion: reduce) { .sky::before, .sky::after { animation: none; } }

.wrap {
  position: relative; z-index: 1;
  max-width: 960px; margin: 0 auto; padding: 32px 16px 48px;
}

h1, h2 { font-family: Fredoka, Inter, sans-serif; margin: 0; }
h1 { font-size: clamp(2rem, 6vw, 3.2rem); letter-spacing: 0.5px; }
h2 { font-size: 1.3rem; margin-bottom: 14px; }

.spark {
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 209, 102, 0.8);
  display: inline-block;
  animation: spin 8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spark { animation: none; } }

.hero { text-align: center; margin-bottom: 24px; }
.hero p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.status { font-size: 0.85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); }

.banner {
  display: inline-block; margin-top: 10px; padding: 8px 14px; border-radius: 10px;
  background: rgba(124, 140, 255, 0.15); border: 1px solid rgba(124, 140, 255, 0.35); font-size: 0.9rem;
}
.banner.error { background: rgba(255, 107, 107, 0.12); border-color: rgba(255, 107, 107, 0.4); }
.banner[hidden] { display: none; }
code { background: rgba(255, 255, 255, 0.1); padding: 1px 6px; border-radius: 6px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Stats */
.stats {
  display: grid; gap: 12px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stat {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; align-items: center; text-align: center;
}
.stat strong { font-family: Fredoka, sans-serif; font-size: 1.8rem; line-height: 1.1; color: var(--gold); }
.stat .muted { font-size: 0.85rem; }

/* Search */
#search {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--card-border); border-radius: 12px; outline: none;
}
#search:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.2); }
.search-results { display: grid; gap: 12px; margin-top: 12px; }
.search-results:empty { display: none; }
.result { padding: 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--card-border); }
.result-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.result-name { font-size: 1.1rem; }
.result-stars { color: var(--gold); margin: 6px 0; font-size: 1.05rem; letter-spacing: 1px; white-space: pre; overflow-wrap: anywhere; }
.result-ranks { white-space: pre-wrap; }
.history { margin: 8px 0 0; padding-left: 18px; font-size: 0.9rem; }
.history li { margin: 2px 0; }

/* Leaderboard */
.board-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.board-head h2 { margin: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  font: 500 0.9rem Inter, sans-serif; color: var(--muted); cursor: pointer;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--card-border);
  padding: 6px 12px; border-radius: 999px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--gold); color: #2a1e00; border-color: var(--gold); }

.podium {
  display: flex; justify-content: center; align-items: flex-end; gap: 12px;
  margin: 20px 0 8px; min-height: 0;
}
.podium:empty { display: none; }
.step { flex: 1 1 0; max-width: 200px; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; }
.medal {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font: 700 1.3rem Fredoka, sans-serif; color: #2a1e00;
  border: 3px solid rgba(255, 255, 255, 0.35); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.medal-1 { background: radial-gradient(circle at 35% 30%, #fff3c4, var(--gold) 45%, var(--gold-2)); }
.medal-2 { background: radial-gradient(circle at 35% 30%, #fff, var(--silver) 45%, #8e9aab); }
.medal-3, .medal-4 { background: radial-gradient(circle at 35% 30%, #ffe0c4, var(--bronze) 45%, #8a5a36); }
.step.first .medal { width: 56px; height: 56px; font-size: 1.6rem; box-shadow: 0 0 22px rgba(255, 209, 102, 0.7); }
.p-name { font-weight: 600; overflow-wrap: anywhere; }
.p-stars { color: var(--gold); font-family: Fredoka, sans-serif; font-size: 1.2rem; }
.plinth { width: 100%; border-radius: 10px 10px 4px 4px; margin-top: 6px; }
.step-1 .plinth { height: 90px; background: linear-gradient(180deg, var(--gold), var(--gold-2)); }
.step-2 .plinth { height: 64px; background: linear-gradient(180deg, var(--silver), #8e9aab); }
.step-3 .plinth { height: 44px; background: linear-gradient(180deg, var(--bronze), #8a5a36); }

.board { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 8px; border-top: 1px solid var(--card-border);
}
.row:first-child { border-top: 0; }
.rank { font-family: Fredoka, sans-serif; color: var(--muted); font-size: 1.05rem; }
.name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; overflow-wrap: anywhere; }
.stars { color: var(--gold); letter-spacing: 1px; white-space: nowrap; }
.empty { padding: 20px 0; text-align: center; }

.chip {
  display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px;
  background: rgba(124, 140, 255, 0.18); color: #c9d0ff; border: 1px solid rgba(124, 140, 255, 0.3);
  white-space: nowrap;
}

/* Feeds */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col .card { margin-bottom: 0; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed-item { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--card-border); }
.feed-item:first-child { border-top: 0; }
.feed-item .date { flex: 0 0 90px; font-size: 0.85rem; }
.reason { font-size: 0.85rem; font-style: italic; }

footer { text-align: center; margin-top: 28px; }

@media (max-width: 640px) {
  .wrap { padding-top: 20px; }
  .two-col { grid-template-columns: 1fr; }
  .two-col .card + .card { margin-top: 0; }
  .card { padding: 16px; }
  .medal { width: 36px; height: 36px; font-size: 1.1rem; }
  .step.first .medal { width: 46px; height: 46px; font-size: 1.35rem; }
  .step-1 .plinth { height: 64px; }
  .step-2 .plinth { height: 46px; }
  .step-3 .plinth { height: 32px; }
  .row { grid-template-columns: 40px 1fr auto; gap: 8px; }
  .stars { letter-spacing: 0; font-size: 0.9rem; }
  .feed-item .date { flex-basis: 76px; }
}
