/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { min-height: 100vh; transition: background 0.4s, color 0.4s; }
button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

/* ══════════════════════════════════════════════════════
   THEME DEFINITIONS
══════════════════════════════════════════════════════ */

/* ── Theme: Dungeon (Pergamino clásico) ─────────────── */
[data-theme="dungeon"] {
  --bg-page:        #2a1f14;
  --bg-surface:     #f5e6c8;
  --bg-surface-2:   #ecdab0;
  --bg-cell:        #f9eed8;
  --bg-cell-win:    #fdf3d8;
  --border-cell:    #9e8f7a;
  --border-win:     #a07830;
  --accent:         #c9a84c;
  --accent-dark:    #a07830;
  --text-primary:   #3a2510;
  --text-muted:     #6b4226;
  --text-hint:      #9e8f7a;
  --btn-main-bg:    #8b5e3c;
  --btn-main-text:  #f5e6c8;
  --btn-main-hover: #6b4226;
  --panel-bg:       #f0ddb8;
  --panel-border:   #c9a84c;
  --player-row-bg:  #f9eed8;
  --player-row-bdr: #d4c4a0;
  --badge-bg:       #fdf3d8;
  --badge-color:    #a07830;
  --theme-font-h:   'Cinzel', serif;
  --theme-font-b:   'Lato', sans-serif;
  --remove-hover:   #8b1a1a;
  --winner-bg:      #fdf3d8;
  --winner-color:   #a07830;
  --winner-border:  #c9a84c;
  --switcher-bg:    rgba(255,255,255,0.15);
  --switcher-active:#c9a84c;
  --switcher-text:  #6b4226;
  --page-texture:   url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='4' height='4' fill='%232a1f14'/%3E%3Crect width='1' height='1' fill='%23362818' opacity='0.6'/%3E%3C/svg%3E");
  --cell-shadow:    inset 0 1px 0 rgba(255,255,255,0.6), 0 1px 2px rgba(0,0,0,0.1);
  --cell-win-glow:  inset 0 0 0 2px #c9a84c;
  --input-bg:       #f9eed8;
  --input-border:   #c9a84c;
}

/* ── Theme: Neon (Cyberpunk oscuro) ─────────────────── */
[data-theme="neon"] {
  --bg-page:        #090c14;
  --bg-surface:     #0d1117;
  --bg-surface-2:   #111827;
  --bg-cell:        #0f1620;
  --bg-cell-win:    #0c1a12;
  --border-cell:    #1e3a5f;
  --border-win:     #00ff88;
  --accent:         #00d4ff;
  --accent-dark:    #00a8cc;
  --text-primary:   #e0f0ff;
  --text-muted:     #7ab8d4;
  --text-hint:      #3a6080;
  --btn-main-bg:    #00d4ff;
  --btn-main-text:  #050810;
  --btn-main-hover: #00b8e0;
  --panel-bg:       #0a1520;
  --panel-border:   #00d4ff44;
  --player-row-bg:  #0d1520;
  --player-row-bdr: #1a3050;
  --badge-bg:       #001a30;
  --badge-color:    #00d4ff;
  --theme-font-h:   'Rajdhani', sans-serif;
  --theme-font-b:   'Share Tech Mono', monospace;
  --remove-hover:   #ff3366;
  --winner-bg:      #001a12;
  --winner-color:   #00ff88;
  --winner-border:  #00ff8844;
  --switcher-bg:    rgba(0,212,255,0.08);
  --switcher-active:#00d4ff;
  --switcher-text:  #7ab8d4;
  --page-texture:   none;
  --cell-shadow:    0 0 8px rgba(0,212,255,0.08), inset 0 0 0 1px rgba(0,212,255,0.05);
  --cell-win-glow:  0 0 12px rgba(0,255,136,0.3), inset 0 0 0 1px rgba(0,255,136,0.4);
  --input-bg:       #0a1520;
  --input-border:   #1e3a5f;
}

