/* PHASE12B Gate 2: responsive mobile Studio shell. Desktop geometry and export behavior are unchanged. */
.project2-mobile-nav {
  display: none;
}

@media (max-width: 1180px) and (min-width: 821px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .workspace {
    gap: 12px;
    grid-template-columns: minmax(300px, 36vw) minmax(0, 1fr);
  }

  .right-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .right-panel .export-card {
    grid-column: span 1;
  }
}

@media (max-width: 820px) {
  :root {
    --project2-mobile-nav-height: 68px;
  }

  html.project2-mobile-studio,
  html.project2-mobile-studio body {
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
  }

  html.project2-mobile-studio body {
    overflow: hidden;
  }

  html.project2-mobile-studio .app-shell {
    width: 100%;
    height: var(--project2-mobile-vh, 100dvh);
    min-height: 0;
    gap: 8px;
    padding: 8px 8px calc(var(--project2-mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  html.project2-mobile-studio .topbar {
    position: relative;
    z-index: 3;
    width: 100%;
    min-height: 56px;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    border-radius: 16px;
    padding: 8px 10px;
  }

  html.project2-mobile-studio .brand-block {
    flex: 1 1 auto;
    gap: 8px;
  }

  html.project2-mobile-studio .logo-mark {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 11px;
  }

  html.project2-mobile-studio h1 {
    overflow: hidden;
    font-size: 14px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html.project2-mobile-studio .top-actions {
    flex: 0 1 auto;
    width: auto;
    max-width: 63%;
    gap: 6px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow-x: auto;
    scrollbar-width: none;
  }

  html.project2-mobile-studio .top-actions::-webkit-scrollbar,
  html.project2-mobile-studio .toolbar-actions::-webkit-scrollbar,
  html.project2-mobile-studio .viewer-footer::-webkit-scrollbar {
    display: none;
  }

  html.project2-mobile-studio .top-actions > * {
    flex: 0 0 auto;
  }

  /* Gate 2 FIX1: mobile header keeps only direct actions. Account/export status
     remains available in the Design account card and My Account. */
  html.project2-mobile-studio .top-actions .project2-guest-badge,
  html.project2-mobile-studio .top-actions .project2-access-badge {
    display: none !important;
  }

  html.project2-mobile-studio .top-actions {
    max-width: none;
    overflow: visible;
  }

  html.project2-mobile-studio .top-actions .btn,
  html.project2-mobile-studio .project2-account-button,
  html.project2-mobile-studio .project2-my-designs-button,
  html.project2-mobile-studio .project2-guest-badge,
  html.project2-mobile-studio .project2-access-badge {
    min-height: 38px;
    padding-inline: 10px;
    border-radius: 11px;
    font-size: 10px;
    white-space: nowrap;
  }

  html.project2-mobile-studio .workspace {
    position: relative;
    display: block;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  html.project2-mobile-studio .workspace > .panel,
  html.project2-mobile-studio .workspace > .preview-panel {
    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: 16px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
  }

  html.project2-mobile-studio .workspace > .panel {
    padding: 8px;
    gap: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
  }

  html.project2-mobile-studio body[data-project2-mobile-tab="design"] .preview-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="design"] .right-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="preview"] .left-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="preview"] .right-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="export"] .left-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="export"] .preview-panel {
    display: none !important;
  }

  html.project2-mobile-studio body[data-project2-mobile-tab="design"] .left-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="preview"] .preview-panel,
  html.project2-mobile-studio body[data-project2-mobile-tab="export"] .right-panel {
    display: flex !important;
  }

  html.project2-mobile-studio .left-panel,
  html.project2-mobile-studio .right-panel {
    flex-direction: column;
  }

  html.project2-mobile-studio .card {
    border-radius: 14px;
    padding: 12px;
  }

  html.project2-mobile-studio .tool-selector-card,
  html.project2-mobile-studio .hero-card {
    scroll-margin-top: 8px;
  }

  html.project2-mobile-studio .tool-selector-menu {
    max-height: min(52vh, 420px);
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    align-content: start;
    padding-right: 3px;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
  }

  html.project2-mobile-studio button,
  html.project2-mobile-studio .btn,
  html.project2-mobile-studio input,
  html.project2-mobile-studio select,
  html.project2-mobile-studio textarea {
    font-size: 16px;
  }

  html.project2-mobile-studio .btn,
  html.project2-mobile-studio .mode-btn,
  html.project2-mobile-studio .tool-selector-toggle,
  html.project2-mobile-studio .tool-menu-item,
  html.project2-mobile-studio input:not([type="range"]):not([type="color"]),
  html.project2-mobile-studio select {
    min-height: 44px;
  }

  html.project2-mobile-studio input[type="range"] {
    min-height: 34px;
    touch-action: pan-y;
  }

  html.project2-mobile-studio .button-grid,
  html.project2-mobile-studio .split-controls {
    gap: 8px;
  }

  html.project2-mobile-studio .preview-panel {
    overflow: hidden;
  }

  html.project2-mobile-studio .preview-toolbar {
    min-height: 0;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }

  html.project2-mobile-studio .preview-toolbar h2 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html.project2-mobile-studio .preview-toolbar .toolbar-actions {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  html.project2-mobile-studio .preview-toolbar .toolbar-actions .btn {
    flex: 0 0 auto;
    min-width: 58px;
    min-height: 40px;
    padding: 0 11px;
    font-size: 11px;
  }

  html.project2-mobile-studio .viewer {
    flex: 1 1 auto;
    min-height: 260px;
    height: auto;
    touch-action: none;
  }

  html.project2-mobile-studio .viewer-footer {
    min-height: 40px;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding: 0 10px;
    font-size: 10px;
    white-space: nowrap;
    scrollbar-width: none;
  }

  html.project2-mobile-studio .viewer-footer .legend-dot {
    flex: 0 0 auto;
  }

  html.project2-mobile-studio .right-panel .export-card {
    order: -10;
  }

  html.project2-mobile-studio .right-panel .project2-secure-export-download-button,
  html.project2-mobile-studio .right-panel .btn-wide {
    min-height: 48px;
  }

  html.project2-mobile-studio .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  html.project2-mobile-studio .project2-mobile-nav {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    min-height: 58px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    background: rgba(15, 20, 31, 0.96);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(18px);
  }

  html.project2-mobile-studio .project2-mobile-nav[hidden] {
    display: none !important;
  }

  html.project2-mobile-studio .project2-mobile-tab {
    min-width: 0;
    min-height: 46px;
    display: grid;
    grid-template-columns: 20px minmax(0, auto);
    place-content: center;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 13px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 900;
  }

  html.project2-mobile-studio .project2-mobile-tab svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.9;
  }

  html.project2-mobile-studio .project2-mobile-tab[aria-selected="true"] {
    border-color: rgba(46, 230, 255, 0.42);
    background: linear-gradient(135deg, rgba(46, 230, 255, 0.18), rgba(60, 140, 255, 0.16));
    color: #c8f7ff;
    box-shadow: inset 0 0 16px rgba(46, 230, 255, 0.08);
  }

  html.project2-mobile-studio .modal-backdrop {
    align-items: end;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom, 0px));
  }

  html.project2-mobile-studio .settings-modal,
  html.project2-mobile-studio .export-modal,
  html.project2-mobile-studio .license-settings-modal,
  html.project2-mobile-studio .custom-editor-modal,
  html.project2-mobile-studio .symbol-picker-modal,
  html.project2-mobile-studio .image-preprocess-modal {
    width: 100%;
    max-width: none;
    max-height: min(92dvh, var(--project2-mobile-vh, 92dvh));
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 20px 20px 14px 14px;
    padding: 14px;
    -webkit-overflow-scrolling: touch;
  }

  html.project2-mobile-studio .settings-grid,
  html.project2-mobile-studio .license-settings-grid,
  html.project2-mobile-studio .custom-editor-composer-body,
  html.project2-mobile-studio .image-preprocess-layout,
  html.project2-mobile-studio .image-preprocess-process-layout {
    grid-template-columns: 1fr;
  }

  html.project2-mobile-studio .modal-header {
    position: sticky;
    top: -14px;
    z-index: 4;
    margin: -14px -14px 10px;
    padding: 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(27, 33, 47, 0.98);
  }

  html.project2-mobile-studio .modal-actions {
    position: sticky;
    bottom: -14px;
    z-index: 4;
    margin: 14px -14px -14px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: rgba(20, 25, 37, 0.98);
  }

  html.project2-mobile-studio .modal-actions .btn {
    flex: 1 1 120px;
    min-height: 46px;
  }

  html.project2-mobile-studio .custom-editor-canvas,
  html.project2-mobile-studio .image-preprocess-canvas {
    min-height: 300px;
  }

  html.project2-mobile-studio .toast {
    left: 12px;
    right: 12px;
    bottom: calc(var(--project2-mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
    width: auto;
    transform: translateY(20px);
  }

  html.project2-mobile-studio .toast.show {
    transform: translateY(0);
  }
}

@media (max-width: 420px) {
  html.project2-mobile-studio .brand-block {
    min-width: 0;
  }

  html.project2-mobile-studio .top-actions {
    max-width: none;
  }

  html.project2-mobile-studio .project2-mobile-tab {
    grid-template-columns: 1fr;
    grid-template-rows: 20px auto;
    gap: 2px;
    font-size: 10px;
  }

  html.project2-mobile-studio .project2-mobile-tab svg {
    justify-self: center;
  }

  html.project2-mobile-studio .split-controls,
  html.project2-mobile-studio .button-grid {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-width: 920px) and (max-height: 600px) {
  html.project2-mobile-studio .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
    padding-top: 6px;
  }

  html.project2-mobile-studio .topbar {
    min-height: 48px;
    padding-block: 5px;
  }

  html.project2-mobile-studio .logo-mark {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }

  html.project2-mobile-studio .preview-toolbar {
    flex-direction: row;
    align-items: center;
  }

  html.project2-mobile-studio .preview-toolbar .toolbar-actions {
    width: auto;
  }

  html.project2-mobile-studio .viewer-footer {
    min-height: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .project2-mobile-tab,
  .project2-mobile-nav,
  .workspace > .panel,
  .workspace > .preview-panel {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

/* PHASE12B HOTFIX3 FIX1: keep mobile image previews visible and fit the Custom Editor canvas. */
@media (max-width: 760px) {
  html.project2-mobile-studio .image-preprocess-process-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
  }

  html.project2-mobile-studio .image-preprocess-preview-shell {
    grid-template-rows: auto minmax(260px, 42dvh);
    min-height: calc(260px + 46px);
    align-self: auto;
  }

  html.project2-mobile-studio .image-preprocess-process-panel .image-preprocess-stage {
    width: 100%;
    height: clamp(260px, 42dvh, 360px);
    min-height: 260px;
    max-height: 360px;
  }

  html.project2-mobile-studio .image-preprocess-process-controls {
    width: 100%;
    min-width: 0;
  }

  html.project2-mobile-studio .custom-editor-canvas-panel {
    min-width: 0;
    overflow: hidden;
  }

  html.project2-mobile-studio .custom-editor-canvas {
    width: 100%;
    min-width: 0;
    overflow: hidden;
    place-items: start center;
  }
}
