:root {
  --bg: #020617;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --yellow: #facc15;
  --sky: #38bdf8;
  --emerald: #34d399;
  --red: #f87171;
  --font: 'Outfit', 'Fredoka', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden { display: none !important; }

/* ---------- Loading ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.spinner {
  width: 64px;
  height: 64px;
  border: 4px solid var(--amber-light);
  border-top-color: transparent;
  border-radius: 50%;
  margin-bottom: 16px;
  animation: spin 1s linear infinite;
}
.loading-text { font-size: 1.25rem; font-weight: 800; letter-spacing: .05em; color: #fcd34d; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- HUD ---------- */
#hud {
  width: 100%;
  flex-shrink: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(15, 23, 42, .9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--slate-800);
}
.hud-group { display: flex; align-items: center; gap: 12px; }
.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(30, 41, 59, .8);
  border: 1px solid;
  font-size: .85rem;
}
.pill-label { font-size: .75rem; font-weight: 600; color: var(--slate-400); }
.pill-amber { border-color: rgba(245, 158, 11, .3); }
.pill-amber b { color: var(--amber-light); font-weight: 900; }
.pill-sky { border-color: rgba(14, 165, 233, .3); }
.pill-sky b { color: var(--sky); }
.pill-gold { border-color: rgba(234, 179, 8, .3); }
.pill-gold b { color: #fde047; }
.best {
  font-size: .75rem;
  color: var(--slate-400);
  background: rgba(30, 41, 59, .5);
  padding: 4px 10px;
  border-radius: 4px;
}
.best b { color: #fff; }

/* ---------- Stage ---------- */
#stage {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#game {
  display: block;
  cursor: pointer;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .6);
  touch-action: none;
}

.flap-btn {
  position: absolute;
  right: 32px;
  bottom: 24px;
  z-index: 30;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .6);
  background: rgba(245, 158, 11, .9);
  color: var(--bg);
  font-family: inherit;
  font-weight: 900;
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, .5);
  touch-action: none;
  cursor: pointer;
}
.flap-btn span { font-size: 11px; letter-spacing: .06em; font-weight: 800; }
.flap-btn:active { transform: scale(.9); }

/* ---------- Overlays & cards ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 6, 23, .6);
  backdrop-filter: blur(3px);
  /* display: none; */
}
.overlay-top { z-index: 50; }
.overlay-higher { z-index: 60; }

.card {
  width: 100%;
  max-width: 448px;
  max-height: 100%;
  overflow-y: auto;
  padding: 32px 24px;
  border-radius: 16px;
  border: 2px solid;
  background: rgba(15, 23, 42, .95);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .6);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.card-amber { border-color: rgba(245, 158, 11, .5); }
.card-red { border-color: rgba(239, 68, 68, .6); }
.card-green { border-color: rgba(16, 185, 129, .6); }
.card-sky { border-color: rgba(14, 165, 233, .6); }

.badge {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  padding: 4px;
  margin-bottom: 12px;
  background: linear-gradient(to top right, var(--amber), var(--sky));
  display: flex;
  align-items: center;
  justify-content: center;
}
.badge img { width: 56px; height: 56px; object-fit: contain; filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .3)); }

.medal { width: 96px; height: 96px; margin-bottom: 16px; }
.medal img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 13px rgba(0, 0, 0, .4));
  animation: bounce 1s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(-15%); animation-timing-function: cubic-bezier(.8, 0, 1, 1); }
  50% { transform: none; animation-timing-function: cubic-bezier(0, 0, .2, 1); }
}

