/* Final project and profile contract. This layer deliberately wins over the
   incremental mobile patches loaded before it. */
:root { --v-blue: #065dfd; --v-ink: #151518; }

@media (min-width: 761px) {
  .project-viewer-header .project-viewer-close { display: none !important; }
  .project-viewer-stage { width: fit-content !important; height: fit-content !important; }
  .project-viewer-image-close { position: absolute; z-index: 6; top: 14px; right: 14px; width: 46px; height: 46px; display: grid; place-items: center; border: 0; border-radius: 50%; background: #151518; color: #fff; }
  #projectsModal .project-date-grid.is-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 12px;
  }
  #projectsModal .project-date-grid.is-grid .result-card {
    min-width: 0;
    min-height: 0;
    padding: 11px;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto;
    overflow: hidden;
  }
  #projectsModal .project-date-grid.is-grid .project-preview,
  #projectsModal .project-date-grid.is-grid .project-preview img,
  #projectsModal .project-date-grid.is-grid .project-preview.mock-preview {
    width: 100%; height: auto; aspect-ratio: 1; min-height: 0;
    object-fit: cover; border-radius: 15px;
  }
  #projectsModal .project-date-grid.is-grid .project-card-heading {
    min-width: 0; margin-top: 9px;
  }
  #projectsModal .project-date-grid.is-grid .project-card-heading h3,
  #projectsModal .project-date-grid.is-grid .project-card-heading h3 button {
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #projectsModal .project-date-grid.is-grid .mini-copy { display: none; }
  #projectsModal .project-date-grid.is-list { grid-template-columns: 1fr !important; gap: 10px; }
  #projectsModal .project-date-grid.is-list .result-card {
    min-height: 132px; padding: 12px; display: grid;
    grid-template-columns: 170px minmax(0, 1fr); grid-template-rows: auto 1fr;
    column-gap: 14px; overflow: hidden;
  }
  #projectsModal .project-date-grid.is-list .project-preview,
  #projectsModal .project-date-grid.is-list .project-preview img,
  #projectsModal .project-date-grid.is-list .project-preview.mock-preview {
    grid-row: 1 / 3; width: 170px; height: 108px; aspect-ratio: auto; object-fit: cover;
  }
}

