/* EOS Casino — Telegram Mini App (fixed brand palette, not Telegram theme) */

:root {
  --app-bg: #0e1117;
  --app-surface: #151a23;
  --app-card: #1c2430;
  --app-primary: #2aabee;
  --app-accent: #f5c542;
  --app-success: #32d583;
  --app-danger: #f04438;
  --app-text: #ffffff;
  --app-muted: #9aa4b2;
  --app-border: rgba(255, 255, 255, 0.08);

  --app-radius-sm: 8px;
  --app-radius: 12px;
  --app-radius-lg: 16px;
  --app-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --app-header-h: 56px;
  --app-nav-h: 64px;
  --app-max-w: 720px;
  --app-transition: 0.2s ease;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--app-bg);
  color: var(--app-text);
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--app-bg);
  color: var(--app-text);
  overflow-x: hidden;
}

a {
  color: var(--app-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img,
svg {
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

/* Never inherit Telegram theme colors into controls */
button {
  color: var(--app-text);
  background-color: var(--app-card);
}

/* Force brand colors — ignore Telegram theme injection on shell */
html,
body,
.app-body,
.app-shell,
.app-header,
.app-view,
.bottom-nav,
.modal,
.gate-page {
  background-color: var(--app-bg) !important;
  color: var(--app-text) !important;
}

/* Kill Telegram CSS variables if injected */
html {
  --tg-theme-bg-color: #0e1117 !important;
  --tg-theme-secondary-bg-color: #151a23 !important;
  --tg-theme-text-color: #ffffff !important;
  --tg-theme-hint-color: #9aa4b2 !important;
  --tg-theme-link-color: #2aabee !important;
  --tg-theme-button-color: #2aabee !important;
  --tg-theme-button-text-color: #ffffff !important;
  --tg-color-scheme: dark !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  background: var(--app-bg);
}

.app-shell--loading {
  align-items: center;
  justify-content: center;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--app-header-h);
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  color: var(--app-text);
  text-decoration: none;
}

.app-header__brand img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.app-header__spacer {
  flex: 1;
}

.balance-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 6px 10px;
  background: var(--app-card);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  min-width: 0;
}

.balance-pill__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--app-muted);
}

.balance-pill__value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: var(--app-radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--app-transition), opacity var(--app-transition), background var(--app-transition), border-color var(--app-transition);
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  text-align: center;
  text-decoration: none;
  box-shadow: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--app-primary) !important;
  border-color: var(--app-primary) !important;
  color: #ffffff !important;
}

.btn--accent {
  background: var(--app-accent) !important;
  border-color: var(--app-accent) !important;
  color: #0e1117 !important;
}

/* Visible secondary action — never transparent on dark UI */
.btn--ghost {
  background: var(--app-card) !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  color: var(--app-text) !important;
}

.btn--ghost:hover,
.btn--ghost:focus-visible {
  border-color: rgba(42, 171, 238, 0.55) !important;
  background: #223044 !important;
}

/* Profile / list menu rows */
.btn--menu {
  background: var(--app-card) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: var(--app-text) !important;
  justify-content: space-between;
  font-weight: 600;
  padding: 14px 16px;
}

.btn--menu::after {
  content: "›";
  color: var(--app-muted);
  font-size: 18px;
  line-height: 1;
}

.btn--back {
  background: var(--app-card) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: var(--app-text) !important;
  justify-content: flex-start;
  gap: 8px;
}

.btn--sm {
  padding: 8px 12px;
  font-size: 13px;
}