/* ── Theme: City Lights (Urbano nocturno) ────────────── */
[data-theme="city"] {
  --bg-page:        #0a0f1a;
  --bg-surface:     #111928;
  --bg-surface-2:   #18243a;
  --bg-cell:        #131d2e;
  --bg-cell-win:    #1a1a08;
  --border-cell:    #2a3a55;
  --border-win:     #f5c518;
  --accent:         #f5c518;
  --accent-dark:    #d4a616;
  --text-primary:   #e8eaf0;
  --text-muted:     #8a9ab8;
  --text-hint:      #4a5a75;
  --btn-main-bg:    #f5c518;
  --btn-main-text:  #0a0f1a;
  --btn-main-hover: #d4a616;
  --panel-bg:       #0d1525;
  --panel-border:   #f5c51833;
  --player-row-bg:  #111928;
  --player-row-bdr: #2a3a55;
  --badge-bg:       #1a1500;
  --badge-color:    #f5c518;
  --theme-font-h:   'Rajdhani', sans-serif;
  --theme-font-b:   'Lato', sans-serif;
  --remove-hover:   #ff4466;
  --winner-bg:      #1a1500;
  --winner-color:   #f5c518;
  --winner-border:  #f5c51844;
  --switcher-bg:    rgba(245,197,24,0.06);
  --switcher-active:#f5c518;
  --switcher-text:  #8a9ab8;
  --page-texture:   none;
  --cell-shadow:    0 2px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.03);
  --cell-win-glow:  0 0 16px rgba(245,197,24,0.25), inset 0 0 0 1px rgba(245,197,24,0.5);
  --input-bg:       #111928;
  --input-border:   #2a3a55;
}

/* ── Theme: Cthulhu (Abismo cósmico) ────────────────── */
/* Púrpura cósmico para la UI · Verde eldritch reservado para la victoria */
[data-theme="cthulhu"] {
  --bg-page:        #05040e;
  --bg-surface:     #0f0c22;
  --bg-surface-2:   #181230;
  --bg-cell:        #160f30;
  --bg-cell-win:    #071510;
  --border-cell:    #352568;
  --border-win:     #4ade80;
  --accent:         #a855f7;
  --accent-dark:    #9333ea;
  --text-primary:   #ede8f5;
  --text-muted:     #9d7ec4;
  --text-hint:      #3d2860;
  --btn-main-bg:    #4c1d95;
  --btn-main-text:  #ede8f5;
  --btn-main-hover: #3b1578;
  --panel-bg:       #0c0820;
  --panel-border:   #a855f733;
  --player-row-bg:  #0f0c22;
  --player-row-bdr: #2a1a58;
  --badge-bg:       #0a0722;
  --badge-color:    #a855f7;
  --theme-font-h:   'Cinzel', serif;
  --theme-font-b:   'Share Tech Mono', monospace;
  --remove-hover:   #f87171;
  --winner-bg:      #041208;
  --winner-color:   #4ade80;
  --winner-border:  #4ade8044;
  --switcher-bg:    rgba(168,85,247,0.08);
  --switcher-active:#a855f7;
  --switcher-text:  #9d7ec4;
  --page-texture:   none;
  --cell-shadow:    0 2px 10px rgba(0,0,0,0.5), inset 0 1px 0 rgba(168,85,247,0.1);
  --cell-win-glow:  0 0 16px rgba(74,222,128,0.3), inset 0 0 0 1px rgba(74,222,128,0.5);
  --input-bg:       #0f0c22;
  --input-border:   #2a1a58;
}

/* ── Theme: Tavern (Madera y vino) ──────────────────── */
[data-theme="tavern"] {
  --bg-page:        #1a0a08;
  --bg-surface:     #f2e8d5;
  --bg-surface-2:   #e8d8be;
  --bg-cell:        #f7efe0;
  --bg-cell-win:    #fff8e8;
  --border-cell:    #b08060;
  --border-win:     #8b1a1a;
  --accent:         #8b1a1a;
  --accent-dark:    #6a1010;
  --text-primary:   #2a1208;
  --text-muted:     #7a3820;
  --text-hint:      #b08060;
  --btn-main-bg:    #8b1a1a;
  --btn-main-text:  #f7efe0;
  --btn-main-hover: #6a1010;
  --panel-bg:       #ecddc8;
  --panel-border:   #8b1a1a55;
  --player-row-bg:  #f7efe0;
  --player-row-bdr: #d4b898;
  --badge-bg:       #fff0e0;
  --badge-color:    #8b1a1a;
  --theme-font-h:   'Cinzel', serif;
  --theme-font-b:   'Lato', sans-serif;
  --remove-hover:   #8b1a1a;
  --winner-bg:      #fff0e8;
  --winner-color:   #8b1a1a;
  --winner-border:  #8b1a1a55;
  --switcher-bg:    rgba(139,26,26,0.08);
  --switcher-active:#8b1a1a;
  --switcher-text:  #7a3820;
  --page-texture:   none;
  --cell-shadow:    inset 0 1px 0 rgba(255,255,255,0.7), 0 1px 3px rgba(0,0,0,0.12);
  --cell-win-glow:  inset 0 0 0 2px #8b1a1a88;
  --input-bg:       #f7efe0;
  --input-border:   #b08060;
}

