:root {
  --bg: #0d1120;
  --surface: #161b2e;
  --surface-2: #1e2540;
  --surface-3: #283055;
  --border: rgba(255, 255, 255, 0.07);
  --text: #eef1f8;
  --muted: #8d95b0;
  --gold: #f5b942;
  --gold-2: #e8941c;
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.16);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.16);
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.2);
  --felt: #0f5132;
  --felt-2: #0b3d26;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tg-top: var(--tg-content-safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { min-height: 100vh; min-height: var(--tg-viewport-stable-height, 100vh); }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
input { font: inherit; color: inherit; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; word-break: break-all; }
.muted { color: var(--muted); }
.win { color: var(--green); }
.lose { color: var(--red); }
.tnum { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-top) + var(--tg-top)) 16px 10px;
  background: linear-gradient(var(--bg) 70%, rgba(13, 17, 32, 0));
}
.profile { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #a855f7);
}
.profile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 7px 14px 7px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 700; font-variant-numeric: tabular-nums;
  transition: transform .15s;
}
.balance.bump { transform: scale(1.08); }
.balance.up #balance-value { color: var(--green); }
.balance.down #balance-value { color: var(--red); }
.coin-icon {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--gold) 45%, var(--gold-2));
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.2);
}

/* ------------------------------------------------------------------ Layout */
.view {
  max-width: 520px; margin: 0 auto;
  padding: 4px 16px calc(28px + var(--safe-bottom));
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
h1 { font-size: 24px; margin: 6px 0 2px; letter-spacing: -0.02em; }
h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.back-link { color: var(--gold); font-weight: 600; padding: 4px 0; margin-bottom: 4px; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 0 12px; }
.view-head .sub { color: var(--muted); font-size: 13px; }
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 20px; }

