/* Blackjack — one look on purpose: a card table is green felt, in any theme. */

:root {
  --felt-1: #13704d;
  --felt-2: #0b4631;
  --felt-3: #05241a;
  --ink: #f4f8f3;
  --muted: #a9c6b7;
  --line: rgba(255, 255, 255, 0.13);
  --panel: rgba(3, 20, 13, 0.42);
  --gold: #f2c14e;
  --gold-ink: #2a1c00;
  --good: #5bdc93;
  --bad: #ff8080;
  --card: #fffdf7;
  --card-ink: #15171c;
  --card-red: #c8102e;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--felt-3); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  /* No background here: it would paint over the felt layer below. html carries the fallback. */
  -webkit-tap-highlight-color: transparent;
}

/* The felt: a lit centre, dark edges and a faint weave, fixed behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E"),
    radial-gradient(120% 85% at 50% 0%, var(--felt-1), var(--felt-2) 55%, var(--felt-3));
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: max(10px, env(safe-area-inset-top)) 0;
}

h1, h2, p { margin: 0; }
a { color: var(--gold); }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* --- controls ------------------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-weight: 650;
  padding: 10px 16px;
  min-height: 48px;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.38; cursor: default; transform: none; }
.btn.primary, .btn.stand { background: var(--gold); color: var(--gold-ink); border-color: transparent; }
.btn.primary:hover, .btn.stand:hover { background: #f6cd68; }
.btn.hit { background: var(--card); color: var(--card-ink); border-color: transparent; }
.btn.hit:hover { background: #fff; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 58px; font-size: 1.15rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.92rem; }
.btn.wide { width: 100%; }
.btn small { font-weight: 500; opacity: 0.75; }

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

.linkish {
  background: none;
  border: 0;
  padding: 6px 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  justify-self: center;
}
.linkish:disabled { text-decoration: none; cursor: default; }

input {
  font: inherit;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 48px;
  min-width: 0;
}
input::placeholder { color: rgba(169, 198, 183, 0.6); }
input:focus { outline: none; border-color: var(--gold); }

.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.row.two > * { flex: 1; }
.row.spread { justify-content: space-between; }

/* --- cards ------------------------------------------------------------------ */