/* ══════════════════════════════════════════════════════
   BASE STYLES
══════════════════════════════════════════════════════ */
body {
  background: var(--bg-page);
  background-image: var(--page-texture);
  color: var(--text-primary);
  font-family: var(--theme-font-b);
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

/* ── Theme Switcher ──────────────────────────────────── */
.theme-switcher {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.theme-btn {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid transparent;
  background: var(--switcher-bg);
  color: var(--switcher-text);
  font-family: var(--theme-font-b);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all 0.2s;
}

.theme-btn:hover { opacity: 0.8; }

.theme-btn.active {
  background: var(--switcher-active);
  color: var(--bg-page);
  border-color: transparent;
}

/* ── Header ─────────────────────────────────────────── */
.header {
  text-align: center;
  margin-bottom: 22px;
}

.header h1 {
  font-family: var(--theme-font-h);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.06em;
  line-height: 1.1;
}

.header p {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-hint);
  margin-top: 4px;
}

[data-theme="neon"] .header h1,
[data-theme="city"] .header h1,
[data-theme="cthulhu"] .header h1 { text-shadow: 0 0 20px var(--accent); }

/* ── Path Grid ──────────────────────────────────────── */
.path-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.cell {
  position: relative;
  height: 90px;
  border: 1.5px solid var(--border-cell);
  border-radius: 12px;
  background: var(--bg-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  box-shadow: var(--cell-shadow);
  transition: background 0.2s;
  overflow: visible;
}

.cell.cell-win {
  grid-column: span 3;
  height: auto;
  min-height: 90px;
  padding: 12px 8px;
  border-color: var(--border-win);
  background: var(--bg-cell-win);
  box-shadow: var(--cell-win-glow);
}

.cell-win .tokens-area {
  padding-top: 4px;
}

/* ── Path Connector ──────────────────────────────────── */
.path-connector {
  grid-column: span 3;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 16px;
  align-items: center;
}

.path-connector .arrow {
  text-align: center;
  color: var(--accent);
  font-size: 13px;
  opacity: 0.5;
  line-height: 1;
}

[data-theme="neon"] .cell-win,
[data-theme="city"] .cell-win,
[data-theme="cthulhu"] .cell-win { animation: pulseWin 2.5s ease-in-out infinite; }

@keyframes pulseWin {
  0%, 100% { box-shadow: var(--cell-win-glow); }
  50% { box-shadow: var(--cell-win-glow), 0 0 24px var(--border-win); }
}

.cell-num {
  font-family: var(--theme-font-h);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-hint);
  position: absolute;
  top: 7px;
  left: 9px;
  line-height: 1;
}

.cell-win .cell-num { color: var(--accent-dark); }

.crown-icon {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
  filter: drop-shadow(0 0 4px var(--accent));
}

.cell-win .crown-icon {
  font-size: 30px;
  margin-bottom: 2px;
}

.tokens-area {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  justify-content: center;
  padding-top: 14px;
  width: 100%;
  padding-left: 2px;
  padding-right: 2px;
}

/* ── Tokens ──────────────────────────────────────────── */
.token {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--theme-font-b);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
  position: relative;
  cursor: default;
  transition: transform 0.15s;
}

.token:hover { transform: scale(1.15); z-index: 5; }

.token-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-page);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  font-family: var(--theme-font-b);
}

.token:hover .token-tip { display: block; }

/* ── Divider ─────────────────────────────────────────── */
.divider {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-cell), transparent);
  margin: 4px 0 18px;
}

/* ── Winner Banner ──────────────────────────────────── */
.winner-banner {
  display: none;
  text-align: center;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--winner-bg);
  border: 1.5px solid var(--winner-border);
  margin-bottom: 16px;
  font-family: var(--theme-font-h);
  font-size: 15px;
  font-weight: 700;
  color: var(--winner-color);
  letter-spacing: 0.04em;
}