.btn--block {
  width: 100%;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--app-radius-sm);
  background: var(--app-card);
  color: var(--app-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Main view */
.app-view {
  flex: 1;
  width: 100%;
  max-width: var(--app-max-w);
  margin: 0 auto;
  padding: 16px 16px calc(var(--app-nav-h) + var(--safe-bottom) + 16px);
  background: var(--app-bg);
}

.app-view--desktop-nav {
  padding-bottom: 24px;
}

.page-title {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
}

.page-subtitle {
  margin: -8px 0 20px;
  color: var(--app-muted);
  font-size: 14px;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 110;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  min-height: var(--app-nav-h);
  padding-bottom: var(--safe-bottom);
  background: var(--app-surface);
  border-top: 1px solid var(--app-border);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  font-size: 11px;
  color: var(--app-muted);
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: color var(--app-transition);
}

.bottom-nav__item svg {
  width: 22px;
  height: 22px;
}

.bottom-nav__item.is-active {
  color: var(--app-primary);
}

.bottom-nav__item.is-active svg {
  stroke: var(--app-primary);
}

/* Cards & grids */
.card {
  background: var(--app-card);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card--interactive {
  cursor: pointer;
  transition: border-color var(--app-transition), transform var(--app-transition);
}

.card--interactive:hover {
  border-color: rgba(42, 171, 238, 0.35);
}

.card--interactive:active {
  transform: scale(0.99);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.game-card {
  position: relative;
  overflow: hidden;
}

.game-card__icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--app-primary), #1a7fb8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 10px;
}

.game-card__title {
  font-weight: 700;
  margin: 0 0 4px;
}

.game-card__desc {
  margin: 0;
  font-size: 13px;
  color: var(--app-muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge--demo {
  background: rgba(245, 197, 66, 0.15);
  color: var(--app-accent);
}

.badge--real {
  background: rgba(50, 213, 131, 0.15);
  color: var(--app-success);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--app-border);
}

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

.stat-row__label {
  color: var(--app-muted);
  font-size: 14px;
}

.stat-row__value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.form-field {
  margin-bottom: 14px;
}

.form-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--app-muted);
}

.form-field input,
.form-field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  background: var(--app-surface);
  color: var(--app-text);
}

.form-field input:focus,
.form-field select:focus {
  outline: 2px solid rgba(42, 171, 238, 0.45);
  outline-offset: 0;
}

.segmented {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: var(--app-surface);
  border-radius: var(--app-radius-sm);
  border: 1px solid var(--app-border);
}

.segmented__btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--app-muted);
  font-weight: 600;
  cursor: pointer;
}

.segmented__btn.is-active {
  background: var(--app-card);
  color: var(--app-text);
}

.alert {
  padding: 12px 14px;
  border-radius: var(--app-radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
}

.alert--error {
  background: rgba(240, 68, 56, 0.12);
  border: 1px solid rgba(240, 68, 56, 0.35);
  color: #ffb4ae;
}

.alert--success {
  background: rgba(50, 213, 131, 0.12);
  border: 1px solid rgba(50, 213, 131, 0.35);
  color: #9ef0c8;
}

.alert--info {
  background: rgba(42, 171, 238, 0.12);
  border: 1px solid rgba(42, 171, 238, 0.35);
  color: #9edcff;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--app-border);
  border-top-color: var(--app-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  background: linear-gradient(90deg, var(--app-card) 25%, var(--app-surface) 50%, var(--app-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--app-radius-sm);
  min-height: 48px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--app-muted);
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--app-border);
}

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

.list-item__meta {
  flex: 1;
  min-width: 0;
}

.list-item__title {
  font-weight: 600;
  margin: 0 0 2px;
}

.list-item__sub {
  margin: 0;
  font-size: 12px;
  color: var(--app-muted);
}

.amount--pos {
  color: var(--app-success);
}

.amount--neg {
  color: var(--app-danger);
}

/* Roulette */
.roulette-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.roulette-wheel-wrap {
  position: relative;
  width: min(280px, 85vw);
  aspect-ratio: 1;
}

.roulette-wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 6px solid var(--app-accent);
  background: conic-gradient(
    #f04438 0deg 9.73deg,
    #1c2430 9.73deg 19.46deg,
    #f04438 19.46deg 29.19deg,
    #1c2430 29.19deg 38.92deg,
    #f04438 38.92deg 48.65deg,
    #1c2430 48.65deg 58.38deg,
    #f04438 58.38deg 68.11deg,
    #1c2430 68.11deg 77.84deg,
    #f04438 77.84deg 87.57deg,
    #1c2430 87.57deg 97.3deg,
    #f04438 97.3deg 107.03deg,
    #1c2430 107.03deg 116.76deg,
    #f04438 116.76deg 126.49deg,
    #1c2430 126.49deg 136.22deg,
    #f04438 136.22deg 145.95deg,
    #1c2430 145.95deg 155.68deg,
    #f04438 155.68deg 165.41deg,
    #1c2430 165.41deg 175.14deg,
    #f04438 175.14deg 184.87deg,
    #1c2430 184.87deg 194.6deg,
    #f04438 194.6deg 204.33deg,
    #1c2430 204.33deg 214.06deg,
    #f04438 214.06deg 223.79deg,
    #1c2430 223.79deg 233.52deg,
    #f04438 233.52deg 243.25deg,
    #1c2430 243.25deg 252.98deg,
    #f04438 252.98deg 262.71deg,
    #1c2430 262.71deg 272.44deg,
    #f04438 272.44deg 282.17deg,
    #1c2430 282.17deg 291.9deg,
    #f04438 291.9deg 301.63deg,
    #1c2430 301.63deg 311.36deg,
    #f04438 311.36deg 321.09deg,
    #1c2430 321.09deg 330.82deg,
    #f04438 330.82deg 340.55deg,
    #1c2430 340.55deg 350.28deg,
    #32d583 350.28deg 360deg
  );
  transition: transform 4s cubic-bezier(0.15, 0.85, 0.25, 1);
  box-shadow: var(--app-shadow);
}

