/* Roulette Royale — HUD and lobby.
   Layout is driven by safe-area insets and clamp() so the same markup works on
   a phone in portrait and a wide laptop without a separate mobile stylesheet. */

:root {
  --gold: #d8b45c;
  --gold-soft: #f0d99a;
  --green: #0c5738;
  --red: #b3202b;
  --ink: #f4efe2;
  --muted: #9aa1ae;
  --panel: rgba(12, 15, 21, 0.82);
  --panel-line: rgba(216, 180, 92, 0.24);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --sans: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05070b;
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font-family: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ── boot ─────────────────────────────────────────────────────────────── */

.boot {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-content: center; justify-items: center; gap: 22px;
  background: radial-gradient(circle at 50% 45%, #101822 0%, #05070b 70%);
  transition: opacity 0.5s ease, visibility 0.5s;
}
.boot[hidden] { display: grid; opacity: 0; visibility: hidden; pointer-events: none; }
.boot__wheel {
  width: 76px; height: 76px; border-radius: 50%;
  border: 4px solid rgba(216, 180, 92, 0.18);
  border-top-color: var(--gold);
  border-right-color: var(--red);
  animation: spin 1.1s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
}
.boot__label { margin: 0; color: var(--muted); letter-spacing: 0.14em; font-size: 12px; text-transform: uppercase; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── shared controls ──────────────────────────────────────────────────── */

.btn {
  border: 1px solid var(--panel-line);
  background: rgba(28, 33, 43, 0.9);
  color: var(--ink);
  padding: 11px 16px;
  border-radius: 11px;
  font-size: 14px; font-weight: 700;
  letter-spacing: 0.03em;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease, opacity 0.18s;
}
.btn:hover:not(:disabled) { background: rgba(44, 51, 65, 0.95); border-color: rgba(216, 180, 92, 0.5); }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.34; cursor: not-allowed; }
.btn--gold { background: linear-gradient(180deg, #e8c877, #c39c48); color: #1a1408; border-color: #e8c877; }
.btn--gold:hover:not(:disabled) { background: linear-gradient(180deg, #f5dc96, #d0a950); }
.btn--ghost { background: rgba(255, 255, 255, 0.04); }
.btn--wide { width: 100%; }
.btn--tiny { padding: 5px 10px; font-size: 11px; border-radius: 8px; }
.btn--icon { padding: 0; width: 44px; height: 44px; font-size: 17px; display: grid; place-items: center; }

.field { display: block; }
.field__label {
  display: block; margin-bottom: 6px;
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
}
.field__input {
  width: 100%; padding: 13px 15px;
  background: rgba(8, 11, 16, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 11px;
  color: var(--ink); font-size: 16px; font-family: inherit;
}
.field__input::placeholder { color: #5d646f; }
.field__input--code { text-transform: uppercase; letter-spacing: 0.22em; text-align: center; font-weight: 700; }

/* ── lobby ────────────────────────────────────────────────────────────── */

.lobby {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: linear-gradient(180deg, rgba(3, 5, 9, 0.72), rgba(3, 5, 9, 0.9));
  backdrop-filter: blur(7px);
  overflow-y: auto;
  animation: fade 0.45s ease;
}
.lobby[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.lobby__panel {
  width: min(430px, 100%);
  display: grid; gap: 14px;
  padding: clamp(20px, 4vw, 30px);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.lobby__head { text-align: center; }
.lobby__title {
  margin: 0; font-family: var(--serif); font-weight: 700;
  font-size: clamp(30px, 8vw, 40px); letter-spacing: 0.02em;
  background: linear-gradient(180deg, #fbe9bb, var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lobby__sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.wallet {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-radius: 11px;
  background: rgba(216, 180, 92, 0.09);
  border: 1px solid rgba(216, 180, 92, 0.3);
}
.wallet__label { font-size: 11px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted); }
.wallet strong { font-size: 20px; color: var(--gold-soft); font-variant-numeric: tabular-nums; }

.lobby__split { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; color: #5d646f; font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; }
.lobby__split::before, .lobby__split::after { content: ''; height: 1px; background: rgba(255, 255, 255, 0.1); }
.lobby__row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.lobby__note { margin: 2px 0 0; text-align: center; color: #5d646f; font-size: 11px; }

.lobby__rooms { border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 12px; }
.lobby__roomsHead {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
}
.roomList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 154px; overflow-y: auto; }
.roomList__empty { color: #5d646f; font-size: 13px; padding: 8px 2px; }
.roomList__item {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid transparent;
  font-size: 13px; width: 100%; text-align: left; color: var(--ink);
}
.roomList__item:hover { border-color: var(--panel-line); background: rgba(255, 255, 255, 0.07); }
.roomList__code { font-weight: 700; letter-spacing: 0.16em; color: var(--gold-soft); }
.roomList__meta { color: var(--muted); font-size: 12px; }
.roomList__seats { color: var(--muted); font-size: 12px; }

/* ── HUD scaffolding ──────────────────────────────────────────────────── */

.hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.hud[hidden] { display: none; }
.hud > * { pointer-events: auto; }

.hud__topLeft {
  position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l));
  display: flex; gap: 8px; align-items: center;
}
.hud__topRight { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); }
.hud__topCenter {
  position: absolute; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  width: min(340px, 52vw);
}

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 13px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-line);
  color: var(--ink); font-size: 13px; backdrop-filter: blur(8px);
}
.pill__label { font-size: 9.5px; letter-spacing: 0.18em; color: var(--muted); }
.pill--btn { transition: border-color 0.2s, transform 0.12s; }
.pill--btn:active { transform: scale(0.95); }
.pill--btn:hover { border-color: rgba(216, 180, 92, 0.55); }
.pill--quiet { color: var(--muted); font-size: 12px; }
.pill--balance strong { font-size: 16px; color: var(--gold-soft); font-variant-numeric: tabular-nums; }
.pill__dot { width: 8px; height: 8px; border-radius: 50%; background: #46c17f; box-shadow: 0 0 8px #46c17f; transition: background 0.3s, box-shadow 0.3s; }
.pill__dot.is-off { background: #d0524f; box-shadow: 0 0 8px #d0524f; }
#roomCode { letter-spacing: 0.2em; color: var(--gold-soft); }

/* phase clock */
.phase {
  position: relative; overflow: hidden;
  height: 38px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-line);
  backdrop-filter: blur(8px);
}
.phase__fill {
  position: absolute; inset: 0; transform-origin: left center;
  background: linear-gradient(90deg, rgba(70, 193, 127, 0.36), rgba(70, 193, 127, 0.16));
  transition: transform 0.24s linear, background 0.4s ease;
}
.phase__text {
  position: relative; height: 100%;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.phase__timer { color: var(--gold-soft); font-variant-numeric: tabular-nums; min-width: 26px; text-align: right; }
.phase.is-closing .phase__fill { background: linear-gradient(90deg, rgba(216, 160, 60, 0.45), rgba(216, 160, 60, 0.18)); }
.phase.is-spinning .phase__fill { background: linear-gradient(90deg, rgba(179, 32, 43, 0.5), rgba(179, 32, 43, 0.2)); }
.phase.is-urgent .phase__text { animation: pulse 0.85s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

/* history */
.history {
  position: absolute; right: calc(10px + var(--safe-r)); top: calc(58px + var(--safe-t));
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 46vh; overflow: hidden;
}
.history li {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; font-family: var(--serif);
  border: 1px solid rgba(255, 255, 255, 0.14);
  animation: dealIn 0.35s cubic-bezier(0.2, 1.3, 0.5, 1);
}
.history li.red { background: var(--red); }
.history li.black { background: #16171b; }
.history li.green { background: var(--green); }
@keyframes dealIn { from { opacity: 0; transform: translateY(-10px) scale(0.7); } }

/* tooltip */
.tooltip {
  position: absolute; z-index: 3;
  display: grid; gap: 1px;
  padding: 8px 11px; border-radius: 10px;
  background: rgba(8, 11, 16, 0.94); border: 1px solid var(--panel-line);
  font-size: 12px; pointer-events: none; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 14px));
  box-shadow: var(--shadow);
}
.tooltip[hidden] { display: none; }
.tooltip strong { font-size: 13px; color: var(--gold-soft); }
.tooltip__on { color: #46c17f; }

/* result banner */
.banner {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  display: grid; place-items: center; gap: 10px;
  pointer-events: none;
  animation: bannerIn 0.55s cubic-bezier(0.15, 1.4, 0.4, 1);
}
.banner[hidden] { display: none; }
.banner__num {
  width: clamp(96px, 24vw, 138px); height: clamp(96px, 24vw, 138px);
  display: grid; place-items: center;
  border-radius: 26px; border: 3px solid var(--gold);
  font-family: var(--serif); font-weight: 700; font-size: clamp(46px, 12vw, 68px);
  box-shadow: 0 0 60px rgba(216, 180, 92, 0.45), var(--shadow);
  background: #16171b;
}
.banner__num.red { background: var(--red); }
.banner__num.green { background: var(--green); }
.banner__meta { display: grid; place-items: center; gap: 3px; text-align: center; }
.banner__meta span { font-size: 12px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--muted); }
.banner__pay { font-size: 17px !important; font-weight: 700; letter-spacing: 0.05em !important; text-transform: none !important; }
.banner__pay.win { color: #6ee7a8 !important; }
.banner__pay.lose { color: #e08a86 !important; }
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.55); } }

/* player-count picker */
.sizes { display: flex; gap: 6px; }
.size {
  flex: 1; height: 42px; border-radius: 10px;
  background: rgba(8, 11, 16, 0.85); border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ink); font-size: 15px; font-weight: 700;
  transition: all 0.16s ease;
}
.size:hover { border-color: var(--panel-line); }
.size[aria-pressed='true'] {
  background: linear-gradient(180deg, #e8c877, #c39c48); color: #1a1408; border-color: #e8c877;
}

/* waiting for the table to fill */
.waitRoom {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, 88vw);
  display: grid; justify-items: center; gap: 10px;
  padding: 24px 22px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--panel-line);
  box-shadow: var(--shadow); backdrop-filter: blur(10px);
  animation: bannerIn 0.4s cubic-bezier(0.15, 1.4, 0.4, 1);
}
.waitRoom[hidden] { display: none; }
.waitRoom__label { margin: 0; font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.waitRoom__count { display: flex; align-items: baseline; gap: 3px; font-family: var(--serif); font-size: 40px; color: var(--muted); }
.waitRoom__count strong { font-size: 52px; color: var(--gold-soft); }
.waitRoom__code {
  display: grid; gap: 2px; justify-items: center;
  padding: 9px 22px; border-radius: 12px;
  background: rgba(216, 180, 92, 0.1); border: 1px solid rgba(216, 180, 92, 0.35);
  color: var(--ink);
}
.waitRoom__code span { font-size: 9.5px; letter-spacing: 0.2em; color: var(--muted); }
.waitRoom__code strong { font-size: 26px; letter-spacing: 0.28em; color: var(--gold-soft); }
.waitRoom__hint { margin: 0; text-align: center; font-size: 12px; color: var(--muted); max-width: 26ch; }
.waitRoom__list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; width: 100%; }
.waitRoom__list li {
  padding: 7px 12px; border-radius: 8px; font-size: 13px;
  background: rgba(255, 255, 255, 0.03); color: #5d646f;
  border: 1px dashed rgba(255, 255, 255, 0.1);
}
.waitRoom__list li.is-here {
  background: rgba(70, 193, 127, 0.12); color: var(--ink);
  border: 1px solid rgba(70, 193, 127, 0.4);
}

/* knocked out / winner */
.matchCard {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 8px; pointer-events: none;
  padding: 22px 34px; border-radius: 20px; text-align: center;
  background: rgba(10, 12, 17, 0.9); border: 1px solid var(--panel-line);
  box-shadow: var(--shadow); backdrop-filter: blur(8px);
  animation: bannerIn 0.5s cubic-bezier(0.15, 1.4, 0.4, 1);
}
.matchCard[hidden] { display: none; }
.matchCard__title { font-family: var(--serif); font-size: clamp(28px, 7vw, 42px); color: var(--ink); }
.matchCard__body { font-size: 13px; color: var(--muted); }
.matchCard.is-out { border-color: rgba(224, 138, 134, 0.5); }
.matchCard.is-out .matchCard__title { color: #e08a86; }
.matchCard.is-win { border-color: var(--gold); box-shadow: 0 0 60px rgba(216, 180, 92, 0.4), var(--shadow); }
.matchCard.is-win .matchCard__title {
  background: linear-gradient(180deg, #fbe9bb, var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* chips counting up and down */
#balance.is-up { color: #6ee7a8; }
#balance.is-down { color: #e08a86; }
.pill--ante strong { font-size: 15px; color: #e0b06a; font-variant-numeric: tabular-nums; }
.pill--ante[hidden] { display: none; }

.seatHint {
  position: absolute; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%);
  padding: 9px 18px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-line);
  font-size: 13px; letter-spacing: 0.04em; backdrop-filter: blur(8px);
  animation: pulse 2.4s ease-in-out infinite;
}
.seatHint[hidden] { display: none; }

/* ── bottom rail ──────────────────────────────────────────────────────── */

.hud__bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 calc(10px + var(--safe-l)) calc(10px + var(--safe-b)) calc(10px + var(--safe-r));
  display: grid; gap: 8px; justify-items: center;
}

.rail {
  display: flex; align-items: center; gap: clamp(8px, 2vw, 18px);
  padding: 10px 14px; border-radius: 18px;
  background: var(--panel); border: 1px solid var(--panel-line);
  box-shadow: var(--shadow); backdrop-filter: blur(10px);
  max-width: 100%;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.rail.is-locked { opacity: 0.38; pointer-events: none; transform: translateY(6px); }

.rail__chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.rail__chips::-webkit-scrollbar { display: none; }

.chip {
  position: relative; flex: 0 0 auto;
  width: 52px; height: 52px; border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, 0.5);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.45);
  transition: transform 0.14s cubic-bezier(0.2, 1.4, 0.5, 1), box-shadow 0.2s;
}
.chip:hover { transform: translateY(-4px); }
.chip[aria-pressed='true'] {
  transform: translateY(-7px) scale(1.06);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.4), 0 0 0 3px var(--gold), 0 8px 18px rgba(0, 0, 0, 0.5);
}
.chip[data-value='1'] { background: #f3f1ea; color: #23252b; text-shadow: none; border-color: #2a2c33; }
.chip[data-value='5'] { background: #c2242f; }
.chip[data-value='25'] { background: #1f7a43; }
.chip[data-value='100'] { background: #1d1f26; border-color: var(--gold); color: var(--gold-soft); }
.chip[data-value='500'] { background: #5b2c86; border-color: var(--gold-soft); }
.chip:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.rail__actions { display: flex; gap: 6px; }
.rail__total { display: grid; gap: 1px; justify-items: end; min-width: 74px; }
.rail__totalLabel { font-size: 9.5px; letter-spacing: 0.16em; color: var(--muted); }
.rail__total strong { font-size: 19px; color: var(--gold-soft); font-variant-numeric: tabular-nums; }

.hud__bottomRow {
  display: flex; align-items: center; justify-content: center;
  gap: clamp(8px, 2vw, 20px); flex-wrap: wrap;
}

.emotes {
  display: flex; gap: 5px;
  padding: 5px 7px; border-radius: 999px;
  background: rgba(12, 15, 21, 0.75); border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}
.emote {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid transparent; background: rgba(255, 255, 255, 0.06);
  font-size: 17px; line-height: 1; padding: 0;
  display: grid; place-items: center;
  transition: transform 0.14s cubic-bezier(0.2, 1.4, 0.5, 1), background 0.18s, border-color 0.18s;
}
.emote:hover { transform: translateY(-3px) scale(1.1); background: rgba(255, 255, 255, 0.13); border-color: var(--panel-line); }
.emote:active { transform: scale(0.9); }

.views { display: flex; gap: 6px; }
.view {
  padding: 7px 15px; border-radius: 999px;
  background: rgba(12, 15, 21, 0.75); border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  backdrop-filter: blur(8px); transition: all 0.18s ease;
}
.view:hover { color: var(--ink); }
.view.is-active { background: var(--gold); color: #1a1408; border-color: var(--gold); }

/* ── toasts ───────────────────────────────────────────────────────────── */

.toasts {
  position: absolute; left: 50%; top: calc(60px + var(--safe-t)); transform: translateX(-50%);
  display: grid; gap: 6px; justify-items: center; pointer-events: none;
}
.toast {
  padding: 9px 16px; border-radius: 999px;
  background: rgba(24, 12, 12, 0.94); border: 1px solid rgba(224, 138, 134, 0.45);
  color: #f3d3d1; font-size: 13px; font-weight: 700;
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.2s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* ── narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 620px) {
  .hud__topCenter { width: min(230px, 46vw); }
  .phase { height: 34px; }
  .phase__text { font-size: 11px; letter-spacing: 0.05em; }
  .history { top: calc(52px + var(--safe-t)); }
  .history li { width: 27px; height: 27px; font-size: 11.5px; }
  .rail { gap: 8px; padding: 8px 10px; border-radius: 15px; width: 100%; }
  .chip { width: 46px; height: 46px; font-size: 13px; }
  .btn--icon { width: 38px; height: 38px; font-size: 15px; }
  .rail__actions { display: grid; grid-template-columns: repeat(2, auto); gap: 5px; }
  .rail__total { min-width: 58px; }
  .rail__total strong { font-size: 16px; }
  .hud__bottomRow { gap: 6px; }
  .emote { width: 30px; height: 30px; font-size: 15px; }
  .view { padding: 6px 11px; font-size: 11px; }
  .seatHint { bottom: calc(178px + var(--safe-b)); font-size: 12px; }
}

@media (max-width: 400px) {
  .pill__label { display: none; }
  .chip { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