[data-theme="neon"] .winner-banner,
[data-theme="city"] .winner-banner,
[data-theme="cthulhu"] .winner-banner { text-shadow: 0 0 12px currentColor; }

/* ── Panel ──────────────────────────────────────────── */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px;
}

.panel-title {
  font-family: var(--theme-font-h);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-hint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

/* ── Add Player ─────────────────────────────────────── */
.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.add-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.add-row input:focus { border-color: var(--accent); }
.add-row input::placeholder { color: var(--text-hint); }
.add-row input:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-add:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-add {
  padding: 8px 16px;
  background: var(--btn-main-bg);
  color: var(--btn-main-text);
  border: none;
  border-radius: 8px;
  font-family: var(--theme-font-h);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-add:hover { background: var(--btn-main-hover); }

/* ── Players List ────────────────────────────────────── */
.players-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--player-row-bg);
  border: 1.5px solid var(--player-row-bdr);
  border-radius: 10px;
  transition: border-color 0.2s;
}

.player-row:hover { border-color: var(--accent); }

/* ── Color Picker Dot ───────────────────────────────── */
.color-dot-wrap {
  position: relative;
  flex-shrink: 0;
}

.color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.35);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.color-dot:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px var(--accent);
}

.color-picker-popup {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 100;
  background: var(--bg-surface);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  width: fit-content;
}

.color-picker-popup.open { display: block; }

.color-picker-title {
  font-size: 10px;
  color: var(--text-hint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-family: var(--theme-font-b);
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(6, 24px);
  gap: 5px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s, border-color 0.12s;
}

.swatch:hover { transform: scale(1.2); }
.swatch.selected { border-color: var(--text-primary); }

/* ── Player Name ─────────────────────────────────────── */
.player-name {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--theme-font-b);
}

/* ── Level Controls ──────────────────────────────────── */
.level-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-lvl {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1.5px solid var(--player-row-bdr);
  background: var(--player-row-bg);
  font-size: 18px;
  line-height: 1;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.btn-lvl:hover { border-color: var(--accent); background: var(--bg-surface-2); }
.btn-lvl:active { transform: scale(0.9); }

.level-badge {
  font-family: var(--theme-font-h);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  min-width: 36px;
  text-align: center;
  background: var(--badge-bg);
  border-radius: 6px;
  padding: 3px 4px;
}

/* ── Remove Button ──────────────────────────────────── */
.btn-remove {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--player-row-bdr);
  background: transparent;
  color: var(--text-hint);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.btn-remove:hover { color: var(--remove-hover); border-color: var(--remove-hover); }

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 16px 0 8px;
  color: var(--text-hint);
  font-size: 13px;
  font-style: italic;
}

/* ── Reset Button ────────────────────────────────────── */
.btn-reset {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--player-row-bdr);
  border-radius: 8px;
  font-family: var(--theme-font-h);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-hint);
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}

.btn-reset:hover { color: var(--remove-hover); border-color: var(--remove-hover); }

/* ── Neon scanlines effect ──────────────────────────── */
body[data-theme="neon"]::before,
body[data-theme="city"]::before,
body[data-theme="cthulhu"]::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.03) 2px,
    rgba(0,0,0,0.03) 4px
  );
  pointer-events: none;
  z-index: 0;
}

[data-theme="neon"] .app,
[data-theme="city"] .app,
[data-theme="cthulhu"] .app { position: relative; z-index: 1; }

/* ── Tablet scaling (≥ 600px) ────────────────────────── */
@media (min-width: 600px) {
  .app { max-width: 860px; }

  .cell { height: 120px; border-radius: 14px; }
  .cell-win { min-height: 120px; padding: 14px 10px; }
  .cell-num { font-size: 15px; top: 9px; left: 11px; }
  .crown-icon { font-size: 28px; }
  .cell-win .crown-icon { font-size: 38px; }
  .path-grid { gap: 12px; }
  .path-connector .arrow { font-size: 16px; }

  .token { width: 36px; height: 36px; font-size: 12px; }
  .color-dot { width: 36px; height: 36px; }

  .player-name { font-size: 17px; }
  .btn-lvl { width: 36px; height: 36px; font-size: 20px; }
  .level-badge { font-size: 15px; min-width: 44px; }
  .btn-remove { width: 30px; height: 30px; font-size: 18px; }

  .header h1 { font-size: 34px; }
  .add-row input { font-size: 15px; }
}
