:root {
  --bg: #071018;
  --panel: #0d1822;
  --line: #1c2e3d;
  --cyan: #2ee6d6;
  --gold: #d4a017;
  --text: #e8f1f7;
  --muted: #8aa0b2;
  --danger: #ff5b45;
  --ok: #15d817;
  --horse: #1ecad8;
  --dog: #f0a020;
  --car: #9b6bff;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  font-family: Roboto, sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(7,16,24,.92), rgba(10,24,36,.95)),
    repeating-linear-gradient(-45deg, #0a1620 0 12px, #0c1a26 12px 24px);
}
button { font: inherit; cursor: pointer; border: 0; }
#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(5,12,18,.85);
  border-bottom: 1px solid var(--line);
}
.brand .logo { height: 36px; display: block; }
.sport-tabs { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.sport-tab {
  min-width: 108px;
  padding: 8px 14px 10px;
  border-radius: 999px;
  background: #132231;
  color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 2px solid transparent;
  position: relative;
}
.sport-tab img { width: 30px; height: 30px; object-fit: contain; display: block; }
.sport-tab .tm { font-family: Rajdhani, sans-serif; font-weight: 700; font-size: 18px; letter-spacing: .04em; }
.sport-tab.active { border-color: var(--cyan); box-shadow: 0 0 0 1px rgba(46,230,214,.25) inset; }
/* Horses idle = same fill as helmet (default sport-tab) */
.sport-tab[data-sport="horses"] {
  background: #132231;
  border-color: rgba(244,187,86,.35);
}
/* Horses active = same purple fill + bright gold border as helmet/nascar */
.sport-tab[data-sport="horses"].active {
  background: linear-gradient(180deg, #2a1f3f, #1a1428);
  border-color: #f4bb56;
  color: var(--text);
  box-shadow: none;
}
.sport-tab[data-sport="horses"].active .tm { color: var(--text); }
.sport-tab[data-sport="greyhound"].active {
  background: linear-gradient(180deg, #2a1f3f, #1a1428);
  border-color: #f4bb56;
  color: var(--text);
  box-shadow: none;
}
.sport-tab[data-sport="nascar"].active { background: linear-gradient(180deg,#2a1f3f,#1a1428); border-color: #f4bb56; }
.sport-tab[data-sport="greyhound"] {
  background: #132231;
  border-color: rgba(244,187,86,.35);
}
.sport-tab[data-sport="nascar"] { border-color: rgba(244,187,86,.35); }
.top-right { display: flex; align-items: center; gap: 12px; }
.clock, .balance { font-family: Rajdhani, sans-serif; font-weight: 700; font-size: 18px; }
.balance { color: var(--cyan); }
.exit-btn { background: #243545; color: #fff; padding: 8px 12px; border-radius: 6px; }

.help-btn {
  width: 34px; height: 34px; padding: 0; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer;
}
.help-btn img {
  width: 26px; height: 26px; display: block;
  filter: brightness(0) saturate(100%) invert(72%) sepia(72%) saturate(1200%) hue-rotate(146deg) brightness(104%) contrast(101%);
}
.help-btn:hover { opacity: .85; }

.lang-switch { position: relative; z-index: 40; }
.lang-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border: 0; border-radius: 6px;
  background: #18222e; color: #fff; cursor: pointer;
}
.lang-btn img { width: 22px; height: 16px; object-fit: cover; border-radius: 2px; }
.lang-btn #lang-code { font-size: 12px; font-weight: 700; }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  max-height: 280px; overflow: auto; min-width: 180px;
  background: #1a222c; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0,0,0,.45);
}
.lang-menu.hide { display: none; }
.lang-item {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; text-align: left; border: 0;
  background: transparent; color: #fff; cursor: pointer; font-size: 12px;
}
.lang-item:hover, .lang-item.on { background: #243040; }
.lang-item img { width: 22px; height: 16px; object-fit: cover; }

.help-modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.7); padding: 16px;
}
.help-modal.hide { display: none; }
.help-modal-card {
  width: min(720px, 100%); max-height: min(86vh, 760px);
  display: flex; flex-direction: column;
  background: #2f343b; border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
  overflow: hidden; color: #fff;
}
.help-modal-head {
  display: flex; align-items: center; justify-content: center;
  position: relative; padding: 14px; border-bottom: 1px solid #444;
}
.help-modal-head h2 { margin: 0; font-size: 16px; }
.help-close {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 22px; width: 32px; height: 32px;
  border: 0; background: transparent; color: #fff; cursor: pointer;
}
.help-modal-body {
  padding: 14px 16px; overflow: auto; flex: 1;
  font-size: 14px; line-height: 1.45; color: #e8eef5;
}
.help-modal-body p { margin: 0 0 12px; }
.stats-footer { padding: 10px 16px; border-top: 1px solid #444; }
.stats-clear {
  background: #243545; border: 0; color: #fff;
  padding: 8px 12px; border-radius: 6px; font-weight: 700; cursor: pointer;
}
.stats-row {
  padding: 8px 0; border-bottom: 1px solid #3a4048; font-size: 13px;
}
.stats-row .sub { opacity: .75; font-size: 12px; margin-top: 2px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 12px;
  padding: 12px 16px 20px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.stage {
  position: relative;
  aspect-ratio: 16/9;
  background: #000 url("/casino/races/modules/FASV/bin_prod/data/images/horses/poster.webp") center/cover;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}
#race-video, .poster {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
#race-video { background: #000; z-index: 1; }
.poster { z-index: 2; }
.poster.hide, #race-video.hide { display: none; }
.mute-btn {
  position: absolute; top: 10px; right: 10px; z-index: 6;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,.45); color: #fff;
}
.track-banner {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: linear-gradient(90deg, #f0b429, #e08a12);
  color: #1a1200; font-family: Rajdhani, sans-serif; font-weight: 700;
  font-size: 15px; letter-spacing: .03em;
  padding: 6px 12px; border-radius: 4px;
}
.phase-label {
  position: absolute; right: 12px; bottom: 12px; z-index: 5;
  background: rgba(0,0,0,.55); padding: 6px 10px; border-radius: 4px;
  font-size: 13px; color: #fff;
}
.racer-grid {
  position: absolute; inset: 0; z-index: 4;
  display: grid; grid-template-columns: repeat(4, minmax(56px, 72px));
  gap: 10px; place-content: center; pointer-events: none;
}
.racer-grid.hide { display: none; }
.racer-grid img { width: 64px; height: 64px; filter: drop-shadow(0 4px 8px rgba(0,0,0,.45)); }

.results {
  position: absolute; inset: 0; z-index: 7;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45);
}
.results.show { display: flex; }
.results-inner {
  width: min(420px, 92%);
  background: linear-gradient(180deg, #102433, #0a1720);
  border: 1px solid rgba(46,230,214,.35);
  border-radius: 10px; padding: 18px 20px;
}
.results-inner h2 {
  margin: 0 0 12px; text-align: center;
  font-family: Rajdhani, sans-serif; color: var(--cyan); letter-spacing: .08em;
}
.results-inner ol { margin: 0; padding: 0; list-style: none; }
.results-inner li {
  display: grid; grid-template-columns: 36px 40px 1fr auto; gap: 10px;
  align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line);
}
.results-inner li:last-child { border-bottom: 0; }
.results-inner .pos { font-family: Rajdhani, sans-serif; font-weight: 700; color: var(--gold); font-size: 18px; }
.results-inner img { width: 34px; height: 34px; }

.status-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; color: var(--muted); font-size: 13px;
}
.status-bar #bets-status { color: var(--cyan); }

.markets {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.market-tabs { display: flex; gap: 4px; padding: 8px; background: #0a141c; }
.market-tabs button {
  background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 6px;
}
.market-tabs button.active { background: #163040; color: var(--cyan); }

.racer-table { max-height: 360px; overflow: auto; }
.rt-head, .rt-row {
  display: grid;
  grid-template-columns: 1fr 90px 90px 70px;
  gap: 8px; align-items: center;
  padding: 8px 12px;
}
.rt-head {
  position: sticky; top: 0; background: #101c27; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; z-index: 1;
}
.rt-row { border-top: 1px solid var(--line); }
.rt-row:hover { background: rgba(46,230,214,.05); }
.racer-meta { display: flex; align-items: center; gap: 10px; min-width: 0; }
.racer-meta img { width: 34px; height: 34px; flex: 0 0 auto; }
.racer-meta .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.racer-meta .form { color: var(--muted); font-size: 12px; }
.odd-btn, .ew-btn {
  background: #152433; color: #fff; border-radius: 6px; padding: 10px 8px;
  font-family: Rajdhani, sans-serif; font-weight: 700; font-size: 16px;
}
.odd-btn:hover, .ew-btn:hover { background: #1d3346; }
.odd-btn.on { background: linear-gradient(180deg, #15d817, #8de706); color: #071008; }
.ew-btn { font-size: 13px; color: var(--cyan); }
.ew-btn.on { background: #163a30; color: #fff; border: 1px solid var(--cyan); }
.odd-btn:disabled, .ew-btn:disabled { opacity: .45; cursor: not-allowed; }

.ticket {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
  align-self: start;
  overflow: hidden;
  transition: box-shadow .35s ease, border-color .35s ease;
}
.ticket.has-bets {
  border-color: #2a3a4c;
  box-shadow: 0 0 0 1px rgba(244,187,86,.15);
}
.ticket-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: inherit;
}
.ticket-toggle:hover { background: rgba(255,255,255,.03); }
.ticket-toggle h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: .04em;
  flex: 1;
  font-family: Rajdhani, sans-serif;
  font-weight: 700;
  color: #fff;
}
.ticket-count {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--gold);
  color: #111;
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ticket-count.hide { display: none; }
.ticket-chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .35s ease;
  margin-top: -4px;
  flex-shrink: 0;
}
.ticket:not(.is-collapsed) .ticket-chevron {
  transform: rotate(225deg);
  margin-top: 4px;
}
.ticket-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .45s cubic-bezier(.22,.61,.36,1);
}
.ticket:not(.is-collapsed) .ticket-panel {
  grid-template-rows: 1fr;
}
.ticket-panel-inner {
  overflow: hidden;
  min-height: 0;
  padding: 0 10px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .3s ease, transform .35s ease, padding .35s ease;
}
.ticket:not(.is-collapsed) .ticket-panel-inner {
  padding: 0 10px 10px;
  opacity: 1;
  transform: translateY(0);
}
.ticket-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}
.linkish {
  background: none;
  color: var(--cyan);
  font-size: 12px;
  cursor: pointer;
  border: 0;
  padding: 0;
}
.stake-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.stake-row input {
  width: 72px;
  text-align: center;
  background: #0a1018;
  border: 1px solid var(--line);
  color: #fff;
  border-radius: 4px;
  padding: 6px;
}
.stake-row button {
  width: 28px;
  height: 28px;
  background: #243545;
  border: 0;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.chips button {
  min-width: 48px;
  padding: 6px 8px;
  background: #1a2836;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #fff;
  font-family: Rajdhani, sans-serif;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.chips button.on {
  background: #2a2210;
  border-color: var(--gold);
  color: #fff;
}
.slip-body {
  overflow: auto;
  min-height: 0;
  max-height: 0;
  transition: max-height .35s ease;
}
.ticket:not(.is-collapsed) .slip-body {
  max-height: 160px;
  min-height: 48px;
}
.ticket.ticket--grow:not(.is-collapsed) .slip-body { max-height: 240px; }
.ticket.ticket--grow2:not(.is-collapsed) .slip-body { max-height: 320px; }
.slip-empty {
  color: var(--cyan);
  font-size: 13px;
  padding: 12px 4px;
}
.slip-item {
  background: #121820;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  position: relative;
  animation: slipIn .28s ease;
}
@keyframes slipIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.slip-item .rm {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.slip-item .title { font-weight: 700; padding-right: 18px; }
.slip-item .sub { color: var(--muted); margin-top: 2px; font-size: 12px; }
.slip-item .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.slip-item input {
  width: 90px;
  background: #0a141c;
  border: 1px solid var(--line);
  color: #fff;
  border-radius: 4px;
  padding: 6px 8px;
}
.ticket-totals {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #fff;
}
.ticket-totals strong {
  float: right;
  color: var(--gold);
  font-family: Rajdhani, sans-serif;
  font-size: 15px;
}
.submit-btn {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  background: linear-gradient(180deg, #8a6110, #5c3f08);
  color: #f7e2a1;
  font-family: Rajdhani, sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .06em;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.submit-btn:enabled {
  background: linear-gradient(180deg, #d4a017, #9a6f0c);
  color: #1a1200;
}
.submit-btn:disabled { opacity: .55; cursor: not-allowed; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(8,16,24,.95); border: 1px solid var(--cyan);
  padding: 10px 16px; border-radius: 8px; display: none; z-index: 50;
}
.toast.show { display: block; }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .ticket { width: 100%; }
  .rt-head, .rt-row { grid-template-columns: 1fr 70px 70px 56px; }
}
