/* ============================================
   MOBILE EDITOR
   Canvas-first, touch-native editing experience
   Only active at < 900px
   ============================================ */

/* ── Main Container (mobile only) ── */
.mobile-editor {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  flex-direction: column;
}

@media (max-width: 899.98px) {
  body.mobile-editor-active .mobile-editor {
    display: flex;
    flex-direction: column;
  }

  /* Hide everything else when mobile editor is active */
  body.mobile-editor-active .main-content,
  body.mobile-editor-active .top-bar,
  body.mobile-editor-active .sidebar,
  body.mobile-editor-active .right-sidebar-wrapper,
  body.mobile-editor-active .mobile-bottom-bar {
    display: none !important;
  }
}

/* ── Canvas ── */
.mobile-editor-canvas {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  z-index: 1;
}

.mobile-editor-canvas iframe {
  width: 100vw;
  height: 100%;
  border: none;
  background: #000;
  min-height: 100%;
  display: block;
  /* Remove any desktop card styling — full bleed on mobile */
  border-radius: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* ── Top Bar (Back + Zoom) ── */
.mobile-editor-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 12px;
  z-index: 520;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  pointer-events: none;
}

.mobile-editor-topbar > * {
  pointer-events: auto;
}

.mobile-editor-topbar-btn {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(30, 30, 30, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.6);
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.mobile-editor-topbar-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.mobile-editor-topbar-btn.is-active {
  background: rgba(255, 255, 255, 0.25);
}

.mobile-editor-topbar-right {
  display: flex;
  gap: 6px;
}

/* ── Component Carousel (Bottom Fixed) ── */
.mobile-editor-carousel {
  position: fixed;
  bottom: -1px;
  left: 0;
  right: 0;
  z-index: 510;
  background: transparent;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  pointer-events: auto;
}

.mobile-editor-carousel::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 150%;
  background: linear-gradient(to top, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%);
  pointer-events: none;
  z-index: -1;
}

.mobile-carousel-scroll {
  display: flex;
  gap: 12px;
  padding: 12px 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  pointer-events: auto;
  touch-action: pan-x;
}

.mobile-carousel-scroll::-webkit-scrollbar {
  display: none;
}

.mobile-carousel-item {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(30, 30, 30, 0.95);
  color: rgba(255, 255, 255, 0.6);
  font-size: 10px;
  font-family: TWKLausanne, -apple-system, sans-serif;
  font-weight: 400;
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
}

.mobile-carousel-item i {
  font-size: 24px;
  line-height: 1;
}

.mobile-carousel-item:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.95);
}

.mobile-carousel-item:hover {
  background: rgba(40, 40, 40, 0.95);
}

.mobile-carousel-item--added {
  animation: carouselDarken 0.6s ease 0.3s forwards;
}

@keyframes carouselDarken {
  from {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.6);
    border-color: rgba(255, 255, 255, 0.08);
  }
  to {
    background: rgba(15, 15, 15, 0.95);
    color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.04);
  }
}

/* Mobile toast — matches desktop ve-toast with gradient border */
.mobile-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #131313;
  color: #fff;
  font-size: 13px;
  font-family: TWKLausanne, -apple-system, sans-serif;
  font-weight: 500;
  padding: 10px 24px;
  border-radius: 9999px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  isolation: isolate;
}

.mobile-toast::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 9999px;
  background: conic-gradient(
    from var(--glow-angle, 0deg),
    #48dbfb, #4ade80, #48dbfb, #54a0ff, #ff9ff3, #54a0ff, #48dbfb
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 2px;
  z-index: -1;
  pointer-events: none;
  animation: toast-glow-rotate 3s linear infinite;
}

@keyframes toast-glow-rotate {
  from { --glow-angle: 0deg; }
  to { --glow-angle: 360deg; }
}

.mobile-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Component Tap Menu ── */
.mobile-component-menu {
  position: fixed;
  z-index: 530;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px;
  display: none;
  gap: 2px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.mobile-component-menu.is-visible {
  display: flex;
  animation: menuPopIn 0.15s ease forwards;
}

@keyframes menuPopIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.mobile-component-menu-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s ease;
}

.mobile-component-menu-btn span {
  font-size: 7px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.mobile-component-menu-btn:active {
  background: rgba(255, 255, 255, 0.1);
}

.mobile-component-menu-btn--danger {
  color: rgba(255, 80, 80, 0.8);
}

/* ── Properties Bottom Sheet ── */
.mobile-editor-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 539;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.mobile-editor-sheet-overlay.is-visible {
  display: block;
  opacity: 1;
}

.mobile-editor-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: #1a1a1a;
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 540;
  overflow-y: auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.mobile-editor-sheet.is-open {
  transform: translateY(0);
}

.mobile-editor-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  margin: 10px auto 16px;
  display: block;
}

.mobile-editor-sheet-title {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 12px;
  font-family: TWKLausanne, -apple-system, sans-serif;
}

/* Dark scheme + larger fields for mobile */
.mobile-editor-sheet .ve-form-group {
  margin-bottom: 16px;
}

.mobile-editor-sheet .ve-form-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  margin-bottom: 6px;
}

.mobile-editor-sheet .ve-form-input,
.mobile-editor-sheet .ve-field-select {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 16px; /* Prevents iOS zoom on focus */
  padding: 12px;
  border-radius: 10px;
  width: 100%;
  box-sizing: border-box;
  -webkit-appearance: none;
}

.mobile-editor-sheet .ve-form-input:focus,
.mobile-editor-sheet .ve-field-select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.3);
}

.mobile-editor-sheet .ve-form-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
}

.mobile-editor-sheet .ve-tab-select {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 4px;
}

.mobile-editor-sheet .ve-tab-select__btn {
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.5);
  border-color: transparent;
}

.mobile-editor-sheet .ve-tab-select__btn.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.mobile-editor-sheet .ve-icon-grid {
  gap: 6px;
}

.mobile-editor-sheet .ve-icon-grid__btn {
  font-size: 18px;
  border-radius: 8px;
  border-color: rgba(255, 255, 255, 0.08);
}

.mobile-editor-sheet .ve-checkbox-label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  padding: 8px 0;
}

.mobile-editor-sheet .ve-checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

/* ── Zoom Out Mode (mobile only) ── */
@media (max-width: 899.98px) {
body.mobile-zoom-out .mobile-editor-canvas iframe {
  transform: scale(0.5);
  transform-origin: top center;
  width: 200%;
  height: 200%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.mobile-zoom-out .mobile-editor-carousel {
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
} /* end @media max-width: 899.98px */

/* ── Minimap/Reticle ── */
.mobile-editor-minimap {
  position: fixed;
  top: calc(50px + env(safe-area-inset-top, 0px));
  right: 6px;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  width: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  z-index: 515;
  display: none;
}

body.mobile-zoom-out .mobile-editor-minimap {
  display: block;
}

.mobile-editor-minimap-viewport {
  position: absolute;
  left: 0;
  width: 100%;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.3);
  min-height: 20px;
  transition: top 0.1s ease;
}
