:root {
  --bg: #070b14;
  --bg2: #121a2c;
  --felt: #0c3b2e;
  --gold: #e4c37a;
  --gold2: #f3e2b0;
  --ink: #f6efe3;
  --muted: #b7c0d0;
  --danger: #c4494a;
  --panel: rgba(10, 16, 28, 0.78);
  --line: rgba(228, 195, 122, 0.35);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: radial-gradient(1200px 700px at 50% -10%, #1c2744 0%, var(--bg) 55%);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
}

img { max-width: 100%; height: auto; display: block; }
button, input, select { font: inherit; }
button { cursor: pointer; }

#app {
  min-height: 100dvh;
  min-height: 100svh;
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-t)) 16px calc(20px + var(--safe-b));
}
.screen.active { display: grid; place-items: center; }

img,
.felt-art,
.felt-wrap::before,
.logo,
.chip-pile,
.dealer-chip,
.pulse-ring,
.spark,
.playing-card,
.pip,
.card-face {
  pointer-events: none;
}
button img { pointer-events: none; }

.menu-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(228, 195, 122, 0.12), transparent 35%),
    radial-gradient(circle at 80% 80%, rgba(20, 90, 70, 0.25), transparent 40%);
  pointer-events: none;
}

.menu-card {
  position: relative;
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px 24px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  text-align: center;
}

.logo { width: 132px; margin: 0 auto 8px; filter: drop-shadow(0 8px 16px rgba(0,0,0,.4)); }
h1, h2, h3 { font-family: Cinzel, serif; font-weight: 700; margin: 0 0 8px; letter-spacing: 0.04em; }
.tagline { color: var(--muted); margin: 0 0 18px; }

.field { display: grid; gap: 6px; text-align: left; margin: 12px 0; color: var(--muted); }
.field input, .field select, .toggle {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  padding: 12px 14px;
}
.menu-actions { display: grid; gap: 10px; margin-top: 8px; }
.cta {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--gold2), var(--gold));
  color: #2a1d08;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(228, 195, 122, 0.25);
}
.cta.alt {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--line);
  box-shadow: none;
}
.cta:disabled { opacity: 0.4; cursor: not-allowed; }
.texty {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px;
}
.career {
  list-style: none;
  padding: 14px 0 0;
  margin: 16px 0 0;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.career li, .result-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}
.toggle { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.how-list { text-align: left; color: var(--muted); line-height: 1.45; padding-left: 18px; }
.hint { color: var(--gold); }

#screen-table.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  justify-items: stretch;
  align-items: stretch;
  place-items: stretch;
  gap: 8px;
  width: 100%;
  padding: calc(8px + var(--safe-t)) 10px calc(8px + var(--safe-b));
  max-width: 1400px;
  margin: 0 auto;
}

.table-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 190px 6px 8px;
}
.hud-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-left img { width: 42px; }
.hud-left small { display: block; color: var(--muted); font-size: 12px; }
.hud-right { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--gold2);
}
.hud-tools {
  position: fixed;
  top: calc(10px + var(--safe-t));
  right: 10px;
  z-index: 16;
  display: flex;
  gap: 6px;
  grid-column: 1 / -1;
  grid-row: 1;
  height: 0;
  overflow: visible;
  justify-content: flex-end;
  pointer-events: none;
}
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(8,12,22,0.7);
  padding: 7px;
  pointer-events: auto;
  touch-action: manipulation;
}
.icon-btn.off { opacity: 0.4; }
.icon-btn img { width: 100%; height: 100%; object-fit: contain; }

.table-root {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  display: grid;
  place-items: center;
}

