/* =======================================================
   Cabify · City drive — top-down geometric city game
   Paleta Cabify: morado #6C2BD9 sobre ciudad clara.
   Interfaz universal, sin texto: solo iconos y cifras.
   ======================================================= */
:root {
  --cabify: #6C2BD9;
  --cabify-deep: #4B1FA6;
  --ink: #1C1430;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-decel: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #E7E4F0; font-family: var(--font); }

.city { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: clamp(12px, 3vw, 20px) clamp(12px, 3vw, 18px);
  pointer-events: none;
}
/* Todos los controles del juego viven en ESTA línea: ganancias (izq) + cluster
   ciudad/ajustes/destino (der). El destino queda SIEMPRE el último (arriba-der). */
.hud__group { display: inline-flex; align-items: center; gap: clamp(6px, 2vw, 10px); }
.hud__fare, .hud__group { pointer-events: auto; }
.hud__fare {
  display: inline-flex; align-items: center; gap: 8px; line-height: 1;
  background: rgba(255,255,255,0.86); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-radius: 16px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(43,18,90,0.16);
}
.hud__icon { color: var(--cabify); flex: 0 0 auto; }
.hud__fare b { font-size: clamp(20px, 5vw, 28px); color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.hud__trips {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 4px; padding-left: 10px; border-left: 1px solid rgba(28,20,48,0.12);
  color: var(--cabify); font-weight: 700; font-size: 14px;
}
.hud__trips svg { color: var(--cabify); }
.hud__trips b { font-variant-numeric: tabular-nums; }

.task {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: 0 0 auto;
  background: var(--cabify); color: #fff; border-radius: 50%;
  box-shadow: 0 10px 28px rgba(108,43,217,0.36);
  position: relative;
}
.task__icon { display: block; }
.task__dot {
  position: absolute; top: -2px; right: -2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--cabify);
  animation: taskPulse 1.4s var(--ease) infinite;
}
@keyframes taskPulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.65); } }

/* ---------- Toast (icono + cifra, sin texto de idioma) ---------- */
.toast {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%) translateY(-8px);
  z-index: 6; display: inline-flex; align-items: center; gap: 8px;
  background: rgba(28,20,48,0.92); color: #fff;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: 999px; padding: 10px 18px; font-size: 15px; font-weight: 700;
  box-shadow: 0 14px 36px rgba(28,20,48,0.3); opacity: 0;
  transition: opacity .3s var(--ease), transform .3s var(--ease); white-space: nowrap;
}
.toast svg { color: #C9B6FF; flex: 0 0 auto; }
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast[hidden] { display: none; }

/* ---------- Selector de ciudad (en la línea superior) ---------- */
.cities {
  position: relative; z-index: 7;
}
.cities__btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px 0 12px; border-radius: 999px;
  color: var(--cabify); font: 600 14px/1 var(--font); letter-spacing: -0.01em;
}
.cities__btn[aria-expanded="true"] { background: #fff; }
.cities__cur { color: var(--ink); font-variant-numeric: tabular-nums; }
.cities__menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  width: max-content; max-width: calc(100vw - 28px);
  background: rgba(255,255,255,0.94);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-radius: 16px; padding: 10px;
  box-shadow: 0 18px 48px rgba(43,18,90,0.26);
  transform-origin: top right;
  animation: citiesMenuIn .34s var(--ease-spring) both;
}
.cities__menu[hidden] { display: none; }
/* Spring open from the trigger corner */
@keyframes citiesMenuIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}
.cities__item {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border: 0; cursor: pointer;
  border-radius: 13px; color: var(--cabify);
  background: rgba(108,43,217,0.07);
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s var(--ease-spring), background .16s var(--ease);
}
/* Glyphs stagger in as the menu springs open */
@keyframes cityGlyphIn {
  from { opacity: 0; transform: translateY(6px) scale(0.8); }
  to   { opacity: 1; transform: none; }
}
.cities__menu .cities__item {
  animation: cityGlyphIn .34s var(--ease-spring) both;
  animation-delay: calc(60ms + var(--i, 0) * 45ms);
}
.cities__item:hover { background: rgba(108,43,217,0.14); }
.cities__item:hover { transform: translateY(-2px); }
.cities__item:active { transform: scale(0.92); transition: transform .12s var(--ease); }
.cities__item.is-on { background: var(--cabify); color: #fff; }
.cities__dot {
  position: absolute; bottom: 5px; right: 5px;
  width: 8px; height: 8px; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.85);
}
.cities__item.is-on .cities__dot { box-shadow: 0 0 0 2px var(--cabify); }

/* ---------- Botones de icono ---------- */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent;
  color: var(--ink); background: rgba(255,255,255,0.86);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(43,18,90,0.16);
  transition: transform .2s var(--ease-spring), background .18s var(--ease), box-shadow .2s var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .iconbtn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(43,18,90,0.2); }
}
.iconbtn:active { transform: scale(0.92); transition: transform .12s var(--ease); }
/* Gear icon gives a tactile quarter-turn nudge on press */
.cfgbtn svg { transition: transform .3s var(--ease-spring); }
.cfgbtn:active svg { transform: rotate(35deg); }
.cfgbtn[aria-expanded="true"] svg { transform: rotate(90deg); }
.cities__btn[aria-expanded="true"] svg { color: var(--cabify); }

.cfgbtn {
  position: relative; z-index: 7;
  width: 46px; height: 46px; border-radius: 14px;
}
.cfgbtn[aria-expanded="true"] { color: var(--cabify); background: #fff; }

/* ---------- Panel de ajustes (en vivo) ---------- */
.cfg {
  position: fixed; z-index: 8;
  top: calc(clamp(14px, 3vw, 22px) + 56px); right: clamp(14px, 3vw, 22px);
  width: min(280px, calc(100vw - 28px));
  background: rgba(255,255,255,0.94); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-radius: 18px; padding: 12px 16px 16px;
  box-shadow: 0 18px 48px rgba(43,18,90,0.26);
  transform-origin: top right;
  animation: cfgIn .34s var(--ease-spring) both;
}
@keyframes cfgIn { from { opacity: 0; transform: translateY(-10px) scale(.92); } to { opacity: 1; transform: none; } }
/* Rows settle in just after the panel springs open */
@keyframes cfgRowIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }
.cfg .cfg__row { animation: cfgRowIn .32s var(--ease-decel) both; }
.cfg .cfg__row:nth-of-type(1) { animation-delay: .10s; }
.cfg .cfg__row:nth-of-type(2) { animation-delay: .16s; }
.cfg .cfg__row:nth-of-type(3) { animation-delay: .22s; }
.cfg[hidden] { display: none; }
.cfg__head { display: flex; align-items: center; justify-content: space-between; color: var(--cabify); margin-bottom: 6px; }
.cfg__close { width: 32px; height: 32px; border-radius: 10px; box-shadow: none; background: rgba(108,43,217,0.08); }
.cfg__row { display: flex; align-items: center; gap: 12px; padding: 10px 2px; color: var(--cabify); }
.cfg__row svg { flex: 0 0 auto; }

/* slider */
.cfg__row input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1;
  height: 6px; border-radius: 999px; background: rgba(108,43,217,0.18); outline: none;
}
.cfg__row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%; background: var(--cabify);
  box-shadow: 0 2px 8px rgba(108,43,217,0.5); cursor: pointer; border: 3px solid #fff;
}
.cfg__row input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--cabify);
  box-shadow: 0 2px 8px rgba(108,43,217,0.5); cursor: pointer; border: 3px solid #fff;
}
.cfg__row input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: rgba(108,43,217,0.18); }

/* ---------- Mando de giro en pantalla (móvil) ---------- */
.steer {
  position: fixed; bottom: 0; top: 38%; width: 34%; z-index: 4;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: clamp(24px, 9vh, 64px);
  border: 0; background: transparent; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: none;
  color: var(--cabify);
}
/* SIN flechas de dirección visibles: las zonas táctiles laterales siguen
   funcionando (girar tocando media pantalla en móvil), pero sin icono/burbuja. */
.steer svg { display: none; }
.steer--l { left: 0; }
.steer--r { right: 0; }
@media (hover: hover) and (pointer: fine) { .steer { display: none; } }

/* ---------- Coreografía de entrada ---------- */
@keyframes cabIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
.hud__fare { animation: cabIn .6s var(--ease) .15s both; }
.task      { animation: cabIn .6s var(--ease) .35s both; }
.cities    { animation: cabIn .6s var(--ease) .4s both; }
.cfgbtn    { animation: cabIn .6s var(--ease) .45s both; }

/* ---------- City rebuild crossfade ----------
   When the map is rebuilt for a new city we briefly veil the canvas so the
   layout swap reads as a settle, not a hard cut. */
.city-fade {
  position: fixed; inset: 0; z-index: 3; pointer-events: none;
  background: #E7E4F0; opacity: 0;
}
.city-fade.is-on { opacity: 1; }
.city-fade.is-settling {
  opacity: 0;
  transition: opacity .42s var(--ease-decel);
}

@media (prefers-reduced-motion: reduce) {
  .task__dot { animation: none; }
  .hud__fare, .task, .cities, .cfgbtn, .cfg, .cities__menu,
  .cfg .cfg__row, .cities__menu .cities__item { animation: none; }
  .cfgbtn svg, .cfgbtn:active svg { transition: none; }
  .city-fade.is-settling { transition: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .toast { font-size: 14px; padding: 9px 16px; }
}
@media (max-width: 360px) {
  .hud__fare b { font-size: 18px; }
  .cfgbtn { width: 42px; height: 42px; }
  .steer svg { width: 54px; height: 54px; padding: 12px; }
  .cities__btn { height: 36px; font-size: 13px; padding: 0 12px 0 10px; }
  .cities__cur { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cities__menu { grid-template-columns: repeat(4, 1fr); }
  .cities__item { width: 42px; height: 42px; }
}
