/* Vía Libre — identidad propia: señalética ferroviaria.
   Fondo verde señal profundo, fichas marfil táctiles, semáforo de vidas. */

:root {
  --verde-anden: #0d3a2d;   /* fondo general */
  --verde-campo: #0a2f24;   /* tablero, un paso más hondo */
  --marfil: #f4efe3;        /* fichas y botón principal */
  --tinta: #14261e;         /* flechas y texto sobre marfil */
  --via-libre: #35c97e;     /* verde señal: éxito, pista, progreso */
  --precaucion: #f0b429;    /* ámbar: estrellas */
  --alto: #e4572e;          /* rojo señal: error */
  --niebla: rgba(244, 239, 227, 0.55);
  --niebla-suave: rgba(244, 239, 227, 0.12);
  --display: "Avenir Next Condensed", "Arial Narrow", "Roboto Condensed", sans-serif-condensed, sans-serif;
  --texto: "Avenir Next", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--texto);
  background: var(--verde-anden);
  color: var(--marfil);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- pantallas ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
}
.screen.active { display: flex; }

/* ---------- inicio ---------- */

#screen-home { align-items: center; justify-content: center; }

.home-inner { text-align: center; max-width: 340px; animation: home-in 0.5s ease-out both; }

@keyframes home-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.eyebrow {
  font-family: var(--display);
  font-size: 0.85rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--via-libre);
  margin-bottom: 10px;
}

.brand {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(4rem, 22vw, 6rem);
  line-height: 0.92;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* la segunda línea es una "vía": una ficha marfil cruza por atrás al cargar */
.brand-track { position: relative; display: inline-block; padding: 0 0.1em; }

.brand-chip {
  position: absolute;
  top: 50%;
  left: -18%;
  width: 0.42em;
  height: 0.42em;
  border-radius: 0.09em;
  background: var(--via-libre);
  opacity: 0.9;
  z-index: -1;
  animation: chip-cross 2.6s cubic-bezier(0.6, 0, 0.3, 1) 0.4s infinite;
}

@keyframes chip-cross {
  0%   { transform: translate(-80%, -50%); opacity: 0; }
  12%  { opacity: 0.9; }
  55%  { transform: translate(320%, -50%); opacity: 0.9; }
  70%  { transform: translate(420%, -50%); opacity: 0; }
  100% { transform: translate(420%, -50%); opacity: 0; }
}

.tagline {
  margin: 18px 0 28px;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--niebla);
}

.home-actions { display: flex; flex-direction: column; gap: 12px; }

.home-stats {
  margin-top: 18px;
  font-family: var(--display);
  font-size: 0.9rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--precaucion);
}


/* ---------- botones ---------- */

.btn {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: none;
  border-radius: 14px;
  padding: 15px 24px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--marfil);
  color: var(--tinta);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.28);
}

.btn-ghost {
  background: transparent;
  color: var(--marfil);
  border: 2px solid var(--niebla-suave);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--niebla-suave);
  color: var(--marfil);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(0.92); }

.sound-toggle {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 16px;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
}

.topbar h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.topbar-spacer { width: 44px; }

/* ---------- semáforo de vidas / estrellas ---------- */

.signal { display: inline-flex; gap: 7px; align-items: center; }

.light {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.light.on {
  background: var(--via-libre);
  box-shadow: 0 0 8px rgba(53, 201, 126, 0.7);
}
.light.err {
  background: var(--alto);
  box-shadow: 0 0 8px rgba(228, 87, 46, 0.7);
}

.signal-big { justify-content: center; gap: 10px; margin-bottom: 14px; }
.signal-big .light { width: 18px; height: 18px; }

/* ---------- strip de par ---------- */

.par-strip {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 6px 0;
  font-family: var(--display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

#par-label { font-size: 1.05rem; font-weight: 800; color: var(--via-libre); }
#slide-label { font-size: 0.8rem; color: var(--niebla); }

/* ---------- tablero ---------- */

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 10px 0;
}

.board {
  position: relative;
  background: var(--verde-campo);
  border-radius: 18px;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.35);
  padding: 8px;
}

.board.combo { animation: combo-pulse 0.32s ease-out; }
@keyframes combo-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.015); box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.35), 0 0 22px rgba(53, 201, 126, 0.35); }
  100% { transform: scale(1); }
}

