:root {
  --felt: #0b3d2e;
  --felt-deep: #06241b;
  --felt-mid: #12523e;
  --felt-light: #1a6b50;
  --gold: #c9a227;
  --gold-bright: #f3e2a0;
  --gold-soft: #e8d48b;
  --gold-dark: #8a6d1f;
  --ivory: #f4efe4;
  --ink: #100c08;
  --wood: #1a100c;
  --red: #b51c14;
  --red-hot: #e03127;
  --black: #141414;
  --green-zero: #0c7a40;
  --rail: #2a1a12;
  --danger: #e8b04a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font-serif: "Cinzel", "Palatino Linotype", Palatino, serif;
  --font-ui: "Outfit", "Segoe UI", sans-serif;
  --radius: 22px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

html {
  color-scheme: dark;
}

body {
  font-family: var(--font-ui);
  color: var(--ivory);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(201, 162, 39, 0.16), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(12, 122, 64, 0.18), transparent 45%),
    linear-gradient(180deg, #07140f 0%, var(--felt-deep) 40%, #04110d 100%);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  z-index: 0;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.45) 100%);
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(26, 16, 12, 0.92), rgba(10, 8, 6, 0.78));
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(243, 226, 160, 0.18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.crest {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: radial-gradient(circle at 30% 30%, var(--gold-bright), var(--gold) 45%, var(--gold-dark));
  box-shadow: 0 0 0 2px rgba(243, 226, 160, 0.4), 0 8px 18px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-soft);
}

.brand h1 {
  margin: 2px 0 0;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(1.15rem, 2.4vw, 1.7rem);
  letter-spacing: 0.08em;
  color: var(--gold-bright);
}

.free-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #b7e0cc;
  border: 1px solid rgba(183, 224, 204, 0.35);
  padding: 1px 8px;
  border-radius: 999px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.players {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 999px;
  padding: 3px;
}

.players button,
.icon-btn,
.ghost-btn,
.chip-btn,
.action-btn,
.track-btn,
.refill-btn,
.spot,
.cell {
  font-family: inherit;
  cursor: pointer;
}

.players button {
  border: 0;
  background: transparent;
  color: var(--ivory);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
}

.players button.on {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.balance-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(11, 61, 46, 0.55);
  border: 1px solid rgba(201, 162, 39, 0.4);
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
}

.balance-box .lbl {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-soft);
}

.balance-box strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  color: var(--gold-bright);
  min-width: 3.5rem;
}

.refill-btn {
  border: 0;
  border-radius: 999px;
  padding: 7px 11px;
  background: linear-gradient(180deg, #2a8a5a, #146043);
  color: white;
  font-weight: 600;
  font-size: 0.82rem;
}

.refill-btn.urgent {
  animation: pulse 1.4s ease-in-out infinite;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--ink);
}

@keyframes pulse {
  50% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(201, 162, 39, 0.2); }
}

.icon-btn,
.ghost-btn {
  border: 1px solid rgba(201, 162, 39, 0.45);
  background: rgba(0, 0, 0, 0.3);
  color: var(--gold-soft);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-btn.muted svg .wave {
  opacity: 0.25;
}

.icon-btn.muted::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 2px;
  background: var(--gold-soft);
  transform: rotate(-35deg);
}

.icon-btn {
  position: relative;
}

/* Layout */
main {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.25fr);
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(8, 36, 28, 0.7), rgba(5, 20, 16, 0.82));
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.wheel-frame {
  position: relative;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(26, 107, 80, 0.45), transparent 55%),
    radial-gradient(circle at 50% 50%, #0e4a38, #07261d 70%);
  border-radius: 50%;
  margin: 0 auto;
  max-width: 520px;
  aspect-ratio: 1;
  box-shadow:
    inset 0 0 0 6px #2a1a12,
    inset 0 0 0 8px rgba(201, 162, 39, 0.7),
    0 20px 40px rgba(0, 0, 0, 0.5);
}

#wheel {
  display: block;
  width: 100%;
  height: auto;
}

.result-badge {
  position: absolute;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%) translateY(8px);
  opacity: 0;
  pointer-events: none;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  border: 1px solid rgba(243, 226, 160, 0.5);
  background: rgba(10, 8, 6, 0.86);
  color: var(--gold-bright);
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-badge.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.result-badge.red { box-shadow: 0 0 0 2px var(--red); }
.result-badge.black { box-shadow: 0 0 0 2px #000; }
.result-badge.green { box-shadow: 0 0 0 2px var(--green-zero); }

.history-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  min-height: 34px;
  align-items: center;
}

.muted-label {
  color: rgba(244, 239, 228, 0.5);
  font-size: 0.85rem;
}

.hist-n {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  border: 1px solid rgba(243, 226, 160, 0.35);
}

