:root {
  color-scheme: dark;
  --felt: #146144;
  --felt-dark: #0a372a;
  --rail: #3b2118;
  --rail-light: #7a4a2f;
  --gold: #f4c15d;
  --cream: #fff8e4;
  --muted: #b9c7bd;
  --danger: #d95a5a;
  --win: #65d58a;
  --panel: rgba(8, 24, 20, 0.78);
  --back-filter: none;
  --deal-speed: 40ms;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(circle at top, rgba(244, 193, 93, 0.18), transparent 28rem),
    linear-gradient(135deg, #190e0b, #070b0a 68%);
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 16px;
  color: #130d07;
  background: #f3ead7;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
  transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.primary {
  color: #1d1307;
  background: var(--gold);
}

.ghost {
  color: var(--cream);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.table-shell {
  width: min(1420px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1;
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr)) auto auto;
  gap: 8px;
  align-items: stretch;
}

.meter {
  min-width: 92px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.08);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meter strong {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-size: 23px;
}

.setup-button {
  min-width: 86px;
  height: 100%;
  color: var(--cream);
  background: rgba(244, 193, 93, 0.16);
  border: 1px solid rgba(244, 193, 93, 0.34);
}

.felt {
  position: relative;
  min-height: 760px;
  overflow: hidden;
  border: 12px solid var(--rail);
  border-radius: 28px;
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.08), transparent 58%),
    repeating-radial-gradient(circle at center, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.025) 2px, transparent 2px, transparent 18px),
    var(--felt);
  box-shadow:
    inset 0 0 0 6px var(--rail-light),
    inset 0 0 80px rgba(0, 0, 0, 0.35),
    0 30px 70px rgba(0, 0, 0, 0.35);
}

.shoe {
  position: absolute;
  top: 26px;
  right: 26px;
  display: grid;
  gap: 8px;
  justify-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.shoe img {
  width: 112px;
  aspect-ratio: 5 / 7;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: -8px 8px 0 rgba(0, 0, 0, 0.28);
}

.back-card {
  filter: var(--back-filter);
  outline: 3px solid rgba(255, 255, 255, 0.92);
  outline-offset: -3px;
  border: 2px solid #111820;
  background: #f8f8f8;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.42),
    0 18px 28px rgba(0, 0, 0, 0.36);
}

.seat {
  width: min(1080px, calc(100% - 44px));
  margin: 0 auto;
  padding: 22px 0;
}

.seat-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.seat-header h2 {
  font-size: 18px;
}

.score {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  height: 34px;
  border-radius: 8px;
  color: #1b1208;
  background: var(--gold);
  font-weight: 900;
}

.dealer-seat {
  padding-top: 8px;
}

.player-seat {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  width: min(1040px, calc(100% - 44px));
}

.hand,
.player-hands {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.player-hands {
  align-items: stretch;
  flex-wrap: wrap;
}

.player-hand {
  min-width: min(610px, 100%);
  border-radius: 8px;
  padding: 16px;
  background: rgba(4, 21, 15, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.player-hands.split-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.player-hands.split-layout .player-hand {
  min-width: 0;
  padding: 12px;
}

.player-hands.split-layout .cards {
  min-height: 198px;
}

.player-hands.split-layout .card {
  width: clamp(104px, 9.4vw, 136px);
  margin-left: -34px;
}

.player-hand.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(244, 193, 93, 0.18);
}

.hand-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 24px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.cards {
  display: flex;
  justify-content: center;
  min-height: 252px;
}

.card {
  width: clamp(142px, 15vw, 182px);
  aspect-ratio: 5 / 7;
  object-fit: cover;
  border-radius: 8px;
  margin-left: -28px;
  box-shadow: 0 18px 28px rgba(0, 0, 0, 0.32);
  animation: dealIn var(--deal-speed) ease both;
}

@keyframes dealIn {
  from {
    transform: translateY(-5px) scale(0.985);
  }

  to {
    transform: translateY(0) scale(1);
  }
}

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

.message-panel {
  position: absolute;
  left: 32px;
  top: 52%;
  width: min(280px, calc(100% - 64px));
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 16px 18px;
  text-align: center;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
}

.message-panel p {
  font-size: 20px;
  font-weight: 900;
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.4fr);
  gap: 12px;
  margin-top: 14px;
}

.bet-panel,
.action-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.chip {
  border-radius: 999px;
  min-width: 64px;
  color: #fff;
  background:
    radial-gradient(circle, var(--chip-color) 0 43%, #f4f4f4 44% 48%, var(--chip-color) 49%);
  border: 3px dashed rgba(255, 255, 255, 0.74);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.chip-10 {
  --chip-color: #2d7dd2;
}

.chip-25 {
  --chip-color: #178f55;
}

.chip-50 {
  --chip-color: #bd2137;
}

.chip-100 {
  --chip-color: #292f36;
}

.history {
  margin-top: 14px;
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.history h2 {
  margin-bottom: 8px;
  font-size: 16px;
}

.history ol {
  display: grid;
  gap: 6px;
  max-height: 104px;
  margin: 0;
  padding-left: 20px;
  overflow: auto;
  color: var(--muted);
}

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

.loss {
  color: var(--danger);
}

.push {
  color: var(--gold);
}

.hidden {
  display: none !important;
}

.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.72);
}

.setup-modal {
  width: min(980px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 18px;
  background: #111815;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.setup-header,
.setup-actions,
.admin-stats {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.setup-login {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  margin-top: 18px;
  align-items: end;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
}

input[type="color"] {
  padding: 4px;
}

input[type="range"] {
  padding: 0;
}

.checkbox-label {
  grid-template-columns: auto 1fr;
  align-items: center;
  align-content: center;
  min-height: 68px;
}

.checkbox-label input {
  width: 20px;
  min-height: 20px;
}

.field-note {
  color: var(--gold);
  font-size: 12px;
}

.setup-error {
  grid-column: 1 / -1;
  min-height: 20px;
  color: var(--danger);
  font-weight: 800;
}

.setup-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 14px;
}

.admin-history {
  margin-top: 16px;
}

.admin-history h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.admin-history-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.admin-history-item {
  display: grid;
  grid-template-columns: 96px 1fr 84px 84px 76px;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
}

.admin-history-item strong {
  color: var(--cream);
}

.meters-modal {
  width: min(1120px, 100%);
  overscroll-behavior: contain;
}

.cloud-status-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.cloud-status-bar > div {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
}

.cloud-status-bar span,
.counter-grid span,
.counter-grid small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.cloud-status-bar strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--cream);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#cloudStatus[data-state="connected"] {
  color: var(--win);
}

#cloudStatus[data-state="pending"],
#cloudStatus[data-state="syncing"] {
  color: var(--gold);
}

#cloudStatus[data-state="error"] {
  color: var(--danger);
}

.counter-section,
.meters-history {
  margin-top: 18px;
}

.counter-section h3,
.meters-history h3 {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 16px;
}

.counter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.counter-grid.compact {
  grid-template-columns: repeat(4, 1fr);
}

.counter-grid article {
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.06);
}