.card {
  --w: 56px;
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: var(--w);
  height: calc(var(--w) * 1.4);
  border-radius: calc(var(--w) * 0.12);
  background: var(--card);
  color: var(--card-ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12), 0 6px 14px rgba(0, 0, 0, 0.34);
  font-family: Georgia, "Times New Roman", serif;
  user-select: none;
}
.card b {
  position: absolute;
  top: 5%;
  left: 9%;
  font-size: calc(var(--w) * 0.3);
  line-height: 1;
  letter-spacing: -0.05em;
}
.card i { font-style: normal; font-size: calc(var(--w) * 0.52); line-height: 1; transform: translateY(10%); }
.card.red { color: var(--card-red); }
.card.back {
  background: repeating-linear-gradient(45deg, #b5283c 0 5px, #971d30 5px 10px);
  border: calc(var(--w) * 0.07) solid var(--card);
}
.card.back::after {
  content: "";
  position: absolute;
  inset: 10%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: calc(var(--w) * 0.06);
}
.card.sm { --w: 30px; }
.card.md { --w: 50px; }
.card.lg { --w: 68px; }
@media (min-width: 640px) {
  .card.sm { --w: 36px; }
  .card.md { --w: 62px; }
  .card.lg { --w: 84px; }
}

.hand { display: flex; align-items: center; flex-wrap: nowrap; }
.hand .card + .card { margin-left: calc(var(--w) * -0.3); }
.mini .card + .card { margin-left: calc(var(--w) * -0.48); }

.total {
  margin-left: 14px;
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.total.bust { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 3px; }

@keyframes deal { from { opacity: 0; transform: translateY(-18px) rotate(-7deg) scale(0.9); } }
.deal { animation: deal 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.d1 { animation-delay: 0.09s; }
.d2 { animation-delay: 0.18s; }
.d3 { animation-delay: 0.27s; }
.d4 { animation-delay: 0.36s; }
.d5 { animation-delay: 0.45s; }

@keyframes flip {
  0% { transform: rotateY(90deg); filter: brightness(0.6); }
  100% { transform: rotateY(0); filter: none; }
}
.flip { animation: flip 0.42s ease-out both; }
.f1 { animation-delay: 0.35s; }
.f2 { animation-delay: 0.7s; }
.f3 { animation-delay: 1.05s; }
.f4 { animation-delay: 1.4s; }
.f5 { animation-delay: 1.75s; }

/* --- home ------------------------------------------------------------------- */

.home { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.brand { text-align: center; margin: 26px 0 10px; }
.brand-cards { display: flex; justify-content: center; margin-bottom: 14px; }
.tilt-l { transform: rotate(-9deg); }
.tilt-r { transform: rotate(8deg) translateY(5px); margin-left: -18px; }
.brand h1 { font-size: clamp(2.4rem, 11vw, 3.4rem); line-height: 1; letter-spacing: -0.035em; }
.tagline { margin-top: 6px; font-size: 1.15rem; font-weight: 700; color: var(--gold); }
.pitch { text-align: center; color: var(--muted); max-width: 30em; margin: 10px auto 18px; text-wrap: balance; }

.panel {
  display: grid;
  gap: 10px;
  margin: 12px 0;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}
.panel h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.label { font-weight: 700; }
.hint { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--bad); font-weight: 600; }
.error:empty { display: none; }
.invite { padding: 10px 12px; border-radius: 10px; background: rgba(242, 193, 78, 0.13); }
.hello { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 1.05rem; }

.chip-count { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.chip-count:not(:empty)::after {
  content: "";
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  margin-left: 0.32em;
  border-radius: 50%;
  vertical-align: -0.04em;
  background: radial-gradient(circle, var(--gold) 0 45%, #fff 46% 56%, var(--gold) 57%);
}

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.steps .n {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(242, 193, 78, 0.18);
  color: var(--gold);
  font-weight: 800;
  font-size: 0.9rem;
}
.steps p { padding-top: 3px; }

.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.ranking li:last-child { border-bottom: 0; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { color: var(--muted); font-size: 0.8rem; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }

.foot { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 22px 0 6px; }
.foot a { color: inherit; }

/* --- table ------------------------------------------------------------------ */

.bar { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
.bar-title { flex: 1; min-width: 0; font-size: 1.05rem; }
.bar-title b { letter-spacing: 0.14em; }

.table { padding-bottom: 12px; }
.offline { text-align: center; color: var(--gold); font-weight: 600; margin: 4px 0; }

.bank {
  margin-top: 8px;
  padding: 12px 14px 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(242, 193, 78, 0.15), rgba(242, 193, 78, 0.04));
  border: 1px solid rgba(242, 193, 78, 0.42);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.bank.mine { margin-top: 12px; }
.bank.turn { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.16); }
.bank.won { border-color: rgba(91, 220, 147, 0.7); }
.bank.lost { border-color: rgba(255, 128, 128, 0.6); }
.bank-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.crown { color: var(--gold); }
.role { color: var(--gold); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.bank-name { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bank-head .chip-count { margin-left: auto; }
.bank .hand { min-height: 78px; margin: 10px 0 8px; }
.bank.mine, .me { scroll-margin-bottom: 190px; }
.hand.empty { min-height: 0 !important; margin-block: 8px 2px; }
.hand.empty .placeholder { font-size: 0.92rem; }
.bank-foot { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.secret { color: var(--gold); }
.delta { font-weight: 800; font-variant-numeric: tabular-nums; }
.bank.won .delta { color: var(--good); }
.bank.lost .delta { color: var(--bad); }
.tip { margin-top: 8px; color: var(--muted); font-size: 0.85rem; }
@media (min-width: 640px) { .bank .hand { min-height: 96px; } }

.status { margin: 16px 0 6px; text-align: center; }
.status-text { font-size: 1.22rem; font-weight: 750; letter-spacing: -0.01em; text-wrap: balance; }
.timer-wrap { display: flex; align-items: center; gap: 10px; max-width: 380px; margin: 10px auto 0; }
.timer { flex: 1; height: 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.13); overflow: hidden; }
.timer-bar { height: 100%; background: var(--gold); transform-origin: left center; transform: scaleX(0); }
.timer-bar.low { background: var(--bad); }
.timer-num { min-width: 1.6em; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; text-align: right; }
.notice { margin-top: 6px; color: var(--muted); font-size: 0.92rem; }
.phase-done .status-text { font-size: 1.45rem; }

.seats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.seat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 108px;
  padding: 8px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: border-color 0.2s ease, opacity 0.2s ease;
}
.seat header { display: flex; justify-content: space-between; gap: 6px; font-size: 0.85rem; }
.seat-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-chips { color: var(--muted); font-variant-numeric: tabular-nums; }
.seat .mini { display: flex; align-items: center; min-height: 44px; }
.seat footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.8rem; margin-top: auto; }
.seat.away { opacity: 0.5; }
.seat.turn { border-color: rgba(242, 193, 78, 0.75); }
.seat.won { border-color: rgba(91, 220, 147, 0.65); }
.seat.lost { border-color: rgba(255, 128, 128, 0.45); }
@media (min-width: 640px) { .seat .mini { min-height: 52px; } }

.tag { padding: 1px 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); font-weight: 650; white-space: nowrap; }
.tag.dim { background: transparent; color: var(--muted); padding-inline: 0; }
.tag.good { background: rgba(91, 220, 147, 0.18); color: var(--good); }
.tag.bad { background: rgba(255, 128, 128, 0.16); color: var(--bad); }
.tag.live { background: rgba(242, 193, 78, 0.18); color: var(--gold); }
.t { font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.bet { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bet::before { content: "● "; font-size: 0.7em; vertical-align: 0.12em; }

.me {
  margin: 12px 0 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.me header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.me .hand { min-height: 100px; margin-top: 8px; }
.me.turn { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.16); }
.me.won { border-color: rgba(91, 220, 147, 0.7); }
.me.lost { border-color: rgba(255, 128, 128, 0.55); }
.me.spectator { text-align: center; }
.placeholder { color: var(--muted); }
.result { margin-top: 4px; font-size: 1.1rem; font-weight: 700; }
.me.won .result b { color: var(--good); }
.me.lost .result b { color: var(--bad); }
@media (min-width: 640px) { .me .hand { min-height: 124px; } }

.emotes { display: flex; justify-content: center; gap: 6px; }
.emote {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.emote:active { transform: scale(0.92); }
.emote-float {
  position: absolute;
  z-index: 50;
  font-size: 2.1rem;
  pointer-events: none;
  animation: rise 1.6s ease-out forwards;
}
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -12px) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -78px) scale(1); }
}

.history { margin: 10px 0; color: var(--muted); font-size: 0.9rem; }
.history summary { cursor: pointer; padding: 6px 0; }
.history ol { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
.history li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; }

.actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  margin-inline: -16px;
  padding: 18px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(5, 36, 26, 0), rgba(5, 36, 26, 0.94) 26%);
}
.leave { text-align: center; margin-top: 6px; }
.blocked { padding: 10px 12px; border-radius: 10px; background: rgba(255, 128, 128, 0.14); color: #ffd6d6; text-align: center; }

/* One row of at most six chips; they shrink a little rather than wrap on a 360px phone. */
.bet-row { display: flex; justify-content: center; gap: 6px; }
.chip {
  --c: #2f7fdc;
  flex: 0 1 52px;
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  touch-action: manipulation;
  background:
    radial-gradient(circle, var(--c) 0 56%, rgba(255, 255, 255, 0.9) 57% 60%, transparent 61%),
    repeating-conic-gradient(var(--c) 0 30deg, #f7f3e8 30deg 45deg);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22), 0 5px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease;
}
.chip:active { transform: scale(0.93); }
@media (min-width: 640px) { .bet-row { gap: 10px; } .chip { flex-basis: 60px; font-size: 1rem; } }
.chip.c10 { --c: #2f7fdc; }
.chip.c20 { --c: #1b9a5a; }
.chip.c50 { --c: #d9362f; }
.chip.c100 { --c: #25272d; }
.chip.c200 { --c: #7a40cf; }
.chip.c500 { --c: #c28a12; }
.chip.cmax { --c: #5d6168; }

.notice-card { text-align: center; padding: 40px 12px; display: grid; gap: 14px; justify-items: center; }
.notice-card p { color: var(--muted); max-width: 26em; }
.loading { display: grid; justify-items: center; gap: 14px; padding: 70px 0; color: var(--muted); }
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #0d1a13;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sheet {
  width: min(92vw, 480px);
  padding: 20px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #0b2a1e;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet h2 { margin-bottom: 10px; }
.sheet p { margin-bottom: 12px; }
.rules { padding-left: 1.2em; margin: 0 0 12px; display: grid; gap: 8px; }

.free { color: var(--ink); }
.packs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.pack {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 14px 6px 12px;
  border-radius: 14px;
  border: 1px solid rgba(242, 193, 78, 0.35);
  background: linear-gradient(180deg, rgba(242, 193, 78, 0.12), rgba(242, 193, 78, 0.03));
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.pack:active { transform: scale(0.97); }
.pack-chips { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pack-label { color: var(--muted); font-size: 0.8rem; }
.pack-price {
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  font-weight: 700;
  font-size: 0.9rem;
}
.soon { padding: 10px 12px; border-radius: 10px; background: rgba(242, 193, 78, 0.13); }
.fine { color: var(--muted); font-size: 0.88rem; }
.code {
  font: 700 1.55rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.32);
  user-select: all;
  overflow-wrap: anywhere;
}
.noscript { padding: 40px 0; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .deal, .flip, .emote-float, .spinner { animation: none !important; }
  .btn, .chip, .toast { transition: none; }
}
