/* ==========================================================================
   HUD Screen Generator
   Editor de tres paneles. En móvil se ve uno cada vez y se cambia con una
   fila de pestañas bajo la barra superior (la barra inferior sigue siendo
   la navegación del sitio).
   ========================================================================== */

.hud-app { display: block; }

@media (min-width: 1100px) {
  .hud-app {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr) 320px;
    height: calc(100dvh - var(--appbar-h) - env(safe-area-inset-top));
  }
}

@media (min-width: 1600px) { .hud-app { grid-template-columns: 380px minmax(0, 1fr) 360px; } }

.hud-panel {
  display: none;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  overflow: hidden;
}

.hud-panel.active {
  display: flex;
  min-height: calc(100dvh - var(--appbar-h) - var(--shell-bottom) - 56px);
}

@media (min-width: 1100px) {
  .hud-panel { display: flex; border-right: 1px solid var(--outline-var); }
  .hud-panel:last-child { border-right: none; border-left: 1px solid var(--outline-var); }
  .hud-panel.canvas-col { background: var(--surface-low); }
}

.hud-panel .panel-head {
  flex-shrink: 0;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--outline-var);
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-5) var(--gutter);
}

/* ── Selector de panel (móvil y tablet) ────────────────────────────────── */

.hud-tabs {
  position: sticky;
  top: calc(var(--appbar-h) + env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-var);
}

@media (min-width: 1100px) { .hud-tabs { display: none; } }

.mob-tab {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 56px;
  color: var(--on-surface-var);
  font-family: var(--font-sans);
  font-size: var(--t-label);
  font-weight: 600;
  cursor: pointer;
  transition: color var(--dur-2) var(--ease-standard);
}

.mob-tab::after {
  content: "";
  position: absolute;
  left: 50%; right: 50%;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--primary);
  opacity: 0;
  transition: left var(--dur-3) var(--ease-standard), right var(--dur-3) var(--ease-standard), opacity var(--dur-2);
}

.mob-tab.active { color: var(--primary); }
.mob-tab.active::after { left: var(--sp-4); right: var(--sp-4); opacity: 1; }
.mob-tab.active .material-icons { font-variation-settings: 'FILL' 1, 'wght' 500; }
.mob-tab .material-icons { font-size: 20px; }

/* ── Lienzo ────────────────────────────────────────────────────────────── */

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  min-height: 0;
}

@media (min-width: 1100px) { .canvas-wrap { padding: var(--sp-6); } }

.canvas-container {
  position: relative;
  width: 100%;
  max-width: 980px;
  aspect-ratio: 4 / 3;
  background: #07070a;
  border-radius: var(--shape-md);
  overflow: hidden;
  box-shadow: var(--elev-3);
}

@media (min-width: 720px) { .canvas-container { aspect-ratio: 16 / 9; } }

.canvas-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .06) 1px, transparent 1px);
  background-size: 32px 32px;
}

.canvas-bg {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .2;
  pointer-events: none;
}

.canvas-viewport { position: absolute; inset: 0; z-index: 5; touch-action: none; }

.canvas-hint {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  pointer-events: none;
  color: rgba(255, 255, 255, .62);
  transition: opacity var(--dur-4) var(--ease-standard);
}

.canvas-hint.hidden { opacity: 0; }
.canvas-hint-icon { font-size: 40px !important; }
.canvas-hint-text { font-size: var(--t-body-sm); }

.hud-el {
  position: absolute;
  z-index: 10;
  cursor: move;
  user-select: none;
  touch-action: none;
  border: 2px solid transparent;
  border-radius: 4px;
  transition: border-color var(--dur-2) var(--ease-standard);
}

.hud-el:hover { border-color: color-mix(in srgb, var(--primary) 55%, transparent); }
.hud-el.selected { border-color: var(--primary); }
.hud-el img { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }

.el-handles { position: absolute; inset: -8px; display: none; z-index: 15; }
.hud-el.selected .el-handles { display: block; }

.r-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  background: var(--primary);
  border: 3px solid #fff;
  border-radius: var(--shape-full);
  cursor: pointer;
  touch-action: none;
  z-index: 20;
  box-shadow: var(--elev-2);
}

.r-handle.nw { top: 0; left: 0; cursor: nw-resize; }
.r-handle.ne { top: 0; right: 0; cursor: ne-resize; }
.r-handle.sw { bottom: 0; left: 0; cursor: sw-resize; }
.r-handle.se { bottom: 0; right: 0; cursor: se-resize; }

/* ── Capas ─────────────────────────────────────────────────────────────── */

#elementsList { display: flex; flex-direction: column; gap: var(--sp-2); }

.el-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--shape-md);
  background: var(--surface-high);
  cursor: pointer;
  transition: background-color var(--dur-2) var(--ease-standard), box-shadow var(--dur-2) var(--ease-standard);
}

@media (hover: hover) { .el-item:hover { background: var(--surface-highest); } }
.el-item.active { background: var(--primary-container); color: var(--on-primary-container); }

.el-thumb {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--shape-xs);
  background: var(--surface-low);
  overflow: hidden;
}

.el-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.el-info { flex: 1; min-width: 0; }
.el-name { font-family: var(--font-mono); font-size: var(--t-body-sm); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.el-meta { margin-top: 2px; font-family: var(--font-mono); font-size: var(--t-label-sm); opacity: .75; }
.el-actions { display: flex; gap: 2px; flex-shrink: 0; }
.el-actions .icon-btn { width: 40px; height: 40px; min-height: 40px; }
.el-actions .icon-btn .material-icons { font-size: 19px; }

.cmd-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: 6px;
  border-radius: var(--shape-xs);
  background: var(--surface-highest);
}

.cmd-text { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--t-label-sm); overflow-wrap: anywhere; }

.uuid-row { display: flex; gap: var(--sp-2); align-items: center; }
.uuid-row .field-input { font-size: var(--t-label); }
.uuid-row .icon-btn { background: var(--surface-high); }

/* En móvil y tablet el panel no es un contenedor con scroll propio: se
   desplaza la página entera. Con "overscroll-behavior: contain" sobre un
   panel que no tiene nada que desplazar, el dedo no movía nada. */
@media (max-width: 1099px) {
  .hud-panel { overflow: visible; }
  .panel-scroll { overflow: visible; overscroll-behavior: auto; min-height: auto; flex: none; }
}
