:root {
  --bg: #121213;
  --text: #fff;
  --muted: #818384;
  --line: #3a3a3c;
  --key: #818384;
  --green: #538d4e;
  --red: #b33a3a;
  --card: #f4f4f4;
  --card-red: #c62828;
  --card-w: clamp(56px, min(20vw, 12dvh), 96px);
}

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



body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  display: flex;
  flex-direction: column;
  max-width: 500px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 16px env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

header {
  border-bottom: 1px solid var(--line);
  text-align: center;
  padding: 10px 0 8px;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
}
header > div { grid-column: 2; }
#open-stats, #close {
  background: none; border: 0; color: var(--text); cursor: pointer;
  width: 40px; height: 40px; display: grid; place-items: center; font-size: 20px;
}
h1 { white-space: nowrap; font-size: clamp(17px, 5vw, 28px); letter-spacing: .08em; font-weight: 800; }
#num { color: var(--muted); font-size: 13px; margin-top: 2px; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

#progress { list-style: none; padding: 0; display: flex; gap: 8px; }
#progress li {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line);
}
#progress li.now { border-color: var(--muted); }
#progress li.ok { background: var(--green); border-color: var(--green); }
#progress li.ko { background: var(--red); border-color: var(--red); }

.seat { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .1em; }

#player { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.hand { display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: .45; }
.hand.active { opacity: 1; }
.total { font-weight: 700; font-size: 15px; }
.total.bust { color: var(--red); }

.cards { display: flex; }
.card {
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  border-radius: calc(var(--card-w) * .1);
  background: var(--card);
  color: #111;
  position: relative;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
  animation: deal .18s ease-out;
}
.card + .card { margin-left: calc(var(--card-w) * -0.35); }
.card.red { color: var(--card-red); }
.card .r {
  position: absolute; top: 6%; left: 9%;
  font-size: calc(var(--card-w) * .3); line-height: 1;
  text-align: center;
}
.card .r small { display: block; font-size: .8em; }
.card .s {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: calc(var(--card-w) * .5);
  padding-top: 18%;
}
.card.back {
  background: repeating-linear-gradient(45deg, #2b2b2e 0 6px, #3a3a3c 6px 12px);
  border: 3px solid var(--card);
}
@keyframes deal { from { transform: translateY(-12px); opacity: 0; } }

#msg { min-height: 2.6em; text-align: center; font-size: 15px; line-height: 1.3; }
#msg b { display: block; font-size: 18px; }
#msg .ok { color: var(--green); }
#msg .ko { color: var(--red); }

#actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 0 12px;
}
#actions button {
  height: clamp(40px, 9dvh, 58px);
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: clamp(13px, 3.6vw, 16px);
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}
#actions button:disabled { opacity: .3; cursor: default; }
#actions button:not(:disabled):active { filter: brightness(.85); }
#actions #next { grid-column: 1 / -1; background: var(--green); }

dialog {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: min(420px, calc(100vw - 32px));
  margin: auto;
  padding: 16px 20px 24px;
  box-shadow: 0 4px 23px rgba(0, 0, 0, .4);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog #close { position: absolute; top: 6px; right: 6px; }
dialog h2 { font-size: 14px; letter-spacing: .08em; text-align: center; margin: 14px 0 10px; }

#stat-nums { display: flex; justify-content: center; gap: 14px; }
#stat-nums div { display: flex; flex-direction: column; align-items: center; width: 64px; }
#stat-nums b { font-size: 32px; font-weight: 400; }
#stat-nums span { font-size: 12px; text-align: center; }

#dist div { display: flex; gap: 6px; align-items: center; margin: 4px 0; font-size: 14px; }
#dist span { width: 10px; }
#dist i {
  font-style: normal; font-weight: 700; text-align: right;
  background: var(--line); padding: 2px 8px;
}
#dist i.me { background: var(--green); }

#after { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
#after[hidden] { display: none; }
#after h2 { margin: 0 0 4px; }
#countdown { font-size: 30px; font-variant-numeric: tabular-nums; text-align: center; }
#share {
  background: var(--green); color: var(--text); border: 0; border-radius: 4px;
  font: inherit; font-weight: 700; font-size: 18px; text-transform: uppercase;
  height: 52px; padding: 0 22px; cursor: pointer;
}

/* Móvil en horizontal: crupier y jugador lado a lado para que quepa sin scroll */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --card-w: 15dvh; }
  header { padding: 2px 0; }
  main { display: grid; grid-template-columns: 1fr 1fr; place-items: center; padding: 4px 0; gap: 4px; }
  #progress, #msg { grid-column: 1 / -1; }
  #actions { padding: 4px 0 8px; }
}
