/* === App Layout === */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  padding: 8px 14px calc(8px + var(--safe-b));
  position: relative;
  overflow: hidden;
  z-index: 1;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 0 6px;
  flex-shrink: 0;
}
.logo {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--gold);
}
.logo span {
  color: var(--text-muted);
  font-weight: 400;
}
.logo a {
  color: inherit;
  text-decoration: none;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.balance {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  padding: 3px 10px;
  background: var(--gold-dim);
  border-radius: 6px;
  border: 1px solid var(--balance-border);
  min-width: 60px;
  text-align: center;
}
.icon-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.icon-btn:hover {
  border-color: var(--border-glow);
  color: var(--text-dim);
}
.icon-btn:active {
  transform: scale(0.95);
}

/* === Table Area === */
.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 0;
  padding: 6px 0;
  background: var(--table-bg);
  border-radius: 14px;
  margin: 2px -4px;
}
.dealer-zone,
.player-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.zone-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* === Dealer Hint === */
.dealer-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  text-align: center;
  min-height: 16px;
  transition: opacity 0.3s;
}

/* === Mid Zone (Result) === */
.mid-zone {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}
.mid-zone.show {
  opacity: 1;
}
.result-text {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
}
.result-payout {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}
.result-sides {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  display: flex;
  gap: 8px;
}

/* === Controls === */
.controls {
  flex-shrink: 0;
  padding-top: 4px;
}
.bet-controls,
.play-controls {
  display: none;
}
.bet-controls.show,
.play-controls.show {
  display: block;
}

/* === Chips === */
.chip-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}
.chip {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px dashed var(--chip-border);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--chip-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.chip:active {
  transform: scale(0.9);
}
.chip[data-val="5"] {
  background: #3060c0;
}
.chip[data-val="10"] {
  background: #209050;
}
.chip[data-val="25"] {
  background: #c03050;
}
.chip[data-val="50"] {
  background: #7040a0;
}
.chip[data-val="100"] {
  background: #b08020;
}
.chip:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.chip.clear-chip {
  background: var(--surface-2) !important;
  border-style: solid !important;
  border-color: var(--border) !important;
  color: var(--text-muted) !important;
  font-size: 15px;
}

/* === Side Bets === */
.side-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 8px;
}
.side-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.side-btn:active {
  transform: scale(0.95);
}
.side-odds {
  font-size: 9px;
  opacity: 0.6;
}
.side-btn.active {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold);
}
.side-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* === Bet Summary === */
.bet-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.bet-info {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 5px;
}
.bet-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
}

/* === Action Buttons === */
.act-btn {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-glow);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}
.act-btn:hover {
  border-color: var(--gold);
  background: var(--surface);
}
.act-btn:active {
  transform: scale(0.96);
}
.act-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.deal-btn {
  background: var(--deal-bg);
  border-color: var(--deal-border);
  color: var(--win);
}
.deal-btn:hover:not(:disabled) {
  background: var(--deal-hover-bg);
  border-color: var(--win);
}

/* === Play Controls === */
.play-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.act-btn.special {
  border-color: var(--invert-border);
  color: var(--invert-color);
  background: var(--invert-bg);
}
.act-btn.special:hover:not(:disabled) {
  border-color: var(--invert-color);
  background: var(--invert-hover-bg);
}
.act-btn.special.active {
  border-color: var(--zero);
  color: var(--zero);
  background: var(--invert-active-bg);
  box-shadow: var(--invert-active-shadow);
}
.act-btn.fold-btn {
  border-color: var(--fold-border);
  color: var(--lose);
  background: var(--fold-bg);
}
.kbd {
  font-size: 9px;
  opacity: 0.45;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  padding: 1px 3px;
  margin-left: 2px;
  letter-spacing: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
@media (max-width: 480px) {
  .kbd {
    display: none;
  }
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-glow);
  color: var(--text-dim);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 200;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  animation: toastEnter 0.3s ease-out;
}
.toast.zero {
  border-color: var(--zero);
  color: var(--zero);
}
.toast.win {
  border-color: var(--gold);
  color: var(--gold);
}