.hist-n.red { background: var(--red); }
.hist-n.black { background: #111; }
.hist-n.green { background: var(--green-zero); }

.stats {
  margin-top: 12px;
  font-size: 0.9rem;
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

.pill.red { background: var(--red); color: #fff; }
.pill.black { background: #111; color: #fff; border: 1px solid #444; }
.pill.green { background: var(--green-zero); color: #fff; }
.pill.muted { background: rgba(255, 255, 255, 0.08); color: var(--ivory); }

.hot {
  margin: 8px 0 0;
  color: var(--gold-soft);
  font-size: 0.85rem;
}

/* Board */
.felt-table {
  position: relative;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(26, 107, 80, 0.55), transparent 55%),
    linear-gradient(160deg, var(--felt-mid), var(--felt) 40%, var(--felt-deep));
  border: 8px solid #2a1a12;
  outline: 2px solid rgba(201, 162, 39, 0.7);
  outline-offset: -4px;
  border-radius: 28px;
  padding: 14px 14px 18px;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.35);
}

.bet-tip {
  margin: 10px 4px 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  color: var(--gold-soft);
  letter-spacing: 0.03em;
  opacity: 0;
  transition: opacity 0.15s;
}

.bet-tip.show { opacity: 1; }

.board-scroller {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.board-stage {
  position: relative;
}
.board-grid {
  display: grid;
  grid-template-columns: 1.2fr repeat(12, 1fr) 1.1fr;
  grid-template-rows: repeat(3, 52px) 42px 42px;
  gap: 3px;
  min-width: 680px;
}

.cell {
  border: 1px solid rgba(201, 162, 39, 0.45);
  color: var(--ivory);
  font-weight: 650;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  background: #1a1a1a;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.cell.num.red,
.bet-red {
  background: linear-gradient(180deg, #d3251c, var(--red));
}

.cell.num.black {
  background: linear-gradient(180deg, #262626, #111);
}

.cell.zero {
  grid-column: 1;
  grid-row: 1 / span 3;
  background: linear-gradient(180deg, #14a055, var(--green-zero));
  font-size: 1.4rem;
  font-family: var(--font-serif);
  border-radius: 18px 6px 6px 18px;
  color: #f7efd2;
}

.cell.outside {
  background: rgba(7, 38, 29, 0.85);
  color: var(--gold-bright);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.cell.column {
  border-radius: 0 8px 8px 0;
}

.bet-red { color: #fff; }
.bet-black { background: linear-gradient(180deg, #262626, #111); color: #fff; }

.cell.hl,
.cell.win {
  box-shadow: 0 0 0 2px var(--gold-bright), 0 0 16px rgba(243, 226, 160, 0.65);
  filter: brightness(1.18);
  z-index: 2;
  position: relative;
}

.cell.win {
  animation: winflash 1s ease-in-out 3;
}

@keyframes winflash {
  50% { filter: brightness(1.45); }
}

.spots-layer,
.chips-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.spot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(243, 226, 160, 0.55);
  background: rgba(201, 162, 39, 0.18);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  padding: 0;
  z-index: 5;
  opacity: 0.55;
}

.spot:hover,
.spot:focus-visible {
  opacity: 1;
  background: var(--gold-bright);
  transform: translate(-50%, -50%) scale(1.35);
  box-shadow: 0 0 10px rgba(243, 226, 160, 0.8);
}

.spot-street,
.spot-six {
  width: 16px;
  height: 10px;
  border-radius: 4px;
}

.spot-corner {
  width: 13px;
  height: 13px;
}

.table-chip {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px dashed currentColor;
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(0, 0, 0, 0.25);
  z-index: 6;
  pointer-events: none;
}

/* Track */
.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 8px;
}

#track {
  display: none;
  margin-bottom: 8px;
}

#track.open { display: block; }

.track-toggle.on {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--ink);
  border-color: transparent;
}

.partage-switch {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--ivory);
  max-width: 420px;
}

.partage-switch input {
  appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #1a1a1a;
  border: 1px solid var(--gold-dark);
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  margin-top: 1px;
}

.partage-switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold-soft);
  transition: transform 0.18s;
}

.partage-switch input:checked {
  background: #146043;
  border-color: var(--gold);
}

.partage-switch input:checked::after {
  transform: translateX(18px);
}

.partage-switch small {
  display: block;
  color: rgba(244, 239, 228, 0.65);
  font-size: 0.75rem;
}

.racetrack-wrap { margin-top: 4px; }

.racetrack {
  width: 100%;
  height: auto;
  display: block;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 16px;
  border: 1px solid rgba(201, 162, 39, 0.25);
}

.track-cell { stroke: rgba(243, 226, 160, 0.55); stroke-width: 0.8; cursor: pointer; }
.track-cell.red { fill: var(--red); }
.track-cell.black { fill: #161616; }
.track-cell.green { fill: var(--green-zero); }
.track-cell:hover { filter: brightness(1.3); stroke: var(--gold-bright); }

.track-label {
  fill: #f7efd2;
  font-size: 11px;
  font-family: var(--font-ui);
  font-weight: 600;
}

.track-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.track-btn {
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: rgba(0, 0, 0, 0.3);
  color: var(--ivory);
  border-radius: 12px;
  padding: 8px 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.track-btn strong { font-size: 0.82rem; color: var(--gold-bright); font-weight: 600; }
.track-btn span { font-size: 0.7rem; color: rgba(244, 239, 228, 0.65); }
.track-btn:hover { border-color: var(--gold-bright); }

.neighbor-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--gold-soft);
}

.neighbor-ctrl .seg {
  display: flex;
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 999px;
  overflow: hidden;
}

.neighbor-ctrl button {
  border: 0;
  background: transparent;
  color: var(--ivory);
  padding: 5px 10px;
  font-family: inherit;
  cursor: pointer;
}

.neighbor-ctrl button.on {
  background: var(--gold);
  color: var(--ink);
}

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chips .lbl {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-soft);
  width: 100%;
}

.chip-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px dashed currentColor;
  font-weight: 700;
  font-size: 0.78rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.12s, box-shadow 0.12s;
}

.chip-btn.on {
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 0 0 3px var(--gold-bright), 0 6px 0 rgba(0, 0, 0, 0.3);
}

.chip-btn.too-rich { opacity: 0.4; }

.chip-btn[data-chip="1"] { background: #f4efe6; color: #1a1208; }
.chip-btn[data-chip="5"] { background: #c41616; color: #fff; }
.chip-btn[data-chip="10"] { background: #1c4ea0; color: #fff; }
.chip-btn[data-chip="25"] { background: #1b7a3a; color: #fff; }
.chip-btn[data-chip="100"] { background: #1a1a1a; color: #e8d48b; }
.chip-btn[data-chip="500"] { background: #5b1d8a; color: #f4efe6; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-btn {
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: rgba(0, 0, 0, 0.3);
  color: var(--ivory);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.88rem;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-btn.primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--ink);
  border-color: transparent;
  min-width: 140px;
  font-family: var(--font-serif);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.95rem;
}

.action-btn.primary:not(:disabled):hover {
  filter: brightness(1.08);
}

.stake-line {
  font-size: 0.85rem;
  color: var(--gold-soft);
}

.stake-line strong { color: var(--gold-bright); }

/* Toast + footer */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(10, 8, 6, 0.92);
  color: var(--ivory);
  border: 1px solid var(--gold);
  padding: 12px 18px;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  max-width: min(92vw, 560px);
  text-align: center;
  box-shadow: var(--shadow);
  transition: opacity 0.25s, transform 0.25s;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.win { border-color: var(--gold-bright); color: var(--gold-bright); }
.toast.warn { border-color: var(--danger); }

.site-footer {
  margin-top: 22px;
  text-align: center;
  color: rgba(244, 239, 228, 0.55);
  font-size: 0.8rem;
}

.site-footer p { margin: 0; }

/* Modal */
#rules-modal {
  max-width: 680px;
  width: calc(100% - 24px);
  border: 1px solid var(--gold);
  border-radius: 18px;
  background: linear-gradient(180deg, #12261f, #0a1612);
  color: var(--ivory);
  padding: 0;
  box-shadow: var(--shadow);
}

#rules-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.rules-body {
  padding: 22px 24px 28px;
}

.rules-body h2 {
  font-family: var(--font-serif);
  color: var(--gold-bright);
  margin: 0 0 8px;
}

.rules-body h3 {
  font-family: var(--font-serif);
  color: var(--gold);
  font-size: 1rem;
  margin: 18px 0 8px;
}

.rules-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.rules-body th,
.rules-body td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(201, 162, 39, 0.2);
}

.rules-body th { color: var(--gold-soft); font-weight: 500; }

.rules-close {
  float: right;
}

.is-spinning .cell,
.is-spinning .spot,
.is-spinning .chip-btn,
.is-spinning .track-btn,
.is-spinning .track-cell,
.is-spinning .players button {
  pointer-events: none;
}

@media (max-width: 980px) {
  main {
    grid-template-columns: 1fr;
  }
  .wheel-frame { max-width: 420px; }
  .topbar { padding: 12px; }
}

@media (max-width: 640px) {
  .app { padding: 10px 10px 28px; }
  .board-grid {
    grid-template-rows: repeat(3, 44px) 38px 38px;
    min-width: 620px;
    gap: 2px;
  }
  .cell { font-size: 0.8rem; }
  .actions { position: sticky; bottom: 8px; z-index: 8; }
  .action-btn.primary { flex: 1; }
  .crest { width: 48px; height: 48px; font-size: 0.8rem; }
  .toast { bottom: 78px; }
  .chip-btn { width: 46px; height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
