/**
 * Motor 3D — tema oscuro, cabecera compacta, panel desplegable y cruces táctiles estilo mando.
 */
:root {
  --bg: #0d0d10;
  --panel: #1a1a22;
  --panel-elevated: #22222c;
  --text: #e8e8ec;
  --text-muted: #8a8a96;
  --accent: #00a8ff;
  --accent-dim: rgba(0, 168, 255, 0.35);
  --accent-glow: rgba(0, 168, 255, 0.22);
  --header-height: 52px;
  --border: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* ---------- Cabecera ---------- */
.site-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  min-height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, #16161c 0%, #121218 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  z-index: 400;
}

.site-brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow: 0 0 20px var(--accent-glow);
  flex-shrink: 0;
}

.header-nav-toggle {
  display: none;
  width: auto;
  margin: 0;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}



.menu-btn {
  width: auto;
  margin: 0;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.menu-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
}
.menu-btn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(0, 168, 255, 0.2) 0%, rgba(0, 168, 255, 0.08) 100%);
  box-shadow: 0 0 16px var(--accent-glow);
  color: #fff;
}

.header-drawer-chevron {
  display: inline-flex;
  align-items: center;
}
.header-drawer-chevron::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid currentColor;
  opacity: 0.75;
  transition: transform 0.28s ease;
}
/* ---------- Layout: solo visor ---------- */
.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewport-wrap {
  flex: 1;
  position: relative;
  min-height: 200px;
  background: radial-gradient(ellipse at 50% 30%, #1a2030 0%, #0a0a0c 70%);
  touch-action: none;
}

#renderCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Panel desplegable ---------- */
.panel-drawer {
  position: fixed;
  top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  z-index: 300;
  max-height: 0;
  width: max-content;
  overflow: hidden;
  transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(26, 26, 34, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}
.panel-drawer.open {
  max-height: min(78vh, 800px);
}
.panel-drawer-inner {
  padding: 14px 16px 22px;
  max-height: min(78vh, 800px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel {
  display: none;
}
.panel.active {
  display: block;
}

.panel-footer-hint {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Formularios ---------- */
label {
  display: block;
  margin: 8px 0;
}
textarea {
  width: 100%;
  min-height: 70px;
  margin-top: 4px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-elevated);
  color: var(--text);
}
input,
select,
button {
  width: 100%;
  margin-top: 1px;
  padding: 1px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-elevated);
  color: var(--text);
}
.panel .actions button,
.panel button#uploadMesh,
.panel button#uploadTexture,
.panel button#addMeshObject,
.panel button#addImageObject,
.panel button#addLightObject {
  background: linear-gradient(180deg, rgba(0, 168, 255, 0.18) 0%, rgba(0, 168, 255, 0.08) 100%);
  border-color: rgba(0, 168, 255, 0.35);
}
.panel .actions button:hover,
.panel button#uploadMesh:hover {
  border-color: var(--accent);
}

ul {
  list-style: none;
  padding: 0;
}
li {
  background: var(--panel-elevated);
  margin: 6px 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
#materialList li.material-edit-active {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.triple {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  margin-top: 8px;
}
.checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.checks input {
  width: auto;
  margin: 0;
}
.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.color-field {
  display: block;
}
.color-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: center;
}
.color-row input[type="color"] {
  width: 52px;
  height: 38px;
  padding: 2px;
}
.texture-preview {
  min-height: 120px;
  border: 1px solid var(--border);
  background: #121218;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
}
.texture-preview img {
  max-width: 100%;
  max-height: 120px;
  display: block;
}
.hidden {
  display: none;
}

.panel-scroll {
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dim) transparent;
}
.subpanel {
  border: 1px solid var(--border);
  padding: 12px;
  margin: 12px 0;
  border-radius: 10px;
  background: var(--panel-elevated);
}
.subpanel h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Cruces estilo mando (dos D-pads): visibles en todo dispositivo ---------- */
.touch-nav {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 80;
}
.touch-nav-row-pads {
  pointer-events: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  padding: 0 max(10px, env(safe-area-inset-left)) 0 max(10px, env(safe-area-inset-right));
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.touch-nav-cluster {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.ds-cluster-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 600;
}
.ds-shell {
  padding: 11px;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(38, 40, 52, 0.94) 0%, rgba(16, 16, 22, 0.96) 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 28px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(0, 0, 0, 0.25);
}
.ds-shell--face {
  border-color: rgba(0, 168, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 28px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(0, 168, 255, 0.08);
}

.ds-cross {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 4px;
  align-items: stretch;
  justify-items: stretch;
}
.ds-cross-cell {
  pointer-events: none;
}
.ds-cross-center {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.1) 0%, rgba(0, 0, 0, 0.35) 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
}
.ds-cross-center--accent {
  border-color: rgba(0, 168, 255, 0.25);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45), 0 0 12px rgba(0, 168, 255, 0.15);
}

.ds-btn {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.04) 100%);
  color: #f0f0f5;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform 0.08s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.ds-btn:active {
  transform: scale(0.96);
  background: linear-gradient(180deg, rgba(0, 168, 255, 0.45) 0%, rgba(0, 168, 255, 0.18) 100%);
  box-shadow: 0 0 16px var(--accent-glow), inset 0 2px 8px rgba(0, 0, 0, 0.35);
}
.ds-arrow-up {
  border-radius: 12px 12px 8px 8px;
}
.ds-arrow-down {
  border-radius: 8px 8px 12px 12px;
}
.ds-arrow-left {
  border-radius: 12px 8px 8px 12px;
}
.ds-arrow-right {
  border-radius: 8px 12px 12px 8px;
}

/* Listas: botones de accion en filas no 100% ancho */
li .actions {
  grid-template-columns: 1fr 1fr;
}
li .actions button {
  width: 100%;
}

/* ---------- Overlay de progreso ---------- */
.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(6, 8, 14, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.progress-overlay.hidden {
  display: none;
}
.progress-card {
  width: min(460px, 94vw);
  background: linear-gradient(180deg, rgba(30, 34, 46, 0.96) 0%, rgba(18, 20, 28, 0.98) 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px 14px 12px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}
.progress-title {
  font-size: 13px;
  color: #eaf4ff;
  margin-bottom: 8px;
}
.progress-track {
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #00a8ff 0%, #63ddff 100%);
  box-shadow: 0 0 16px rgba(0, 168, 255, 0.35);
  transition: width 120ms linear;
}
.progress-percent {
  margin-top: 7px;
  font-size: 12px;
  color: #b5dfff;
  text-align: right;
}
.ds-cluster-label {
  width: auto;
  margin: 0;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, #293a42 0%, #294958 100%);
  color: var(--text);
  font-size: 13px;
}
/* ---------- panel de materiales ---------- */

#subpanel-lista-materiales {
  height: 90%;
  overflow-y: auto;
}
#subpanel-materiales {
  height: 60vh;
  width: 60vw;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  
}
#subpanel-parametros-materiales {
  height: 90%;
  overflow-y: auto;
  
}
  /* ---------- configuracion para mobile ---------- */
@media (max-width: 900px) {
  /* ---------- Panel desplegable ---------- */
  .panel-drawer {
    padding-top: 30px;
    width: 100%;
  }
  .site-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 8px;
  }
  .header-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .header-nav {
    display: none;
    width: 100%;
    flex-basis: 100%;
    padding-top: 4px;
  }
  .site-header.mobile-nav-open .header-nav {
    display: flex;
  }
  /* ---------- panel de materiales ---------- */
  #subpanel-materiales {
    width: 100%;
    display: grid;
    grid-template-columns: auto auto;
  }
}