@media (max-width: 760px) {
  /* Legacy liquid controls are still hydrated on mobile. Keep dark primary
     actions legible after that desktop interaction layer runs. */
  #mobileApp .m-mode-pill.is-active.liquid-control,
  #mobileApp .m-generate-button.liquid-control,
  #mobileApp .m-dock button.is-active.liquid-control {
    color: #fff !important;
    background-color: var(--m-ink) !important;
  }
  #mobileApp .m-mode-pill.is-active.liquid-control .material-symbols-outlined,
  #mobileApp .m-mode-pill.is-active.liquid-control span,
  #mobileApp .m-generate-button.liquid-control .material-symbols-outlined,
  #mobileApp .m-generate-button.liquid-control,
  #mobileApp .m-dock button.is-active.liquid-control .material-symbols-outlined,
  #mobileApp .m-dock button.is-active.liquid-control small {
    color: #fff !important;
  }

  /* One reliable mobile project layout: the date owns its item grid. */
  #mobileProjectsPage .m-scroll-content { padding: 2px 4px 30px !important; overflow-x: visible !important; }
  #mobileProjectsList { display: block !important; min-width: 0; }
  #mobileProjectsList .m-project-group { display: block !important; margin: 0 0 18px !important; }
  #mobileProjectsList .m-project-date { margin: 0 2px 8px !important; }
  #mobileProjectsList .m-project-items { display: grid; grid-template-columns: 1fr; gap: 10px; }
  #mobileProjectsList .m-project {
    position: relative; min-width: 0; min-height: 92px; height: 92px; padding: 10px;
    display: grid !important; grid-template-columns: 70px minmax(0,1fr) 26px; gap: 10px;
    align-items: center; overflow: hidden; border-radius: 20px; text-align: left;
  }
  #mobileProjectsList .m-project-media,
  #mobileProjectsList .m-project-media > img,
  #mobileProjectsList .m-project-placeholder {
    display: grid; width: 70px; height: 70px; min-width: 0; min-height: 0;
    place-items: center; overflow: hidden; border-radius: 15px; background: #eef0f5; object-fit: cover;
  }
  #mobileProjectsList .m-project-media > img { width: 100%; height: 100%; object-fit: cover; }
  #mobileProjectsList .m-project-copy { min-width: 0; }
  #mobileProjectsList .m-project h3 { margin: 0; overflow: hidden; color: var(--m-ink); font-size: 14px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
  #mobileProjectsList .m-project p { margin: 5px 0 0; overflow: hidden; color: var(--m-muted); font-size: 11px; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
  #mobileProjectsList .m-project-status { position: static !important; color: var(--v-blue); font-size: 20px; }
  #mobileProjectsList .m-project-status.is-loading { width: 20px; height: 20px; border: 2px solid rgba(6,93,253,.2); border-top-color: var(--v-blue); border-radius: 50%; animation: v-project-spin 900ms linear infinite; }
  #mobileProjectsList.is-grid .m-project-items { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
  #mobileProjectsList.is-grid .m-project {
    height: 142px; padding: 7px; display: grid !important; grid-template-columns: 1fr; grid-template-rows: minmax(0,1fr) 26px; gap: 6px; align-items: stretch;
  }
  #mobileProjectsList.is-grid .m-project-media,
  #mobileProjectsList.is-grid .m-project-media > img,
  #mobileProjectsList.is-grid .m-project-placeholder { width: 100%; height: auto; min-height: 0; aspect-ratio: 1; border-radius: 12px; }
  #mobileProjectsList.is-grid .m-project-copy { display: block; min-width: 0; }
  #mobileProjectsList.is-grid .m-project h3 { font-size: 10px; line-height: 1.2; text-align: center; }
  #mobileProjectsList.is-grid .m-project p { display: none; }
  #mobileProjectsList.is-grid .m-project-status { position: absolute !important; top: 11px; right: 11px; z-index: 2; }
  #mobileProjectsList.is-grid .m-project-status.is-loading { width: 18px; height: 18px; background: rgba(255,255,255,.85); }
  .m-projects-tab .project-nav-badge.is-loading { background: var(--v-blue) !important; color: #fff !important; }
  .m-projects-tab .project-nav-badge.is-loading .material-symbols-outlined { color: inherit; }
  @keyframes v-project-spin { to { transform: rotate(360deg); } }

  /* Editing is allowed to hide statistics only. The identity portion keeps its geometry. */
  #mobileProfilePage .m-page-heading { min-height: 42px; margin-bottom: 10px !important; }
  #mobileProfileEditButton { width: 40px !important; height: 40px !important; }
  #mobileProfileContent { overflow: visible !important; padding: 2px 4px 32px !important; }
  #mobileProfileContent .m-profile-hero,
  #mobileProfileContent.is-editing .m-profile-hero {
    height: auto !important; min-height: 0 !important; overflow: hidden !important;
    border-radius: 24px !important; opacity: 1 !important; filter: none !important; transform: none !important;
  }
  #mobileProfileContent .m-profile-cover,
  #mobileProfileContent.is-editing .m-profile-cover {
    position: static !important; inset: auto !important; height: 118px !important; min-height: 118px !important;
    border-radius: 0 !important; opacity: 1 !important; filter: none !important; transform: none !important;
  }
  #mobileProfileContent .m-profile-main,
  #mobileProfileContent.is-editing .m-profile-main {
    display: block !important; min-height: 130px !important; height: auto !important; padding: 0 16px 16px !important;
    background: var(--m-tile) !important; opacity: 1 !important; filter: none !important; transform: none !important;
  }
  #mobileProfileContent .m-profile-avatar,
  #mobileProfileContent.is-editing .m-profile-avatar { display: block !important; width: 78px !important; height: 78px !important; margin-top: -38px !important; }
  #mobileProfileContent .m-profile-main h2,
  #mobileProfileContent.is-editing .m-profile-main h2 { margin: 13px 0 0 !important; font-size: 22px !important; }
  #mobileProfileContent .m-profile-main p,
  #mobileProfileContent.is-editing .m-profile-main p { margin: 4px 0 0 !important; }
  #mobileProfileContent.is-editing .m-profile-stats { display: none !important; }
  #mobileProfileContent.is-editing .m-profile-data { margin-top: 22px !important; }
  #mobileProfileContent .m-mobile-achievements { min-height: 56px !important; align-items: center; }
  #mobileProfileContent .m-mobile-achievements button { flex: 0 0 48px; width: 48px !important; height: 40px !important; }

  /* Keep the project source clearly represented on mobile while editing. */
  .m-upload-tile.is-project-editing .m-upload-icon { display: none; }
  .m-upload-tile.is-project-editing .m-project-source-stack { display: flex; width: 48px; height: 48px; position: relative; }
  .m-project-source-stack img { position: absolute; width: 36px; height: 36px; border: 2px solid #fff; border-radius: 11px; object-fit: cover; box-shadow: 0 5px 12px rgba(18,19,24,.15); }
  .m-project-source-stack img:nth-child(1) { left: 0; top: 8px; }
  .m-project-source-stack img:nth-child(2) { left: 7px; top: 4px; }
  .m-project-source-stack img:nth-child(3) { left: 12px; top: 0; }
  .m-upload-tile.is-project-editing #mobileUploadAction { background: #d92d45 !important; color: #fff !important; }

  /* Image viewer: the image owns the close control and its compact action rail. */
  .project-viewer-header { inset: 0 !important; pointer-events: none; }
  .project-viewer-header .project-viewer-close { display: none !important; }
  .project-viewer-name, .project-viewer-save-title { display: none !important; }
  .project-viewer-close { position: fixed !important; z-index: 12; width: 42px !important; height: 42px !important; }
  .project-viewer-media { padding: 0 14px 106px !important; align-items: center !important; }
  .project-viewer-stage { width: fit-content !important; height: fit-content !important; }
  .project-viewer-image { width: auto !important; max-width: calc(100vw - 28px) !important; height: auto !important; max-height: calc(100dvh - 186px) !important; border-radius: 20px !important; }
  .project-viewer-actions { bottom: max(24px, env(safe-area-inset-bottom)) !important; }
  .project-viewer-dots { bottom: max(94px, calc(env(safe-area-inset-bottom) + 74px)) !important; }
  .project-viewer-image-close { position: absolute; z-index: 5; top: 12px; right: 12px; width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 50%; background: #151518; color: #fff; }
}