.roulette-wheel.is-spinning {
  transition-duration: 4s;
}

.roulette-pointer {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 18px solid var(--app-accent);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  z-index: 2;
}

.roulette-bets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.roulette-bet {
  padding: 12px;
  border-radius: var(--app-radius-sm);
  border: 1px solid var(--app-border);
  background: var(--app-surface);
  font-weight: 600;
  cursor: pointer;
}

.roulette-bet.is-selected {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 1px var(--app-primary);
}

.roulette-bet--red {
  color: #ff8a82;
}

.roulette-bet--black {
  color: #cbd5e1;
}

.roulette-bet--green {
  color: var(--app-success);
}

.roulette-result {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  min-height: 28px;
}

/* Mines */
.mines-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-width: 360px;
  margin: 0 auto 16px;
}

.mines-cell {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--app-radius-sm);
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  font-size: 20px;
  cursor: pointer;
  transition: background var(--app-transition), transform var(--app-transition);
}

.mines-cell:disabled {
  cursor: default;
}

.mines-cell--safe {
  background: rgba(50, 213, 131, 0.2);
  border-color: rgba(50, 213, 131, 0.45);
}

.mines-cell--mine {
  background: rgba(240, 68, 56, 0.25);
  border-color: rgba(240, 68, 56, 0.5);
  animation: mine-shake 0.4s ease;
}

.mines-cell--hidden:active:not(:disabled) {
  transform: scale(0.95);
}

@keyframes mine-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

.mines-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.mines-meta .card {
  flex: 1;
  margin: 0;
  text-align: center;
}

.mines-meta__val {
  font-size: 20px;
  font-weight: 700;
}

.mines-meta__lbl {
  font-size: 11px;
  color: var(--app-muted);
  text-transform: uppercase;
}

/* Gate */
.gate-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: radial-gradient(ellipse at top, #1c2430 0%, var(--app-bg) 55%);
}

.gate-page__logo {
  width: 88px;
  height: 88px;
  margin-bottom: 24px;
  border-radius: 22px;
  box-shadow: var(--app-shadow);
}

.gate-page h1 {
  margin: 0 0 12px;
  font-size: 22px;
}

.gate-page p {
  margin: 0 0 28px;
  max-width: 320px;
  color: var(--app-muted);
  line-height: 1.55;
}

.legal-doc {
  max-width: 720px;
  margin: 0 auto;
}

