:root {
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --tg-section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --tg-text: var(--tg-theme-text-color, #000000);
  --tg-hint: var(--tg-theme-hint-color, #8e8e93);
  --tg-link: var(--tg-theme-link-color, #007aff);
  --tg-button: var(--tg-theme-button-color, #007aff);
  --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-separator: rgba(60, 60, 67, 0.29);
  --win: #34c759;
  --lose: #ff3b30;

  /* Floating glass dock tokens (light), matched to the Telegram Mini App
     reference tab bar: blurred glass pill with a sliding selection. */
  --dock-glass: rgba(242, 242, 242, .6);
  --dock-glass-shadow: 0 8px 30px rgba(0, 0, 0, .09), 0 2px 8px rgba(0, 0, 0, .045);
  --dock-glass-rim: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 0 0 .8px rgba(255, 255, 255, .35), inset 0 0 0 1.6px rgba(0, 0, 0, .02);
  --dock-selection: rgba(0, 0, 0, .05);
  --dock-label: #1a1a1a;
  --dock-accent: #008bff;
  --dock-h: calc(78px + max(25px, env(safe-area-inset-bottom, 0px)));
}

:root[data-theme="dark"] {
  --dock-glass: rgba(29, 29, 29, .6);
  --dock-glass-shadow: 0 8px 30px rgba(0, 0, 0, .34), 0 2px 8px rgba(0, 0, 0, .2);
  --dock-glass-rim: inset 0 1px 0 rgba(255, 255, 255, .08), inset 0 0 0 .8px rgba(255, 255, 255, .08);
  --dock-selection: rgba(255, 255, 255, .1);
  --dock-label: #f5f5f5;
  --dock-accent: #0091ff;
}

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

html, body {
  margin: 0;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--dock-h);
}

#pages {
  padding-top: 16px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.balance-card {
  margin: 0 16px 12px;
  background: var(--tg-section-bg);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.balance-label {
  font-size: 15px;
  color: var(--tg-hint);
}

.balance-value {
  font-size: 17px;
  font-weight: 600;
  color: var(--tg-link);
}

.stage-card {
  margin: 0 16px 12px;
  background: var(--tg-section-bg);
  border-radius: 14px;
  padding: 28px 16px 22px;
  text-align: center;
}

.result-emoji {
  font-size: 64px;
  line-height: 1;
  transition: transform 0.15s;
}

.result-emoji.spinning {
  animation: spin 0.08s linear infinite;
}

@keyframes spin {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.12) rotate(8deg); }
  100% { transform: scale(1) rotate(-8deg); }
}

.result-text {
  margin-top: 10px;
  font-size: 14px;
  color: var(--tg-hint);
  min-height: 18px;
}

.result-text.win { color: var(--win); font-weight: 600; }
.result-text.lose { color: var(--lose); font-weight: 600; }

.section {
  margin: 0 16px 12px;
}

.section-header {
  font-size: 13px;
  font-weight: 400;
  color: var(--tg-hint);
  letter-spacing: 0.2px;
  padding: 0 4px 6px;
}

.segmented {
  display: flex;
  background: rgba(118, 118, 128, 0.12);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.segment {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 7px;
  font-size: 20px;
  padding: 7px 0;
  cursor: pointer;
  color: var(--tg-text);
  transition: background 0.15s;
}

.segment.active {
  background: var(--tg-section-bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.list-card {
  background: var(--tg-section-bg);
  border-radius: 14px;
  overflow: hidden;
}

.list-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--tg-separator);
}

.list-row:last-child {
  border-bottom: none;
}

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.stepper-btn {
  background: rgba(118, 118, 128, 0.12);
  border: none;
  color: var(--tg-link);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1;
}

.bet-amount {
  font-size: 22px;
  font-weight: 600;
  min-width: 90px;
  text-align: center;
}

.quick-row {
  display: flex;
  gap: 8px;
}

#depositPresets {
  margin-bottom: 12px;
}

.quick {
  flex: 1;
  background: rgba(118, 118, 128, 0.12);
  border: none;
  color: var(--tg-text);
  padding: 8px 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.action-area {
  margin: 4px 16px 20px;
}

.play-btn {
  width: 100%;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.play-btn:disabled {
  opacity: 0.5;
}

.history-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--tg-separator);
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item.win { color: var(--win); }
.history-item.lose { color: var(--tg-hint); }

.history-empty {
  padding: 16px;
  text-align: center;
  color: var(--tg-hint);
  font-size: 13px;
}

/* Profile page */

.profile-card {
  text-align: center;
  padding: 24px 16px 8px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--tg-section-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

.profile-name {
  font-size: 20px;
  font-weight: 600;
}

.profile-username {
  font-size: 14px;
  color: var(--tg-hint);
  margin-top: 2px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
}

.stat-value {
  font-weight: 600;
  color: var(--tg-link);
}

.hint-text {
  padding: 8px 20px;
  text-align: center;
  color: var(--tg-hint);
  font-size: 12px;
}

/* Floating glass dock — matches the bottom tab bar pattern used by
   nftshniy's Telegram Mini App (blurred pill + sliding selection). */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  padding: 16px 25px max(25px, env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.tabbar__pill {
  position: relative;
  flex: 1;
  display: flex;
  padding: 3px 4px;
  border-radius: 31px;
  overflow: hidden;
  background: var(--dock-glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.7);
  backdrop-filter: blur(18px) saturate(1.7);
  box-shadow: var(--dock-glass-shadow), var(--dock-glass-rim);
  pointer-events: auto;
}

.tabbar__sel {
  position: absolute;
  top: 4px;
  left: 0;
  height: 54px;
  border-radius: 28px;
  background: var(--dock-selection);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1), width .3s cubic-bezier(.4, 0, .2, 1);
}

.tab {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 6.5px 8px;
  border: none;
  background: none;
  color: var(--dock-label);
  cursor: pointer;
  transition: color .2s;
}

.tab--active {
  color: var(--dock-accent);
}

.tab__icon {
  font-size: 22px;
  line-height: 30px;
  height: 30px;
}

.tab__label {
  max-width: 100%;
  font-size: 10px;
  font-weight: 700;
  line-height: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Top-up button + deposit bottom sheet */

.topup-btn {
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: flex-end;
}

.sheet-overlay.open {
  display: flex;
}

.sheet {
  width: 100%;
  background: var(--tg-secondary-bg);
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  max-height: 80vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--tg-separator);
  margin: 2px auto 14px;
}

.sheet-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 14px;
}

.deposit-pane {
  margin-top: 14px;
}

.deposit-pane .list-card {
  margin-bottom: 10px;
}

.text-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--tg-text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.text-input::placeholder {
  color: var(--tg-hint);
}

.referral-link {
  font-size: 13px;
  color: var(--tg-link);
  word-break: break-all;
}

.room-card {
  padding: 12px 16px;
  border-bottom: 1px solid var(--tg-separator);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.room-card:last-child {
  border-bottom: none;
}

.room-card-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-card-emoji {
  font-size: 24px;
}

.room-card-name {
  font-size: 14px;
  color: var(--tg-hint);
}

.room-card-bet {
  font-size: 15px;
  font-weight: 600;
}

.room-join-btn {
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.result-lottie {
  width: 120px;
  height: 120px;
  margin: 0 auto;
  display: none;
}

.result-lottie.active {
  display: block;
}