/* === Modals === */
.modal-bg {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
.modal-bg.show {
  display: flex;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  padding: 20px;
  max-width: 380px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: popIn 0.25s ease-out;
}
.modal-box h3 {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 12px;
  text-align: center;
}
.modal-box p {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 10px;
}
.modal-btns {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

/* === Payout Table === */
.pay-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.pay-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.pay-table td {
  padding: 4px 6px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--pay-border);
}
.pay-table td:last-child {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--gold);
  text-align: right;
}
.res-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: center;
}
.res-chart-cell {
  padding: 3px 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.res-chart-head {
  font-weight: 700;
  font-size: 11px;
}

/* === Stats === */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0;
}
.stat-item {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
}
.stat-val {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.stat-lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* === Tutorial === */
.tut-bg {
  position: fixed;
  inset: 0;
  background: var(--tut-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 20px;
}
.tut-bg.show {
  display: flex;
}
.tut-card {
  background: var(--surface);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  padding: 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  animation: popIn 0.3s ease-out;
}
.tut-step {
  display: none;
}
.tut-step.active {
  display: block;
}
.tut-icon {
  font-size: 36px;
  margin-bottom: 10px;
}
.tut-title {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 8px;
}
.tut-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 14px;
}
.tut-desc code {
  font-family: var(--font-mono);
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
}
.tut-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}
.tut-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.3s;
}
.tut-dot.on {
  background: var(--gold);
}
.tut-next {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 9px 18px;
  border: 1px solid var(--deal-border);
  border-radius: 8px;
  background: var(--deal-bg);
  color: var(--win);
  cursor: pointer;
  transition: all 0.15s;
}
.tut-next:hover {
  background: var(--deal-hover-bg);
}
.tut-next:active {
  transform: scale(0.96);
}

/* === Tap-to-continue hint === */
.tap-hint {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
  z-index: 150;
  white-space: nowrap;
}
.tap-hint.show {
  opacity: 1;
  animation: tapPulse 1.8s ease-in-out infinite;
}
@keyframes tapPulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.85;
  }
}

/* === Flash Overlays === */
.flash-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
}
.win-flash {
  background: radial-gradient(
    ellipse at center,
    rgba(240, 192, 64, 0.25),
    transparent 70%
  );
}
.lose-flash {
  background: radial-gradient(
    ellipse at center,
    rgba(224, 64, 96, 0.2),
    transparent 70%
  );
}
.flash-overlay.flash {
  animation: winFlash 0.6s ease-out;
}

/* === Animations === */
@keyframes winFlash {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
@keyframes loseShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(2px);
  }
}
@keyframes chipBounce {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes fadeSlideUp {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
@keyframes popIn {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes toastEnter {
  from {
    transform: translateX(-50%) translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}
.app.shake {
  animation: loseShake 0.35s ease-out;
}
.mid-zone.show .result-text,
.mid-zone.show .result-payout {
  animation: fadeSlideUp 0.35s ease-out both;
}
.mid-zone.show .result-payout {
  animation-delay: 0.08s;
}

/* === Responsive === */
@media (max-width: 390px) {
  .chip {
    width: 36px;
    height: 36px;
    font-size: 10px;
  }
  .act-btn {
    padding: 8px 14px;
    font-size: 12px;
  }
  .result-text {
    font-size: 18px;
  }
  .balance {
    font-size: 15px;
  }
}
@media (max-height: 600px) {
  .table {
    gap: 2px;
    padding: 2px 0;
  }
  .mid-zone {
    min-height: 40px;
  }
  .hand {
    min-height: calc(var(--card-h) + 2px);
  }
  .chip-row {
    margin-bottom: 5px;
  }
  .side-row {
    margin-bottom: 5px;
  }
}
@media (min-height: 700px) and (max-width: 430px) {
  .table {
    gap: 8px;
  }
  .mid-zone {
    min-height: 64px;
  }
}
@media (min-width: 521px) {
  .chip {
    width: 48px;
    height: 48px;
    font-size: 13px;
  }
}
