/* ── Jacks or Better — clean, quiet, dark ──────────────────────────────── */

:root {
  --bg: #0d1117;
  --bg-raise: #131a24;
  --bg-inset: #0a0e14;
  --line: #232d3b;
  --line-soft: #1a2230;
  --text: #e8e6df;
  --text-dim: #8b95a5;
  --text-faint: #5a6474;
  --gold: #d4af5f;
  --gold-soft: rgba(212, 175, 95, .12);
  --gold-text: #e6c87e;
  --card-red: #c0392b;
  --card-black: #232a33;
  --focus: #6d8bd6;

  /* theme: board felt + card backs (slate default) */
  --felt: #131a24;
  --felt-line: #232d3b;
  --back-bg: #0a0e14;
  --back-line: #232d3b;
  --back-soft: #1a2230;
}

[data-theme="forest"] {
  --felt: #0f2119; --felt-line: #21422f;
  --back-bg: #0d241a; --back-line: #2c5c40; --back-soft: #1a3a29;
}
[data-theme="navy"] {
  --felt: #0f1c33; --felt-line: #223a63;
  --back-bg: #0e1e3d; --back-line: #2c4f8f; --back-soft: #1a3260;
}
[data-theme="wine"] {
  --felt: #251016; --felt-line: #4a2029;
  --back-bg: #2b1017; --back-line: #5e2733; --back-soft: #401b24;
}
[data-theme="plum"] {
  --felt: #1b1229; --felt-line: #37255a;
  --back-bg: #201434; --back-line: #4a2f7c; --back-soft: #2f1f52;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "Inter", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 50% -15%, #141c2a 0%, transparent 65%),
    var(--bg);
  background-attachment: fixed;
  display: flex;
  justify-content: center;
  padding: clamp(12px, 3vh, 40px) 16px;
  -webkit-user-select: none;
  user-select: none;
}

.cabinet {
  position: relative;
  width: min(860px, 100%);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.2vh, 24px);
}

/* centers the table in whatever vertical space is left */
.stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.marquee { text-align: center; padding-top: 4px; }

.marquee h1 {
  font-size: clamp(1.15rem, 3vw, 1.6rem);
  font-weight: 600;
  letter-spacing: .32em;
  text-indent: .32em;
  color: var(--text);
}

.marquee .amp {
  color: var(--gold);
  font-weight: 500;
}

.marquee-sub {
  margin-top: 6px;
  font-size: clamp(.62rem, 1.4vw, .72rem);
  font-weight: 500;
  letter-spacing: .38em;
  text-indent: .38em;
  color: var(--text-faint);
}

/* corner buttons (paytable / sound) */
.corner-btn {
  position: absolute;
  top: 6px;
  z-index: 5;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: .64rem;
  font-weight: 550;
  letter-spacing: .18em;
  color: var(--text-faint);
  cursor: pointer;
  padding: 6px 2px;
  transition: color .15s ease;
}
.corner-btn:hover { color: var(--text-dim); }
.corner-left { left: 0; }
.corner-right { right: 0; text-align: right; }

.corner-group {
  position: absolute;
  top: 6px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.corner-group .corner-btn { position: static; }
.corner-group.corner-left { left: 0; }
.corner-name {
  color: var(--gold);
  opacity: .8;
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.corner-name:hover { color: var(--gold-text); }
.corner-name:empty { display: none; }

.swatches { display: flex; gap: 7px; }
.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  opacity: .65;
  transition: opacity .12s ease, box-shadow .12s ease;
}
.swatch:hover { opacity: 1; }
.swatch.active {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--text-faint);
}

/* ── Mode switch ────────────────────────────────────────────────────────── */

.mode-switch {
  display: flex;
  width: max-content;
  align-self: center;
  margin-top: -4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}
.mode-opt {
  font-family: inherit;
  font-size: .6rem;
  font-weight: 550;
  letter-spacing: .18em;
  text-indent: .18em;
  color: var(--text-faint);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 4px 14px 5px;
  cursor: pointer;
  transition: color .12s ease, background .12s ease;
}
.mode-opt:hover { color: var(--text-dim); }
.mode-opt.active {
  color: var(--gold-text);
  background: var(--gold-soft);
}

