:root {
  --bg-top: #3a1a4a;
  --bg-bottom: #140818;
  --primary: #f0a05a;
  --accent: #e85d4c;
  --text: #f7f0f4;
  --text-dim: #bba3c4;
  --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;
  z-index: 2;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.screen.dim { background: rgba(6, 10, 22, 0.78); backdrop-filter: blur(3px); }

.logo-img {
  width: 128px;
  height: 128px;
  object-fit: cover;
  border-radius: 28px;
  box-shadow: 0 10px 28px rgba(232, 93, 76, 0.35), 0 0 0 2px rgba(240, 160, 90, 0.35);
}

h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0.4px;
  background: linear-gradient(180deg, #fdf1e6, var(--primary) 55%, #906036);
  -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(240, 160, 90, 0.28);
  border-radius: 14px;
  background: rgba(232, 93, 76, 0.1);
}
.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(240, 160, 90, 0.35);
  border-radius: 14px;
  background: rgba(240, 160, 90, 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, #f7cba4, var(--primary) 50%, #a8703f);
  color: #100613;
  font-size: 19px;
  box-shadow: 0 6px 24px rgba(240, 160, 90, 0.35);
}
.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(240, 160, 90, 0.2);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.3);
  text-align: left;
  white-space: pre-wrap;
}
.card.top { list-style: none; margin: 0; padding: 8px 12px; }
.card.top li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.card.top li.you { color: var(--primary); font-weight: 700; }

.tabs { display: flex; gap: 8px; width: 100%; max-width: 360px; }
.tab {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(240, 160, 90, 0.25);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
}
.tab.active { background: rgba(240, 160, 90, 0.15); color: var(--primary); }

#hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 3;
  pointer-events: none;
}
#hud .icon-btn { pointer-events: auto; }
#hud-score { font-size: 42px; font-weight: 800; text-shadow: 0 2px 12px rgba(0,0,0,0.45); }
#hud-combo { min-height: 22px; color: var(--primary); font-weight: 700; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-size: 14px;
}
.big-score { font-size: 56px; font-weight: 800; color: var(--primary); }
.record { color: var(--accent); font-weight: 700; }
.note { color: var(--text-dim); margin: 0; max-width: 360px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