.felt-wrap {
  position: relative;
  width: min(100%, 1100px);
  aspect-ratio: 16 / 10.4;
  max-height: min(52dvh, 580px);
  pointer-events: none;
}
.felt-wrap .seat,
.felt-wrap .seat-body {
  pointer-events: none;
}
.felt-wrap::before {
  content: "";
  position: absolute;
  inset: 8% 6% 10%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 40%, #1c6b52 0%, #0b3a2d 55%, #07261e 100%);
  box-shadow: inset 0 0 0 10px #c6a35a, 0 24px 40px rgba(0,0,0,.45);
  z-index: 0;
}
.felt-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 40px rgba(0,0,0,.55));
  pointer-events: none;
  z-index: 1;
}
.felt-core {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(72%, 560px);
  z-index: 2;
}
.pot-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
}
.pot-display img { width: 36px; }
.pot-display small { color: var(--muted); font-size: 10px; letter-spacing: 0.12em; }
.board-row {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1.2vw, 10px);
}
.street-pill {
  font-family: Cinzel, serif;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--gold);
  background: rgba(0,0,0,0.28);
  border-radius: 999px;
  padding: 4px 10px;
}

.seat {
  position: absolute;
  width: min(180px, 32vw);
  display: grid;
  justify-items: center;
  gap: 4px;
  transition: opacity 0.3s, filter 0.3s;
  z-index: 3;
}
.seat.folded { opacity: 0.48; filter: grayscale(0.4); }
.seat.busted { opacity: 0.28; }
.seat.acting .avatar-wrap { box-shadow: 0 0 0 2px var(--gold); }
.seat.winner .avatar-wrap { box-shadow: 0 0 24px rgba(228,195,122,0.7); }
.seat-0 { bottom: 1%; left: 50%; transform: translateX(-50%); width: min(210px, 46vw); }
.seat-1 { bottom: 16%; left: 1%; }
.seat-2 { top: 10%; left: 4%; }
.seat-3 { top: 0; left: 50%; transform: translateX(-50%); }
.seat-4 { top: 10%; right: 4%; }
.seat-5 { bottom: 16%; right: 1%; }