/* board tabs inside the leaderboard modal */
.mode-switch-tabs { margin: 2px auto 12px; }

/* ── Table / cards ──────────────────────────────────────────────────────── */

.table {
  position: relative;
  border: 1px solid var(--felt-line);
  border-radius: 12px;
  background: var(--felt);
  padding: clamp(16px, 2.8vh, 30px) clamp(12px, 2.4vw, 28px) clamp(22px, 3.4vh, 36px);
  transition: background .25s ease, border-color .25s ease;
  overflow: hidden;
}

.message {
  text-align: center;
  font-size: clamp(.78rem, 2vw, .95rem);
  font-weight: 550;
  letter-spacing: .22em;
  text-indent: .22em;
  min-height: 1.6em;
  margin-bottom: clamp(14px, 2.2vh, 24px);
  color: var(--text-dim);
  transition: color .2s ease;
}
.message.win { color: var(--gold-text); }
.message.lose { color: var(--text-faint); }

.cards {
  display: flex;
  justify-content: center;
  gap: clamp(8px, 1.8vw, 18px);
}

.slot {
  position: relative;
  flex: 0 1 clamp(58px, 15.5vw, 132px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* HELD tag */
.held-badge {
  position: absolute;
  top: -0.6em;
  left: 50%;
  transform: translateX(-50%) scale(0);
  z-index: 3;
  font-size: clamp(.52rem, 1.3vw, .64rem);
  font-weight: 650;
  letter-spacing: .18em;
  text-indent: .18em;
  color: #14100a;
  background: var(--gold);
  border-radius: 999px;
  padding: .32em .9em .3em;
  transition: transform .14s cubic-bezier(.34,1.4,.64,1);
}
.slot.held .held-badge { transform: translateX(-50%) scale(1); }

/* keyboard cursor — thin underline beneath the card */
.slot::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -10px;
  height: 2px;
  border-radius: 2px;
  background: var(--focus);
  opacity: 0;
  transition: opacity .12s ease;
}
.slot.cursor::after { opacity: 1; }

.card {
  aspect-ratio: 5 / 7;
  perspective: 900px;
  transition: transform .3s cubic-bezier(.22, .72, .3, 1.04), opacity .26s ease;
}

/* fly-in start position: tossed from the dealer, above the table */
.slot.off .card {
  transform: translateY(-140%) rotate(-5deg) scale(.96);
  opacity: 0;
  transition: none;
}

/* fly-out: discarded straight down off the table */
.slot.gone .card {
  transform: translateY(130%) rotate(4deg) scale(.98);
  opacity: 0;
}

/* kill all motion while repositioning between animations */
.slot.notrans .card,
.slot.notrans .card-inner { transition: none !important; }

.card-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transform: rotateY(180deg);
  transition: transform .3s cubic-bezier(.4, .1, .3, 1);
}
.slot.up .card-inner { transform: rotateY(0deg); }

.card-face, .card-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: clamp(6px, 1vw, 9px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}

.card-back {
  transform: rotateY(180deg);
  background: var(--back-bg);
  border: 1px solid var(--back-line);
}
.card-back::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: inherit;
  border: 1px solid var(--back-line);
  background: repeating-linear-gradient(45deg,
    transparent 0 5px, var(--back-soft) 5px 6px);
}

