:root {
  --bg-0: #0d1117;
  --bg-1: #131a24;
  --panel: #1a2330;
  --panel-2: #223045;
  --line: #2b3a4e;
  --text: #e6edf3;
  --muted: #93a4b8;
  --accent: #f2b705;
  --accent-2: #3fb950;
  --danger: #f85149;
  --p1: #4ea1ff;
  --p2: #ff7eb6;
  --felt: #0b6b3a;
  --shadow: rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, #16202e 0%, var(--bg-0) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: linear-gradient(180deg, rgba(20, 28, 40, 0.95), rgba(15, 21, 30, 0.9));
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: 0.5px; }
.brand h1 .accent { color: var(--accent); }
.brand__ball {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #3a3a3a, #000 70%);
  color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
  box-shadow: inset 0 0 6px rgba(255,255,255,0.25);
}

.players { display: flex; align-items: stretch; gap: 10px; flex: 1; justify-content: center; }

.player {
  min-width: 170px;
  padding: 8px 12px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.player.is-turn { border-color: var(--accent); box-shadow: 0 0 18px rgba(242,183,5,0.35); }
.player__name { font-weight: 700; font-size: 14px; }
.player__group { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 16px; }
.player__group.solid { color: #ffd54a; }
.player__group.stripe { color: #6cc4ff; }
.player__balls { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; min-height: 16px; }

.ball-chip {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.25);
  display: inline-block;
}
.ball-chip.stripe { background: linear-gradient(180deg, #fff 0 25%, var(--c) 25% 75%, #fff 75% 100%); }
.ball-chip.solid { background: var(--c); }
.ball-chip.b8 { background: radial-gradient(circle at 35% 30%, #444, #000 70%); }

.turn-indicator {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 16px; border-radius: 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 2px dashed var(--line);
  min-width: 150px;
}
#turn-text { font-weight: 700; font-size: 14px; }

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

.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 10px;
}
.chk input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; cursor: pointer; }

/* ---------- Botones ---------- */
.btn {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  transition: transform .08s, background .15s, border-color .15s;
  user-select: none;
}
.btn:hover { background: #2c3e57; border-color: #3a4f6b; }
.btn:active { transform: translateY(1px); }
.btn--small { padding: 5px 10px; font-size: 12px; }
.btn--primary { background: var(--accent); color: #20160a; border-color: var(--accent); font-weight: 700; }
.btn--primary:hover { background: #ffc61a; }

/* ---------- Escenario ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.table-frame {
  width: 100%;
  max-width: 1360px;
  padding: 10px;
  background: linear-gradient(180deg, #3a2412, #241608);
  border-radius: 20px;
  box-shadow: 0 24px 60px var(--shadow), inset 0 2px 0 rgba(255,255,255,0.06);
  border: 2px solid #4a2f16;
}

#game {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  background: var(--felt);
  touch-action: none;
  cursor: crosshair;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.35);
}

/* ---------- HUD ---------- */
.hud {
  width: 100%;
  max-width: 1360px;
  display: grid;
  grid-template-columns: 1fr auto 1.4fr;
  gap: 10px;
  align-items: stretch;
}
.hud__block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}
.hud__spin { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.hud__label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}
.hud__hint { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; }

.power-meter {
  height: 16px;
  border-radius: 8px;
  background: #0d1420;
  border: 1px solid var(--line);
  overflow: hidden;
}
.power-meter__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3fb950, #f2b705 60%, #f85149);
  transition: width .05s linear;
}

.spin-pad {
  position: relative;
  width: 76px;
  height: 76px;
  margin: 0 auto;
  border-radius: 50%;
}
#spin { border-radius: 50%; display: block; }
.spin-pad__dot {
  position: absolute;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: rgba(242,183,5,0.9);
  border: 2px solid #fff;
  box-shadow: 0 0 6px rgba(242,183,5,0.8);
  transform: translate(-50%, -50%);
  left: 50%; top: 50%;
  pointer-events: none;
  transition: left .08s, top .08s;
}

.msg {
  font-size: 14px;
  min-height: 34px;
  display: flex;
  align-items: center;
  color: var(--text);
}

/* ---------- Insignia de build (diagnóstico: ¿qué versión ejecuta el móvil?) ---------- */
.build-badge {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 60; /* por encima de todo, incluida la pantalla de inicio */
  background: var(--accent);
  color: #20160a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* ---------- Pantalla de inicio ---------- */
.start-overlay {
  position: fixed; inset: 0;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
  /* SIN backdrop-filter: en iOS Safari rompe el position:fixed (la capa
     se ancla al viewport de layout y los toques no caen sobre el contenido) */
  background: radial-gradient(1100px 650px at 50% -10%, #182636 0%, #080c12 62%);
  transition: opacity .25s;
}
.start-overlay.hidden { opacity: 0; pointer-events: none; }
.start-card {
  width: min(92vw, 440px);
  display: flex; flex-direction: column; gap: 13px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 28px;
  box-shadow: 0 30px 80px var(--shadow);
}
.start-brand { display: flex; align-items: center; gap: 12px; }
.start-brand h1 { margin: 0; font-size: 27px; letter-spacing: 0.5px; }
.start-brand h1 .accent { color: var(--accent); }
.start-sub { margin: 0; font-size: 13px; color: var(--muted); }

.start-field { display: flex; flex-direction: column; gap: 5px; }
.start-field > span {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted);
}
.start-field input, .start-field select {
  background: #0d1420; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; outline: none;
  font-family: inherit;
}
.start-field input:focus, .start-field select:focus { border-color: var(--accent); }
.chk--inline { border: 0; background: none; padding: 0; }
.start-btn { font-size: 17px; font-weight: 700; padding: 12px; width: 100%; margin-top: 5px; }
.start-ver {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  opacity: 0.6;
  letter-spacing: 1px;
}

/* ---------- Popup de cambio de turno ---------- */
.turn-popup {
  position: fixed; inset: 0;
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; /* no bloquea el juego */
  opacity: 0;
}
.turn-popup.show { animation: turnflash 2s ease forwards; }
@keyframes turnflash {
  0%   { opacity: 0; transform: scale(0.7); }
  12%  { opacity: 1; transform: scale(1.06); }
  24%  { transform: scale(1); }
  76%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.95); }
}
.turn-popup__card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 2px solid var(--accent);
  border-radius: 22px;
  padding: 26px 56px;
  text-align: center;
  box-shadow: 0 0 70px rgba(242, 183, 5, 0.3), 0 30px 80px var(--shadow);
}
.turn-popup__label {
  display: block;
  font-size: 14px; text-transform: uppercase; letter-spacing: 3px;
  color: var(--muted);
}
.turn-popup__name {
  display: block;
  margin-top: 6px;
  font-size: 42px; font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(242, 183, 5, 0.45);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70vw;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 8, 12, 0.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  opacity: 1;
  transition: opacity .25s;
}
.modal.hidden { opacity: 0; pointer-events: none; }
.modal__card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 34px;
  text-align: center;
  max-width: 420px;
  box-shadow: 0 30px 80px var(--shadow);
}
.modal__card h2 { margin: 0 0 10px; font-size: 26px; }
.modal__card p { color: var(--muted); margin: 0 0 20px; font-size: 15px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .hud { grid-template-columns: 1fr; }
  .players { order: 3; width: 100%; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar__actions { justify-content: flex-end; }
}