:root {
  color-scheme: dark;
  font-family: "Arial Narrow", "Segoe UI", Arial, sans-serif;
  --ink: #f5f7f2;
  --muted: #9fb3aa;
  --felt: #0d4c3c;
  --felt-dark: #071d19;
  --panel: #0a1716;
  --gold: #d7b553;
  --gold-bright: #ffe491;
  --red: #a6282b;
  --green: #28cf78;
  --line: rgba(215, 181, 83, 0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 35%, rgba(32, 107, 80, 0.22), transparent 42%),
    #030908;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }

.machine-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background:
    linear-gradient(rgba(2, 8, 7, 0.18), rgba(2, 8, 7, 0.65)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.012) 0 2px, transparent 2px 8px);
  border: 3px solid #896d27;
}

.machine-header {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 22px;
  background: #08100f;
  border-bottom: 1px solid var(--line);
}

.brand-block { text-align: center; }
.brand-kicker, .dialog-kicker {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.brand-block h1 {
  margin: 2px 0 0;
  color: var(--gold-bright);
  font-family: Georgia, serif;
  font-size: clamp(25px, 3vw, 42px);
  letter-spacing: 0;
}

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--gold-bright);
  background: #121f1d;
  font-size: 22px;
  font-weight: 800;
}

.denomination-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.denomination-control select {
  height: 42px;
  border: 1px solid var(--gold);
  border-radius: 5px;
  padding: 0 30px 0 10px;
  color: var(--gold-bright);
  background: #102622;
  font-weight: 800;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(215, 181, 83, 0.25);
  border-bottom: 1px solid var(--line);
}
.status-strip > div {
  min-width: 0;
  padding: 7px 14px;
  background: #091614;
  text-align: center;
}
.status-strip span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.status-strip strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cloudStatus[data-state="connected"] { color: var(--green); }
#cloudStatus[data-state="pending"], #cloudStatus[data-state="syncing"] { color: var(--gold-bright); }
#cloudStatus[data-state="error"] { color: #ff6868; }

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(500px, 0.9fr) minmax(610px, 1.2fr);
  gap: 18px;
  padding: 18px;
  background: var(--felt-dark);
}

.paytable-panel, .playfield {
  min-width: 0;
  border: 2px solid var(--gold);
  border-radius: 7px;
  background: rgba(4, 15, 13, 0.92);
}

.panel-heading {
  height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  color: var(--gold-bright);
  font-size: 13px;
  font-weight: 900;
  border-bottom: 1px solid var(--line);
}

.paytable-scroll { overflow: auto; }
.paytable {
  width: 100%;
  min-width: 670px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}
.paytable th, .paytable td {
  height: 38px;
  padding: 4px;
  border: 1px solid rgba(135, 174, 154, 0.15);
  text-align: center;
}
.paytable th:first-child {
  width: 160px;
  text-align: left;
  padding-left: 9px;
}
.paytable thead th {
  color: var(--gold-bright);
  background: #0f2924;
}
.paytable tbody tr:nth-child(even) { background: rgba(25, 79, 62, 0.22); }
.paytable .active-bet {
  color: #12120d;
  background: var(--gold);
  font-weight: 900;
}

.playfield {
  min-height: 500px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 22px 18px;
  background:
    linear-gradient(rgba(7, 45, 35, 0.75), rgba(3, 18, 15, 0.92)),
    var(--felt);
}

.game-message {
  min-height: 34px;
  margin-bottom: 18px;
  color: var(--gold-bright);
  font-size: clamp(17px, 2vw, 24px);
  font-weight: 900;
  text-align: center;
}

.cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(70px, 1fr));
  gap: 10px;
  width: min(100%, 780px);
  margin: 0 auto;
}