.card-face {
  background: #f7f5ef;
  border: 1px solid #d8d3c4;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 7% 9%;
  transition: box-shadow .15s ease;
}
.card-face .corner {
  font-weight: 650;
  font-size: clamp(.8rem, 2.7vw, 1.45rem);
  line-height: .95;
  letter-spacing: -.01em;
}
.card-face .corner .suit-sm {
  display: block;
  font-size: .78em;
  margin-top: .05em;
}
.card-face .pip {
  align-self: center;
  justify-self: center;
  font-size: clamp(1.5rem, 5.6vw, 3rem);
  line-height: 1;
  padding-bottom: 14%;
}
.card-face .pip .face-letter {
  font-weight: 650;
  font-size: .85em;
  display: block;
  text-align: center;
}
.card-face .pip .face-letter + .suit-under {
  display: block;
  text-align: center;
  font-size: .52em;
  margin-top: .08em;
}
.card-face.red { color: var(--card-red); }
.card-face.black { color: var(--card-black); }
.card-face.joker { color: #8a6d2f; }
.card-face.joker .pip .suit-under {
  font-size: .28em;
  font-weight: 650;
  letter-spacing: .22em;
  text-indent: .22em;
  margin-top: .4em;
}

/* held / cursor / winning states — rings, no glow */
.slot.held .card-face {
  box-shadow: 0 2px 10px rgba(0,0,0,.4), 0 0 0 2px var(--gold);
}
.slot.cursor .card-face,
.slot.cursor .card-back {
  box-shadow: 0 2px 10px rgba(0,0,0,.4), 0 0 0 2px var(--focus);
}
.slot.cursor.held .card-face {
  box-shadow: 0 2px 10px rgba(0,0,0,.4), 0 0 0 2px var(--gold), 0 0 0 4px rgba(109,139,214,.45);
}
.slot.hit .card-face {
  box-shadow: 0 4px 16px rgba(0,0,0,.45), 0 0 0 2px var(--gold);
}
.slot.hit .card { transform: translateY(-8px); }
.slot.dim .card { opacity: .5; }

/* ── Console ────────────────────────────────────────────────────────────── */

.console {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: clamp(10px, 2vw, 20px);
  flex-wrap: wrap;
}

.meters {
  display: flex;
  gap: clamp(8px, 1.6vw, 14px);
  flex: 1 1 auto;
}

.meter {
  flex: 1 1 0;
  min-width: 84px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-raise);
  padding: 8px 14px 10px;
  text-align: center;
}
.meter label {
  display: block;
  font-size: clamp(.56rem, 1.3vw, .66rem);
  font-weight: 550;
  letter-spacing: .26em;
  text-indent: .26em;
  color: var(--text-faint);
}
.meter output {
  font-size: clamp(1.15rem, 3vw, 1.6rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.25;
}
#win:not([data-zero]) { color: var(--gold-text); }
.meter.bump output { animation: bump .18s ease; display: inline-block; }
@keyframes bump { 50% { transform: scale(1.12); } }

/* bet stepper */
.bet-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.stepper {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  line-height: 1;
  width: 24px;
  height: 24px;
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease, opacity .12s ease;
}
.stepper:hover:not(:disabled) { border-color: var(--text-faint); color: var(--text); }
.stepper:disabled { opacity: .3; cursor: default; }

.buttons {
  display: flex;
  flex: 0 0 auto;
}

.btn {
  font-family: inherit;
  font-size: clamp(.68rem, 1.6vw, .8rem);
  font-weight: 600;
  letter-spacing: .16em;
  text-indent: .16em;
  border-radius: 10px;
  padding: 0 clamp(14px, 2.6vw, 28px);
  min-height: 54px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease,
              transform .06s ease, opacity .12s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }

.btn-deal {
  background: var(--gold);
  border: 1px solid var(--gold);
  color: #14100a;
  min-width: clamp(120px, 18vw, 170px);
}
.btn-deal:hover:not(:disabled) { background: var(--gold-text); border-color: var(--gold-text); }

.btn-toggle {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-faint);
}
.btn-toggle:hover { border-color: var(--text-faint); color: var(--text-dim); }
.btn-toggle[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold-text);
  background: var(--gold-soft);
}

/* ── Paytable modal ─────────────────────────────────────────────────────── */

