:root {
  --felt-green: #1b4d2e;
  --felt-dark: #0f331d;
  --wood-border: #3d2314;
  --tg-theme-bg-color: #182533;

  /* Responsive Card Scale */
  --card-width: clamp(46px, 12vw, 58px);
  --card-height: clamp(66px, 17vw, 84px);
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

/* App Viewport & Mobile Gesture Lock */
html, body {
  position: fixed;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  touch-action: none;
  background-color: var(--tg-theme-bg-color);
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.online-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #4caf50;
  border-radius: 50%;
  display: inline-block;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(76, 175, 80, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

.provably-fair {
  font-size: 10px;
  color: #90a4ae;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Lobby */
.lobby-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.025) 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(315deg, rgba(255,255,255,0.018) 25%, transparent 25%) 0 0 / 22px 22px;
}

.lobby-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 30px 20px;
  border-radius: 16px;
  text-align: center;
  width: 100%;
  max-width: 320px;
  animation: fadeIn 0.4s ease-out;
}

.menu-screen {
  width: min(100%, 430px);
  text-align: center;
  animation: menuEnter 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.menu-brand {
  position: relative;
  padding: 30px 20px 24px;
}

.brand-mark {
  width: 92px;
  height: 105px;
  margin: 0 auto 25px;
  position: relative;
  transform: rotate(-4deg);
}

.brand-card {
  width: 58px;
  height: 80px;
  position: absolute;
  border-radius: 7px;
  box-shadow: 0 12px 22px rgba(0,0,0,0.38);
}

.brand-card-back {
  top: 12px;
  left: 12px;
  border: 2px solid rgba(255,255,255,0.8);
  background: repeating-linear-gradient(45deg, #8e242d 0 5px, #b93d45 5px 10px);
  transform: rotate(-16deg);
}

.brand-card-front {
  top: 0;
  left: 28px;
  padding-top: 8px;
  background: #fffdf7;
  color: #1b2026;
  font: 800 20px Georgia, serif;
  transform: rotate(10deg);
}

.brand-card-front span { display: block; color: #c7383b; font-size: 25px; }
.menu-kicker { margin: 0 0 8px; color: #e1b86a; font-size: 10px; font-weight: 800; letter-spacing: 3px; }
.menu-screen h1 { margin: 0; color: #f9f5e9; font: 700 clamp(38px, 10vw, 54px)/1 Georgia, serif; letter-spacing: 0; }
.menu-screen h1 em { color: #e1b86a; font-style: normal; }
.menu-tagline { margin: 15px auto 0; max-width: 290px; color: #aab5ae; font-size: 14px; line-height: 1.5; }
.balance-panel { display: inline-flex; align-items: baseline; gap: 6px; margin-top: 18px; padding: 8px 14px; border: 1px solid rgba(225,184,106,0.35); border-radius: 20px; color: #aab5ae; font-size: 12px; }
.balance-panel strong { color: #f2dfb1; font: 700 20px Georgia, serif; }
.menu-actions { padding: 4px 20px 24px; }
.bet-control { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; color: #b9c8bd; font-size: 12px; }
.menu-message { min-height: 18px; margin: 0 0 8px; color: #ff9b8f; font-size: 12px; }
.bet-control input, .wallet-actions input { width: 68px; border: 1px solid rgba(255,255,255,0.18); border-radius: 6px; padding: 8px; background: rgba(0,0,0,0.2); color: #fff; text-align: center; }
.wallet-actions { display: grid; gap: 8px; margin-top: 10px; }
.wallet-button { width: 100%; min-height: 42px; border-radius: 8px; padding: 10px 14px; cursor: pointer; font-size: 12px; font-weight: 700; }
.wallet-button-primary { border: 1px solid #e1b86a; background: rgba(225,184,106,0.14); color: #f2dfb1; }
.wallet-button-test { border: 1px dashed rgba(125,187,117,0.55); background: rgba(125,187,117,0.08); color: #a9d5a2; }
.wallet-button-secondary { border: 1px solid rgba(255,255,255,0.12); background: transparent; color: #aab5ae; }
.wallet-modal { background: #20352a; border: 1px solid rgba(225,184,106,0.3); text-align: left; }
.wallet-modal h2 { margin: 0 0 10px; color: #f9f5e9; font: 700 28px Georgia, serif; }
.wallet-copy { margin: 0 0 20px; color: #aab5ae; font-size: 13px; line-height: 1.45; }
.wallet-message { min-height: 18px; margin: -8px 0 12px; color: #ff9b8f; font-size: 12px; }
.wallet-input-label { display: block; margin-bottom: 7px; color: #c5d0c8; font-size: 12px; font-weight: 700; }
.wallet-input-wrap { display: flex; align-items: center; gap: 8px; border: 1px solid rgba(255,255,255,0.18); border-radius: 7px; padding: 0 12px; background: rgba(0,0,0,0.2); color: #f2dfb1; }
.wallet-input-wrap input { width: 100%; border: 0; outline: 0; padding: 12px 0; background: transparent; color: #fff; font-size: 18px; }
.wallet-submit { margin-top: 16px; }
.menu-play { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 12px 16px; border-radius: 8px; background: #d7a746; color: #182018; box-shadow: 0 8px 20px rgba(0,0,0,0.25); }
.menu-play:hover:not(:disabled) { background: #efc35f; box-shadow: 0 10px 24px rgba(0,0,0,0.35); }
.play-icon { font-size: 12px; }
.button-arrow { margin-left: auto; font-size: 22px; line-height: 1; }
.menu-secondary { border: 0; margin-top: 14px; padding: 8px 12px; background: transparent; color: #b9c8bd; font-size: 13px; cursor: pointer; }
.menu-secondary span { display: inline-grid; place-items: center; width: 17px; height: 17px; margin-left: 4px; border: 1px solid #718278; border-radius: 50%; font-size: 11px; }
.menu-details { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 17px 12px; border-top: 1px solid rgba(255,255,255,0.1); border-bottom: 1px solid rgba(255,255,255,0.1); }
.menu-detail { display: flex; flex-direction: column; gap: 5px; min-width: 72px; }
.menu-detail strong { color: #f2dfb1; font: 700 17px Georgia, serif; }
.menu-detail span { color: #84958a; font-size: 10px; }
.menu-detail-divider { width: 1px; height: 27px; background: rgba(255,255,255,0.12); }
.menu-footnote { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 20px 0 0; color: #718278; font-size: 11px; }
.menu-live-dot { width: 6px; height: 6px; border-radius: 50%; background: #7dbb75; box-shadow: 0 0 0 4px rgba(125,187,117,0.12); }

@keyframes menuEnter { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }

.rules-overlay { position: fixed; border-radius: 0; }
.rules-modal { position: relative; max-width: 380px; text-align: left; background: #20352a; border: 1px solid rgba(225,184,106,0.3); }
.rules-modal h2 { margin: 0 0 20px; color: #f9f5e9; font: 700 30px Georgia, serif; }
.modal-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; color: #aab5ae; font-size: 28px; cursor: pointer; }
.rules-list { display: grid; gap: 15px; margin: 0; padding: 0; list-style: none; }
.rules-list li { display: grid; grid-template-columns: 28px 1fr; gap: 11px; align-items: start; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 14px; }
.rules-list li > span { color: #e1b86a; font-size: 11px; font-weight: 800; }
.rules-list p { margin: 0; color: #c5d0c8; font-size: 13px; line-height: 1.45; }

/* Table Area */
.table-area {
  flex: 1;
  margin: 4px;
  background: radial-gradient(circle, var(--felt-green) 0%, var(--felt-dark) 100%);
  border: 2px solid var(--wood-border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px;
  position: relative;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.player-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.player-info {
  font-size: 12px;
  font-weight: 600;
  color: #e0e0e0;
  margin-bottom: 4px;
}

/* Hands & Cards */
/* Arched Hand Container */
.hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: calc(var(--card-height) + 24px);
  width: 100%;
  padding-bottom: 8px;
  position: relative;
}

/* Fan/Curve transform logic */
.hand .card {
  /* Pivot point at bottom center for fanning */
  transform-origin: 50% 120%; 
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s ease;
  
  /* Read dynamic positioning variables calculated in JS */
  transform: rotate(calc(var(--card-angle, 0deg))) translateY(calc(var(--card-arc-y, 0px)));
  margin: 0 -8px; /* Slightly overlap cards */
}

/* Preserve hover behavior only on devices with a real hover pointer */
@media (hover: hover) and (pointer: fine) {
  .hand .card:hover {
    z-index: 50 !important;
    transform: rotate(0deg) translateY(-24px) scale(1.15) !important;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6) !important;
  }
}

.hand .card.selected {
  z-index: 60 !important;
  transform: rotate(0deg) translateY(-28px) scale(1.18) !important;
  box-shadow: 0 0 12px #64b5f6, 0 12px 24px rgba(0, 0, 0, 0.7) !important;
  border: 2px solid #64b5f6 !important;
}
/* Base Card */
.card {
  width: var(--card-width);
  height: var(--card-height);
  background: #ffffff;
  color: #111111;
  border-radius: 7px;
  position: relative;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  cursor: grab;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
  box-sizing: border-box;
}

.card.red {
  color: #d32f2f;
}

.card.selected {
  transform: translateY(-16px) scale(1.08) !important;
  box-shadow: 0 0 12px #64b5f6, 0 8px 16px rgba(0, 0, 0, 0.6) !important;
  border: 2px solid #64b5f6 !important;
}

/* Floating clone during mobile touch-drag */
.card-drag-clone {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  transform: scale(1.1) rotate(4deg);
  opacity: 0.9;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
}

/* Corner Indexes */
.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.card-corner .rank {
  font-size: 11px;
  font-weight: 800;
}

.card-corner .suit {
  font-size: 10px;
  margin-top: 1px;
}

.card-corner.top-left {
  top: 4px;
  left: 4px;
}

.card-corner.bottom-right {
  bottom: 4px;
  right: 4px;
  transform: rotate(180deg);
}

/* Large Suit Symbol in Center */
.card-center-suit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  pointer-events: none;
  opacity: 0.9;
}

/* Face-down Card Back */
.card-back {
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  border: 2px solid #ffffff;
}

.card-back .card-corner,
.card-back .card-center-suit {
  display: none;
}

/* Keyframe Animations */
.anim-deal {
  animation: dealCard 0.4s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}

.anim-play-attack {
  animation: playAttack 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.anim-play-defend {
  animation: playDefend 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes dealCard {
  0% {
    opacity: 0;
    transform: translateY(-80px) scale(0.5) rotate(-15deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@keyframes playAttack {
  0% {
    opacity: 0;
    transform: translateY(50px) scale(0.8) rotate(-10deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@keyframes playDefend {
  0% {
    opacity: 0;
    transform: translate(-20px, 30px) scale(0.8) rotate(15deg);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Felt Table Pairs */
.table-felt {
  flex: 1;
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  min-height: calc(var(--card-height) + 20px);
  padding: 6px 0;
}

.card-pair {
  width: var(--card-width);
  height: var(--card-height);
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  position: relative;
  transition: border-color 0.2s ease;
}

.card-pair.highlight {
  border-color: #64b5f6;
  background: rgba(100, 181, 246, 0.1);
}

.card-pair .attack-card {
  position: absolute;
  top: 0;
  left: 0;
}

.card-pair .defend-card {
  position: absolute;
  top: 14px;
  left: 10px;
  z-index: 2;
  box-shadow: -2px 4px 10px rgba(0, 0, 0, 0.6);
}

/* Deck & Trump Container */
.deck-container {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 10;
}

/* Explicit Trump Suit Badge */
.trump-badge {
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid #ffd700;
  border-radius: 12px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  color: #ffd700;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.trump-badge.red {
  color: #ff5252;
  border-color: #ff5252;
  box-shadow: 0 0 10px rgba(255, 82, 82, 0.3);
}

/* Deck Stack & Trump Card Positioning */
.deck-stack {
  position: relative;
  width: calc(var(--card-width) + 24px);
  height: var(--card-height);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-trump {
  position: absolute;
  left: -12px;
  top: 0;
  transform: rotate(-90deg);
  transform-origin: center;
  border: 2px solid #ffd700 !important;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.6) !important;
  z-index: 1;
}

.card-deck {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 2;
  box-shadow: -4px 4px 10px rgba(0, 0, 0, 0.6);
}

.deck-count {
  font-size: 11px;
  font-weight: 600;
  color: #e0e0e0;
  margin-top: 8px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Status Banner & Controls */
.status-banner {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #81d4fa;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  transition: color 0.3s ease;
}

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom, 10px);
}

.btn {
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

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

.btn-primary { background: #2481cc; color: #ffffff; width: 100%; }
.btn-danger { background: #e53935; color: #ffffff; }
.btn-success { background: #43a047; color: #ffffff; }

/* Overlay Modal */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
}

.modal {
  background: #212d3b;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  max-width: 280px;
  width: 100%;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.seed-box {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: 6px;
  margin: 15px 0;
  font-size: 10px;
  word-break: break-all;
}