:root {
  color-scheme: dark;
  --bg: #0d1712;
  --felt: #123525;
  --felt-deep: #0b261a;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f5f2e8;
  --muted: #b8b5a8;
  --gold: #d9a441;
  --red: #b83a37;
  --ink: #151313;
  --button: #efe5cf;
  --button-text: #18140e;
  --button-muted: rgba(255, 255, 255, 0.09);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.04), transparent 38%),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

.game-shell {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 100svh;
  max-width: 760px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  gap: 12px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}

.meta-label,
.wager-readout span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.top-bar strong,
.wager-readout strong {
  display: block;
  font-size: clamp(22px, 7vw, 34px);
  line-height: 1.05;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.icon-button.active {
  border-color: rgba(217, 164, 65, 0.7);
  color: var(--gold);
}

.table {
  position: relative;
  display: grid;
  grid-template-rows: minmax(155px, 1fr) auto minmax(176px, 1fr);
  gap: 12px;
  min-height: 0;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(180deg, var(--felt), var(--felt-deep));
  background-size: 34px 34px, 34px 34px, auto;
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.14);
}

.hand-zone {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.player-zone {
  align-content: end;
}

.hand-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--muted);
  font-size: 15px;
}

.hand-header strong {
  color: var(--text);
  font-size: 24px;
}

.hand {
  display: flex;
  min-height: 112px;
  padding-inline: 4px;
}

.card {
  position: relative;
  flex: 0 0 clamp(62px, 20vw, 92px);
  aspect-ratio: 0.68;
  margin-left: calc(var(--card-index) * -14px);
  border-radius: 9px;
  background: #fbf7ef;
  color: var(--ink);
  border: 1px solid rgba(20, 20, 20, 0.28);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.24);
  transform: translateZ(0);
}

.card:first-child {
  margin-left: 0;
}

.card.entering {
  animation: dealIn 180ms ease-out both;
}

.rank,
.suit {
  position: absolute;
  left: 8px;
  line-height: 1;
}

.rank {
  top: 8px;
  font-weight: 800;
  font-size: clamp(18px, 5vw, 26px);
}

.suit {
  top: 34px;
  font-size: clamp(20px, 6vw, 30px);
}

.lower {
  inset: auto 8px 8px auto;
  transform: rotate(180deg);
}

.red {
  color: var(--red);
}

.black {
  color: var(--ink);
}

.card-back {
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.14) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.14) 25%, transparent 25%),
    #4f1717;
  background-size: 16px 16px;
}

.card-back span {
  width: 46%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 245, 218, 0.8);
  transform: rotate(45deg);
}

.status-board {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(4, 16, 10, 0.52);
}

.status-board p {
  margin: 0;
  font-size: clamp(18px, 5.3vw, 26px);
  font-weight: 750;
  line-height: 1.12;
}

.status-board p[data-result="win"],
.status-board p[data-result="blackjack"] {
  color: #f1ca75;
}

.status-board p[data-result="loss"] {
  color: #ff8b80;
}

.wager-readout {
  min-width: 86px;
  text-align: right;
}

.chip-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.chip {
  position: relative;
  min-height: 58px;
  border-radius: 50%;
  border: 5px dashed rgba(255, 255, 255, 0.72);
  background: #222;
  font-weight: 850;
  color: #fff;
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.22);
  transition: opacity 140ms ease, border-color 140ms ease;
}

.chip-10 {
  background: #5e2c8c;
}

.chip-25 {
  background: #27734a;
}

.chip-100 {
  background: #2b5f94;
}

.chip-500 {
  background: #6f2222;
}

.chip.selected {
  outline: 3px solid rgba(217, 164, 65, 0.9);
  outline-offset: 2px;
}

.chip.tapped {
  animation: chipTap 180ms ease-out;
}

.action-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.action-bar button {
  min-height: 54px;
  border-radius: 10px;
  font-weight: 820;
  font-size: 17px;
  transition: opacity 140ms ease, background-color 140ms ease;
}

.primary {
  background: var(--button);
  color: var(--button-text);
}

.secondary {
  border: 1px solid var(--line);
  background: var(--button-muted);
}

button:disabled {
  opacity: 0.38;
}

#dealAgain {
  grid-column: 1 / -1;
}

body[data-phase="player"] #deal,
body[data-phase="player"] #clearBet,
body[data-phase="done"] #deal,
body[data-phase="done"] #clearBet,
body[data-phase="done"] #hit,
body[data-phase="done"] #stand,
body[data-phase="betting"] #hit,
body[data-phase="betting"] #stand,
body[data-phase="betting"] #dealAgain {
  display: none;
}

body[data-phase="player"] #hit,
body[data-phase="player"] #stand,
body[data-phase="done"] #dealAgain {
  display: block;
}

body[data-phase="done"] #dealAgain {
  grid-column: 1 / -1;
}

@keyframes dealIn {
  from {
    opacity: 0;
    transform: translateY(-12px) rotate(-2deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0);
  }
}

@keyframes chipTap {
  50% {
    transform: scale(0.96);
  }
}

@media (min-width: 680px) {
  .game-shell {
    padding-block: 24px;
  }

  .table {
    min-height: 650px;
  }

  .action-bar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  #dealAgain {
    grid-column: auto;
  }
}

@media (max-height: 700px) {
  .game-shell {
    gap: 8px;
    padding-top: 8px;
  }

  .table {
    grid-template-rows: minmax(122px, 1fr) auto minmax(136px, 1fr);
    padding: 12px;
  }

  .hand {
    min-height: 96px;
  }

  .chip {
    min-height: 50px;
  }

  .action-bar button {
    min-height: 48px;
  }
}
