:root {
  --bg-deep: #050f0b;
  --bg-table: #0b2218;
  --bg-panel: #0e1e17;
  --bg-elevated: #142a21;
  --border: rgba(0, 230, 118, 0.16);
  --border-strong: rgba(0, 230, 118, 0.35);
  --emerald: #00e676;
  --emerald-dark: #00b85c;
  --gold: #ffb300;
  --gold-light: #ffd54f;
  --red: #ff3b5c;
  --red-dark: #c91e3e;
  --ink: #eef7f2;
  --muted: #7da190;
  --card-ivory: #fcfcfa;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

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

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #0e2d1f 0%, var(--bg-deep) 65%);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow-x: hidden;
  user-select: none;
}

.app-shell {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  gap: 10px;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: linear-gradient(135deg, #133626, #0a1f16);
  border: 1px solid var(--border-strong);
  padding: 5px 11px;
  border-radius: 10px;
  box-shadow: 0 0 18px rgba(0, 230, 118, 0.15);
}

.brand-badge span {
  color: var(--emerald);
  margin-left: 2px;
}

.icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 230, 118, 0.08);
  border: 1px solid var(--border);
  color: var(--emerald);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 6px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
}

.icon-pill:active { transform: scale(0.95); }

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover { color: var(--ink); }

