:root {
  --bg: #0b0f1c;
  --bg-2: #0f1424;
  --panel: #161d33;
  --panel-2: #1d2745;
  --line: #2a3557;
  --text: #e8ecf7;
  --muted: #8a97bd;
  --accent: #6c8cff;
  --accent-2: #4cd6b4;
  --win: #43d787;
  --gold: #ffcd4d;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* El atributo hidden debe ganar siempre a los display:flex de las clases */
[hidden] { display: none !important; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(108, 140, 255, .18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(76, 214, 180, .14), transparent 60%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dice { font-size: 26px; }
.brand-name { font-weight: 800; letter-spacing: 3px; font-size: 20px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.ghost-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; width: 42px; height: 40px; font-size: 18px; cursor: pointer;
  display: grid; place-items: center; transition: border-color .15s, background .15s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.on { border-color: var(--accent-2); background: linear-gradient(180deg, rgba(76,214,180,.25), rgba(76,214,180,.06)); }

.primary-btn {
  border: none; border-radius: 14px; cursor: pointer;
  font-size: 17px; font-weight: 800; letter-spacing: .5px; color: #0b0f1c;
  padding: 15px 22px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 20px rgba(76, 214, 180, .3);
  transition: transform .08s, filter .15s;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:active { transform: scale(.98); }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.4); }

/* Panels */
.setup, .game, .scoreboard, .arena {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* ---------- Setup ---------- */
.setup-title { font-size: 20px; margin-bottom: 18px; }
.setup-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 22px; }
.field { display: flex; flex-direction: column; }
.field-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.field-label.mt { margin-top: 18px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.4; }

/* Selector de modo de juego */
.field-mode { margin-bottom: 18px; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gm {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; cursor: pointer; transition: border-color .15s, background .15s;
}
.gm:hover { border-color: var(--accent); }
.gm.active { border-color: var(--accent); background: linear-gradient(180deg, rgba(108,140,255,.25), rgba(108,140,255,.08)); }
.gm-title { font-weight: 800; font-size: 15px; }
.gm-sub { font-size: 11px; color: var(--muted); }

.stepper { display: flex; gap: 8px; align-items: stretch; }
.step {
  width: 42px; font-size: 20px; font-weight: 800; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px;
  transition: border-color .15s;
}
.step:hover { border-color: var(--accent); }
.step-input {
  flex: 1; min-width: 0; text-align: center; font-size: 22px; font-weight: 800;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--gold);
  border-radius: 10px; padding: 8px; font-variant-numeric: tabular-nums;
}
.step-input::-webkit-outer-spin-button, .step-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.players-names { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.player-name-input {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 14px;
}
.player-name-input:focus { outline: none; border-color: var(--accent); }

.dice-colors { display: flex; flex-wrap: wrap; gap: 10px; }
.color-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.color-item input[type="color"] {
  width: 44px; height: 44px; border: 2px solid var(--line); border-radius: 12px;
  background: none; cursor: pointer; padding: 2px;
}
.color-item span { font-size: 10px; color: var(--muted); }

/* ---------- Game ---------- */
.game { display: flex; flex-direction: column; gap: 16px; }
.game-status {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 18px;
}
.turn-info { display: flex; flex-direction: column; }
.turn-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.turn-player { font-size: 22px; font-weight: 800; color: var(--gold); }
.round-info { font-size: 15px; color: var(--muted); font-weight: 600; }
.round-info span { color: var(--text); font-weight: 800; }

.arena { display: flex; flex-direction: column; align-items: center; gap: 18px; min-height: 220px; justify-content: center; }
.dice-wrap {
  display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; perspective: 700px;
  cursor: pointer; border-radius: 18px; padding: 10px; transition: transform .08s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.dice-wrap:hover { transform: scale(1.02); }
.dice-wrap:active { transform: scale(.97); }
.dice-wrap:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 4px; }

.tap-hint { color: var(--accent-2); font-weight: 700; font-size: 14px; display: none; }

.die {
  width: 76px; height: 76px;
  border-radius: 16px;
  position: relative;
  box-shadow: inset 0 -6px 12px rgba(0,0,0,.22), 0 8px 18px rgba(0,0,0,.4);
  display: grid; place-items: center;
}
.die.rolling { animation: roll .6s ease; }
.die .pips {
  width: 100%; height: 100%;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 12px; gap: 3px;
}
.die .pips i {
  width: 13px; height: 13px; border-radius: 50%;
  align-self: center; justify-self: center;
  background: rgba(0,0,0,.6);
  box-shadow: inset 0 2px 3px rgba(0,0,0,.5);
}

.roll-total { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.roll-total-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 2px; }
.roll-total-value { font-size: 40px; font-weight: 800; line-height: 1; color: var(--accent-2); }
.roll-btn { min-width: 200px; }

/* Scoreboard */
.side-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; }
.scores { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.score-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px;
  transition: border-color .2s, background .2s;
}
.score-row.active { border-color: var(--gold); background: linear-gradient(90deg, rgba(255,205,77,.14), transparent); }
.score-rank { font-size: 14px; color: var(--muted); width: 22px; font-weight: 800; }
.score-name { flex: 1; font-weight: 700; }
.score-round { font-size: 12px; color: var(--muted); }
.score-total { font-size: 22px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
.score-row.leader .score-total { color: var(--win); }
/* Swatch de color (modo por color, identifica al jugador) */
.score-name .swatch {
  display: inline-block; width: 26px; height: 26px; border-radius: 7px; vertical-align: middle;
  margin-right: 8px; border: 2px solid rgba(255,255,255,.25); box-shadow: 0 2px 6px rgba(0,0,0,.4);
}

/* Winner overlay */
.winner-overlay {
  position: fixed; inset: 0; background: rgba(6, 9, 18, .82);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  backdrop-filter: blur(4px);
}
.winner-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--gold); border-radius: 20px; padding: 34px 40px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); max-width: 380px; width: 100%;
  animation: pop .4s ease;
}
.winner-crown { font-size: 54px; }
.winner-name { font-size: 28px; font-weight: 800; margin: 10px 0 4px; color: var(--gold); }
.win-swatches { display: flex; gap: 12px; justify-content: center; margin: 6px 0; }
.win-swatch {
  display: inline-block; width: 54px; height: 54px; border-radius: 14px;
  border: 3px solid rgba(255,255,255,.35); box-shadow: 0 6px 16px rgba(0,0,0,.5);
}
.win-tie { font-size: 22px; color: var(--gold); margin-top: 8px; }
.winner-score { color: var(--muted); margin-bottom: 22px; }
.winner-actions { display: flex; flex-direction: column; gap: 10px; }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding-top: 6px; margin-top: auto; }

