/* ============================================================
   Víboras Divertidas — estilos
   Misma familia visual que Luisorama: paleta infantil rosa/morado,
   fuente Comic, tarjetas redondeadas, sombras suaves.
   ============================================================ */

:root {
  --radius: 20px;
  --card-radius: 16px;
  --shadow: 0 6px 16px rgba(80, 50, 90, .14);
  --shadow-lg: 0 14px 34px rgba(80, 50, 90, .22);
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;

  --bg1: #fbf1ff; --bg2: #ffe9f4;
  --primary: #d29bf0; --primary-d: #9b6fd4; --primary-dd: #7a4fc0;
  --accent: #fff0fa; --ink: #4a3a63; --on-primary: #fff;

  /* Colores del campo de juego (canvas) */
  --field-1: #d8f5d2;
  --field-2: #b8ecc8;
  --field-stripe: #c4eccc;
  --wall: #ff90c0;
  --wall-d: #d96ea4;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid rgba(255, 255, 255, .6);
}
.topbar .title {
  margin: 0; font-size: clamp(1.2rem, 3.5vw, 1.7rem);
  color: var(--primary-dd); text-align: center; flex: 1;
}
.btn-icon {
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; color: var(--primary-dd);
  background: #fff; border: 2px solid var(--primary);
  padding: 8px 14px; border-radius: 999px;
  font: inherit; font-size: .95rem;
  box-shadow: var(--shadow); white-space: nowrap; cursor: pointer;
}
.btn-icon:hover { background: var(--accent); }
.btn-icon.is-off {
  opacity: .55; background: #f3eef8; color: #999;
  border-color: #ddd;
}

main { padding: 18px 14px 40px; max-width: 1000px; margin: 0 auto; }

/* ---------- Pantalla de inicio ---------- */
.setup-card {
  background: rgba(255, 255, 255, .85);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 28px 24px; max-width: 600px; margin: 18px auto; text-align: center;
}
.setup-title {
  margin: 0 0 6px;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  color: var(--primary-dd);
}
.setup-sub { margin: 0 0 16px; color: var(--ink); opacity: .85; }
.setup-label { margin: 18px 0 10px; font-size: 1.15rem; color: var(--ink); }

.input-name {
  font: inherit; font-size: 1.25rem;
  text-align: center;
  background: #fff; color: var(--primary-dd);
  border: 3px solid var(--primary);
  border-radius: 14px; padding: 12px 18px;
  box-shadow: var(--shadow);
  width: min(320px, 100%);
}
.input-name:focus { outline: none; border-color: var(--primary-d); }

.btn-play {
  margin-top: 22px; font: inherit; font-weight: bold; cursor: pointer;
  color: var(--on-primary);
  background: linear-gradient(145deg, var(--primary), var(--primary-d));
  border: none; border-radius: 999px; padding: 16px 40px;
  font-size: 1.4rem; box-shadow: var(--shadow-lg);
  transition: transform .1s;
}
.btn-play:hover { transform: scale(1.04); }
.btn-play:active { transform: scale(.98); }
.btn-play.small { font-size: 1.05rem; padding: 12px 26px; margin-top: 12px; }

/* ---------- Ranking ---------- */
.scores {
  margin: 16px auto 0;
  text-align: left;
  max-width: 360px;
}
.scores h3 {
  margin: 0 0 8px;
  color: var(--primary-dd);
  text-align: center;
}
.scores ol {
  list-style: none; padding: 0; margin: 0;
}
.scores li {
  display: flex; justify-content: space-between;
  background: #fff;
  border-radius: 12px; padding: 8px 14px;
  margin-bottom: 6px;
  box-shadow: var(--shadow);
}
.scores li.empty { justify-content: center; opacity: .6; }

/* ---------- Configuración ---------- */
.config-row {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; padding: 14px 18px;
  border-radius: 14px; box-shadow: var(--shadow);
  margin: 10px 0;
  text-align: left;
}
.config-row label { font-size: 1.05rem; }
.toggle {
  position: relative; width: 56px; height: 30px;
  background: #ddd; border-radius: 999px;
  cursor: pointer; transition: background .15s;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; background: #fff;
  border-radius: 50%; transition: left .15s;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.toggle.on { background: var(--primary-d); }
.toggle.on::after { left: 29px; }

.radio-group { display: flex; gap: 8px; }
.radio-group button {
  font: inherit; cursor: pointer;
  background: #fff; color: var(--primary-dd);
  border: 2px solid var(--primary);
  border-radius: 999px; padding: 6px 14px;
  font-size: .95rem;
}
.radio-group button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--primary-d);
}
.radio-group button:disabled {
  opacity: .45; cursor: not-allowed; border-color: #ccc; color: #888;
}

/* ---------- Pantalla de juego ---------- */
.game-page {
  margin: 0; padding: 0;
  min-height: 100vh;
  display: flex; flex-direction: column;
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
  overflow: hidden;
}
.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 14px;
  background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid rgba(255, 255, 255, .6);
}
.game-topbar .hud-info {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
}
.hud-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border-radius: 999px;
  padding: 6px 14px;
  font-size: 1.05rem; box-shadow: var(--shadow);
  color: var(--primary-dd);
}
.hud-pill .label { color: var(--ink); opacity: .7; font-size: .85rem; margin-right: 4px; }
.hud-pill.time.urgent { animation: pulse 1s infinite; color: #d63030; }

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

.canvas-wrap {
  flex: 1;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  min-height: 0;
}
canvas.game-canvas {
  display: block;
  background: linear-gradient(180deg, var(--field-1), var(--field-2));
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  max-width: 100%; max-height: 100%;
  cursor: crosshair;
}

.countdown-big {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(1);
  font-size: clamp(5rem, 16vw, 12rem);
  font-weight: bold;
  color: rgba(214, 48, 48, .88);
  text-shadow: 0 0 18px rgba(255,255,255,.9), 0 4px 14px rgba(214,48,48,.4);
  pointer-events: none;
  animation: count-pulse 1s ease-out;
}
@keyframes count-pulse {
  0%   { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.4); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: .9; }
}

/* ---------- Modal final ---------- */
.end-overlay {
  position: fixed; inset: 0;
  background: rgba(80, 50, 90, .55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.end-card {
  background: #fff;
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 28px 30px;
  max-width: 460px; width: calc(100% - 28px);
  text-align: center;
}
.end-title {
  margin: 0 0 8px;
  font-size: 2rem;
  color: var(--primary-dd);
}
.end-title.lose { color: #d63030; }
.end-title.win  { color: #1da14e; }
.end-list {
  list-style: none; padding: 0; margin: 14px 0 0;
  max-height: 220px; overflow-y: auto;
}
.end-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px dashed #eee;
  font-size: 1.05rem;
}
.end-list li:last-child { border-bottom: none; }
.end-list li.me { background: var(--accent); border-radius: 8px; font-weight: bold; }
.end-list li .pos { width: 32px; text-align: left; color: var(--primary-dd); }
.end-list li .nm  { flex: 1; text-align: left; }
.end-list li .pts { font-weight: bold; color: var(--primary-dd); }
.end-actions { margin-top: 18px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Decoraciones ---------- */
.snake-decor {
  font-size: 2.4rem;
  letter-spacing: 6px;
  margin: 6px 0;
  user-select: none;
}

/* Pantalla angosta */
@media (max-width: 600px) {
  .game-topbar { padding: 6px 8px; gap: 6px; }
  .hud-pill { padding: 4px 10px; font-size: .9rem; }
  .canvas-wrap { padding: 4px; }
}