.balance-pill {
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: linear-gradient(180deg, #132c21, #0b1c15);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 6px 12px;
}

.balance-pill .cur {
  font-size: 10px;
  font-weight: 700;
  color: var(--emerald);
  letter-spacing: 0.06em;
}

.balance-pill .bal {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

/* HUD Bar */
.hud-bar {
  display: grid;
  grid-template-columns: 1fr auto 0.7fr auto 1fr;
  align-items: center;
  background: rgba(14, 30, 23, 0.88);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.hud-val {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.hud-val.mult { color: var(--emerald); }
.hud-val.gold { color: var(--gold-light); }
.hud-val.pop { transform: scale(1.22); }

.hud-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

/* Felt Table Stage */
.table-stage {
  position: relative;
  flex: 1;
  min-height: 235px;
  background: radial-gradient(ellipse at 50% 45%, #123b28 0%, #091d14 68%, #06130d 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
}

.table-glow {
  position: absolute;
  inset: -40px;
  background: radial-gradient(circle at 55% 48%, rgba(0, 230, 118, 0.12), transparent 55%);
  pointer-events: none;
}

.rank-guide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
  z-index: 1;
}

.rank-end {
  font-weight: 800;
  color: var(--ink);
}

.rank-end em {
  font-style: normal;
  font-size: 9px;
  color: var(--emerald);
  margin-left: 2px;
}

.rank-dots {
  font-size: 9px;
  opacity: 0.65;
}

.card-arena {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 0;
  z-index: 2;
}

/* Deck & Skip */
.deck-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.deck-stack {
  position: relative;
  width: 68px;
  height: 98px;
}

.deck-layer {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #0d3b26, #061b11);
  border: 1.5px solid rgba(0, 230, 118, 0.4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.deck-layer.l3 { transform: translate(-4px, 4px); opacity: 0.5; }
.deck-layer.l2 { transform: translate(-2px, 2px); opacity: 0.75; }
.deck-layer.l1 {
  background-image:
    repeating-linear-gradient(45deg, rgba(0, 230, 118, 0.14) 0 4px, transparent 4px 8px),
    linear-gradient(135deg, #0e3f28, #071e13);
}

.skip-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s, opacity 0.15s;
}

.skip-btn:hover:not(:disabled) {
  background: rgba(0, 230, 118, 0.16);
}

.skip-btn:active:not(:disabled) { transform: scale(0.95); }

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

.skip-count {
  background: rgba(0, 230, 118, 0.18);
  color: var(--emerald);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
}

/* 3D Playing Card */
.card-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card-scene {
  width: 126px;
  height: 178px;
  perspective: 1000px;
}

.card-3d {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  border-radius: 14px;
}

.card-3d.is-back {
  transform: rotateY(180deg);
}

.card-3d.flip-out {
  transform: rotateY(90deg) scale(0.94);
  transition: transform 0.16s ease-in;
}

.card-3d.win-glow {
  box-shadow: 0 0 0 2px var(--emerald), 0 0 28px rgba(0, 230, 118, 0.55);
}

.card-3d.loss-glow {
  box-shadow: 0 0 0 2px var(--red), 0 0 28px rgba(255, 59, 92, 0.6);
  animation: shake 0.36s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-2deg); }
  40% { transform: translateX(8px) rotate(2deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: var(--shadow);
}

.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, #0f3f28, #071d13);
  border: 2px solid rgba(0, 230, 118, 0.45);
  padding: 7px;
}

.back-frame {
  width: 100%;
  height: 100%;
  border-radius: 9px;
  border: 1px solid rgba(0, 230, 118, 0.35);
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.back-pattern {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(0, 230, 118, 0.14) 0 6px, transparent 6px 12px),
    repeating-linear-gradient(-45deg, rgba(0, 230, 118, 0.14) 0 6px, transparent 6px 12px);
}

.back-emblem {
  position: relative;
  z-index: 1;
  background: #071d13;
  border: 1px solid var(--emerald);
  color: var(--emerald);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.1em;
  padding: 5px 9px;
  border-radius: 8px;
}

.card-front {
  background: linear-gradient(160deg, #ffffff 0%, #f1f4f2 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 11px;
}

.card-front.suit-red { color: #e02447; }
.card-front.suit-black { color: #161d24; }

.corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: fit-content;
  line-height: 1;
}

.corner.bottom-right {
  align-self: flex-end;
  transform: rotate(180deg);
}

.c-rank {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.c-suit {
  font-size: 17px;
  margin-top: 1px;
}

.center-pip {
  font-size: 58px;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.08));
}

.stage-toast {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  animation: toastPop 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.stage-toast.win { background: var(--emerald); color: #042112; }
.stage-toast.loss { background: var(--red); color: #fff; }
.stage-toast.gold { background: linear-gradient(135deg, var(--gold), var(--gold-light)); color: #1f1400; }

@keyframes toastPop {
  from { opacity: 0; transform: translate(-50%, 8px) scale(0.85); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.hash-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 10px;
  color: var(--muted);
  z-index: 1;
}

.hash-tag {
  background: rgba(0, 230, 118, 0.12);
  color: var(--emerald);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 9px;
}

.hash-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

/* Controls Panel */
.controls-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}

.play-controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.guess-btn {
  border: none;
  border-radius: 13px;
  padding: 12px 12px;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: transform 0.12s, filter 0.15s, opacity 0.15s;
}

.guess-btn:active:not(:disabled) { transform: scale(0.97); }
.guess-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-hi {
  background: linear-gradient(180deg, #00d96f 0%, #009e4f 100%);
  color: #032111;
  box-shadow: 0 4px 16px rgba(0, 217, 111, 0.28);
}

.btn-lo {
  background: linear-gradient(180deg, #ffb829 0%, #e08200 100%);
  color: #211200;
  box-shadow: 0 4px 16px rgba(255, 179, 0, 0.25);
}

.g-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.g-arrow { font-size: 13px; }
.g-title { font-size: 13px; font-weight: 900; letter-spacing: 0.04em; }

.g-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.color-row .guess-btn {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
}

.btn-red {
  background: linear-gradient(180deg, #f23557 0%, #b81936 100%);
  box-shadow: 0 4px 14px rgba(242, 53, 87, 0.25);
}

.btn-black {
  background: linear-gradient(180deg, #273742 0%, #152028 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.cashout-btn {
  width: 100%;
  border: none;
  border-radius: 13px;
  padding: 13px 16px;
  background: linear-gradient(135deg, #ffd54f 0%, #ff9f00 100%);
  color: #1f1300;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(255, 179, 0, 0.35);
  transition: transform 0.12s, opacity 0.15s;
}

.cashout-btn:active:not(:disabled) { transform: scale(0.98); }

.cashout-btn:disabled {
  background: #1b2f26;
  color: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
}

.co-val {
  font-variant-numeric: tabular-nums;
}

/* Idle Bet Controls */
.bet-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bet-input-row {
  display: grid;
  grid-template-columns: 40px 1fr 40px 42px 42px;
  gap: 6px;
  align-items: center;
}

.step-btn, .mod-btn {
  height: 44px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.mod-btn { font-size: 13px; color: var(--emerald); }
.step-btn:active, .mod-btn:active { transform: scale(0.95); }

.bet-field {
  height: 44px;
  background: #081510;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2px 10px;
}

.bet-label {
  font-size: 8px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.bet-field input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.quick-bets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.q-btn {
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.q-btn:hover, .q-btn.active {
  background: rgba(0, 230, 118, 0.14);
  border-color: var(--emerald);
  color: var(--emerald);
}

.bet-submit-btn {
  width: 100%;
  height: 50px;
  border: none;
  border-radius: 13px;
  background: linear-gradient(180deg, #00e676 0%, #00a854 100%);
  color: #032111;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0, 230, 118, 0.32);
  transition: transform 0.12s;
}

.bet-submit-btn:active:not(:disabled) { transform: scale(0.98); }
.bet-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Card History Strip */
.history-bar {
  background: rgba(10, 24, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 7px;
}

.card-history-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.card-history-strip::-webkit-scrollbar { display: none; }

.history-empty {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.65;
  padding: 12px 0;
  width: 100%;
  text-align: center;
}

.mini-card-wrap {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.mini-card {
  width: 40px;
  height: 52px;
  border-radius: 7px;
  background: var(--card-ivory);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  font-weight: 900;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

.mini-card.suit-red { color: #e02447; }
.mini-card.suit-black { color: #161d24; }
.mini-card.is-loss { box-shadow: 0 0 0 2px var(--red); }
.mini-card.is-skip { opacity: 0.6; }

.mini-rank { font-size: 14px; }
.mini-suit { font-size: 13px; }

.mini-badge {
  font-size: 9px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.mini-badge.win { background: rgba(0, 230, 118, 0.16); color: var(--emerald); }
.mini-badge.loss { background: rgba(255, 59, 92, 0.22); color: #ff7b93; }
.mini-badge.skip { background: rgba(255, 255, 255, 0.07); color: var(--muted); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 10, 7, 0.78);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: #0d2219;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-head h3 { font-size: 16px; font-weight: 800; color: var(--emerald); }

.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.pf-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 12px;
}

.pf-field {
  margin-bottom: 10px;
}

.pf-field label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 3px;
}

.pf-field code {
  display: block;
  background: #07140e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 11px;
  color: var(--ink);
  word-break: break-all;
}