.cells, .tiles { position: absolute; inset: 8px; }

.cell {
  position: absolute;
  border-radius: 12%;
  background: rgba(0, 0, 0, 0.16);
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--marfil);
  border-radius: 16%;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
  touch-action: manipulation;
  will-change: transform, opacity;
}

.tile svg { width: 62%; height: 62%; color: var(--tinta); }

.tile.d-U svg { transform: rotate(0deg); }
.tile.d-R svg { transform: rotate(90deg); }
.tile.d-D svg { transform: rotate(180deg); }
.tile.d-L svg { transform: rotate(270deg); }

/* ---------- acciones de juego ---------- */

.game-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding-top: 8px;
}
.game-actions .btn { flex: 1; max-width: 200px; font-size: 1rem; padding: 13px 16px; }

/* ---------- ranking ---------- */

.topbar-spacer { width: 44px; }

.tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 8px 0 14px;
}

.tab {
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: transparent;
  color: var(--niebla);
  border: 2px solid var(--niebla-suave);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
}
.tab.active {
  background: var(--marfil);
  color: var(--tinta);
  border-color: var(--marfil);
}

.ranking-list {
  list-style: none;
  overflow-y: auto;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.ranking-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--niebla-suave);
  font-size: 1rem;
}
.ranking-row .pos {
  font-family: var(--display);
  font-weight: 800;
  width: 28px;
  color: var(--niebla);
}
.ranking-row .nombre { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-row .patios {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--via-libre);
}
.ranking-row:nth-child(1) .pos, .ranking-row:nth-child(2) .pos, .ranking-row:nth-child(3) .pos { color: var(--precaucion); }
.ranking-row.own { background: rgba(53, 201, 126, 0.12); border-radius: 10px; }

.ranking-meta {
  text-align: center;
  padding: 12px 0 4px;
  color: var(--niebla);
  font-size: 0.9rem;
}

/* ---------- registro de apodo ---------- */

.register-label {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

#apodo-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid rgba(20, 38, 30, 0.25);
  border-radius: 12px;
  font-family: var(--texto);
  font-size: 1.05rem;
  text-align: center;
  background: #fff;
  color: var(--tinta);
  margin-bottom: 8px;
}
#apodo-input:focus { outline: 3px solid var(--via-libre); border-color: transparent; }

.apodo-error {
  color: var(--alto);
  font-size: 0.85rem;
  min-height: 1.1em;
  margin-bottom: 8px;
}

#modal-register { margin-bottom: 16px; }
#modal-register .btn { width: 100%; background: var(--tinta); color: var(--marfil); }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 20, 14, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--marfil);
  color: var(--tinta);
  border-radius: 20px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
  animation: modal-in 0.28s cubic-bezier(0.2, 1.2, 0.4, 1) both;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.modal h3 {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.modal p { color: rgba(20, 38, 30, 0.7); line-height: 1.45; margin-bottom: 20px; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.modal-actions .btn-primary { background: var(--tinta); color: var(--marfil); }
.modal-actions .btn-ghost { color: var(--tinta); border-color: rgba(20, 38, 30, 0.2); }

.modal .light { background: rgba(0, 0, 0, 0.15); box-shadow: none; }
.modal .light.on { background: var(--via-libre); box-shadow: 0 0 8px rgba(53, 201, 126, 0.5); }
.modal .light.err-final { background: var(--alto); box-shadow: 0 0 8px rgba(228, 87, 46, 0.5); }

/* ---------- escritorio ---------- */

@media (min-width: 700px) {
  .topbar, .game-actions { max-width: 560px; width: 100%; margin-left: auto; margin-right: auto; }
}

/* ---------- accesibilidad ---------- */

button:focus-visible {
  outline: 3px solid var(--via-libre);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .brand-chip { animation: none; opacity: 0; }
  .home-inner, .modal { animation-duration: 0.01s; }
}
