/* =========================================================
   MAQUETA DIGITAL 3D — SUSTENTABILIDAD · styles.css
   Interfaz mínima: la maqueta ocupa toda la pantalla.
   ========================================================= */

:root {
  --ink: #1f2d26;
  --muted: #5d6b63;
  --green: #2f7d4a;
  --glass: rgba(255, 255, 255, 0.82);
  --line: rgba(31, 45, 38, 0.1);
  --shadow: 0 8px 28px rgba(31, 45, 38, 0.16);
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: #e6f0ef;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ---------- Lienzo 3D ---------- */
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
#scene canvas.grab { cursor: grabbing; }
#scene canvas.pointer { cursor: pointer; }

/* ---------- Barra superior ---------- */
.bar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
.bar h1 {
  margin: 0;
  padding: 9px 16px;
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 12px rgba(31, 45, 38, 0.08);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 2.5px;
  white-space: nowrap;
  pointer-events: auto;
}
.bar h1 span { color: var(--green); font-weight: 700; }
.bar-actions { display: flex; gap: 6px; pointer-events: auto; }
.bar-actions button {
  border: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 12px rgba(31, 45, 38, 0.08);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  transition: background 0.2s, transform 0.15s;
}
.bar-actions button:hover { background: #fff; transform: translateY(-1px); }
.bar-actions button.on { color: var(--green); }
.bar-actions button.off { color: var(--muted); opacity: 0.75; }

/* ---------- Etiquetas flotantes ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#labels.hide { display: none; }
.lbl {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  border: 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 10px rgba(31, 45, 38, 0.18);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: auto;
  transition: opacity 0.25s;
}
.lbl::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 8px;
  height: 8px;
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(-50%) rotate(45deg);
}
.lbl:hover { background: #fff; }

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed;
  z-index: 12;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(31, 45, 38, 0.88);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
#tooltip.show { opacity: 1; }

/* ---------- Ficha informativa ---------- */
.card {
  position: fixed;
  left: 16px;
  bottom: 52px;
  z-index: 11;
  width: min(340px, calc(100% - 32px));
  padding: 18px 18px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}
.card[hidden], .about[hidden] { display: none; }
.card-head { display: flex; align-items: center; gap: 10px; padding-right: 26px; margin-bottom: 8px; }
.card-head span {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 12px;
  background: #edf5ef;
}
.card-head h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.card-text { font-size: 14px; line-height: 1.55; color: #33433a; }
.card-text p { margin: 0 0 6px; }
.card-text ul { margin: 6px 0 0; padding-left: 18px; }
.card-text li { margin-bottom: 3px; }
.close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: #f0f3f1;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}
.close:hover { background: #e3ebe6; color: var(--ink); }

/* ---------- Panel de información ---------- */
.about {
  position: fixed;
  top: 64px;
  right: 12px;
  z-index: 11;
  width: min(330px, calc(100% - 24px));
  max-height: calc(100% - 140px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}
.about h2 { margin: 0 0 8px; font-size: 18px; padding-right: 28px; }
.about h3 { margin: 16px 0 8px; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: var(--green); }
.about p { margin: 0 0 8px; font-size: 13.5px; line-height: 1.55; color: #33433a; }
.keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
kbd {
  display: inline-block;
  min-width: 22px;
  margin-right: 3px;
  padding: 2px 6px;
  border-radius: 5px;
  background: #f0f3f1;
  border: 1px solid #d9e1dc;
  border-bottom-width: 2px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.place-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.place-list button {
  border: 0;
  padding: 8px 9px;
  border-radius: 10px;
  background: #f2f6f3;
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}
.place-list button:hover { background: #e3efe7; }

/* ---------- Ayuda y controles ---------- */
.hint {
  position: fixed;
  left: 16px;
  bottom: 14px;
  z-index: 6;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
  pointer-events: none;
}
.pad {
  position: fixed;
  right: 16px;
  bottom: 14px;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(4, 38px);
  gap: 5px;
  opacity: 0.72;
  transition: opacity 0.2s;
  user-select: none;
  -webkit-user-select: none;
}
.pad:hover { opacity: 1; }
.pad button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(31, 45, 38, 0.1);
  font-size: 15px;
  color: var(--ink);
  touch-action: none;
}
.pad button:active, .pad button.held { background: #fff; color: var(--green); }
.pad .zoom { font-weight: 700; font-size: 18px; }

/* ---------- Carga y error ---------- */
#loader, #error {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: #e6f0ef;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1px;
  transition: opacity 0.6s;
}
#loader.done { opacity: 0; pointer-events: none; }
#error { text-align: center; padding: 24px; }
#error[hidden] { display: none; }
#error h2 { margin: 0; color: var(--ink); letter-spacing: 0; }
#error p { max-width: 420px; margin: 0; line-height: 1.5; letter-spacing: 0; font-weight: 500; }
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #cfe0d6;
  border-top-color: var(--green);
  animation: spin 0.9s linear infinite;
}

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pantallas pequeñas ---------- */
@media (max-width: 900px) {
  .bar-actions button span { display: none; }
  .bar-actions button { padding: 8px 10px; font-size: 15px; }
}
@media (max-width: 640px) {
  .bar { flex-direction: column; align-items: flex-start; }
  .bar h1 { font-size: 11px; letter-spacing: 1.5px; }
  .hint { display: none; }
  .about { top: 104px; }
  .card { bottom: 112px; }
}

/* =========================================================
   AMPLIACIÓN · RESPONSIVO Y CONTROLES TÁCTILES
   (solo se agregan reglas; en PC y laptop todo se ve igual)
   ========================================================= */

/* Evita el rebote, la selección y el zoom de página en móviles */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.touch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.about { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
button { touch-action: manipulation; }

/* Márgenes seguros (notch y barra inferior del iPhone / Android) */
@supports (padding: env(safe-area-inset-top)) {
  .bar { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }
  .hint { bottom: max(14px, env(safe-area-inset-bottom)); left: max(16px, env(safe-area-inset-left)); }
  .pad { bottom: max(14px, env(safe-area-inset-bottom)); right: max(16px, env(safe-area-inset-right)); }
}

/* Los controles táctiles solo existen en pantallas táctiles */
.joystick, .tpad { display: none; }
body.touch .pad { display: none; }
body.touch .joystick, body.touch .tpad { display: block; }

/* Joystick virtual */
.joystick {
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 7;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.55) 0 38%, rgba(255, 255, 255, 0.32) 39% 100%);
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 6px 22px rgba(31, 45, 38, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}
.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 10px rgba(31, 45, 38, 0.25);
  border: 3px solid var(--green);
  pointer-events: none;
}
.joystick.active .joy-knob { background: #eaf5ee; }

/* Botones táctiles de zoom y giro */
.tpad {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 7;
  display: none;
}
body.touch .tpad { display: grid; grid-template-columns: repeat(2, 48px); gap: 8px; }
.tpad button {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 3px 12px rgba(31, 45, 38, 0.14);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  touch-action: none;
}
.tpad button.held { background: #fff; color: var(--green); }

/* Interfaz en pantallas táctiles */
body.touch .bar-actions button { min-width: 40px; min-height: 40px; }
body.touch .lbl { font-size: 11px; padding: 4px 9px; }
body.touch .card { bottom: calc(158px + env(safe-area-inset-bottom)); max-height: calc(100% - 240px); overflow-y: auto; }
body.touch .hint { left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); white-space: nowrap; }

/* Teléfonos en vertical */
@media (max-width: 640px) {
  .bar h1 { max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis; }
  .bar-actions { flex-wrap: wrap; }
  .about { left: 12px; right: 12px; width: auto; top: calc(108px + env(safe-area-inset-top)); max-height: calc(100% - 290px); }
  body.touch .card { left: 12px; right: 12px; width: auto; }
  .place-list { grid-template-columns: 1fr; }
}

/* Teléfonos en horizontal (poca altura) */
@media (max-height: 520px) {
  .joystick { width: 104px; height: 104px; }
  .joy-knob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  body.touch .hint { display: none; }
  body.touch .card {
    top: calc(58px + env(safe-area-inset-top));
    bottom: auto;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: min(420px, calc(100% - 300px));
    max-height: calc(100% - 70px);
  }
  .about { top: calc(58px + env(safe-area-inset-top)); max-height: calc(100% - 70px); }
}

/* Instrucciones de gestos y panel de información en pantallas táctiles */
.touch-keys { display: none; }
body.touch .touch-keys { display: grid; }
body.touch .keys:not(.touch-keys) { display: none; }
body.touch .about { max-height: calc(100% - 64px - 160px); }
@media (max-height: 520px) { body.touch .about { max-height: calc(100% - 70px); right: max(130px, env(safe-area-inset-right)); } }
