:root {
  --bg-top: #0f2a1a;
  --bg-bottom: #06130b;
  --primary: #f5c542;
  --accent: #4cc970;
  --text: #f3f7e9;
  --text-dim: #a9c4a0;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-bottom);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  text-align: center;
  overflow-y: auto;
}

.screen.dim { background: rgba(3, 12, 6, 0.75); backdrop-filter: blur(3px); }

.logo { font-size: 64px; filter: drop-shadow(0 0 18px rgba(76, 201, 112, 0.6)); }

h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #fff3c4, var(--primary) 55%, #b5850f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 { margin: 0; font-size: 26px; color: var(--primary); }

.tagline { margin: 0; color: var(--text-dim); }

.stats { display: flex; gap: 10px; width: 100%; max-width: 360px; }

.stats > div {
  flex: 1;
  padding: 10px 6px;
  border: 1px solid rgba(245, 197, 66, 0.25);
  border-radius: 14px;
  background: rgba(245, 197, 66, 0.07);
}

.stats span { display: block; font-size: 12px; color: var(--text-dim); }
.stats b { font-size: 20px; color: var(--text); }

.btn {
  width: 100%;
  max-width: 360px;
  padding: 14px 18px;
  border: 1px solid rgba(245, 197, 66, 0.35);
  border-radius: 14px;
  background: rgba(245, 197, 66, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:active { transform: scale(0.98); }

.btn.primary {
  border: 0;
  background: linear-gradient(180deg, #ffe08a, var(--primary) 50%, #c9940f);
  color: #2b1e00;
  font-size: 19px;
  box-shadow: 0 6px 24px rgba(245, 197, 66, 0.3);
}

.row { display: flex; gap: 10px; width: 100%; max-width: 360px; }
.row .btn { flex: 1; }

.card {
  width: 100%;
  max-width: 400px;
  padding: 16px;
  border: 1px solid rgba(245, 197, 66, 0.2);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.3);
  text-align: left;
}

.card.text { white-space: pre-line; color: var(--text); }

.tabs { display: flex; gap: 6px; }

.tab {
  padding: 8px 16px;
  border: 1px solid rgba(245, 197, 66, 0.3);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
}

.tab.active { background: var(--primary); color: #2b1e00; border-color: var(--primary); }

ol.top { margin: 0; padding: 8px 16px; list-style: none; max-height: 55vh; overflow-y: auto; }

ol.top li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

ol.top li:last-child { border-bottom: 0; }
ol.top li.me { color: var(--primary); font-weight: 700; }
ol.top .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol.top .empty { justify-content: center; color: var(--text-dim); }

.big-score {
  font-size: 64px;
  font-weight: 800;
  color: var(--primary);
  text-shadow: 0 0 24px rgba(245, 197, 66, 0.5);
}

.record {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  animation: pulse 1s ease-in-out infinite;
}

.note { margin: 0; min-height: 1.4em; color: #ff9b8a; font-size: 14px; }

@keyframes pulse { 50% { transform: scale(1.08); } }

#hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

#hud-score { font-size: 28px; font-weight: 800; color: var(--primary); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
#hud-level { font-size: 14px; font-weight: 700; color: var(--accent); }
#hud-info { padding-top: 6px; font-size: 18px; font-weight: 700; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); }
.hud-right { display: flex; align-items: center; gap: 10px; }
#hud-lives { font-size: 20px; letter-spacing: 2px; }

.icon-btn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(245, 197, 66, 0.4);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 14px;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(245, 197, 66, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
