/* Phones. Same look as the desktop editor, laid out for a narrow screen:
   the video on top, the chat's box (suggestions, write a change, Run AI) right under it, nothing else.
   Two round buttons at the right of the video: Chat (the whole chat, as a sheet) and Edit (play bar extras + timeline).
   Desktop is untouched: every rule sits in the media query, the .m-only pieces are hidden elsewhere.
   Look rules: STYLE.md (flat, no borders, no shadows, no gradients). Loaded last on purpose. */
.m-only { display: none; }
@media (min-width: 821px) { #mProjects, .m-only { display: none !important; } }   /* the hamburger and the other phone pieces never show on desktop */

@media (max-width: 820px) {
  :root { --accent: #cfcfcf; }
  #play, #aiAdd, #aiRun { background: #cfcfcf !important; border-color: #cfcfcf !important; color: #0a0a0a !important; }
  #aiRun.idle { background: transparent !important; }
  :root { --m-tl-h: min(40dvh, 290px); --m-bg: #000000; }   /* the desktop's background: top bar, chat box area */
  html, body { height: 100dvh; }
  body { -webkit-text-size-adjust: 100%; overscroll-behavior: none; background: var(--m-bg); }
  .layout { background: var(--m-bg); }
  .m-only { display: inline-flex; }
  button, select, [role="button"] { touch-action: manipulation; }
  textarea, input[type="text"], input[type="search"], input[type="number"], select { font-size: 16px !important; }   /* no zoom-in on focus (iOS) */

  /* ---- top bar: no bar. Small round buttons float over the video (logo = projects at the left;
     undo, redo, export and ... at the right), so the video gets the whole height. */
  .topbar { position: relative; flex: 0 0 auto; z-index: 30; padding: 4px 10px 4px; padding-top: calc(env(safe-area-inset-top, 0px) + 12px); gap: 6px; min-height: 0; background: var(--m-bg) !important; border-bottom: 0 !important; }   /* its own row ABOVE the video: nothing sits on the picture */
  .topbar > * { pointer-events: auto; }
  .topbar .spacer { pointer-events: none; }
  .brand-d { display: none !important; }
  .topbar .brand, .topbar button#render, .topbar .app-version, .topbar .ai-mode, .topbar #trainSave { display: none !important; }
  .topbar #mProjects, .topbar .m-ic, .topbar #moreBtn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: rgba(255,255,255,0.08); color: #f2f2f2; }
  .topbar #mProjects svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
  .topbar .m-ic svg, .topbar #moreBtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .topbar #moreBtn svg { fill: currentColor; stroke: none; }
  .topbar #mExport { width: auto; padding: 0 13px 0 11px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
  .topbar #mExport svg { width: 16px; height: 16px; }
  .topbar .m-ic:disabled { opacity: 0.35; }
  .topbar .m-ic:active, .topbar #moreBtn:active { background: rgba(255,255,255,0.16); }
  .more .dd-menu { min-width: 220px; }
  .topbar .menu-item { padding: 12px 12px; font-size: 14px; }
  /* no project open (the new project page): a normal bar again, with the name */
  body.no-project .topbar { padding: 6px 8px; position: absolute; top: 0; left: 0; right: 0; background: transparent !important; pointer-events: auto; min-height: 48px; outline: 0; }   /* no bar: the light runs to the top, as on desktop */
  body.no-project .topbar .brand { display: flex !important; position: static; transform: none; font-size: 14px; }
  body.no-project .topbar .m-ic { display: none !important; }
  body.no-project .topbar #mProjects, body.no-project .topbar #moreBtn { background: transparent; }

  /* ---- one column: the video, the timeline row (closed until Edit), the chat box */
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) var(--m-tl-h) auto; }
  body.tl-closed .layout { grid-template-rows: minmax(0, 1fr) 0px auto; }
  .splitter { display: none !important; }
  .stage, body.no-project .stage { grid-column: 1; grid-row: 1; padding: 6px 8px; }
  body:not(.no-project) .stage { padding-top: 4px; }   /* the top of the video always stays on screen */
  body:not(.no-project) .stage, body.tl-closed:not(.no-project) .stage { padding-bottom: 6px; }
  .timeline-wrap { grid-column: 1; grid-row: 2; height: var(--m-tl-h); border-top: 0; padding-bottom: 6px; }
  body.no-project .stage { grid-row: 1 / 3; }
  body.tl-closed .timeline-wrap { height: 0; visibility: hidden; padding: 0; }   /* closed: it must not hang over the chat box */
  body:not(.no-project) .stage { background: #050505; }   /* behind the video, as on desktop */
  .tl-toggle, body.tl-closed .tl-toggle { display: none !important; }   /* the Edit button opens the timeline */

  /* ---- the video and its play bar: play + time; Preview edit and Add only while editing */
  .player { gap: 6px; width: 100%; position: relative; --m-rw: min(100%, max(var(--m-fw, 100%), 320px)); }   /* the row is the video's width, but never narrower than its buttons need */
  .frame { max-width: 100%; }
  .preview-note, .preview-making { display: none !important; }
  .transport { gap: 12px; padding: 4px 16px 4px 4px; }
  .transport .time { min-width: 0; font-size: 12px; white-space: nowrap; }
  .transport .switch, .transport .stage-plus { display: none; }
  body.m-edit .transport { width: 100%; justify-content: space-between; gap: 8px; padding: 4px 8px 4px 4px; }
  body.m-edit .transport .switch { display: flex; font-size: 12px; gap: 6px; white-space: nowrap; }
  body.m-edit .transport .stage-plus { display: inline-flex; width: 36px; padding: 0; margin-left: 0; justify-content: center; }
  .transport .stage-plus span { display: none; }

  /* smaller play bar, to save room */
  .transport { gap: 8px !important; padding: 3px 12px 3px 3px !important; background: rgba(14,14,14,0.92) !important; }
  .transport .playbtn { width: 30px !important; height: 30px !important; }
  .transport .playbtn svg { width: 13px !important; height: 13px !important; }
  .transport .time { font-size: 11px !important; }
  body.m-edit .transport .stage-plus { width: 30px; height: 30px; }

  /* ---- Chat and Edit: small buttons on the play bar's row, at the right, so the video gets the whole width and height */
  .m-fabs { position: absolute; right: calc((100% - var(--m-rw)) / 2); bottom: 0; z-index: 7; flex-direction: row; align-items: center; gap: 6px; height: 36px; }
  .m-fab { width: auto; height: 36px; padding: 0 12px; border: 0; border-radius: 10px; background: rgba(255,255,255,0.06); display: flex; flex-direction: row; align-items: center; gap: 6px; color: #f2f2f2; font-size: 12.5px; font-weight: 600; }
  .m-fab i { width: auto; height: auto; background: none; border-radius: 0; color: inherit; display: grid; place-items: center; }
  .m-fab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .m-fab:active { background: rgba(255,255,255,0.14); }
  #mEditBtn .i-done { display: none; }
  body.m-edit #mEditBtn { background: #cfcfcf; color: #0a0a0a; }
  body.m-edit #mEditBtn .i-edit { display: none; }
  body.m-edit #mEditBtn .i-done { display: block; }
  body.ai-busy .m-fabs { display: none; }
  body.m-edit #mChatBtn { display: none; }
  /* Chat: grayish white, on the right */
  #mChatBtn { order: 2; background: #cfcfcf; color: #0b0b0b; }
  #mChatBtn:active { background: #b9b9b9; }
  #mEditBtn { order: 1; }
  .transport { align-self: flex-start; margin-left: calc((100% - var(--m-rw)) / 2); height: 36px; box-sizing: border-box; max-width: calc(var(--m-rw) - 150px); }
  body.m-edit .transport { width: calc(100% - 94px); margin-left: 2px; max-width: none; gap: 6px; }   /* editing: the bar gets the full width, Done sits at the right */
  body.m-edit .m-fabs { right: 2px; }
  body.m-edit .transport .time { font-size: 11px; }
  .selbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .selbar::-webkit-scrollbar { display: none; }
  .selbar > * { flex: none; }
  .timeline-scroll { touch-action: pan-x pan-y; }

  /* ---- the chat box under the video: only what the desktop chat shows at its bottom
     (suggestions, write a change, Run AI), fitted to the width */
  .panel, body.m-chat .panel { background: var(--m-bg) !important; background-image: none !important; }   /* the desktop panel has a gradient */
  .panel { grid-column: 1; grid-row: 3; border-left: 0; background: var(--m-bg); }
  body.m-edit:not(.m-chat) .panel { display: none; }   /* editing: video + tools, the chat box comes back after */
  body:not(.m-chat) .panel > .tabs, body:not(.m-chat) .panel > .tabs-bar, body:not(.m-chat) .panel > .m-sheet-head,
  body:not(.m-chat) .panel > .tab:not(#tab-ai), body:not(.m-chat) #tab-ai .ai-head,
  body:not(.m-chat) #tab-ai .ai-scroll, body:not(.m-chat) #tab-ai .ai-empty { display: none !important; }
  body:not(.m-chat) #tab-ai { display: flex !important; flex-direction: column; padding: 0; overflow: visible; flex: none; }
  body:not(.m-chat) #tab-ai .ai-foot { padding: clamp(0.7rem, 1.8dvh, 1.1rem) 10px 4px; padding-bottom: max(10px, env(safe-area-inset-bottom)); gap: 8px; }
  #tab-ai #aiRun.idle, body:not(.m-chat) #tab-ai #aiRun { display: none !important; }   /* the sheet has it: tapping the box opens the chat */
  body:not(.m-chat) #tab-ai #aiSugs { display: none !important; }   /* suggestions only show in the open chat */
  body:not(.m-chat) .peek { max-height: 34dvh; }
  body.m-typing #tab-ai #aiSugs, body.m-typing #tab-ai .ai-empty { display: none !important; }   /* typing: nothing but the message */
  #tab-ai .ai-compose textarea { max-height: 40dvh !important; overflow-y: auto; }

  body:not(.m-chat) .ai-compose textarea { min-height: 28px; }

  /* ---- the whole chat: just Ask AI, a full screen page that slides in from the right */
  .m-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,0.55); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  body.m-projects .m-backdrop { opacity: 1; pointer-events: auto; background: rgba(0,0,0,0.65); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }   /* the page behind the open drawer: darker and blurred */
  body.m-chat .panel { position: fixed; inset: 0; bottom: var(--m-kb, 0px); z-index: 60; height: auto; border-radius: 0; background: var(--m-bg);
    padding-top: env(safe-area-inset-top); background: var(--m-bg); animation: m-in 0.28s cubic-bezier(0.4, 0, 0.2, 1); }
  @keyframes m-in { from { transform: translateX(100%); } to { transform: none; } }
  body.ai-busy .panel { display: none; }
  .panel > .tabs-bar, .panel > .tabs, .panel > .tab:not(#tab-ai) { display: none !important; }   /* the phone chat is Ask AI only */
  .m-sheet-head { display: flex; flex: none; position: relative; align-items: center; justify-content: flex-start; gap: 10px; height: 50px; padding: 0 10px; margin-top: max(0.5rem, 1.2dvh); touch-action: pan-y; }
  .m-grab { font-size: 15px; font-weight: 600; color: #f2f2f2; line-height: 1; }
  .m-sheet-x { position: static; flex: none; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: #101011; color: #fff; align-items: center; justify-content: center; display: inline-flex; }
  .m-sheet-x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  body.m-chat #tab-ai .ai-head { display: none; }   /* the page head says it */
  body.m-chat #tab-ai .ai-foot { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .panel .tab { min-height: 0; }

  /* ---- smaller parts in the chat box, to save room (sizes only; the look is the desktop one) */
  #tab-ai .ai-foot { gap: 6px; }
  #tab-ai .ai-compose { min-height: 0 !important; padding: 8px 8px 8px 12px !important; row-gap: 4px !important; border-radius: 12px !important; }
  #tab-ai .ai-compose textarea { min-height: 4.5rem !important; font-size: 16px !important; line-height: 1.4 !important; }
  #tab-ai .ai-plus, #tab-ai .ai-peek-btn { width: 32px !important; height: 32px !important; border-radius: 9px !important; }
  #tab-ai .ai-plus svg, #tab-ai .ai-peek-btn svg { width: 16px !important; height: 16px !important; }
  #tab-ai .ai-compose .ai-stamp { height: 32px !important; padding: 0 10px !important; border-radius: 9px !important; font-size: 12.5px !important; }
  #tab-ai .ai-compose .ai-send { width: 32px !important; height: 32px !important; border-radius: 9px !important; }
  #tab-ai .ai-compose .ai-send svg { width: 15px !important; height: 15px !important; }
  #tab-ai .ai-sugs-title { margin-bottom: 0.25rem; font-size: 0.72rem; }
  #tab-ai .ai-sug { gap: 0.5rem; padding: 0.6rem 0.5rem 0.6rem 0.8rem !important; border-radius: 0.6rem; }
  #tab-ai .ai-sug-text { font-size: 0.85rem; line-height: 1.4; }
  #tab-ai .ai-sug .ai-stamp { font-size: 0.72rem; padding: 0.08rem 0.35rem; }
  #tab-ai .ai-sug-plus { width: 2.1rem; height: 2.1rem; border-radius: 0.5rem; }
  #tab-ai .ai-sug-plus { background: #cfcfcf; }   /* a greyer white */
  #tab-ai .ai-sug-plus svg { width: 1rem; height: 1rem; }
  #tab-ai #aiSugs .ai-sugs-in, #tab-ai .ai-sugs { gap: 0.3rem; }
  #tab-ai .ai-run { height: 52px !important; border-radius: 14px !important; font-size: 15px !important; font-weight: 700 !important; background: #cfcfcf !important; color: #0a0a0a !important; opacity: 1 !important; }   /* taller, easy to see, grayish white */
  #tab-ai .ai-run::before { width: 16px; height: 16px; }

  /* ---- the project list: a drawer from the left */
  .videos { position: fixed; left: 0; top: 0; bottom: 0; z-index: 70; width: min(86vw, 340px); grid-row: auto; border-right: 0; background: #000000 !important;
    padding-top: max(12px, env(safe-area-inset-top)); transform: translateX(-102%); visibility: hidden; transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s 0.28s; }
  body.m-projects .videos { transform: none; visibility: visible; transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s; }
  /* the project list's scrollbar: the desktop's slim one, 3 px from the drawer's edge, clear of the cards */
  .videos #videoList { margin-right: -7px !important; padding-right: 7px !important; scrollbar-width: auto !important; scrollbar-color: auto !important; }
  .videos #videoList::-webkit-scrollbar { width: 6px; }
  .videos #videoList::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
  .videos #videoList::-webkit-scrollbar-track { background: transparent; }
  .videos #videoList::-webkit-scrollbar-thumb { background: #262626; border-radius: 6px; border: 1px solid transparent; background-clip: padding-box; }
  .m-drawer-brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 14px; font-size: 16px; font-weight: 600; color: #f2f2f2; }
  .m-drawer-brand img { height: 20px; width: auto; }
  .videos .video-item .item-more { opacity: 1 !important; visibility: visible !important; }   /* no hover on a phone: the ... always shows */
  .videos .video-item .item-text { padding-right: 38px; }   /* a long name stops before the ... */
  .videos .side-head .iconbtn { width: 38px; height: 38px; }

  /* ---- the new project page and popups fit the width */
  .np-inner, .np-card { max-width: 100%; }
  .empty:has(> .newpage:not(.hidden)) { padding-top: 64px !important; padding-bottom: 24px !important; }
  /* the blog: small rows one under the other, no arrows */
  .np-blog { width: 100% !important; margin: 28px 0 0 !important; }
  .np-blog.has-arrow .np-blog-head, .np-blog-head { padding: 0 2px !important; margin-bottom: 10px; }
  .np-posts-wrap { display: block; }
  .np-posts { flex-direction: column; gap: 8px; overflow: visible; scroll-snap-type: none; }
  .np-prev, .np-next { display: none !important; }
  .np-post { flex: none; width: 100%; display: grid; grid-template-columns: 104px minmax(0, 1fr); grid-template-rows: auto auto; align-content: center; column-gap: 12px; padding: 6px; border-radius: 12px; }
  .np-art { grid-row: 1 / 3; width: 104px; margin: 0; border-radius: 8px; }
  .np-post b { align-self: end; min-height: 0; padding: 0; font-size: 13px; }
  .np-desc { align-self: start; margin-top: 3px; padding: 0; font-size: 11.5px; }
  .modal-box, .xp-box, .ovwin-card { max-width: calc(100vw - 20px); }

  .ai-empty > span { display: none !important; }   /* empty chat: just the icon and "No comments yet" */
  /* the timeline's top strip must fit a phone: undo / redo live in the top row already, the Help text and the Basic / Pro switch are dropped */
  .timeline-wrap .selbar { max-width: 100%; box-sizing: border-box; gap: 8px; padding-left: 10px; padding-right: 10px; overflow: hidden; }
  .timeline-wrap .selbar .history, .timeline-wrap .selbar .viewtoggle, .timeline-wrap .tl-help span { display: none !important; }
  .timeline-wrap .tl-zoom { flex: 1 1 auto; min-width: 0; max-width: 100%; }
  .timeline-wrap .tl-zoom input[type="range"] { flex: 1 1 auto; min-width: 0; width: auto; }
  .timeline-wrap .timeline-scroll { max-width: 100%; overflow-x: auto; }
}

/* Phones: Storage, Plan, Help, Settings and Profile under the projects, as on desktop; popups always above the drawer */
@media (max-width: 820px) {
  .videos { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .videos .side-nav { flex: none; padding-bottom: 10px; }
  #projMenu, .sel-menu, .dd-menu, .modal, .dlg-back { z-index: 90 !important; }
  /* Settings opens Upload Preferences as a full page, like the chat */
  body.m-prefs .panel > #tab-settings { display: flex !important; flex: 1; min-height: 0; }
  body.m-prefs .panel > #tab-ai { display: none !important; }
}

/* a phone turned sideways: little height */
@media (max-width: 920px) and (max-height: 480px) {
  :root { --m-tl-h: 56dvh; }

}
