/* ==========================================================================
   Visor 3D · estilos
   ========================================================================== */

:root {
  --bg: #0a0d16;
  --panel: rgba(17, 23, 39, 0.66);
  --panel-strong: rgba(17, 23, 39, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #e9eefb;
  --muted: #93a1bd;
  --accent: #4f8cff;
  --accent-dark: #2f6ae0;
  --danger: #ff6b6b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --pad: max(14px, env(safe-area-inset-left));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

/* --------------------------------------------------------------------------
   Lienzo 3D
   -------------------------------------------------------------------------- */

#scene {
  display: block;
  width: 100%;
  height: 100%;
  /* Imprescindible: sin esto el navegador se queda los gestos táctiles
     (scroll / zoom de página) y no llegan a los controles de three.js. */
  touch-action: none;
  cursor: grab;
  outline: none;
}

#scene:active {
  cursor: grabbing;
}

/* --------------------------------------------------------------------------
   Capas de interfaz (HUD)
   -------------------------------------------------------------------------- */

.hud {
  position: absolute;
  z-index: 2;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  pointer-events: none;
}

.hud--top {
  top: var(--pad);
  left: var(--pad);
  padding: 12px 16px;
  max-width: min(60vw, 320px);
}

.title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.source {
  margin: 3px 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud--hints {
  top: var(--pad);
  right: var(--pad);
  padding: 11px 14px;
  max-width: min(46vw, 230px);
}

.hints {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.74rem;
  line-height: 1.7;
  color: var(--muted);
}

.hints li {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.key {
  flex: 0 0 auto;
  min-width: 74px;
  color: var(--text);
  font-weight: 600;
}

/* Solo se muestra la ayuda que corresponde al tipo de dispositivo */
.hints--touch {
  display: none;
}

@media (hover: none), (pointer: coarse) {
  .hints--mouse {
    display: none;
  }

  .hints--touch {
    display: block;
  }
}

.hints__drop {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Botones
   -------------------------------------------------------------------------- */

.hud--actions {
  bottom: var(--pad);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  pointer-events: auto;
  max-width: calc(100vw - 2 * var(--pad));
}

.btn {
  flex: 0 0 auto;
  padding: 9px 15px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.34);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn[aria-pressed="false"] {
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Solapas de arriba
   -------------------------------------------------------------------------- */

.hud--flaps {
  left: var(--pad);
  bottom: calc(var(--pad) + 58px);
  width: min(40vw, 255px);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  pointer-events: auto;
}

.hud--flaps[hidden] {
  display: none;
}

.panel__title {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.flaps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flap {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name value"
    "range range";
  align-items: center;
  gap: 1px 8px;
}

.flap__name {
  grid-area: name;
  font-size: 0.72rem;
  color: var(--text);
}

.flap__value {
  grid-area: value;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}

.flap__unit {
  font-size: 0.68rem;
  color: var(--muted);
}

.flap__range {
  grid-area: range;
  width: 100%;
  height: 16px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.flap__range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.flap__range::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.flap__range::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.flap__range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

.flap__range:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.flap__num {
  width: 4.6em;
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  text-align: right;
}

.flap__num:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn--small {
  align-self: stretch;
  padding: 6px 10px;
  font-size: 0.72rem;
}

/* --------------------------------------------------------------------------
   Estado de carga
   -------------------------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 45%, #131b30 0%, var(--bg) 70%);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.overlay--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay--error .spinner {
  display: none;
}

.overlay--error .overlay__text {
  color: var(--danger);
  max-width: 34ch;
}

.overlay__text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

/* --------------------------------------------------------------------------
   Zona para soltar archivos
   -------------------------------------------------------------------------- */

.dropzone {
  position: absolute;
  inset: 12px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: rgba(79, 140, 255, 0.1);
  color: var(--text);
  font-size: 0.9rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  pointer-events: none;
}

.dropzone--active {
  opacity: 1;
  visibility: visible;
}

/* --------------------------------------------------------------------------
   Móvil
   -------------------------------------------------------------------------- */

@media (max-width: 600px) {
  .hud--top {
    padding: 9px 12px;
    max-width: 46vw;
  }

  .title {
    font-size: 0.86rem;
  }

  .source {
    font-size: 0.68rem;
  }

  .hud--hints {
    padding: 9px 11px;
    max-width: 48vw;
  }

  .hints {
    font-size: 0.68rem;
    line-height: 1.55;
  }

  .key {
    min-width: 58px;
  }

  .hints__drop {
    display: none;
  }

  .hud--actions {
    width: calc(100% - 2 * var(--pad));
    justify-content: center;
    flex-wrap: wrap;
    padding: 6px;
    gap: 6px;
  }

  .btn {
    flex: 1 1 auto;
    padding: 10px 8px;
    font-size: 0.74rem;
    text-align: center;
  }

  .hud--flaps {
    left: var(--pad);
    right: var(--pad);
    bottom: calc(var(--pad) + 104px);
    width: auto;
    padding: 10px 12px;
    gap: 7px;
  }
}