.legal-doc h2 {
  font-size: 18px;
  margin: 24px 0 8px;
}

.legal-doc p,
.legal-doc li {
  color: var(--app-muted);
  font-size: 14px;
}

.legal-doc ul {
  padding-left: 20px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--app-card);
  border: 2px solid var(--app-border);
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.referral-link-box {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.referral-link-box input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--app-radius-sm);
  border: 1px solid var(--app-border);
  background: var(--app-surface);
  color: var(--app-text);
  font-size: 13px;
}

#ton-connect-button {
  margin: 12px 0;
}

.desktop-sidebar {
  display: none;
}

/* Breakpoints */
@media (min-width: 360px) {
  .app-view {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (min-width: 480px) {
  :root {
    --app-max-w: 480px;
  }

  .page-title {
    font-size: 24px;
  }
}

@media (min-width: 768px) {
  :root {
    --app-max-w: 640px;
    --app-nav-h: 0px;
  }

  .bottom-nav {
    display: none;
  }

  .desktop-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
  }

  .desktop-nav .btn {
    font-size: 14px;
  }

  .app-view {
    padding-bottom: 32px;
  }

  .app-view--desktop-nav {
    padding-bottom: 32px;
  }
}

@media (min-width: 1024px) {
  :root {
    --app-max-w: 960px;
  }

  .app-layout-wide {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
  }

  .desktop-sidebar {
    display: block;
    position: sticky;
    top: calc(var(--app-header-h) + 16px);
    align-self: start;
    padding: 16px;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
  }

  .desktop-sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .desktop-sidebar a,
  .desktop-sidebar button {
    text-align: left;
    padding: 10px 12px;
    border-radius: var(--app-radius-sm);
    color: var(--app-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
  }

  .desktop-sidebar a.is-active,
  .desktop-sidebar button.is-active {
    background: var(--app-card);
    color: var(--app-primary);
  }

  .bottom-nav {
    display: none;
  }
}

@media (min-width: 1440px) {
  :root {
    --app-max-w: 1040px;
  }

  body {
    font-size: 16px;
  }
}

@media (max-width: 767px) {
  .desktop-nav {
    display: none;
  }
}

/* Telegram Stars packages */
.stars-packages {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.stars-pkg {
  border: 1px solid var(--app-border);
  background: var(--app-surface);
  color: var(--app-text);
  border-radius: 12px;
  padding: 14px 8px;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
.stars-pkg:hover {
  border-color: var(--app-primary);
}
.stars-pkg.is-selected {
  border-color: var(--app-accent);
  background: rgba(245, 197, 66, 0.08);
  box-shadow: inset 0 0 0 1px rgba(245, 197, 66, 0.35);
}
.stars-pkg__amount {
  font-weight: 700;
  font-size: 15px;
}
@media (max-width: 480px) {
  .stars-packages {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.header-balances {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 58%;
  overflow: hidden;
}
.balance-pill--real {
  border-color: rgba(245, 197, 66, 0.35);
}
.balance-pill--real .balance-pill__label {
  color: var(--app-accent);
}
@media (max-width: 480px) {
  .header-balances {
    max-width: 52%;
    gap: 4px;
  }
  .balance-pill {
    padding: 4px 8px;
  }
  .balance-pill__label {
    font-size: 10px;
  }
  .balance-pill__value {
    font-size: 11px;
  }
}

/* Legal documents */
.legal-doc {
  background: var(--app-card);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  padding: 16px;
}
.legal-body {
  color: var(--app-text);
  font-size: 14px;
  line-height: 1.6;
}
.legal-body h2 {
  margin: 22px 0 10px;
  font-size: 17px;
  color: var(--app-accent);
}
.legal-body h3 {
  margin: 16px 0 8px;
  font-size: 15px;
}
.legal-body p,
.legal-body li {
  color: #d7dee8;
  margin: 0 0 10px;
}
.legal-body ul,
.legal-body ol {
  padding-left: 20px;
  margin: 0 0 12px;
}
.legal-body strong {
  color: #fff;
}
.profile-docs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