/* Animations */
@keyframes pop { 0% { transform: scale(.9); } 45% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes roll {
  0%   { transform: rotate(0) translateY(0); }
  25%  { transform: rotate(-18deg) translateY(-14px); }
  50%  { transform: rotate(20deg) translateY(-6px); }
  75%  { transform: rotate(-8deg) translateY(-10px); }
  100% { transform: rotate(0) translateY(0); }
}

/* Responsive */
@media (max-width: 780px) {
  .setup-grid { grid-template-columns: 1fr; }
  .game-status { flex-direction: column; gap: 6px; align-items: flex-start; }
  .mode-toggle { grid-template-columns: 1fr; }
}

/* Móvil: dados GRANDES y tocar para lanzar (sin botón) */
@media (max-width: 640px) {
  .arena { min-height: 300px; gap: 14px; }
  .die {
    width: 120px; height: 120px; border-radius: 22px;
    box-shadow: inset 0 -7px 14px rgba(0,0,0,.22), 0 10px 24px rgba(0,0,0,.45);
  }
  .die .pips { padding: 18px; gap: 5px; }
  .die .pips i { width: 20px; height: 20px; }
  .dice-wrap { gap: 16px; animation: tapPulse 2.4s ease-in-out infinite; }
  .tap-hint { display: block; }   /* se ve la pista */
  .roll-btn { display: none; }    /* el botón no hace falta en móvil */
}
@media (max-width: 380px) {
  .die { width: 100px; height: 100px; }
  .die .pips { padding: 15px; }
  .die .pips i { width: 17px; height: 17px; }
}

@keyframes tapPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
