/* Isolated mobile application shell. Desktop markup remains untouched. */
#mobileApp,
.m-settings-sheet { display: none; }
.mobile-brand,
.mobile-tabbar { display: none; }

@media (max-width: 760px) {
  :root {
    --m-blue: #065dfd;
    --m-ink: #121318;
    --m-muted: #72757f;
    --m-canvas: #f4f6fa;
    --m-tile: #ffffff;
    --m-line: #e6e8ee;
    --m-edge: 16px;
    --m-header: 58px;
    --m-dock: 72px;
    --m-gap: 10px;
    --m-radius: 22px;
    --m-shadow: 0 10px 26px rgba(26, 37, 57, .08);
  }

  html, body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden !important;
    background: var(--m-canvas) !important;
    overscroll-behavior: none;
  }
  body { padding: 0 !important; }
  body > .app-topbar,
  body > .product-layout,
  body > .mobile-tabbar,
  body > .header-generation-progress,
  #billingModal,
  #projectsModal,
  #profileModal {
    display: none !important;
  }
  #custom-cursor { display: none !important; }

  #mobileApp {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: block;
    overflow: hidden;
    color: var(--m-ink);
    background: var(--m-canvas);
    font-family: Manrope, sans-serif;
  }
  #mobileApp *,
  #mobileApp *::before,
  #mobileApp *::after { box-sizing: border-box; }
  #mobileApp button,
  #mobileApp input,
  #mobileApp textarea { font: inherit; }
  #mobileApp button { -webkit-tap-highlight-color: transparent; }
  #mobileApp .liquid-control,
  #mobileApp .liquid-control.is-fluid-active,
  #mobileApp .liquid-control.is-fluid-exiting,
  #mobileApp .liquid-control.is-pressing {
    --fluid-radius: 0px !important;
    background-image: none !important;
    color: inherit !important;
    transform: none !important;
  }
  #mobileApp .m-upload-tile.liquid-control,
  #mobileApp .m-upload-tile.liquid-control.is-fluid-active {
    background-color: var(--m-tile) !important;
    border-color: var(--m-line) !important;
    box-shadow: var(--m-shadow) !important;
  }
  #mobileApp .m-upload-tile.liquid-control strong { color: var(--m-ink) !important; }
  #mobileApp .m-upload-tile.liquid-control small { color: var(--m-muted) !important; }

  .m-topbar {
    position: absolute;
    z-index: 4;
    top: 0;
    right: 0;
    left: 0;
    height: calc(var(--m-header) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--m-edge) 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--m-canvas);
  }
  .m-brand { display: inline-flex; width: 108px; height: 34px; align-items: center; transform: translateX(-8px); }
  .m-brand img { width: 104px; height: auto; display: block; }
  .m-topbar-actions { display: flex; align-items: center; gap: 8px; }
  .m-credit-button,
  .m-account-button,
  .m-icon-button {
    border: 1px solid rgba(18,19,24,.06);
    background: rgba(255,255,255,.9);
    color: var(--m-ink);
    box-shadow: 0 6px 16px rgba(28,40,62,.08);
    transition: background 180ms ease, color 180ms ease, transform 180ms ease;
  }
  .m-credit-button {
    min-width: 56px;
    height: 40px;
    padding: 0 12px;
    border-radius: 20px;
    display: inline-flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
  }
  .m-credit-button .material-symbols-outlined { font-size: 19px; }
  .m-credit-button strong { font-size: 13px; }
  .m-credit-free { display: none; color: var(--m-blue); font: 800 8px/1 "IBM Plex Mono", monospace; }
  .m-credit-button.is-free { gap: 4px; }
  .m-credit-button.is-free .m-credit-free { display: inline; }
  .m-account-button,
  .m-icon-button {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
  }
  .m-account-button .material-symbols-outlined,
  .m-icon-button .material-symbols-outlined { font-size: 21px; }

  .m-stage {
    position: absolute;
    inset: calc(var(--m-header) + env(safe-area-inset-top)) 0 calc(var(--m-dock) + env(safe-area-inset-bottom) + 12px);
    overflow: hidden;
  }
  .m-page {
    position: absolute;
    inset: 0;
    padding: 7px var(--m-edge) 0;
    display: none;
    min-height: 0;
    animation: m-page-in 260ms cubic-bezier(.2,.9,.25,1) both;
  }
  .m-page.is-active { display: flex; flex-direction: column; }
  .m-page[data-mobile-view="create"] { overflow-y: auto; scrollbar-width: none; }
  .m-page[data-mobile-view="create"] { overscroll-behavior-y: contain; }
  .m-page::-webkit-scrollbar,
  .m-scroll-content::-webkit-scrollbar { display: none; }
  .m-page-heading {
    min-height: 42px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }
  .m-page-heading-row { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .m-eyebrow {
    display: block;
    color: var(--m-muted);
    font-family: "IBM Plex Mono", monospace;
    font-size: 9px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .m-page h1,
  .m-settings-sheet h2 {
    margin: 3px 0 0;
    color: var(--m-ink);
    font-size: 23px;
    font-weight: 500;
    line-height: 1;
    letter-spacing: 0;
  }

  .m-upload-tile,
  .m-field-tile,
  .m-setting-tile,
  .m-balance-tile,
  .m-plan,
  .m-empty-state,
  .m-project,
  .m-profile-hero,
  .m-profile-data,
  .m-profile-action,
  .m-ledger-row {
    border: 1px solid var(--m-line);
    background: var(--m-tile);
    box-shadow: var(--m-shadow);
  }
  .m-upload-tile {
    width: 100%;
    min-height: 106px;
    margin: 0 0 var(--m-gap);
    padding: 16px;
    display: grid;
    grid-template-columns: 48px minmax(0,1fr) 40px;
    gap: 12px;
    align-items: center;
    border-radius: var(--m-radius);
    text-align: left;
    color: var(--m-ink);
  }
  .m-upload-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    background: rgba(6,93,253,.1);
    color: var(--m-blue);
    font-size: 23px;
  }
  .m-upload-tile strong { display: block; font-size: 14px; font-weight: 700; }
  .m-upload-tile small { display: block; margin-top: 3px; color: var(--m-muted); font-size: 11px; }
  .m-tile-arrow {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #f1f2f5;
    font-size: 20px;
  }
  .m-upload-tile.has-files #mobileUploadAction { background: var(--m-ink); color: #fff; }

  .m-field-tile {
    position: relative;
    width: 100%;
    min-height: 62px;
    margin-bottom: var(--m-gap);
    padding: 10px 14px 9px;
    display: block;
    border-radius: 18px;
  }
  .m-field-tile > span { display: block; color: var(--m-muted); font-size: 10px; font-weight: 700; }
  .m-field-tile input,
  .m-field-tile textarea {
    width: 100%;
    margin-top: 4px;
    min-width: 0;
    padding: 0 34px 0 2px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--m-ink);
    font-size: 14px;
    line-height: 1.35;
    resize: none;
    text-indent: 0;
    overflow-x: hidden;
    -webkit-appearance: none;
    -webkit-text-fill-color: var(--m-ink);
    clip-path: none !important;
    transform: none !important;
  }
  .m-field-tile input::placeholder,
  .m-field-tile textarea::placeholder { color: #a2a5ad; }
  .m-description-tile { min-height: 102px; }
  .m-description-tile textarea { min-height: 63px; }
  .m-field-tile small {
    position: absolute;
    right: 12px;
    bottom: 10px;
    color: #a2a5ad;
    font-family: "IBM Plex Mono", monospace;
    font-size: 8px;
  }

  .m-settings-grid {
    width: 100%;
    margin-bottom: var(--m-gap);
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 8px;
  }
  .m-setting-tile {
    position: relative;
    min-width: 0;
    height: 76px;
    padding: 9px 7px 8px;
    border-radius: 18px;
    color: var(--m-ink);
    text-align: left;
  }
  .m-setting-tile small { display: block; color: var(--m-muted); font-size: 8px; font-weight: 700; }
  .m-setting-tile > .material-symbols-outlined { display: block; margin-top: 7px; font-size: 22px; }
  .m-setting-tile strong {
    position: absolute;
    right: 8px;
    bottom: 9px;
    left: 8px;
    overflow: hidden;
    color: var(--m-ink);
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .m-generate-row { display: grid; grid-template-columns: 82px minmax(0,1fr); gap: 8px; margin-bottom: 12px; }
  .m-cost {
    min-height: 48px;
    display: inline-flex;
    gap: 3px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--m-line);
    border-radius: 16px;
    background: var(--m-tile);
    color: var(--m-blue);
    box-shadow: var(--m-shadow);
    font-size: 13px;
    font-weight: 800;
  }
  .m-cost .material-symbols-outlined { font-size: 18px; }
  .m-generate-button {
    min-height: 48px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 16px;
    background: var(--m-ink);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    box-shadow: 0 12px 24px rgba(18,19,24,.16);
  }
  .m-generate-button .material-symbols-outlined { font-size: 21px; }

  .m-template-section {
    width: 100%;
    min-height: 98px;
    margin: 2px 0 22px;
    padding: 0 0 10px;
    overflow: visible;
  }
  .m-template-label {
    min-height: 26px;
    margin: 0 0 5px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--m-blue);
    font-family: "IBM Plex Mono", monospace;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .m-template-label .material-symbols-outlined { font-size: 20px; }
  .m-template-mask {
    width: calc(100% + var(--m-edge));
    margin-right: calc(-1 * var(--m-edge));
    overflow: hidden;
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 42px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 42px), transparent 100%);
  }
  .m-template-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 10px 44px 14px 0;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .m-template-list::-webkit-scrollbar { display: none; }
  .m-template-card {
    min-width: 132px;
    height: 58px;
    padding: 6px;
    display: grid;
    grid-template-columns: 42px minmax(0,1fr);
    gap: 8px;
    align-items: center;
    border: 1px solid var(--m-line);
    border-radius: 18px;
    background: rgba(255,255,255,.88);
    color: var(--m-ink);
    box-shadow: 0 10px 22px rgba(32,42,60,.1);
    scroll-snap-align: start;
    text-align: left;
  }
  .m-template-card img { width: 42px; height: 42px; border-radius: 13px; object-fit: cover; }
  .m-template-card strong { display: block; overflow: hidden; font-size: 10px; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
  .m-template-card.is-active { border-color: var(--m-blue); background: rgba(6,93,253,.1); }

  .m-scroll-content { flex: 1; min-height: 0; overflow-y: auto; padding: 0 1px 18px; scrollbar-width: none; }
  .m-scroll-content > * + * { margin-top: 10px; }
  .m-empty-state { min-height: 180px; padding: 22px; border-radius: 22px; }
  .m-empty-state h2 { margin: 0; font-size: 22px; font-weight: 600; }
  .m-empty-state p { margin: 10px 0 0; color: var(--m-muted); font-size: 14px; line-height: 1.45; }
  .m-project-group + .m-project-group { margin-top: 16px; }
  .m-project-date { margin: 0 0 7px 2px; color: var(--m-muted); font-family: "IBM Plex Mono", monospace; font-size: 9px; text-transform: uppercase; }
  .m-project { min-height: 88px; padding: 9px; display: grid; grid-template-columns: 70px minmax(0,1fr) 30px; gap: 10px; align-items: center; border-radius: 20px; }
  .m-project img,
  .m-project-placeholder { width: 70px; height: 70px; border-radius: 15px; object-fit: cover; background: #eef0f5; }
  .m-project h3 { margin: 0; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
  .m-project p { margin: 4px 0 0; color: var(--m-muted); font-size: 11px; line-height: 1.3; }
  .m-project p.m-project-error { color: #b4233d; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .m-project-status { color: var(--m-blue); font-size: 20px; }

  .m-balance-tile { min-height: 132px; padding: 18px; border-radius: 24px; color: #fff; background: var(--m-blue); border-color: var(--m-blue); box-shadow: 0 16px 34px rgba(6,93,253,.22); }
  .m-balance-tile > span { display: block; font-size: 12px; font-weight: 700; opacity: .82; }
  .m-balance-tile strong { display: inline-block; margin-top: 5px; font-size: 42px; line-height: 1; font-weight: 500; }
  .m-balance-tile small { margin-left: 5px; font-size: 12px; opacity: .86; }
  .m-balance-tile button { float: right; margin-top: 33px; padding: 10px 13px; border: 0; border-radius: 14px; background: #fff; color: var(--m-ink); font-size: 12px; font-weight: 800; }
  .m-section-title { margin: 18px 2px 8px; color: var(--m-ink); font-size: 15px; font-weight: 800; }
  .m-plan-list { display: grid; gap: 9px; }
  .m-plan { padding: 16px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; border-radius: 22px; }
  .m-plan .m-eyebrow { margin-bottom: 8px; }
  .m-plan h3 { margin: 0; font-size: 18px; }
  .m-plan p { margin: 6px 0 0; color: var(--m-muted); font-size: 12px; line-height: 1.35; }
  .m-plan strong { align-self: center; font-size: 19px; font-weight: 500; white-space: nowrap; }
  .m-plan button { grid-column: 1 / -1; min-height: 42px; border: 0; border-radius: 14px; background: var(--m-ink); color: #fff; font-weight: 800; }
  .m-ledger-list { display: grid; gap: 7px; }
  .m-ledger-row { min-height: 58px; padding: 11px 14px; display: flex; align-items: center; justify-content: space-between; border-radius: 16px; }
  .m-ledger-row span { font-size: 12px; font-weight: 700; }
  .m-ledger-row small { display: block; margin-top: 2px; color: var(--m-muted); font-size: 10px; }
  .m-ledger-row strong { color: var(--m-blue); }

  .m-profile-hero { overflow: hidden; border-radius: 24px; }
  .m-profile-cover { height: 118px; background: center / cover no-repeat; }
  .m-profile-main { min-height: 130px; padding: 0 16px 16px; position: relative; }
  .m-profile-avatar { width: 78px; height: 78px; margin-top: -38px; border: 4px solid #fff; border-radius: 50%; object-fit: cover; background: #fff; }
  .m-profile-main h2 { margin: 8px 0 0; font-size: 22px; line-height: 1.1; }
  .m-profile-main p { margin: 4px 0 0; color: var(--m-muted); font-size: 11px; }
  .m-profile-stats { margin-top: 14px; display: grid; grid-template-columns: .56fr .56fr 1.88fr; border-top: 1px solid var(--m-line); }
  .m-profile-stats span { padding-top: 10px; text-align: center; border-right: 1px solid var(--m-line); }
  .m-profile-stats > :last-child { border-right: 0; }
  .m-profile-stats strong { display: block; font-size: 16px; }
  .m-profile-stats small { color: var(--m-muted); font-size: 9px; }
  .m-profile-email-stat { min-width: 0; padding: 10px 8px 0; border: 0; background: transparent; color: var(--m-ink); text-align: center; }
  .m-profile-email-stat strong { overflow: hidden; font-size: clamp(9px, 2.8vw, 15px); font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
  .m-profile-data { padding: 14px; border-radius: 20px; }
  .m-mobile-achievements { min-height: 44px; padding: 8px 11px; display: flex; gap: 8px; overflow-x: auto; border: 1px solid var(--m-line); border-radius: 17px; background: var(--m-tile); box-shadow: var(--m-shadow); scrollbar-width: none; }
  .m-mobile-achievements::-webkit-scrollbar { display: none; }
  .m-mobile-achievements button { width: 40px; min-width: 40px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 11px; color: #b7bac1; background: #f2f3f6; transition: transform 180ms cubic-bezier(.2,1.1,.25,1), color 180ms ease, background 180ms ease; }
  .m-mobile-achievements button.is-unlocked { color: var(--m-blue); background: rgba(6,93,253,.1); }
  .m-mobile-achievements button:active { transform: scale(.92); }
  .m-mobile-achievements i { font-size: 18px; }
  .m-profile-data label { display: block; color: var(--m-muted); font-size: 10px; font-weight: 700; }
  .m-profile-data input { width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--m-line); border-radius: 13px; outline: none; font-size: 14px; }
  .m-avatar-choice-row, .m-cover-choice-row { margin-top: 11px; display: flex; gap: 8px; overflow-x: auto; padding: 5px 8px 9px; scroll-snap-type: x proximity; scroll-behavior: smooth; overscroll-behavior-x: contain; scrollbar-width: none; }
  .m-avatar-choice-row::-webkit-scrollbar, .m-cover-choice-row::-webkit-scrollbar { display: none; }
  .m-avatar-choice { width: 46px; height: 46px; min-width: 46px; padding: 2px; border: 2px solid transparent; border-radius: 50%; background: #fff; scroll-snap-align: center; transition: border-color 180ms ease, transform 180ms cubic-bezier(.2,1.15,.25,1), box-shadow 180ms ease; }
  .m-avatar-choice img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
  .m-cover-choice { width: 82px; height: 46px; min-width: 82px; border: 2px solid transparent; border-radius: 13px; background: center / cover no-repeat; scroll-snap-align: center; transition: border-color 180ms ease, transform 180ms cubic-bezier(.2,1.15,.25,1), box-shadow 180ms ease; }
  .m-avatar-choice.is-selected, .m-cover-choice.is-selected { border-color: var(--m-blue); box-shadow: 0 0 0 4px rgba(6,93,253,.12); }
  .m-avatar-choice:active, .m-cover-choice:active { transform: scale(.94); }
  .m-profile-save { width: 100%; min-height: 44px; margin-top: 13px; border: 0; border-radius: 14px; background: var(--m-ink); color: #fff; font-weight: 800; }
  .m-profile-action { width: 100%; min-height: 56px; padding: 0 15px; display: grid; grid-template-columns: 22px minmax(0,1fr) 22px; gap: 8px; align-items: center; border-radius: 18px; color: var(--m-ink); text-align: left; font-size: 13px; font-weight: 800; }
  .m-profile-action.danger { color: #c5273c; }
  .m-profile-action.m-profile-admin { color: var(--m-blue); }
  .m-profile-action.m-profile-admin .material-symbols-outlined:first-child { font-variation-settings: 'FILL' 1,'wght' 500,'GRAD' 0,'opsz' 24; }

  .m-dock {
    position: absolute;
    z-index: 5;
    right: var(--m-edge);
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: var(--m-edge);
    height: var(--m-dock);
    padding: 5px;
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 4px;
    border: 1px solid rgba(18,19,24,.05);
    border-radius: 24px;
    background: rgba(255,255,255,.94);
    box-shadow: 0 15px 35px rgba(26,37,57,.14);
    backdrop-filter: blur(18px);
  }
  .m-dock button {
    min-width: 0;
    border: 0;
    border-radius: 18px;
    background: transparent;
    color: var(--m-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
  }
  .m-dock .material-symbols-outlined { font-size: 21px; }
  .m-dock small { font-size: 8px; line-height: 1; }
  .m-dock button.is-active { color: #fff; background: var(--m-ink); }

  .m-settings-sheet[open] { position: fixed; z-index: 300; inset: 0; display: block; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; }
  .m-settings-sheet::backdrop { background: rgba(18,19,24,.28); backdrop-filter: blur(7px); }
  .m-settings-sheet-card { position: absolute; right: 0; bottom: 0; left: 0; max-height: min(68dvh,560px); padding: 10px var(--m-edge) calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; border-radius: 28px 28px 0 0; background: #fff; box-shadow: 0 -16px 50px rgba(18,19,24,.18); animation: m-sheet-in 260ms cubic-bezier(.2,.9,.25,1) both; will-change: transform, opacity; }
  .m-sheet-grabber { width: 38px; height: 4px; margin: 0 auto 14px; border-radius: 99px; background: #d8dbe2; }
  .m-sheet-grabber,
  .m-settings-sheet header { touch-action: none; }
  .m-settings-sheet header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
  .m-settings-sheet h2 { margin: 0; font-size: 21px; line-height: 1.1; }
  #mobileSettingsClose { background: var(--m-ink); color: #fff; box-shadow: none; }
  .m-settings-options { display: grid; gap: 7px; }
  .m-setting-option { min-height: 58px; padding: 10px 13px; display: grid; grid-template-columns: 28px minmax(0,1fr) auto; gap: 10px; align-items: center; border: 1px solid transparent; border-radius: 17px; background: #f4f5f8; color: var(--m-ink); text-align: left; }
  .m-setting-option .material-symbols-outlined { color: var(--m-ink); font-size: 22px; }
  .m-setting-option strong { display: block; font-size: 14px; }
  .m-setting-option small { display: block; margin-top: 2px; color: var(--m-muted); font-size: 11px; }
  .m-setting-option.is-selected { border-color: var(--m-blue); background: rgba(6,93,253,.09); color: var(--m-blue); }
  .m-setting-option.is-selected .material-symbols-outlined { color: var(--m-blue); }
  .m-setting-option.is-selected::after { content: "check"; font-family: "Material Symbols Outlined"; color: var(--m-blue); font-size: 20px; }

  #authModal[open] { position: fixed; z-index: 310; inset: 0; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; }
  #authModal::backdrop { background: rgba(18,19,24,.28); backdrop-filter: blur(8px); }
  #authModal .modal-card { position: absolute; right: 10px; bottom: 10px; left: 10px; width: auto; max-width: none; max-height: min(78dvh,590px); margin: 0; padding: 24px 18px 18px; border-radius: 26px; background: #fff; box-shadow: 0 20px 60px rgba(18,19,24,.22); }
  #authModal .modal-close { width: 40px; height: 40px; top: 14px; right: 14px; }
  #authModal .modal-heading h2 { font-size: 26px; }
  #authModal .auth-view input { min-height: 50px; }

  #deleteProjectModal[open],
  #deleteAccountModal[open],
  #emailChangeModal[open],
  #passwordChangeModal[open] {
    position: fixed;
    z-index: 320;
    inset: 0;
    display: block;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }
  #deleteProjectModal::backdrop,
  #deleteAccountModal::backdrop,
  #emailChangeModal::backdrop,
  #passwordChangeModal::backdrop { background: rgba(18,19,24,.28); backdrop-filter: blur(8px); }
  #deleteProjectModal .modal-card,
  #deleteAccountModal .modal-card,
  #emailChangeModal .modal-card,
  #passwordChangeModal .modal-card {
    position: absolute;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 10px;
    width: auto;
    max-width: none;
    max-height: min(76dvh,560px);
    margin: 0;
    overflow-y: auto;
    border-radius: 26px;
  }

  .m-topbar button:active,
  .m-upload-tile:active,
  .m-setting-tile:active,
  .m-template-card:active,
  .m-dock button:active,
  .m-generate-button:active,
  .m-plan button:active,
  .m-profile-action:active { transform: scale(.97); }
  .m-profile-action.m-profile-admin:active { background: var(--m-blue); color: #fff; }
  @media (hover: hover) {
    .m-credit-button:hover,
    .m-account-button:hover,
    .m-icon-button:hover { background: var(--m-blue); color: #fff; }
    .m-setting-tile:hover,
    .m-template-card:hover { border-color: rgba(6,93,253,.35); background: rgba(6,93,253,.06); }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  }
}

@media (max-width: 380px) {
  :root { --m-edge: 12px; --m-gap: 8px; }
  .m-upload-tile { min-height: 92px; padding: 12px; }
  .m-description-tile { min-height: 92px; }
  .m-setting-tile { height: 70px; }
  .m-template-section { min-height: 62px; }
}

@keyframes m-page-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes m-sheet-in { from { transform: translateY(32px); opacity: .4; } to { transform: translateY(0); opacity: 1; } }

/* Mobile product shell: fixed controls, a free central canvas, and touch-first feedback. */
@media (max-width: 760px) {
  #mobileApp { isolation: isolate; }
  .m-topbar { padding-inline: var(--m-edge); }
  .m-brand { margin-right: auto; }
  .m-mode-rail {
    display: flex;
    gap: 8px;
    margin: 0 0 var(--m-gap);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .m-mode-rail::-webkit-scrollbar { display: none; }
  .m-mode-pill {
    min-height: 40px;
    padding: 0 12px;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--m-line);
    border-radius: 14px;
    background: rgba(255,255,255,.82);
    color: var(--m-muted);
    font-size: 11px;
    font-weight: 800;
    transition: transform 180ms cubic-bezier(.2,.85,.24,1), background 180ms ease, color 180ms ease;
  }
  .m-mode-pill .material-symbols-outlined { font-size: 18px; }
  .m-mode-pill small { padding: 2px 4px; border-radius: 6px; background: rgba(6,93,253,.12); color: var(--m-blue); font-size: 7px; }
  .m-mode-pill.is-active { background: var(--m-ink); color: #fff; border-color: var(--m-ink); }
  .m-mode-pill:active { transform: scale(.96); }

  .m-template-section { min-height: 126px; margin: 5px 0 30px; padding-bottom: 22px; overflow: visible; }
  .m-template-label { margin-left: 0; padding-left: 0; }
  .m-template-mask {
    width: 100vw;
    margin-left: calc(-1 * var(--m-edge));
    margin-right: 0;
    overflow: visible;
    -webkit-mask-image: none;
    mask-image: none;
    position: relative;
  }
  .m-template-mask::after {
    content: "";
    position: absolute;
    z-index: 3;
    top: -16px;
    right: 0;
    bottom: -16px;
    width: 52px;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(241,244,250,0), var(--m-bg) 94%);
  }
  .m-template-list {
    gap: 12px;
    padding: 14px calc(var(--m-edge) + 46px) 26px var(--m-edge);
    scroll-behavior: smooth;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    /* The first snap point remains at the grid edge instead of snapping its
       card flush to the viewport's left edge on initial paint. */
    scroll-padding-left: var(--m-edge);
    scroll-padding-right: calc(var(--m-edge) + 46px);
  }
  .m-template-card { scroll-snap-align: start; box-shadow: 0 14px 30px rgba(32,42,60,.14); transition: transform 200ms cubic-bezier(.22,.9,.25,1), box-shadow 200ms ease, background 180ms ease; }
  .m-template-card:active { transform: scale(.97) translateY(1px); box-shadow: 0 7px 16px rgba(32,42,60,.12); }
  .m-template-list:active { scroll-snap-type: x proximity; }

  .m-field-tile { overflow: visible; }
  .m-field-tile input,
  .m-field-tile textarea { padding-left: 0; clip-path: none; }
  .m-field-tile:focus-within { border-color: rgba(6,93,253,.44); box-shadow: 0 12px 26px rgba(6,93,253,.12); }
  .m-setting-tile, .m-upload-tile, .m-field-tile, .m-generate-button, .m-cost, .m-plan, .m-project, .m-profile-action, .m-icon-button { transition: transform 190ms cubic-bezier(.2,.88,.25,1), background 190ms ease, border-color 190ms ease, box-shadow 190ms ease; }
  .m-setting-tile:active, .m-upload-tile:active, .m-field-tile:active, .m-plan:active, .m-project:active { transform: scale(.985); }
  .m-upload-tile.has-files #mobileUploadAction { background: #151518; color: #fff; }
  .m-upload-tile.has-files #mobileUploadAction .material-symbols-outlined { color: inherit; }

  .m-project-toolbar { display: flex; align-items: center; gap: 6px; }
  .m-project-toolbar .m-icon-button { width: 34px; height: 34px; }
  .m-project-toolbar .m-icon-button.is-active { background: var(--m-blue); color: #fff; }
  .m-scroll-content { padding: 1px 2px 26px; overflow-x: visible; }
  .m-scroll-content::before, .m-scroll-content::after { content: ""; position: sticky; display: block; height: 8px; pointer-events: none; }
  .m-scroll-content.is-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; align-content: start; }
  .m-scroll-content.is-grid .m-project-group { display: contents; }
  .m-scroll-content.is-grid .m-project-date { grid-column: 1 / -1; margin-top: 10px; }
  .m-scroll-content.is-grid .m-project { min-height: 0; padding: 6px; display: block; border-radius: 16px; }
  .m-scroll-content.is-grid .m-project img,
  .m-scroll-content.is-grid .m-project-placeholder { width: 100%; height: auto; aspect-ratio: 1; border-radius: 11px; display: block; }
  .m-scroll-content.is-grid .m-project h3 { margin-top: 6px; font-size: 10px; }
  .m-scroll-content.is-grid .m-project p, .m-scroll-content.is-grid .m-project-status { display: none; }

  .m-projects-tab { position: relative; }
  .project-nav-badge {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: var(--m-blue);
    color: #fff;
    font-family: "IBM Plex Mono", monospace;
    font-size: 8px;
    font-weight: 700;
    line-height: 1;
    transform: translateZ(0);
    transition: background 180ms ease, transform 180ms cubic-bezier(.2,1.1,.25,1);
  }
  .m-projects-tab .project-nav-badge { position: absolute; top: 5px; right: calc(50% - 18px); }
  .project-nav-badge.is-loading { background: #151518; animation: project-badge-breathe 1s ease-in-out infinite; }
  .project-nav-badge.is-loading .material-symbols-outlined { font-size: 11px; animation: project-badge-spin 1s linear infinite; }
  .project-nav-badge.is-ready { background: var(--m-blue); animation: project-badge-pop 360ms cubic-bezier(.2,1.45,.3,1) both; }
  .project-nav-badge.is-ready .material-symbols-outlined { font-size: 12px; }

  .m-profile-hero { overflow: visible; }
  .m-profile-data { position: relative; }
  .m-profile-data::before { content: ""; position: absolute; inset: -8px; z-index: -1; border-radius: 25px; background: rgba(6,93,253,.08); opacity: 0; transition: opacity 200ms ease; }
  .m-page:has(.m-profile-data) .m-mobile-achievements,
  .m-page:has(.m-profile-data) .m-profile-action { transition: opacity 220ms ease, filter 220ms ease; }
  .m-page:has(.m-profile-data) .m-mobile-achievements { opacity: .56; filter: saturate(.72); }
  .m-page:has(.m-profile-data) .m-profile-data::before { opacity: 1; }
  .m-profile-utility { display: grid; grid-template-columns: 48px minmax(0,1fr); gap: 9px; }
  .m-profile-utility button { min-height: 50px; border: 1px solid var(--m-line); border-radius: 17px; background: var(--m-tile); color: var(--m-ink); box-shadow: var(--m-shadow); font-weight: 800; }
  .m-profile-utility button:first-child { display: grid; place-items: center; }
  .m-profile-utility .material-symbols-outlined { font-size: 21px; }
  body.authed .m-account-button { background: var(--m-ink); color: #fff; }
  #mobileProfileEditButton[hidden] { display: none; }

  #mobileSettingsClose { background: var(--m-ink); color: #fff; }
  .m-settings-sheet-card { touch-action: pan-y; overscroll-behavior: contain; }
  .m-settings-options { padding-bottom: 10px; }
  .m-setting-option:active { transform: scale(.985); background: rgba(6,93,253,.11); }

  #authModal[open] { display: grid; place-items: center; padding: 18px; }
  #authModal .modal-card { position: relative; inset: auto; width: min(100%, 410px); max-height: min(76dvh, 590px); }
  #authModal .auth-brand-mark { position: absolute; left: 50%; top: -54px; width: 122px; transform: translateX(-50%); }
  #authModal .modal-heading { padding-top: 5px; }

  .project-flight { position: fixed; z-index: 1000; width: 28px; height: 28px; border-radius: 10px; background: var(--m-blue); box-shadow: 0 0 0 7px rgba(6,93,253,.12); pointer-events: none; animation: project-flight 670ms cubic-bezier(.22,.9,.25,1) both; }
}

@keyframes project-badge-spin { to { transform: rotate(1turn); } }
@keyframes project-badge-breathe { 50% { transform: scale(.88); } }
@keyframes project-badge-pop { 0% { transform: scale(.1); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes project-flight { 0% { transform: translate(0,0) scale(.6); opacity: 0; } 20% { opacity: 1; } 55% { transform: translate(calc(var(--flight-x) * .55), calc(var(--flight-y) * .28 - 28px)) scale(1); } 100% { transform: translate(var(--flight-x), var(--flight-y)) scale(.18); opacity: 0; } }