.card-slot {
  position: relative;
  aspect-ratio: 0.7;
  min-width: 0;
  overflow: hidden;
  border: 4px solid #f4f0de;
  border-radius: 7px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.38);
  background: #f7f4e9;
}
.card-slot:not(:disabled):hover { transform: translateY(-3px); }
.card-back {
  background: #171e51 url("/assets/card_back.jpg") center/cover no-repeat;
}
.card-number {
  position: absolute;
  right: 6px;
  bottom: 4px;
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  font-weight: 900;
}
.card-face { color: #111; }
.card-face.red { color: var(--red); }
.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
  font-family: Georgia, serif;
  font-style: normal;
}
.corner b { font-size: clamp(18px, 2.4vw, 34px); }
.corner i { font-size: clamp(15px, 2vw, 28px); font-style: normal; }
.corner.top { top: 7px; left: 8px; }
.corner.bottom { right: 8px; bottom: 7px; transform: rotate(180deg); }
.suit-large {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: clamp(42px, 7vw, 92px);
}
.held {
  border-color: #5cff9e;
  transform: translateY(-11px);
  box-shadow: 0 0 0 3px rgba(92, 255, 158, 0.28), 0 10px 18px rgba(0,0,0,0.4);
}
.hold-label, .dealer-label {
  position: absolute;
  left: 50%;
  top: 5px;
  z-index: 2;
  transform: translateX(-50%);
  padding: 3px 7px;
  border-radius: 3px;
  color: #06140d;
  background: #5cff9e;
  font-size: 11px;
  font-weight: 900;
}
.dealer-label { color: #131008; background: var(--gold-bright); }

.main-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 26px;
}
.game-button {
  min-height: 46px;
  padding: 0 17px;
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 5px;
  color: #f8faf6;
  background: #263532;
  font-weight: 900;
}
.game-button.primary { color: #121208; background: var(--gold); }
.game-button.success { color: #06140d; background: var(--green); }
.game-button.warning { color: #171006; background: #e5963f; }
.game-button.secondary { background: #24312f; }

.credit-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 78px;
  background: #070e0d;
  border-top: 2px solid var(--gold);
}
.credit-bar > div {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-content: center;
  gap: 1px 10px;
  padding: 10px 24px;
  border-right: 1px solid var(--line);
}
.credit-bar > div:last-child { border-right: 0; }
.credit-bar span {
  align-self: end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.credit-bar strong {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
  justify-self: end;
  color: var(--gold-bright);
  font-size: clamp(26px, 3vw, 42px);
}
.credit-bar small { color: var(--ink); font-weight: 800; }

dialog {
  width: min(940px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--gold);
  border-radius: 7px;
  color: var(--ink);
  background: #081311;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.78); }
.dialog-panel { padding: 20px; }
.dialog-panel > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.dialog-panel h2 { margin: 2px 0 0; color: var(--gold-bright); font-size: 25px; }
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.mode-grid button {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border: 2px solid var(--gold);
  border-radius: 6px;
  color: var(--ink);
  background: #0d2822;
}
.mode-grid strong { color: var(--gold-bright); font-size: 20px; }
.mode-grid span { color: var(--muted); }

.meters-dialog { overflow: auto; }
.cloud-settings {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.cloud-settings label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.cloud-settings input {
  width: 100%;
  height: 44px;
  border: 1px solid #47625a;
  border-radius: 4px;
  padding: 0 10px;
  color: var(--ink);
  background: #0c1c19;
}
.meter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.meter-grid article {
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12px;
  border: 1px solid #2d5147;
  border-radius: 5px;
  background: #0d211d;
}
.meter-grid span, .meter-grid small { color: var(--muted); }
.meter-grid strong { margin: 3px 0; color: var(--gold-bright); font-size: 25px; }
.meters-actions { display: flex; gap: 8px; }
.history-wrap { margin-top: 18px; overflow: auto; }
.history-wrap h3 { color: var(--gold-bright); }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 8px; border-bottom: 1px solid #28453e; text-align: center; }
.history-table th { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 20;
  max-width: calc(100% - 30px);
  transform: translate(-50%, 20px);
  padding: 10px 15px;
  border: 1px solid var(--gold);
  border-radius: 5px;
  color: var(--ink);
  background: #101c1a;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1050px) {
  .game-layout { grid-template-columns: 1fr; }
  .paytable-panel { order: 2; }
  .playfield { min-height: 460px; }
}

@media (max-width: 680px) {
  .machine-shell { border-width: 0; }
  .machine-header { grid-template-columns: auto 1fr auto; padding: 8px; }
  .brand-block h1 { font-size: 22px; }
  .denomination-control > span { display: none; }
  .denomination-control select { width: 90px; padding-left: 6px; }
  .header-actions { gap: 5px; }
  .icon-button { width: 40px; height: 40px; }
  .status-strip { grid-template-columns: repeat(2, 1fr); }
  .game-layout { padding: 8px; gap: 8px; }
  .playfield { min-height: 410px; padding: 16px 6px; }
  .cards { gap: 4px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .card-slot { border-width: 2px; border-radius: 4px; }
  .corner.top { top: 4px; left: 4px; }
  .corner.bottom { right: 4px; bottom: 4px; }
  .hold-label, .dealer-label { padding: 2px 4px; font-size: 8px; }
  .main-controls { gap: 5px; margin-top: 20px; }
  .game-button { min-height: 43px; padding: 0 9px; font-size: 12px; }
  .credit-bar > div { padding: 8px; }
  .credit-bar strong { font-size: 25px; }
  .credit-bar span, .credit-bar small { font-size: 9px; }
  .mode-grid, .meter-grid { grid-template-columns: 1fr; }
  .mode-grid button { min-height: 105px; }
  .cloud-settings { grid-template-columns: 1fr; }
  .dialog-panel { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