/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600; transition: transform .08s, filter .15s, background .15s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold-2)); color: #1d1405; border: 0; }
.btn.green { background: linear-gradient(180deg, #2fd46c, #16a34a); color: #04210f; border: 0; }
.btn.red { background: linear-gradient(180deg, #f87171, #dc2626); color: #fff; border: 0; }
.btn.blue { background: linear-gradient(180deg, #60a5fa, #2563eb); color: #fff; border: 0; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 17px; border-radius: 14px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.seg { display: flex; padding: 3px; gap: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.seg button { flex: 1; min-height: 36px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--muted); transition: background .15s, color .15s; }
.seg button.on { background: var(--surface-3); color: var(--text); }
.field-label { font-size: 12px; color: var(--muted); margin: 0 0 6px 2px; }

/* ------------------------------------------------------------------ Einsatz */
.bet { display: grid; gap: 8px; }
.bet-main { display: flex; gap: 6px; }
.bet-input {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
}
.bet-input input { width: 100%; min-width: 0; height: 44px; border: 0; outline: 0; background: none; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.bet-input:focus-within { border-color: var(--gold); }
.bet-main .btn { min-height: 46px; padding: 0 12px; min-width: 46px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 1 0 auto; min-height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--muted);
}
.chip.on { color: var(--text); border-color: var(--gold); }

/* ------------------------------------------------------------------ Startseite */
.hero { margin: 4px 0 14px; }
.hero p { margin: 2px 0 0; color: var(--muted); }
.daily {
  display: flex; align-items: center; gap: 12px; padding: 14px; margin-bottom: 14px;
  border-radius: var(--radius); border: 1px solid rgba(245, 185, 66, .35);
  background: linear-gradient(120deg, rgba(245, 185, 66, .18), rgba(168, 85, 247, .12));
}
.daily .gift { font-size: 30px; }
.daily { text-align: left; width: 100%; }
.daily .txt { flex: 1; }
.daily .txt b { display: block; }
.daily .txt span { font-size: 13px; color: var(--muted); }
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game-tile {
  position: relative; overflow: hidden; text-align: left;
  min-height: 118px; padding: 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; justify-content: flex-end; gap: 2px;
  transition: transform .1s;
}
.game-tile:active { transform: scale(.97); }
.game-tile .emoji { position: absolute; top: 10px; right: 12px; font-size: 38px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.4)); }
.game-tile b { font-size: 17px; }
.game-tile span { font-size: 12px; color: var(--muted); }
.game-tile.wide { grid-column: span 2; min-height: 92px; }
.game-tile::before { content: ""; position: absolute; inset: 0; opacity: .5; background: var(--glow); }
.game-tile > * { position: relative; }
.badge { position: absolute; top: 10px; left: 12px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--gold); color: #1d1405; }
.links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.link-tile { padding: 12px 6px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); display: grid; justify-items: center; gap: 4px; font-size: 13px; font-weight: 600; }
.link-tile .emoji { font-size: 22px; }

/* ------------------------------------------------------------------ Ergebnis-Banner */
.banner { text-align: center; padding: 10px 12px; border-radius: 12px; font-weight: 700; min-height: 44px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); }
.banner.win { background: var(--green-dim); border-color: rgba(34,197,94,.4); color: #86efac; }
.banner.lose { background: var(--red-dim); border-color: rgba(239,68,68,.35); color: #fca5a5; }
.banner.push { background: var(--blue-dim); border-color: rgba(59,130,246,.4); color: #bfdbfe; }
.banner small { display: block; font-weight: 500; font-size: 12px; opacity: .8; }
.pop { animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }

/* ------------------------------------------------------------------ Coinflip */
.coin-stage { height: 190px; display: grid; place-items: center; perspective: 900px; }
.coin { width: 140px; height: 140px; position: relative; transform-style: preserve-3d; transition: transform 1.4s cubic-bezier(.2, .7, .15, 1); }
.coin .face {
  position: absolute; inset: 0; border-radius: 50%; backface-visibility: hidden;
  display: grid; place-items: center; font-size: 54px;
  border: 6px solid rgba(0,0,0,.15);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.25), 0 14px 30px rgba(0,0,0,.45);
}
.coin .front { background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--gold) 50%, var(--gold-2)); }
.coin .back { background: radial-gradient(circle at 35% 30%, #f1f5f9, #b8c2d6 50%, #7d889f); transform: rotateY(180deg); }
.history { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 28px; }
.history span { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--surface); border: 2px solid var(--border); }
.history span.w { border-color: var(--green); }
.history span.l { border-color: var(--red); opacity: .7; }
.history .m { width: auto; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }

/* ------------------------------------------------------------------ Towers */
.tower { display: grid; gap: 6px; padding: 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.tower-row { display: grid; grid-template-columns: 64px 1fr; gap: 6px; align-items: center; }
.tower-row .mult { font-size: 12px; font-weight: 700; color: var(--muted); text-align: right; padding-right: 4px; font-variant-numeric: tabular-nums; }
.tower-row.current .mult { color: var(--gold); }
.tower-fields { display: grid; gap: 6px; }
.tile {
  height: 36px; border-radius: 10px; font-size: 19px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); transition: transform .1s, background .2s;
}
.tile.active { background: var(--surface-3); border-color: rgba(245,185,66,.55); box-shadow: 0 0 0 1px rgba(245,185,66,.25), 0 0 18px rgba(245,185,66,.15); }
.tile.active:active { transform: scale(.94); }
.tile.locked { opacity: .45; }
.tile.safe { background: var(--green-dim); border-color: rgba(34,197,94,.5); }
.tile.boom { background: var(--red-dim); border-color: var(--red); animation: shake .4s; }
.tile.bomb { background: rgba(239,68,68,.08); }
.tile.dim { opacity: .55; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.tower-info { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.tower-info b { color: var(--text); }

/* ------------------------------------------------------------------ Plinko */
.plinko-wrap { position: relative; border-radius: var(--radius); background: radial-gradient(ellipse at top, #1d2547, var(--surface) 70%); border: 1px solid var(--border); padding: 8px 4px 6px; }
.plinko-wrap canvas { display: block; width: 100%; }
.recent { display: flex; gap: 6px; overflow: hidden; min-height: 26px; }
.recent span { flex: none; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #111; animation: pop .3s; }

/* ------------------------------------------------------------------ Keno */
.keno-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.kn {
  position: relative; height: 44px; border-radius: 10px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--border); transition: transform .1s, background .15s;
}
.kn:active { transform: scale(.94); }
.kn.pick { background: var(--surface-3); border-color: var(--gold); color: var(--gold); }
.kn.drawn { background: var(--blue-dim); border-color: rgba(59,130,246,.6); }
.kn.hit { background: var(--green); border-color: var(--green); color: #04210f; animation: pop .3s; }
.kn.hit::after { content: "💎"; position: absolute; top: -7px; right: -4px; font-size: 13px; }
.kn.miss { border-color: rgba(239,68,68,.6); color: #fca5a5; background: var(--surface); }
.paytable { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-height: 40px; }
.paytable::-webkit-scrollbar { display: none; }
.paytable div { flex: none; padding: 4px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); text-align: center; font-size: 12px; }
.paytable div b { display: block; font-size: 13px; }
.paytable div.hit { border-color: var(--green); background: var(--green-dim); }

/* ------------------------------------------------------------------ Blackjack */
.table {
  border-radius: 22px; padding: 16px 12px; min-height: 290px;
  background: radial-gradient(ellipse at center, #17734a, var(--felt) 55%, var(--felt-2));
  border: 3px solid #5b3a1e; box-shadow: inset 0 0 40px rgba(0,0,0,.45);
  display: grid; gap: 14px; align-content: space-between;
}
.seat { display: grid; gap: 8px; justify-items: center; }
.seat-label { font-size: 12px; font-weight: 700; color: rgba(255,255,255,.75); display: flex; gap: 8px; align-items: center; }
.score { background: rgba(0,0,0,.35); padding: 2px 9px; border-radius: 999px; font-variant-numeric: tabular-nums; color: #fff; }
.hands { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hand { display: grid; gap: 6px; justify-items: center; padding: 6px; border-radius: 14px; border: 2px solid transparent; }
.hand.active { border-color: rgba(245,185,66,.7); background: rgba(0,0,0,.12); }
.cards { display: flex; min-height: 78px; }
.pcard {
  width: 54px; height: 78px; border-radius: 8px; margin-left: -18px; flex: none;
  background: #fff; color: #111; box-shadow: 0 4px 10px rgba(0,0,0,.35);
  display: grid; grid-template-rows: auto 1fr; padding: 4px 6px; font-weight: 800; line-height: 1;
}
.pcard:first-child { margin-left: 0; }
.pcard .r { font-size: 17px; }
.pcard .s { font-size: 26px; align-self: center; justify-self: center; }
.pcard.red { color: #d61f2c; }
.pcard.back { background: repeating-linear-gradient(45deg, #2c3e8f 0 6px, #22327a 6px 12px); border: 3px solid #fff; }
.pcard.new { animation: deal .35s cubic-bezier(.2,.9,.3,1.2); }
@keyframes deal { from { transform: translate(40px, -60px) rotate(12deg); opacity: 0; } }
.hand-result { font-size: 12px; font-weight: 800; padding: 2px 10px; border-radius: 999px; }
.hand-result.win, .hand-result.blackjack { background: var(--green); color: #04210f; }
.hand-result.lose { background: var(--red); color: #fff; }
.hand-result.push { background: var(--blue); color: #fff; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ------------------------------------------------------------------ Listen */
.list { display: grid; gap: 6px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); text-align: left; width: 100%; }
.list-item.me { border-color: var(--gold); }
.list-item .rank { width: 28px; text-align: center; font-weight: 800; color: var(--muted); }
.list-item .name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.kv { display: grid; gap: 4px; }
.kv .k { font-size: 12px; color: var(--muted); }
.text-input { width: 100%; height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); outline: 0; }
.text-input:focus { border-color: var(--gold); }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ------------------------------------------------------------------ Toast & Sheet */
.toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-top) + var(--tg-top)); z-index: 50;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  background: #2a3152; border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: pop .25s;
}
.toast.error { background: #4a1d24; border-color: rgba(239,68,68,.45); }
.toast.success { background: #143a26; border-color: rgba(34,197,94,.45); }
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow-y: auto;
  padding: 8px 16px calc(20px + var(--safe-bottom)); border-radius: 20px 20px 0 0;
  background: var(--surface); border-top: 1px solid var(--border);
  animation: up .25s cubic-bezier(.2,.9,.3,1);
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--surface-3); margin: 0 auto 12px; }

.center-screen { min-height: 70vh; display: grid; place-items: center; text-align: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--gold); animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