.title { font-size: 2.2rem; font-weight: 900; letter-spacing: -.02em; color: var(--yellow); margin-bottom: 8px; line-height: 1.1; }
.title.red { color: var(--red); }
.title.sky { color: var(--sky); }
.small-title { font-size: 1.6rem; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 20px; display: flex; gap: 8px; align-items: center; }
.subtitle { font-size: .95rem; color: var(--slate-300); margin-bottom: 24px; }
.subtitle.green { color: #a7f3d0; }

.stats {
  width: 100%;
  display: flex;
  justify-content: space-around;
  padding: 12px;
  margin-bottom: 20px;
  border-radius: 12px;
  background: rgba(30, 41, 59, .8);
  border: 1px solid var(--slate-700);
}
.divider { border-right: 1px solid var(--slate-700); }
.stat-label { font-size: .72rem; text-transform: uppercase; font-weight: 600; color: var(--slate-400); }
.stat-value { font-size: 1.25rem; font-weight: 900; }
.stat-value.huge { font-size: 1.9rem; }
.amber { color: var(--amber-light); }
.sky { color: var(--sky); }
.gold { color: #fde047; }
.yellow { color: var(--yellow); }
.green { color: var(--emerald); }
.small { font-size: .75rem; margin-top: 8px; font-weight: 600; }

.breakdown {
  width: 100%;
  padding: 16px;
  margin-bottom: 24px;
  border-radius: 12px;
  background: rgba(30, 41, 59, .9);
  border: 1px solid var(--slate-700);
}
.card-green .breakdown { border-color: rgba(16, 185, 129, .4); }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(51, 65, 85, .6);
  font-size: .875rem;
  color: var(--slate-400);
}
.row:last-child { border-bottom: 0; padding-bottom: 0; }
.row b { color: #fff; font-size: 1rem; }
.row b.big { font-size: 1.25rem; font-weight: 900; }

.text-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 14px;
  margin-bottom: 14px;
  border-radius: 999px;
  border: 1px solid var(--slate-700);
  background: var(--slate-800);
  color: #fff;
  font-family: inherit;
  font-size: .9rem;
  text-align: center;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.text-input:focus { border-color: var(--amber); }

.stack { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.leaderboard { width: 100%; margin-top: 20px; text-align: left; }
.leaderboard .stat-label { text-align: center; margin-bottom: 6px; }
.leaderboard ol { list-style: none; counter-reset: rank; }
.leaderboard li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  padding: 4px 10px;
  font-size: .85rem;
  color: var(--slate-300);
  border-radius: 6px;
}
.leaderboard li:nth-child(odd) { background: rgba(30, 41, 59, .6); }
.leaderboard li::before { content: counter(rank) "."; width: 24px; color: var(--slate-400); }
.leaderboard li .lb-name { flex: 1; }
.leaderboard li .lb-score { font-weight: 800; color: var(--amber-light); }

.tips { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; text-align: left; font-size: .85rem; color: var(--slate-300); }
.tip { padding: 12px; border-radius: 12px; background: rgba(30, 41, 59, .8); border: 1px solid var(--slate-700); }
.tip b { display: block; margin-bottom: 4px; }

/* ---------- Buttons ---------- */
.btn2 {
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 800;
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .15s, background .15s;
}
.btn:active { transform: scale(.95); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.btn-primary, .btn-white, .btn-green, .btn-sky {
  border-radius: 999px;
  padding: 14px 24px;
  font-weight: 900;
  font-size: 1.1rem;
  color: var(--bg);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .4);
}
.btn-primary { background: var(--amber-light); }
.btn-primary:hover { background: #fde047; transform: scale(1.02); }
.btn-white { background: #fff; }
.btn-white:hover { background: var(--yellow); transform: scale(1.02); }
.btn-green { background: var(--emerald); }
.btn-green:hover { background: #6ee7b7; transform: scale(1.02); }
.btn-sky { background: var(--sky); }
.btn-sky:hover { background: #7dd3fc; }
.btn-amber { background: var(--amber); color: var(--bg); font-weight: 900; }
.btn-amber:hover { background: var(--amber-light); }
.btn-dark { background: var(--slate-800); color: #fff; border: 1px solid var(--slate-700); }
.btn-dark:hover { background: var(--slate-700); }
.btn-howto { border-radius: 999px; font-size: .85rem; }
.btn-danger { background: rgba(69, 10, 10, .6); color: #fca5a5; border: 1px solid rgba(153, 27, 27, .4); margin-top: 8px; }
.btn-danger:hover { background: rgba(127, 29, 29, .8); }

.btn-menu { width: auto; min-width: 48px; padding: 4px 12px; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) { .hide-sm { display: none !important; } }
@media (max-width: 768px) { .hide-md { display: none !important; } }
@media (max-width: 480px) {
  .title { font-size: 1.8rem; }
  .hud-group { gap: 6px; }
  #hud { padding: 6px 8px; }
  .pill { padding: 3px 8px; }
  .btn-menu span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .medal img, .spinner { animation: none; }
}
