/* Phase 14 — Final UI/UX polish */

:root {
  --touch-min: 44px;
  --sheet-radius: 20px;
  --motion-fast: 160ms;
  --motion-med: 240ms;
}

/* —— Responsive breakpoints: 1920 → 375 —— */
@media (min-width: 1440px) {
  .content { max-width: 1280px; }
  .promo-grid,
  .card-grid,
  .models-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1280px) {
  :root { --sidebar-w: 240px; }
  .promo-grid,
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1024px) {
  .promo-grid,
  .card-grid,
  .models-grid,
  .media-grid,
  .tool-catalog {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .studio-layout { gap: 16px; }
}

@media (max-width: 768px) {
  .home-title { font-size: clamp(1.6rem, 6vw, 2.2rem); }
  .page-head { flex-wrap: wrap; gap: 12px; }
  .tool-catalog,
  .tools-grid,
  .card-grid.tools-2col {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .btn, .icon-btn, .avatar-btn, .credit-pill, .modal-close {
    min-height: var(--touch-min);
    min-width: var(--touch-min);
  }
  .icon-btn { width: var(--touch-min); height: var(--touch-min); }
  .modal-close { width: var(--touch-min); height: var(--touch-min); font-size: 20px; }
  .form-row input,
  .form-row select,
  .form-row textarea,
  .btn {
    font-size: 16px; /* avoid iOS zoom */
  }
}

@media (max-width: 430px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .create-orb { width: 56px; height: 56px; }
  .mobile-nav { font-size: 10px; }
  .cookie-banner { bottom: calc(var(--mobile-nav-h, 72px) + 12px); }
}

@media (max-width: 390px) {
  .brand-logo { max-width: 110px; }
  .promo-card h3 { font-size: 1rem; }
}

@media (max-width: 375px) {
  .content { padding-left: 10px; padding-right: 10px; }
  .tool-catalog,
  .tools-grid { gap: 8px; }
}

/* —— Desktop sidebar collapse polish —— */
.app-shell {
  transition: grid-template-columns var(--motion-med) ease;
}
.sidebar {
  transition: width var(--motion-med) ease, transform var(--motion-med) ease;
}
.app-shell.sidebar-collapsed .nav-link {
  justify-content: center;
  padding-inline: 10px;
}
.app-shell.sidebar-collapsed .brand {
  justify-content: center;
}
.main {
  min-width: 0; /* prevent overflow when expanding */
}

/* —— Bottom sheets —— */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-fast) ease;
}
.sheet-backdrop[hidden] {
  display: none !important;
}
.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 91;
  max-height: min(86vh, 720px);
  background: color-mix(in srgb, var(--card, #151522) 96%, #000);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  transform: translateY(110%);
  transition: transform var(--motion-med) cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
}
.bottom-sheet.open { transform: translateY(0); }
.bottom-sheet__handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  margin: 10px auto 6px;
}
.bottom-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.bottom-sheet__body {
  overflow: auto;
  padding: 14px 16px 24px;
  -webkit-overflow-scrolling: touch;
}
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.sheet-grid a,
.sheet-grid button.sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  text-decoration: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: transform var(--motion-fast) ease, background var(--motion-fast) ease;
}
.sheet-grid a:hover,
.sheet-grid button.sheet-item:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}
.sheet-grid .sheet-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 50%, transparent), transparent);
  flex-shrink: 0;
}

@media (min-width: 901px) {
  .bottom-sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(480px, 92vw);
    max-height: 80vh;
    border-radius: 18px;
    border-bottom: 1px solid var(--border);
    transform: translate(-50%, -46%) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--motion-med) ease, opacity var(--motion-fast) ease;
  }
  .bottom-sheet.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
  }
  .bottom-sheet__handle { display: none; }
}

/* —— Modal polish —— */
.modal-backdrop {
  animation: none;
}
.modal-backdrop.open {
  animation: fadeIn var(--motion-fast) ease;
}
.modal-backdrop.open .modal {
  animation: scaleIn var(--motion-med) cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-enter,
.content > section,
.content > .page-head,
.content > .card,
.content > .section-block {
  animation: slideUp var(--motion-med) ease both;
}

.progress-bar {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  animation: progressSlide 1.1s ease infinite;
}
@keyframes progressSlide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(280%); }
}

/* —— Sticky studio controls —— */
.studio-sticky-bar {
  display: none;
}
@media (max-width: 900px) {
  .studio-v2 .studio-actions {
    position: sticky;
    bottom: calc(var(--mobile-nav-h, 72px) + 8px);
    z-index: 40;
    display: flex;
    gap: 10px;
    padding: 12px;
    margin: 0 -4px;
    background: color-mix(in srgb, #0a0a0e 92%, transparent);
    border: 1px solid var(--border);
    border-radius: 16px;
    backdrop-filter: blur(12px);
  }
  .studio-v2 .studio-actions .btn {
    flex: 1;
    min-height: 48px;
  }
  .studio-mobile-triggers {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .studio-mobile-triggers .btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

@media (min-width: 901px) {
  .studio-mobile-triggers { display: none; }
}

/* —— Touch-friendly lists —— */
.virt-list {
  position: relative;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.virt-list__spacer { width: 100%; }
.virt-list__window {
  position: absolute;
  left: 0;
  right: 0;
}

img[loading="lazy"] {
  content-visibility: auto;
}
.media-thumb,
.promo-thumb,
.prompt-thumb img,
.tool-card img {
  background: rgba(255, 255, 255, 0.04);
}

/* Prevent accidental horizontal page scroll */
html, body { max-width: 100%; overflow-x: hidden; }
.creator-selector,
.asset-tabs,
.tool-tabs {
  scrollbar-width: thin;
}

@media (max-width: 900px) {
  .asset-toolbar {
    position: sticky;
    top: 60px;
    z-index: 30;
    padding: 10px;
    margin: 0 -4px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, #0a0a0e 92%, transparent);
    backdrop-filter: blur(12px);
  }
  .asset-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .asset-toolbar-row select,
  .asset-toolbar-row input,
  .asset-toolbar-row .btn {
    min-height: var(--touch-min);
    flex: 1 1 120px;
  }
  .asset-actions .btn,
  .asset-actions button {
    min-height: var(--touch-min);
    min-width: var(--touch-min);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
