:root {
  --bg: #0f1020;
  --text: #f2f2f7;
  --hint: #8a8aa3;
  --card: #1a1b33;
  --accent: rgba(255,255,255,.12); /* frosted glass buttons */
  --accent-glow: 0 0 0 1px rgba(255,255,255,.22), 0 0 10px rgba(255,255,255,.07);
  --accent-text: #ffffff;
  /* In full screen, Telegram draws its Close/menu buttons over the top of the page.
     These variables (set by Telegram) tell us how much room to leave. */
  --top-safe: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom-safe: calc(var(--tg-safe-area-inset-bottom, 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%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* Menu */
#menu { padding: calc(24px + var(--top-safe)) 16px calc(16px + var(--bottom-safe)); overflow-y: auto; }
.brand { text-align: center; margin-bottom: 20px; }
.logo { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.logo span { width: 16px; height: 16px; border-radius: 50%; animation: bob 1.4s ease-in-out infinite; }
.logo span:nth-child(1) { background: #ff1f3d; }
.logo span:nth-child(2) { background: #f6ff00; animation-delay: .2s; }
.logo span:nth-child(3) { background: #7dff1f; animation-delay: .4s; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.brand h1 { margin: 0; font-size: 32px; letter-spacing: -0.5px; }
.tag { margin: 4px 0 0; color: var(--hint); }
.game-list { display: grid; gap: 12px; max-width: 520px; width: 100%; margin: 0 auto; }
.game-card {
  display: flex; align-items: center; gap: 14px; padding: 14px; border: 0; width: 100%;
  background: var(--card); color: var(--text); border-radius: 18px; text-align: left; cursor: pointer;
  transition: transform .1s;
}
.game-card:active { transform: scale(.98); }
.game-card .dot-icon { width: 56px; height: 56px; flex: none; }
.game-card h3 { margin: 0 0 2px; font-size: 18px; }
.game-card p { margin: 0; color: var(--hint); font-size: 14px; line-height: 1.3; }
.game-card .best { margin-left: auto; text-align: right; font-size: 12px; color: var(--hint); }
.game-card .best b { display: block; font-size: 18px; color: var(--text); }
.game-card .play-ic { margin-left: auto; flex: none; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-text); box-shadow: var(--accent-glow); }
.foot { text-align: center; color: var(--hint); font-size: 13px; margin-top: 18px; }

/* Play */
.hud {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  padding-top: calc(10px + var(--top-safe));
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--card);
  color: var(--text); font-size: 28px; line-height: 36px; cursor: pointer;
}
.hud-title { font-weight: 700; font-size: 17px; flex: 1; }
.in-telegram #back { display: none; }
.in-telegram .hud { padding-left: 16px; }
.hud-score { display: flex; gap: 14px; text-align: center; }
.hud-score small { display: block; font-size: 10px; color: var(--hint); letter-spacing: 1px; }
.hud-score b { font-size: 20px; font-variant-numeric: tabular-nums; display: inline-block; }
.hud-score > div { position: relative; }
/* "+N" that floats up from the score when you eat a dot */
.score-pop { position: absolute; left: 50%; top: 14px; font-size: 17px; font-weight: 800; pointer-events: none; white-space: nowrap; animation: score-pop .7s ease-in forwards; }
/* appears left of the score, then slides right into the number and fades as it lands */
@keyframes score-pop { 0% { opacity: 0; transform: translateX(calc(-50% - 56px)) scale(.7); } 20% { opacity: 1; transform: translateX(calc(-50% - 52px)) scale(1.15); } 40% { opacity: 1; transform: translateX(calc(-50% - 48px)) scale(1); } 100% { opacity: 0; transform: translateX(-50%) scale(.5); } }
#score.bump, #best.bump { animation: score-bump .3s ease-out; }
#score.flash, #best.flash { animation: star-flash .9s ease-out; }
@keyframes star-flash { 0% { color: var(--flash); transform: scale(1); } 25% { color: var(--flash); text-shadow: 0 0 10px var(--flash); transform: scale(1.5); } 45% { transform: scale(.9); } 60% { color: var(--flash); transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes score-bump { 40% { transform: scale(1.25); } }
.stage { position: relative; flex: 1; margin: 0 12px calc(12px + var(--bottom-safe)); border-radius: 18px; overflow: hidden; background: #0a0b18; touch-action: none; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 6, 15, .72); backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.card { background: var(--card); border-radius: 20px; padding: 22px 20px; width: min(320px, 86%); text-align: center; }
.card h2 { margin: 0 0 8px; }
.card p { margin: 0 0 18px; color: var(--hint); line-height: 1.45; white-space: pre-line; }
.big-btn {
  border: 0; border-radius: 999px; padding: 13px 34px; font-size: 17px; font-weight: 700;
  background: var(--accent); color: var(--accent-text); cursor: pointer; box-shadow: var(--accent-glow);
}

/* Settings button: sits in Telegram's top bar, left of its ⌄ ⋯ buttons (position set in app.js) */
.gear {
  position: fixed; z-index: 20; top: calc(10px + var(--top-safe)); right: 16px;
  width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.1); color: #fff; cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.gear:active { transform: scale(.94); }
/* outside full screen, the gear sits at the top right, so keep the score clear of it */
:root:not(.gear-in-bar) .hud-score, :root:not(.gear-in-bar) .brand { margin-right: 48px; }
:root.two-btns:not(.gear-in-bar) .hud-score { margin-right: 96px; }
.intro-card { text-align: center; }
.intro-card p { margin: 0 0 8px; color: var(--hint); line-height: 1.5; white-space: pre-line; }
/* Rules list on the intro card */
.card p.rules, .intro-card p.rules { display: flex; flex-direction: column; gap: 12px; text-align: left; white-space: normal; margin: 6px 0 20px; }
.rule { display: flex; align-items: center; gap: 12px; }
.rule b { display: block; color: var(--text); font-size: 15px; font-weight: 600; }
.rule small { display: block; color: var(--hint); font-size: 13px; line-height: 1.35; }
.ri { width: 34px; height: 34px; flex: none; border-radius: 11px; background: rgba(255,255,255,.06); display: flex; align-items: center; justify-content: center; gap: 2px; position: relative; }
.ri i { display: block; border-radius: 50%; }
.ri .ri-x { position: absolute; right: 3px; bottom: 0; font-size: 13px; line-height: 1; color: #ff1f3d; font-weight: 800; }
:root:not(.gear-in-bar) .brand { margin-left: 48px; }

.settings {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(5,6,15,.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); padding: 16px;
}
.settings.hidden { display: none; }
.settings-card { background: var(--card); border-radius: 20px; padding: 20px; width: min(340px, 100%); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.settings-card .sec { margin: 8px 4px -2px; font-size: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--hint, #8a8aa3); }
.swatches { display: flex; gap: 12px; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; background: var(--sw); box-shadow: 0 0 8px var(--sw); transition: box-shadow .2s, transform .2s; }
.swatches button.on { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--sw), 0 0 14px var(--sw); transform: scale(1.05); }
.row:disabled { opacity: .35; cursor: default; }
.settings-card h2 { margin: 0 0 6px; text-align: center; }
/* section wrappers (hidden in Linky) keep the card's normal spacing */
#set-ui, #set-score { display: contents; }
.settings-card .big-btn { margin-top: 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 0 16px; border-radius: 14px; border: 0;
  background: rgba(255,255,255,.06); color: var(--text); font: inherit; font-size: 16px; text-align: left; cursor: pointer;
}
.row.danger { color: #ff1f3d; justify-content: center; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: rgba(255,255,255,.2); position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }
