/* Nota sobre tipografía: usamos pilas de fuentes del sistema con carácter editorial (Georgia/Iowan
   para display, system-ui para cuerpo, ui-monospace para timer/contador) en vez de fuentes web
   externas — el festival puede tener wifi inestable, y así el juego no depende de ningún CDN.
   Si más adelante quieres Fraunces/Inter/IBM Plex Mono reales, se agregan con @font-face aquí y los
   navegadores las tomarán automáticamente (los nombres ya están declarados en js/config.js FONTS). */

:root {
  --navy: #12213B;
  --navy-deep: #0A1526;
  --gold: #D4AF37;
  --gold-soft: #E8CE7A;
  --burgundy: #6E1F2A;
  --cream: #F4ECD8;
  --paper: #FBF6EA;
  --ink: #1B1B1B;

  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-body: -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--navy-deep);
  font-family: var(--font-body);
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh; /* fallback — la unidad dinámica de abajo la reemplaza donde el navegador la soporte */
  width: 100dvw;
  height: 100dvh;
}

/* El tamaño CSS real del canvas también lo fija main.js en px directos en cada resize() (mismos
   valores que window.innerWidth/innerHeight, los que ya usa el motor de dibujo) — este 100%/100% es
   solo el valor inicial antes de que corra ese primer resize(). Sin ese ajuste en JS, en navegadores
   móviles el 100vh/100dvh de #app puede no coincidir al pixel con el viewport visible real mientras la
   barra de direcciones se muestra/oculta (el bug clásico "100vh en mobile"), y eso desalinea el mapeo
   de coordenadas de touch en pointerPosFromEvent (que depende de canvas.getBoundingClientRect())
   respecto a dónde el juego cree que están los botones — se ve como "no responde al tocar".
*/
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--navy-deep);
  touch-action: none;
}

/* ---------- Overlay DOM (formularios reales) ---------- */

#overlay {
  /* fixed (no absolute) — ancla directo al viewport real, no a la caja de #app, que en navegadores
     móviles puede quedar más alta que lo visible mientras la barra de direcciones se anima (ver nota
     junto a #app arriba). Con absolute, este panel podía terminar centrado fuera de lo que el usuario
     ve realmente en pantalla. */
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.overlay-panel {
  pointer-events: auto;
  width: min(420px, 88vw);
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--navy);
  border-radius: 4px;
  padding: 2rem 1.75rem;
  box-shadow: 0 20px 50px rgba(10, 21, 38, 0.5);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.overlay-panel.hidden { display: none; }

.overlay-eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--burgundy);
}

.overlay-title {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--navy);
}

.overlay-copy {
  margin: 0 0 0.5rem;
  font-size: 0.92rem;
  line-height: 1.4;
  color: #3a3a3a;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--navy);
}

.field-input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.7rem 0.8rem;
  border: 2px solid #cfc6ac;
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

.field-input:focus {
  outline: none;
  border-color: var(--gold);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.82rem;
  line-height: 1.35;
  color: #3a3a3a;
  cursor: pointer;
}

.checkbox-row input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.checkbox-row a { color: var(--burgundy); }

.btn-primary {
  margin-top: 0.5rem;
  padding: 0.85rem 1.2rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  background: var(--burgundy);
  color: var(--cream);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover:not(:disabled) { background: #8c303d; }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-primary:disabled {
  background: #b9ae94;
  cursor: not-allowed;
}

/* ---------- Feedback toast ("sigue buscando") ---------- */

#feedback-toast {
  position: fixed;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%) translateY(10px);
  background: var(--navy);
  color: var(--gold-soft);
  border: 2px solid var(--gold);
  font-family: var(--font-display);
  font-size: 1rem;
  padding: 0.7rem 1.4rem;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  /* antes tenía white-space:nowrap y sin max-width: los mensajes largos (p.ej. "¡Lo lograste! Ahora
     sí, vamos a descubrir a los artistas del fin de semana…") se salían del viewport en móvil y, como
     el toast queda centrado sobre la franja inferior, ese desborde pasaba justo por encima del
     joystick y del botón de acción — el "joystick se encima con texto" reportado en producción no era
     un tema de fuentes, era este overflow. Con max-width + wrap el toast siempre cabe en pantalla. */
  max-width: min(86vw, 360px);
  text-align: center;
  white-space: normal;
  word-wrap: break-word;
  z-index: 10;
}

#feedback-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#feedback-toast.hidden { display: none; }

/* En touch, además del wrap de arriba, el toast se sube por encima de la franja donde viven el
   joystick (bottom-left) y el botón de acción (bottom-right) — así ninguna combinación de mensaje
   largo + viewport angosto puede volver a quedar visualmente encimada con los controles. */
body.touch-device #feedback-toast {
  bottom: calc(max(24px, env(safe-area-inset-bottom, 0px) + 16px) + 144px);
}

/* ---------- Botón contextual "¡Pruébalo!" ---------- */

#interact-button {
  position: fixed;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%) translateY(0) scale(1);
  background: var(--gold);
  color: var(--navy-deep);
  border: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.85rem 1.8rem;
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(10, 21, 38, 0.45);
  cursor: pointer;
  z-index: 10;
  animation: interact-pulse 1.1s ease-in-out infinite;
}

#interact-button:active {
  transform: translateX(-50%) scale(0.95);
}

#interact-button.hidden { display: none; }

@keyframes interact-pulse {
  0%, 100% { box-shadow: 0 10px 24px rgba(10, 21, 38, 0.45), 0 0 0 0 rgba(212, 175, 55, 0.5); }
  50% { box-shadow: 0 10px 24px rgba(10, 21, 38, 0.45), 0 0 0 8px rgba(212, 175, 55, 0); }
}

/* ---------- Controles táctiles (solo dispositivos táctiles, ver touchControls.js) ---------- */

/* En touch, el botón de acción se mueve a la esquina inferior derecha (patrón clásico: joystick con
   el pulgar izquierdo, acción con el pulgar derecho) en vez de quedar centrado abajo. */
body.touch-device #interact-button {
  left: auto;
  right: max(24px, env(safe-area-inset-right, 0px) + 16px);
  bottom: max(28px, env(safe-area-inset-bottom, 0px) + 20px);
  transform: none;
}

body.touch-device #interact-button:active {
  transform: scale(0.95);
}

#mobile-joystick {
  /* fixed, no absolute — ver nota en #overlay arriba: si #app queda más alto que el viewport visible
     real (el bug clásico "100vh en mobile"), un `bottom` relativo a #app puede caer fuera de lo que el
     usuario ve, que es exactamente el síntoma reportado ("el joystick no aparece" en celular real). */
  position: fixed;
  left: max(24px, env(safe-area-inset-left, 0px) + 16px);
  bottom: max(24px, env(safe-area-inset-bottom, 0px) + 16px);
  width: 128px;
  height: 128px;
  z-index: 15;
  touch-action: none;
}

#mobile-joystick.hidden { display: none; }

#joystick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(10, 21, 38, 0.4);
  border: 2px solid rgba(212, 175, 55, 0.45);
  touch-action: none;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(212, 175, 55, 0.88);
  border: 2px solid rgba(244, 236, 216, 0.9);
  box-shadow: 0 6px 14px rgba(10, 21, 38, 0.45);
  pointer-events: none;
}
