:root {
  color-scheme: dark;
  --bg: #080c18;
  --panel: rgba(18, 25, 44, 0.92);
  --panel-2: #111a2d;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f7f8fc;
  --muted: #8d98af;
  --gold: #ffca63;
  --orange: #ff8b54;
  --green: #42d6a4;
  --red: #ff687b;
  --blue: #7297ff;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.35);
  --composer-height: 4.15rem;
  --drawer-collapsed: 3.5rem;
  --visual-viewport-height: 100dvh;
  --visual-viewport-bottom: 0px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background:
    radial-gradient(circle at 80% -10%, rgba(114, 151, 255, 0.18), transparent 32rem),
    radial-gradient(circle at 0% 20%, rgba(255, 139, 84, 0.12), transparent 26rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.card { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.eyebrow { color: var(--gold); font-size: 0.67rem; font-weight: 800; letter-spacing: 0.18em; }
.logo-orb {
  width: 4.2rem; height: 4.2rem; display: grid; place-items: center; margin: 0 auto 1rem;
  border-radius: 1.35rem; background: linear-gradient(145deg, var(--gold), var(--orange));
  color: #2c1904; font-size: 2.25rem; font-weight: 900; box-shadow: 0 16px 40px rgba(255, 139, 84, 0.28);
}
.primary-btn {
  border: 0; border-radius: 0.85rem; padding: 0.85rem 1rem; color: #251707;
  background: linear-gradient(135deg, var(--gold), var(--orange)); font-weight: 850;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
input, select {
  width: 100%; border: 1px solid var(--line); border-radius: 0.75rem; padding: 0.78rem 0.85rem;
  color: var(--text); background: rgba(7, 11, 21, 0.72); outline: none;
}
input:focus, select:focus { border-color: rgba(255, 202, 99, 0.65); box-shadow: 0 0 0 3px rgba(255, 202, 99, 0.1); }
.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); z-index: 20;
  max-width: min(90vw, 32rem); transform: translateX(-50%); padding: 0.85rem 1.1rem;
  border: 1px solid var(--line); border-radius: 0.8rem; background: #202a3d; box-shadow: var(--shadow);
}

/* Player H5 */
.player-body { display: flex; justify-content: center; }
.phone-shell { width: min(100%, 31rem); min-height: 100dvh; position: relative; padding-bottom: env(safe-area-inset-bottom); }
.gate { margin: 16vh 1.25rem 0; padding: 2.4rem 1.5rem; border-radius: 1.25rem; text-align: center; }
.gate h1 { margin: 0.5rem 0; }
.gate p { color: var(--muted); }
.room { min-height: 100dvh; display: flex; flex-direction: column; }
.room-header { flex: 0 0 auto; position: relative; z-index: 2; background: var(--bg); }
.topbar { display: flex; justify-content: space-between; align-items: center; min-height: 2.75rem; padding: 0.55rem 0.85rem 0.35rem; }
.topbar h1 { font-size: 1rem; margin: 0; }
.balance-pill { display: flex; align-items: baseline; gap: 0.35rem; min-width: 0; padding: 0.22rem 0.55rem; border: 1px solid var(--line); border-radius: 0.7rem; background: rgba(255,255,255,.035); text-align: right; }
.balance-pill span { color: var(--muted); font-size: 0.65rem; }
.balance-pill strong { color: var(--gold); font-size: 0.95rem; }
.round-card { margin: 0 0.75rem 0.45rem; padding: 0.5rem 0.72rem; border: 1px solid rgba(255,202,99,.16); border-radius: 0.8rem; background: linear-gradient(145deg, rgba(38,43,65,.96), rgba(22,27,44,.96)); box-shadow: 0 8px 22px rgba(0,0,0,.22); }
.round-main { display: flex; align-items: center; justify-content: space-between; }
.round-main > div:first-child { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.round-main h2 { margin: 0; font-size: 0.9rem; white-space: nowrap; }
.status-badge { display: inline-flex; padding: 0.2rem 0.42rem; border-radius: 99px; color: var(--green); background: rgba(66,214,164,.12); font-size: 0.66rem; font-weight: 800; white-space: nowrap; }
.status-badge.closed { color: var(--red); background: rgba(255,104,123,.12); }
.countdown { text-align: right; }
.countdown span { display: block; color: var(--muted); font-size: 0.7rem; }
.countdown strong { font-variant-numeric: tabular-nums; color: var(--gold); font-size: 1.25rem; }
.countdown.warning strong { color: var(--orange); }
.countdown.critical strong { color: var(--red); animation: countdown-pulse 850ms ease-in-out infinite alternate; }
.countdown.closed strong { color: var(--red); }
@keyframes countdown-pulse { from { opacity: 0.68; } to { opacity: 1; } }
.latest-result { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.7rem; }
.latest-result.alert { color: var(--red); font-weight: 750; }
.messages { flex: 1; min-height: 15rem; overflow-y: auto; overscroll-behavior: contain; padding: 0.25rem 0.85rem calc(var(--composer-height) + var(--drawer-collapsed) + 0.75rem + env(safe-area-inset-bottom)); scrollbar-width: thin; }
.message { display: flex; gap: 0.48rem; margin: 0.5rem 0; align-items: flex-start; }
.avatar { flex: 0 0 auto; width: 1.75rem; height: 1.75rem; border-radius: 0.55rem; display: grid; place-items: center; background: #24304a; color: var(--gold); font-size: 0.66rem; font-weight: 900; }
.message-body { min-width: 0; }
.message-name { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.18rem; color: var(--muted); font-size: 0.68rem; }
.bot-chip { color: var(--blue); font-size: 0.67rem; font-weight: 800; }
.bubble { display: inline-block; max-width: 100%; padding: 0.5rem 0.65rem; border-radius: 0.22rem 0.75rem 0.75rem 0.75rem; background: #172138; overflow-wrap: anywhere; font-size: 0.86rem; }
.message.system { justify-content: center; }
.message.system .bubble { color: var(--muted); background: rgba(255,255,255,.045); border-radius: 99px; font-size: 0.72rem; }
.message.bet .bubble { border: 1px solid rgba(255,202,99,.2); color: var(--gold); }
.bet-backdrop {
  position: fixed; inset: 0 0 calc(var(--composer-height) + env(safe-area-inset-bottom) + var(--visual-viewport-bottom)); z-index: 14;
  width: min(100%, 31rem); margin: auto; border: 0; background: rgba(3, 6, 14, 0.52);
}
.bet-panel {
  position: fixed; left: 50%; bottom: calc(var(--composer-height) + env(safe-area-inset-bottom) + var(--visual-viewport-bottom)); z-index: 16;
  width: min(calc(100% - 1rem), 30rem); height: 52vh; height: clamp(22rem, 52dvh, 30rem);
  max-height: calc(var(--visual-viewport-height) - var(--composer-height) - env(safe-area-inset-bottom) - 0.5rem); margin: 0;
  padding: 0; border-radius: 1.2rem 1.2rem 0 0; overflow: hidden;
  translate: -50% 0; transform: translateY(calc(100% - var(--drawer-collapsed)));
  transition: transform 220ms cubic-bezier(.2,.75,.25,1); will-change: transform;
  box-shadow: 0 -18px 48px rgba(0,0,0,.42); touch-action: none;
}
.bet-panel.expanded { transform: translateY(0); }
.bet-panel.dragging { transition: none; }
.bet-drawer-toggle {
  width: 100%; height: var(--drawer-collapsed); display: grid;
  grid-template-columns: auto 1fr auto; grid-template-rows: 0.8rem 1fr; align-items: center;
  gap: 0 0.55rem; padding: 0.2rem 1rem 0.55rem; border: 0; color: var(--text);
  background: linear-gradient(180deg, rgba(35,44,67,.99), rgba(23,31,51,.99)); text-align: left;
}
.drawer-grabber { grid-column: 1 / -1; justify-self: center; width: 2.7rem; height: 0.25rem; border-radius: 99px; background: rgba(255,255,255,.28); }
.drawer-title { color: var(--gold); font-size: 0.78rem; font-weight: 850; }
.bet-drawer-toggle strong { overflow: hidden; color: var(--text); font-size: 0.78rem; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.drawer-chevron { color: var(--muted); font-size: 1rem; transition: transform 180ms ease; }
.bet-panel.expanded .drawer-chevron { transform: rotate(180deg); }
.bet-panel-content { height: calc(100% - var(--drawer-collapsed)); padding: 0.75rem calc(0.85rem + env(safe-area-inset-right)) 0.9rem calc(0.85rem + env(safe-area-inset-left)); overflow-y: auto; overscroll-behavior: contain; opacity: 0; pointer-events: none; transition: opacity 120ms ease; touch-action: pan-y; }
.bet-panel.expanded .bet-panel-content { opacity: 1; pointer-events: auto; transition-delay: 80ms; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 0.25rem; border-radius: 0.75rem; background: rgba(0,0,0,.25); }
.segment { min-height: 2.75rem; border: 0; border-radius: 0.6rem; padding: 0.5rem; color: var(--muted); background: transparent; font-weight: 750; }
.segment.active { color: var(--text); background: #26314a; }
.number-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin: 0.75rem 0; }
.number-grid button, .quick-stakes button {
  min-height: 2.75rem; border: 1px solid var(--line); border-radius: 0.72rem; padding: 0.55rem 0.25rem; color: var(--text); background: rgba(255,255,255,.035); font-weight: 800;
}
.number-grid button.selected { border-color: var(--gold); color: #261a08; background: var(--gold); }
.stake-row { display: grid; grid-template-columns: 5rem 1fr; align-items: center; gap: 0.7rem; }
.stake-row label { color: var(--muted); font-size: 0.76rem; }
.quick-stakes { display: grid; grid-template-columns: repeat(4,1fr); gap: 0.4rem; margin: 0.55rem 0 0.7rem; }
.quick-stakes button { min-height: 2.25rem; padding: 0.35rem; color: var(--muted); font-size: 0.74rem; }
.bet-panel .primary-btn { width: 100%; }
.rule-hint { margin: 0.55rem 0 0; color: var(--muted); text-align: center; font-size: 0.68rem; }
.chat-composer {
  position: fixed; left: 50%; bottom: var(--visual-viewport-bottom); z-index: 17; translate: -50% 0;
  width: min(100%, 31rem); min-height: calc(var(--composer-height) + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: 1fr auto; gap: 0.5rem;
  padding: 0.6rem calc(0.75rem + env(safe-area-inset-right)) calc(0.6rem + env(safe-area-inset-bottom)) calc(0.75rem + env(safe-area-inset-left));
  border-top: 1px solid var(--line); background: rgba(8,12,24,.97);
}
.chat-composer input { padding: 0.65rem 0.75rem; }
.chat-composer button { border: 0; border-radius: 0.72rem; padding: 0 0.95rem; color: #291b06; background: var(--gold); font-weight: 800; }
html.drawer-open, .player-body.drawer-open { overflow: hidden; overscroll-behavior: none; }

/* Mobile is the baseline. Do not add transform/filter/contain to .room or
   .phone-shell: that would re-anchor the fixed composer and betting sheet. */
.phone-shell { padding-bottom: 0; }
.room { min-height: 0; height: var(--visual-viewport-height); overflow: hidden; }
.room-header { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.messages {
  min-height: 0;
  padding-left: calc(0.85rem + env(safe-area-inset-left));
  padding-right: calc(0.85rem + env(safe-area-inset-right));
}

/* Admin */
.admin-shell { width: min(100% - 2rem, 75rem); margin: 0 auto; padding: 2rem 0 4rem; }
.admin-login { width: min(100%, 26rem); margin: 12vh auto 0; padding: 2rem; border-radius: 1.25rem; text-align: center; }
.admin-login p { color: var(--muted); }
.admin-login form { display: grid; gap: 0.75rem; margin-top: 1.25rem; }
.error-text { min-height: 1rem; color: var(--red) !important; font-size: 0.8rem; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.admin-header h1 { margin: 0.2rem 0 0; font-size: clamp(1.35rem, 3vw, 2rem); }
.header-actions { display: flex; gap: 0.5rem; }
.header-actions button, .panel-title button { border: 1px solid var(--line); border-radius: 0.7rem; padding: 0.55rem 0.75rem; color: var(--text); background: rgba(255,255,255,.04); }
.metrics-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 0.8rem; }
.metric { padding: 1rem; border-radius: 1rem; }
.metric span, .metric small { color: var(--muted); }
.metric span { display: block; font-size: 0.75rem; }
.metric strong { display: block; margin: 0.45rem 0 0.25rem; color: var(--gold); font-size: 1.4rem; }
.metric small { font-size: 0.68rem; }
.admin-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 0.8rem; margin-top: 0.8rem; }
.admin-panel { padding: 1rem; border-radius: 1rem; }
.span-two { grid-column: span 2; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.85rem; }
.panel-title h2 { margin: 0; font-size: 1rem; }
.panel-title > span { color: var(--muted); font-size: 0.7rem; }
.stack-form { display: grid; gap: 0.65rem; }
.stack-form label, .template-form label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.7rem; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.template-form { display: grid; grid-template-columns: 9rem 1fr 8rem auto; gap: 0.55rem; align-items: end; }
.entry-result { margin-top: 0.8rem; padding: 0.75rem; border: 1px dashed rgba(255,202,99,.3); border-radius: 0.75rem; color: var(--gold); overflow-wrap: anywhere; }
.data-list { display: grid; gap: 0.45rem; }
.data-row { display: grid; grid-template-columns: minmax(8rem,1.4fr) repeat(3,minmax(5rem,1fr)); gap: 0.6rem; align-items: center; padding: 0.65rem 0.75rem; border: 1px solid var(--line); border-radius: 0.75rem; background: rgba(0,0,0,.12); font-size: 0.78rem; }
.data-row small { color: var(--muted); }
.status-ok { color: var(--green) !important; }
.status-error { color: var(--red) !important; }

@media (max-width: 760px) {
  .admin-shell { width: min(100% - 1rem, 75rem); padding-top: 1rem; }
  .metrics-grid { grid-template-columns: repeat(2,1fr); }
  .admin-grid { grid-template-columns: 1fr; }
  .span-two { grid-column: span 1; }
  .template-form { grid-template-columns: 1fr; }
  .data-row { grid-template-columns: 1fr 1fr; }
}

@media (width < 768px) and (orientation: landscape) and (max-height: 420px) {
  .topbar { padding-top: 0.4rem; padding-bottom: 0.35rem; }
  .latest-result:not(.alert) { display: none; }
  .round-card { margin-bottom: 0.3rem; padding-block: 0.4rem; }
}

@media (min-width: 768px) {
  .phone-shell { padding-bottom: env(safe-area-inset-bottom); }
  .room { min-height: 100dvh; height: auto; overflow: visible; }
  .room-header { padding: 0; }
  .messages { min-height: 15rem; max-height: 36dvh; padding-right: 0.85rem; padding-bottom: 0.65rem; padding-left: 0.85rem; }
  .bet-backdrop { display: none !important; }
  .bet-panel { position: static; width: auto; height: auto; max-height: none; margin: 0 0.75rem; padding: 0.8rem; border-radius: 1.1rem; overflow: visible; translate: none; transform: none !important; transition: none; touch-action: auto; }
  .bet-drawer-toggle { display: none; }
  .bet-panel-content { height: auto; padding: 0; overflow: visible; opacity: 1; pointer-events: auto; transition: none; }
  .chat-composer { position: static; width: auto; min-height: 0; translate: none; border-top: 0; background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .bet-panel, .drawer-chevron, .bet-panel-content { transition-duration: 1ms !important; }
  .countdown.critical strong { animation: none; }
}

@media (prefers-contrast: more) {
  .bet-panel, .chat-composer { background: var(--panel-2); border-color: rgba(255,255,255,.35); }
  .bet-backdrop { background: rgba(0,0,0,.72); }
}