.modal-backdrop[hidden] { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(5, 8, 13, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity .16s ease;
}
.modal-backdrop.show { opacity: 1; }

.modal {
  width: min(560px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 22px 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
  transform: translateY(8px) scale(.98);
  transition: transform .16s ease;
}
.modal-backdrop.show .modal { transform: none; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-head h2 {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .3em;
  text-indent: .3em;
  color: var(--text-dim);
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  transition: color .12s ease;
}
.modal-close:hover { color: var(--text); }

.modal-foot {
  margin-top: 12px;
  text-align: center;
  font-size: .66rem;
  letter-spacing: .06em;
  color: var(--text-faint);
}

.paytable {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) repeat(5, minmax(0, 1fr));
  font-size: clamp(.7rem, 1.7vw, .84rem);
  font-weight: 450;
  overflow: hidden;
  border-radius: 8px;
}

.paytable .pt-cell {
  padding: 5px 10px;
  line-height: 1.4;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--line-soft);
}
.paytable .pt-cell:nth-last-child(-n+6) { border-bottom: none; }

.paytable .pt-name { letter-spacing: .06em; font-size: .92em; }

.paytable .pt-pay {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.paytable .pt-active {
  background: var(--gold-soft);
  color: var(--gold-text);
}

/* ── Leaderboard modal ──────────────────────────────────────────────────── */

.lb-list { border-radius: 8px; overflow: hidden; }

.lb-row {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 6px 12px;
  font-size: .84rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line-soft);
}
.lb-row:last-child { border-bottom: none; }
.lb-row .lb-rank { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.lb-row .lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: .04em;
}
.lb-row .lb-score { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.lb-row.me { background: var(--gold-soft); }
.lb-row.me .lb-name, .lb-row.me .lb-score { color: var(--gold-text); }
.lb-empty {
  padding: 22px 0;
  text-align: center;
  font-size: .8rem;
  letter-spacing: .08em;
  color: var(--text-faint);
}

/* ── Name modal ─────────────────────────────────────────────────────────── */

.modal-narrow { width: min(360px, 100%); }

.name-input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 550;
  letter-spacing: .14em;
  text-align: center;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color .12s ease;
}
.name-input:focus { border-color: var(--text-faint); }
.name-input::placeholder { color: var(--text-faint); letter-spacing: .14em; }

.btn-block { width: 100%; min-height: 46px; }

.nm-error {
  margin: -4px 0 10px;
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
  color: #d98a7f;
}

/* ── How-to modal ───────────────────────────────────────────────────────── */

.howto p {
  font-size: .84rem;
  line-height: 1.55;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.howto b { color: var(--text); font-weight: 600; }
.howto-keys {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px 14px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
  font-size: .74rem;
  color: var(--text-faint);
  padding-top: 12px;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */

/* sits on the message line, just above the cards */
.toast {
  position: absolute;
  top: clamp(10px, 2vh, 22px);
  left: 50%;
  z-index: 15; /* below modal backdrops */
  transform: translate(-50%, 8px);
  background: var(--bg-raise);
  border: 1px solid var(--gold);
  color: var(--gold-text);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .18em;
  text-indent: .18em;
  border-radius: 999px;
  padding: 10px 26px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ── Footer / misc ──────────────────────────────────────────────────────── */

.help {
  text-align: center;
  color: var(--text-faint);
  font-size: clamp(.64rem, 1.4vw, .74rem);
  font-weight: 450;
  letter-spacing: .04em;
}
.key {
  display: inline-block;
  font-size: .88em;
  font-weight: 550;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .05em .45em .1em;
  margin: 0 .12em;
  color: var(--text-dim);
}

/* portrait phones: corner controls leave the corners (they overlap the
   title) and become centered rows under it */
@media (max-width: 720px) and (orientation: portrait) {
  .cabinet { gap: clamp(10px, 1.6vh, 16px); }
  .marquee { order: -1; }
  .corner-group {
    position: static;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px 18px;
  }
  .corner-btn { padding: 2px; }
}

@media (max-width: 560px) {
  .console { flex-direction: column; }
  .buttons { width: 100%; }
  .buttons .btn { flex: 1 1 0; min-height: 50px; }
  .help { display: none; }
}

/* landscape phones: height is the scarce dimension — drop the title,
   keep controls in the corners, compact everything else */
@media (max-height: 520px) and (orientation: landscape) {
  body { padding: 8px 14px; }
  .cabinet { padding-top: 28px; gap: 8px; }
  .marquee { display: none; }
  /* the title is gone, so the switch docks top-center with the corner buttons */
  #modeswitch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    margin: 0;
    padding: 2px;
  }
  #modeswitch .mode-opt { padding: 3px 12px 4px; }
  .table { padding: 10px 14px 16px; }
  .message { margin-bottom: 8px; min-height: 1.3em; font-size: .72rem; }
  .slot { flex: 0 1 clamp(48px, 10.5vw, 92px); }
  .meter { padding: 4px 10px 6px; min-width: 72px; }
  .meter output { font-size: 1.05rem; }
  .meter label { font-size: .54rem; }
  .btn { min-height: 38px; }
  .btn-deal { min-width: 104px; }
  .help { display: none; }
}