.seat-cards { display: flex; gap: 4px; min-height: 46px; }
.seat-body {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(8, 12, 20, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  max-width: 100%;
}
.avatar-wrap { position: relative; width: 44px; height: 44px; flex: none; }
.avatar {
  width: 44px;
  height: 44px;
  object-fit: cover;
  object-position: top;
  border-radius: 50%;
  background: #1a2236;
}
.pulse-ring {
  position: absolute;
  inset: -4px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  animation: pulse 1.4s ease-out infinite;
}
.pname { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; display: block; }
.stack-row { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--gold2); }
.stack-row img { width: 14px; height: 14px; }
.blind-tag, .status-tag {
  font-size: 10px;
  color: #1a1408;
  background: var(--gold);
  border-radius: 999px;
  padding: 1px 6px;
  font-weight: 700;
}
.status-tag { background: #31415f; color: #fff; display: inline-block; margin-top: 2px; }
.dealer-chip {
  position: absolute;
  width: 28px;
  left: -6px;
  top: 18px;
  z-index: 2;
  filter: drop-shadow(0 2px 4px #000);
}
.street-bet {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--gold2);
}
.chip-pile { display: flex; }
.chip-pile img {
  width: 18px;
  margin-left: -8px;
  filter: drop-shadow(0 2px 2px #000);
}
.chip-pile img:first-child { margin-left: 0; }

.playing-card {
  width: clamp(42px, 7vw, 72px);
  height: auto;
  aspect-ratio: 2.5 / 3.5;
  overflow: visible;
  perspective: 600px;
  animation: dealIn 0.45s ease both;
}
.playing-card.sm { width: clamp(28px, 4.6vw, 44px); }
.playing-card.ghost {
  border: 1px dashed rgba(228,195,122,0.3);
  border-radius: 8px;
  background: rgba(0,0,0,0.15);
  animation: none;
}
.card-3d {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: visible;
  transform-style: preserve-3d;
  transition: transform 0.55s;
}
.playing-card.is-hidden .card-3d { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 8px;
  overflow: visible;
  box-shadow: 0 6px 12px rgba(0,0,0,0.35);
}
.card-front {
  background: url("../assets/img/card-face.webp") center / contain no-repeat;
  color: #1a1a1a;
}
.playing-card.red .card-front { color: #a11b2b; }
.card-back {
  background: url("../assets/img/card-back.webp") center / contain no-repeat;
  transform: rotateY(180deg);
}
.corner {
  position: absolute;
  display: grid;
  justify-items: center;
  font-weight: 700;
  font-size: 0.72em;
  line-height: 1;
}
.corner img { width: 0.7em; height: 0.7em; display: block; object-fit: contain; }
.corner.tl { top: 10%; left: 12%; }
.corner.br { bottom: 12%; right: 14%; transform: rotate(180deg); }
.pip {
  position: absolute;
  width: 42%;
  height: 42%;
  left: 50%;
  top: 50%;
  object-fit: contain;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.2));
}

.log-wrap {
  display: none;
}
.action-bar {
  position: relative;
  z-index: 12;
  width: 100%;
  background: linear-gradient(180deg, rgba(12,18,32,0.2), rgba(12,18,32,0.92));
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(10px + var(--safe-b));
  pointer-events: auto;
}
button, input, select, .act, .cta, .texty, .icon-btn {
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}
.action-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.act {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  color: var(--ink);
  background: #141c2e;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  font-weight: 600;
}
.act img { width: 18px; height: 18px; }
.act.danger { background: #4a1f28; }
.act.gold { background: linear-gradient(180deg, #d7b56a, #b8893a); color: #241806; }
.act.fire { background: #5a2a12; }
.act:disabled { opacity: 0.35; }
.raise-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.raise-row input[type="range"] { width: 100%; accent-color: var(--gold); }
.raise-presets { display: flex; gap: 4px; }
.raise-presets button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold2);
  border-radius: 999px;
  padding: 6px 8px;
  font-size: 11px;
}
.raise-amt { color: var(--muted); font-size: 13px; white-space: nowrap; }
.wait-line { text-align: center; color: var(--muted); padding: 12px; }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  margin-right: 8px;
  animation: pulse 1s infinite;
}

.spark {
  width: 120px;
  margin: 0 auto 8px;
  animation: spinGlow 2.4s linear infinite;
}
.result-list { list-style: none; padding: 0; margin: 12px 0; }
.result-list li.win { color: var(--gold2); }
.result-hand { margin: -4px 0 8px; color: var(--gold2); font-style: italic; }
.pot-line { color: var(--muted); }

@keyframes dealIn {
  from { transform: translateY(-16px) scale(0.85); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.25); }
}
@keyframes spinGlow {
  from { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(12deg) scale(1.08); }
  to { transform: rotate(0deg) scale(1); }
}

@media (min-width: 1024px) {
  #screen-table.active {
    grid-template-columns: minmax(0, 1fr) 220px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    justify-items: stretch;
  }
  .table-hud { grid-column: 1 / -1; }
  .table-root { grid-column: 1; }
  .log-wrap {
    display: block;
    grid-column: 2;
    grid-row: 2;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    overflow: auto;
    max-height: 62dvh;
  }
  .log-wrap ul { list-style: none; padding: 0; margin: 0; color: var(--muted); font-size: 12px; }
  .log-wrap li { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
  .action-bar { grid-column: 1 / -1; }
  .felt-wrap { max-height: min(58dvh, 640px); }
}

@media (max-width: 760px) {
  .felt-wrap {
    aspect-ratio: 4 / 5.05;
    max-height: min(58dvh, 640px);
    width: 100%;
  }
  .felt-core { width: min(88%, 420px); top: 42%; }
  .seat { width: min(46vw, 160px); }
  .seat-1 { bottom: 22%; left: 0; }
  .seat-5 { bottom: 22%; right: 0; }
  .seat-2 { top: 14%; left: 0; }
  .seat-4 { top: 14%; right: 0; }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .raise-row { grid-template-columns: 1fr; }
  .hud-left small { display: none; }
  .pname { max-width: 72px; }
  .table-hud { padding-right: 168px; }
}

@media (max-width: 420px) {
  .avatar, .avatar-wrap { width: 36px; height: 36px; }
  .playing-card.sm { width: 26px; }
  h1 { font-size: 1.5rem; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .felt-wrap { aspect-ratio: 16 / 9; max-height: 58dvh; }
  .action-bar { padding: 6px; }
  .act { min-height: 38px; padding: 8px; }
}
