/* Light palette (default). JS adds .dark for dark mode and overrides --bg/--fg/
   --muted/--card from Telegram themeParams for an exact match. */
:root {
  --bg: #ffffff;
  --fg: #1d1d1f;
  --muted: #8a8a8e;
  --card: #f1f1f4;
  --accent: #e8590c;
  --accent2: #f59e0b;
  --golden1: #e8a317;
  --golden2: #ffd24a;
}
:root.dark {
  --bg: #18191c;
  --fg: #ececef;
  --muted: #9a9aa1;
  --card: #25262b;
  --accent: #ff7a18;
  --accent2: #ffb347;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none;
}

#app { display: flex; flex-direction: column; height: 100vh; max-width: 520px; margin: 0 auto; padding: 12px 16px; }

header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.controls { display: flex; gap: 6px; flex-shrink: 0; }
.ctrl { background: var(--card); border: 1px solid rgba(128,128,128,0.2); color: var(--fg); border-radius: 9px; padding: 6px 9px; font-size: 13px; font-weight: 700; min-width: 36px; }
.points { font-size: 28px; font-weight: 800; }
.muted { color: var(--muted); font-size: 14px; font-weight: 400; }
h2 { margin: 12px 0; }

.view { display: none; flex: 1; overflow-y: auto; }
.view.active { display: block; }

.back { background: none; border: none; color: var(--muted); font-size: 15px; padding: 4px 0 8px; }

/* Hub cards */
.card { display: flex; align-items: center; gap: 14px; width: 100%; background: var(--card); border: none; color: inherit; text-align: left; border-radius: 16px; padding: 16px; margin-bottom: 12px; font-size: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.card-emoji { font-size: 40px; }

/* Tapper */
.grill-wrap { position: relative; display: grid; place-items: center; margin: 24px 0; }
.grill { font-size: 120px; background: radial-gradient(circle at 50% 35%, #3a2a1c, #1a1209); border: 4px solid var(--accent); border-radius: 50%; width: 220px; height: 220px; color: inherit; box-shadow: 0 0 40px rgba(255,122,24,0.35); transition: transform 0.06s ease; }
.grill:active { transform: scale(0.94); }
.floaters { position: absolute; inset: 0; pointer-events: none; }
.floater { position: absolute; font-weight: 800; color: var(--accent2); animation: rise 0.8s ease-out forwards; }
.gain-float { position: fixed; left: 18px; top: 52px; font-size: 24px; font-weight: 800; color: var(--accent2); pointer-events: none; z-index: 60; animation: rise 0.9s ease-out forwards; }
@keyframes rise { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-60px); } }

.energy { margin: 8px 0 20px; }
.energy-bar { height: 12px; background: var(--card); border: 1px solid rgba(128,128,128,0.2); border-radius: 6px; overflow: hidden; }
.energy-bar.big { height: 22px; border-radius: 11px; margin: 16px 0; }
.energy-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.2s ease; }
.energy-label { text-align: center; font-size: 13px; color: var(--muted); margin-top: 6px; }

h3 { margin: 16px 0 8px; font-size: 16px; }

.upgrades { display: flex; flex-direction: column; gap: 8px; }
.upgrade { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: none; color: inherit; border-radius: 12px; padding: 12px 14px; text-align: left; }
.upgrade:disabled { opacity: 0.5; }
.upgrade .u-name { font-weight: 700; }
.upgrade .u-desc { font-size: 12px; color: var(--muted); }
.upgrade .u-cost { font-weight: 800; color: var(--accent2); white-space: nowrap; }

/* Hold game (marshmallow) + reaction game (flip): big press areas */
.hold-stage, .flip-stage { width: 100%; border: none; background: var(--card); border-radius: 16px; display: grid; place-items: center; height: 200px; margin: 16px 0 12px; color: inherit; position: relative; touch-action: none; }
.flip-stage:active, .hold-stage:active { filter: brightness(1.05); }
.big-emoji { font-size: 96px; transition: filter 0.08s linear, transform 0.15s ease; }
.flip-cue { position: absolute; bottom: 14px; font-size: 22px; font-weight: 800; color: var(--accent); }

/* Marshmallow doneness bar: neutral track + a tight GLOWING golden target zone
   (center hairline = perfect) + a white marker you release inside the zone. */
.timing-track { position: relative; height: 26px; background: var(--card); border: 1px solid rgba(128,128,128,0.25); border-radius: 13px; overflow: hidden; }
.timing-golden { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, var(--golden1), var(--golden2)); box-shadow: 0 0 16px var(--golden2); display: none; }
.timing-golden::after { content: ''; position: absolute; left: 50%; transform: translateX(-50%); top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,0.9); }
.timing-fill { position: absolute; top: -4px; bottom: -4px; width: 4px; left: 0; background: #fff; box-shadow: 0 0 8px #fff; display: none; border-radius: 2px; }

.result { text-align: center; min-height: 24px; margin: 12px 0; font-weight: 700; }
.big-btn { width: 100%; padding: 16px; border: none; border-radius: 14px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 800; }
.big-btn:disabled { opacity: 0.5; }

/* Shashlik */
.shashlik-board { position: relative; height: 320px; margin: 16px 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.sk-piece { position: absolute; height: 22px; border-radius: 5px; background: linear-gradient(90deg, var(--accent), var(--accent2)); display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* Leaderboard */
.board-toggle { display: flex; gap: 8px; margin: 12px 0; }
.seg { flex: 1; padding: 10px; border: none; border-radius: 10px; background: var(--card); color: var(--muted); font-weight: 700; }
.seg.active { background: var(--accent); color: #fff; }
.board-games { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border: none; border-radius: 9px; background: var(--card); color: var(--muted); font-weight: 700; font-size: 14px; }
.chip.active { background: var(--accent); color: #fff; }
.board { list-style: none; padding: 0; margin: 0; }
.board li { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 10px; }
.board li.me { background: var(--card); font-weight: 800; }
.board .b-rank { color: var(--muted); width: 32px; }
.board .b-name { flex: 1; }

/* Bottom nav */
.tabs { display: flex; gap: 8px; padding-top: 10px; }
.tab-btn { flex: 1; padding: 12px; border: none; border-radius: 12px; background: var(--card); color: var(--muted); font-size: 15px; font-weight: 700; }
.tab-btn.active { background: var(--accent); color: #fff; }

#ton-connect-btn { display: flex; justify-content: center; margin: 16px 0; }
