:root {
  --bg: #1a1033;
  --bg2: #2a1a4f;
  --card: rgba(255, 255, 255, 0.06);
  --card-solid: #2c2050;
  --line: rgba(255, 255, 255, 0.12);
  --txt: #f4f1ff;
  --muted: #b3a8d4;
  --accent: #ffd23f;
  --accent2: #ff5d8f;
  --good: #4ade80;
  --bad: #f87171;
  --c1: #ff5d8f;
  --c2: #ffd23f;
  --c3: #4ade80;
  --c4: #38bdf8;
  --c5: #a78bfa;
  --c6: #fb923c;
  --c7: #f472b6;
  --c8: #2dd4bf;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg2), var(--bg) 60%);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

/* ---------- Header ---------- */
.topbar {
  text-align: center;
  padding: 14px 16px 8px;
}
.logo {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.5px;
  text-shadow: 0 3px 0 rgba(0,0,0,0.25);
}
.tagline {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- Screen ---------- */
.screen {
  flex: 1;
  padding: 8px 16px 16px;
  animation: fade 0.25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin: 18px 4px 10px;
  font-weight: 700;
}

/* ---------- Cards / buttons ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  backdrop-filter: blur(8px);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 16px;
  font-size: 17px;
  font-weight: 800;
  color: #1a1033;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18);
}
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.18); }
.btn.secondary { background: var(--card-solid); color: var(--txt); border: 1px solid var(--line); box-shadow: 0 6px 0 rgba(0,0,0,0.25); }
.btn.pink { background: var(--accent2); color: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-lg { font-size: 20px; padding: 20px; }

/* ---------- Home / game picker ---------- */
.hero-pick {
  text-align: center;
  margin: 6px 0 18px;
}
.players-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 10px 0 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 15px;
  font-size: 14px;
  font-weight: 700;
  color: var(--txt);
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.chip:active { transform: scale(0.93); }
.chip[aria-pressed="true"] { border-color: rgba(255, 255, 255, 0.4); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; transition: 0.15s; }
.chip.off { opacity: 0.45; text-decoration: line-through; text-decoration-color: rgba(255, 255, 255, 0.45); }
.chip.off .dot { background: #6b6190 !important; }

.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.game-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  position: relative;
  overflow: hidden;
}
.game-tile:active { transform: scale(0.96); }
.game-tile .emoji { font-size: 40px; display: block; }
.game-tile .name { font-weight: 800; margin-top: 8px; font-size: 15px; }
.game-tile .desc { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.3; }

/* ---------- Riders config ---------- */
.rider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.rider-row:last-child { border-bottom: none; }
.rider-dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.rider-name { flex: 1; font-weight: 700; font-size: 16px; }
.rider-name.off { opacity: 0.45; text-decoration: line-through; }
.rider-sub { font-size: 12px; color: var(--muted); font-weight: 500; }

/* toggle switch */
.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: #4a3d70; border-radius: 999px;
  transition: 0.2s; cursor: pointer;
}
.slider:before {
  content: ""; position: absolute;
  height: 22px; width: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--good); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.icon-btn {
  background: none; border: none; color: var(--bad);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
}

.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row input {
  flex: 1; background: var(--card-solid); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; color: var(--txt); font-size: 16px;
}
.add-row input::placeholder { color: var(--muted); }
.add-row button {
  width: auto; padding: 0 20px; border-radius: 14px;
  background: var(--good); color: #04210f; font-weight: 800; border: none;
  font-size: 22px; cursor: pointer;
}

/* ---------- Stats ---------- */
.stat-cards { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.stat-card { text-align: center; padding: 14px 8px; }
.stat-num { font-size: 26px; font-weight: 900; color: var(--accent); }
.stat-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

.bar-row { margin: 14px 4px; }
.bar-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.bar-head .pct { color: var(--muted); font-weight: 600; }
.bar-track { height: 14px; background: var(--card-solid); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.6s cubic-bezier(.2,.8,.2,1); }

.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.history-item:last-child { border-bottom: none; }
.history-item .h-win { font-weight: 800; flex: 1; }
.history-item .h-game { color: var(--muted); font-size: 12px; }
.history-item .h-time { color: var(--muted); font-size: 11px; }

.empty {
  text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; line-height: 1.5;
}
.empty .big { font-size: 48px; display: block; margin-bottom: 10px; }

.link-btn {
  background: none; border: none; color: var(--accent2);
  font-size: 14px; font-weight: 700; cursor: pointer; text-decoration: underline;
  display: block; margin: 18px auto 0;
}

/* ---------- Bottom nav ---------- */
.tabbar {
  position: sticky;
  bottom: 0;
  display: flex;
  background: rgba(20, 12, 40, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bot);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 0 8px; cursor: pointer; display: flex;
  flex-direction: column; align-items: center; gap: 2px;
  transition: color 0.15s ease;
}
.tab .tab-ico { font-size: 22px; filter: grayscale(0.4); transition: 0.15s; }
.tab .tab-lbl { font-size: 11px; font-weight: 700; }
.tab.active { color: var(--txt); }
.tab.active .tab-ico { filter: none; transform: translateY(-1px); }

/* ---------- Game overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(900px 500px at 50% 0%, var(--bg2), var(--bg) 70%);
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 14px) 18px calc(var(--safe-bot) + 18px);
  animation: fade 0.2s ease;
}
.overlay-head { display: flex; align-items: center; justify-content: space-between; }
.overlay-head h2 { font-size: 19px; font-weight: 900; }
.close-x { background: none; border: none; color: var(--muted); font-size: 30px; cursor: pointer; line-height: 1; }
.game-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.game-prompt { font-size: 17px; color: var(--muted); max-width: 320px; line-height: 1.4; }

/* Reaction game */
.react-pad {
  width: 100%; flex: 1; border-radius: 24px; display: flex;
  align-items: center; justify-content: center; font-size: 24px; font-weight: 900;
  margin: 16px 0; transition: background 0.1s; min-height: 240px;
}
.react-pad.wait { background: #b91c1c; }
.react-pad.go { background: var(--good); color: #04210f; }
.react-pad.idle { background: var(--card-solid); }

/* Big result */
.result-name {
  font-size: 44px; font-weight: 900;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: pop 0.5s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.result-crown { font-size: 64px; animation: bounce 0.8s ease infinite alternate; }
@keyframes bounce { to { transform: translateY(-12px); } }

/* Wheel */
.wheel-wrap { position: relative; width: 280px; height: 280px; margin: 8px auto; }
.wheel {
  width: 100%; height: 100%; border-radius: 50%;
  border: 6px solid rgba(255,255,255,0.15);
  transition: transform 4.5s cubic-bezier(.12,.7,.12,1);
}
.wheel-pointer {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  font-size: 36px; z-index: 2; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.4));
}
.wheel-hub {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 44px; height: 44px; background: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}

/* dice / coin / countdown big */
.big-emoji { font-size: 120px; }
.dice { font-size: 130px; animation: shake 0.5s ease; }
@keyframes shake { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-12deg)} 75%{transform:rotate(12deg)} }
.coin { font-size: 130px; }
.spin-anim { animation: flip 0.4s linear infinite; }
@keyframes flip { 0%{transform:rotateY(0)} 100%{transform:rotateY(360deg)} }

.countdown { font-size: 96px; font-weight: 900; color: var(--accent); }

/* Tap-race buttons (whack) */
.tap-targets { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; margin: 10px 0; }
.tap-target {
  border-radius: 18px; padding: 22px 8px; font-size: 18px; font-weight: 800;
  border: none; color: #fff; cursor: pointer; position: relative;
  transition: transform 0.06s;
}
.tap-target:active { transform: scale(0.94); }
.tap-target .cnt { display:block; font-size: 30px; margin-top: 4px; }

/* hold-the-button */
.hold-btn {
  width: 220px; height: 220px; border-radius: 50%; border: none;
  font-size: 22px; font-weight: 900; color: #fff; cursor: pointer;
  background: radial-gradient(circle at 30% 30%, var(--accent2), #c81e5b);
  box-shadow: 0 10px 30px rgba(255,93,143,0.4);
  transition: transform 0.1s;
}
.hold-btn:active { transform: scale(0.93); }

.toast {
  position: fixed; bottom: calc(var(--safe-bot) + 80px); left: 50%; transform: translateX(-50%);
  background: var(--card-solid); border: 1px solid var(--line); color: var(--txt);
  padding: 12px 20px; border-radius: 999px; font-weight: 700; font-size: 14px;
  z-index: 100; animation: toastIn 0.3s ease; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%,0); } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }

.crown-tag { font-size: 12px; color: var(--accent); font-weight: 800; }
.muted-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 8px; line-height: 1.4; }