.counter-grid strong {
  display: block;
  margin: 4px 0;
  color: var(--gold);
  font-size: 25px;
}

.counter-grid.compact article {
  min-height: 74px;
}

.counter-operations,
.cloud-settings {
  display: grid;
  align-items: end;
  gap: 10px;
  margin-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 16px;
}

.counter-operations {
  grid-template-columns: minmax(180px, 1fr) auto auto;
}

.cloud-settings {
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) auto auto auto;
}

.handpay-button {
  color: #fff8e4;
  background: #8b2e32;
}

.meters-table-wrap {
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.meters-table-wrap table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

.meters-table-wrap th,
.meters-table-wrap td {
  padding: 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.meters-table-wrap th {
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 40;
  max-width: calc(100% - 30px);
  transform: translate(-50%, 18px);
  border: 1px solid rgba(244, 193, 93, 0.5);
  border-radius: 8px;
  padding: 11px 15px;
  color: var(--cream);
  background: #111815;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.38);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 820px) {
  .topbar,
  .controls {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    align-items: stretch;
  }

  .meter-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .setup-button {
    grid-column: 1 / -1;
  }

  .felt {
    min-height: 820px;
    border-width: 8px;
    border-radius: 20px;
  }

  .shoe {
    top: 16px;
    right: 16px;
  }

  .shoe img {
    width: 78px;
  }

  .player-hand {
    min-width: 100%;
  }

  .player-seat {
    width: min(100% - 28px, 1040px);
  }

  .player-hands.split-layout {
    gap: 10px;
  }

  .player-hands.split-layout .cards {
    min-height: 154px;
  }

  .player-hands.split-layout .card {
    width: 88px;
    margin-left: -42px;
  }

  .setup-grid,
  .setup-login,
  .admin-stats,
  .admin-history-item,
  .counter-grid,
  .counter-grid.compact,
  .cloud-status-bar {
    grid-template-columns: 1fr;
  }

  .counter-operations,
  .cloud-settings {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .table-shell {
    width: min(100vw - 12px, 1180px);
    padding-top: 8px;
  }

  .meter-grid {
    gap: 6px;
  }

  .meter {
    padding: 8px;
  }

  .meter strong {
    font-size: 20px;
  }

  .felt {
    min-height: 770px;
  }

  .shoe {
    top: 14px;
    right: 12px;
    font-size: 11px;
  }

  .shoe img {
    width: 72px;
  }

  .message-panel {
    left: 50%;
    top: 44%;
    width: min(620px, calc(100% - 42px));
    transform: translate(-50%, -50%);
  }

  .message-panel p {
    font-size: 20px;
  }

  .card {
    width: 108px;
    margin-left: -36px;
  }

  .cards {
    min-height: 166px;
  }

  .player-seat {
    bottom: 18px;
  }

  .player-hands.split-layout {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .player-hands.split-layout .player-hand {
    padding: 8px;
  }

  .player-hands.split-layout .hand-title {
    font-size: 10px;
  }

  .player-hands.split-layout .cards {
    min-height: 130px;
  }

  .player-hands.split-layout .card {
    width: 68px;
    margin-left: -22px;
  }

  .seat-header {
    margin-bottom: 14px;
  }
}
