/* Phone and tablet layer: loaded last so it refines the desktop layout without changing it. */

/* Every size: app-like touch behaviour and notch-safe edges. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
html,body{overflow-x:clip;overscroll-behavior-y:none}
body{-webkit-tap-highlight-color:transparent;padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right)}
header{padding-top:env(safe-area-inset-top)}
button,a,.clip{touch-action:manipulation}
.install-app{border:1px solid var(--accent);color:var(--accent);background:transparent;border-radius:8px;padding:7px 10px;font-size:12px;white-space:nowrap}
/* Typing on a phone must not zoom the page (iOS zooms inputs under 16px). */
html.touch input:not([type=range]):not([type=checkbox]):not([type=radio]),html.touch textarea,html.touch select{font-size:16px!important}
/* Fingers need bigger targets than a mouse. */
html.touch .timeline-toolbar button,html.touch .transport button,html.touch .chat-tabs button{min-height:40px;min-width:40px}
html.touch .clip{min-height:40px}
html.touch #ruler{height:28px}
.clip.touch-dragging{opacity:.55;outline:2px dashed var(--accent)}
.clip.touch-target{box-shadow:inset 3px 0 0 var(--accent)}

/* Phones (portrait). */
@media (max-width:700px){
 /* Gallery header. */
 header .lyric-entry{white-space:nowrap;font-size:12px;padding:6px 8px}
 .chat-suggestions{grid-template-columns:1fr}
 .creation-station{grid-template-columns:minmax(0,1fr)}
 .footage-drop,.brief-builder{min-width:0}

 /* EDITOR ON A PHONE: one fixed screen, top to bottom:
    slim header (back, title + saved, mode, export) -> preview -> timeline -> chat history -> message bar.
    Only the chat history scrolls, so the preview and timeline never move. */
 body.mode-assistant:not(.view-gallery){height:var(--app-h,100dvh);overflow:hidden}
 body:not(.view-gallery) header{position:static;flex-wrap:nowrap;height:auto;min-height:0;padding:calc(6px + env(safe-area-inset-top)) 10px 6px;gap:8px}
 body:not(.view-gallery) header .brand,body:not(.view-gallery) header .lyric-entry,body:not(.view-gallery) .install-app,body:not(.view-gallery) #aiSettings{display:none!important}
 body:not(.view-gallery) #backGallery{display:inline-flex!important;order:0;flex:0 0 auto;font-size:0;padding:6px 8px;min-width:0}
 body:not(.view-gallery) #backGallery::before{content:"‹";font-size:24px;line-height:18px}
 body:not(.view-gallery) .project{display:flex!important;order:1;flex:1 1 auto;min-width:0;width:auto;margin:0;flex-direction:column;align-items:flex-start;gap:0}
 body:not(.view-gallery) .project input{width:100%;min-width:0;font-size:15px!important;font-weight:600;padding:0;height:22px;border:0;background:transparent;text-overflow:ellipsis}
 body:not(.view-gallery) .project .local-label{display:block;font-size:10px;color:var(--muted);line-height:1.2}
 body:not(.view-gallery) .mode-tabs{order:2;flex:0 0 auto;margin:0;padding:2px}
 body:not(.view-gallery) .mode-tabs button{font-size:11px;padding:5px 8px;min-height:0;min-width:0}
 body:not(.view-gallery) .header-actions{order:3;flex:0 0 auto;margin:0}
 body:not(.view-gallery) #export{font-size:0;padding:7px 11px}
 body:not(.view-gallery) #export::after{content:"Export";font-size:12px}
 body:not(.view-gallery) .mode-tabs button{font-size:10.5px;padding:5px 7px}

 .mode-assistant .workspace{height:calc(var(--app-h,100dvh) - var(--header-h,48px));min-height:0;grid-template-columns:minmax(0,1fr);grid-template-rows:auto auto minmax(0,1fr)}
 .mode-assistant .stage{grid-column:1;grid-row:1;height:auto;position:static;box-shadow:none;border-bottom:1px solid var(--line)}
 .mode-assistant .stagebar,.mode-assistant .quick-actions{display:none}
 .mode-assistant .viewport{flex:none;height:min(23dvh,52vw);margin:6px 8px 0}
 .mode-assistant .transport{padding:2px 8px;min-height:0}
 .mode-assistant .transport{height:44px}
 .mode-assistant .transport button{min-height:34px;min-width:34px}
 .mode-assistant #play{width:38px;height:38px;min-height:0}
 .mode-assistant .timeline{grid-column:1;grid-row:2;height:auto;min-height:0;border-bottom:1px solid var(--line)}
 .mode-assistant .timeline-toolbar{height:34px;min-height:0;padding:0 8px}
 .mode-assistant .timeline-toolbar button{min-height:30px;min-width:30px}
 .mode-assistant .timeline-body{flex:none;height:min(15dvh,118px);max-height:none;overflow:auto}
 .mode-assistant #tracks{min-height:0}
 .mode-assistant .timeline{display:flex;flex-direction:column}
 .mode-assistant .timeline footer{display:none}
 .mode-assistant .chat-panel{grid-column:1;grid-row:3;min-height:0;height:auto;display:flex;flex-direction:column;border:0}
 .mode-assistant .chat-heading,.mode-assistant .chat-privacy{display:none}
 .mode-assistant .chat-tabs{flex:none;padding:0 10px;gap:14px}
 .mode-assistant .chat-tabs button{min-height:32px;font-size:12px;padding:4px 0}
 .mode-assistant .chat-content{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;padding:10px 12px}
 .mode-assistant #goalBarSlot{flex:none;padding:0 8px}
 .mode-assistant .goal-bar{padding:4px 0 0;gap:5px}
 .mode-assistant .goal-bar button{padding:5px 10px;font-size:11.5px;min-height:30px}
 .mode-assistant .ai-progress{flex:none;padding:6px 12px;font-size:11px;gap:7px}
 .mode-assistant .ai-progress button{min-height:28px;min-width:28px;font-size:18px}
 .mode-assistant .chat-content{min-height:96px}

 /* Message bar: + and mic on the left, text grows as you type, send on the right. */
 .mode-assistant .chat-compose{flex:none;position:static;display:grid;grid-template-columns:32px 32px minmax(0,1fr) 38px;align-items:end;gap:4px;margin:6px 8px calc(6px + env(safe-area-inset-bottom));padding:5px;border-radius:22px}
 .mode-assistant .chat-compose .compose-actions,.mode-assistant .chat-compose .compose-actions>div{display:contents}
 .mode-assistant #chatAddMedia{grid-column:1;grid-row:1}
 .mode-assistant #dictate{grid-column:2;grid-row:1}
 .mode-assistant #chatInput{grid-column:3;grid-row:1;min-height:34px!important;height:34px;max-height:110px;padding:7px 4px;resize:none;line-height:20px}
 .mode-assistant #sendChat{grid-column:4;grid-row:1;width:36px;height:36px;min-width:0;border-radius:50%}
 .mode-assistant #connectionLabel{display:none}
 .mode-assistant .chat-compose button.icon{width:32px;height:34px;min-width:0;min-height:0;padding:0}
 .mode-assistant .dictation-status{grid-column:1/5;grid-row:2;font-size:11px}
 .mode-assistant .dictation-status:empty{display:none}

 /* Timeline: tools move to a bottom tab bar you can reach with a thumb. */
 .mode-advanced .workspace{grid-template-columns:minmax(0,1fr);grid-template-rows:auto auto auto;padding-bottom:calc(70px + env(safe-area-inset-bottom))}
 .mode-advanced .stage,.mode-advanced .library,.mode-advanced .timeline{grid-column:1}
 .mode-advanced .stage{grid-row:1}.mode-advanced .library{grid-row:3;max-height:none}.mode-advanced .timeline{grid-row:2;min-height:250px}
 .mode-advanced .library{scroll-margin-top:calc(var(--header-h,0px) + min(36dvh,320px) + 8px)}
 .mode-advanced .rail{position:fixed;left:0;right:0;bottom:0;z-index:40;grid-row:auto;flex-direction:row;justify-content:flex-start;align-items:stretch;gap:0;padding:4px 6px calc(4px + env(safe-area-inset-bottom));overflow-x:auto;overflow-y:hidden;border-right:0;border-top:1px solid var(--line);background:#171819f2;backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);scrollbar-width:none}
 .mode-advanced .rail::-webkit-scrollbar{display:none}
 .mode-advanced .rail button{flex:0 0 auto;width:64px;min-height:52px;padding:6px 2px}
 .mode-advanced .rail .rail-bottom{display:flex;flex-direction:row;margin:0}
 .mode-advanced .stage{height:min(36dvh,320px);position:sticky;top:var(--header-h,0px);z-index:20;background:var(--bg);box-shadow:0 8px 18px #0008}

 /* Timeline scrolls sideways inside itself, never the page. */
 .timeline-body{overflow-x:auto;-webkit-overflow-scrolling:touch}
 .timeline-toolbar{overflow-x:auto;scrollbar-width:none}
 .timeline-toolbar::-webkit-scrollbar{display:none}

 /* Dialogs and sheets fill the phone instead of floating off-screen. */
 dialog,.modal,.sheet{max-width:calc(100vw - 20px)!important;max-height:calc(var(--app-h,100dvh) - 40px);overflow:auto}
}

/* Phones sideways and small tablets: keep the editor header on one line. */
@media (max-width:1024px){
 body:not(.view-gallery) header .lyric-entry{display:none}
 header .primary,header .lyric-entry,.ai-connect{white-space:nowrap}
 header .primary span{display:none}
}

/* Very small phones (iPhone SE, older Android). */
@media (max-width:360px){
 .brand{font-size:16px}
 .brandmark{width:22px;height:24px;font-size:24px;line-height:25px}
 .header-actions .primary{padding:6px 7px;font-size:10px}
 .ai-connect{max-width:84px}
 .create-heading h1{font-size:25px}
 .project-grid{grid-template-columns:1fr}
 .mode-tabs button{padding:5px 4px}
 .transport{gap:4px}
 .transport .playback{gap:0}
 .transport button{min-width:34px!important}
 #timecode{font-size:9px!important}
 #speed{max-width:56px;padding-left:4px;padding-right:4px}
}

/* Phones held sideways: preview and panel side by side, no wasted height. */
@media (max-height:500px) and (orientation:landscape){
 header{position:static;min-height:46px}
 .mode-assistant .workspace{grid-template-columns:minmax(0,1.2fr) minmax(0,1fr);grid-template-rows:calc(var(--app-h,100dvh) - 10px) auto}
 .mode-assistant .stage{grid-column:1;grid-row:1;position:sticky;top:0;height:calc(var(--app-h,100dvh) - 10px);box-shadow:none}
 .mode-assistant .chat-panel{grid-column:2;grid-row:1;min-height:0;height:calc(var(--app-h,100dvh) - 10px);overflow:auto;border-top:0;border-left:1px solid var(--line)}
 .mode-assistant .timeline{grid-column:1/3;grid-row:2}
 .mode-advanced .stage{height:calc(var(--app-h,100dvh) - 60px)}
 .chat-compose{margin-bottom:6px}
}

/* Installed app: no browser chrome, so respect the status bar and home indicator. */
html.installed body{padding-bottom:env(safe-area-inset-bottom)}
html.installed .gallery-view{padding-bottom:calc(22px + env(safe-area-inset-bottom))}

/* Typing in chat on a phone: pinned to the visible area above the keyboard, like a messaging app. */
@media (max-width:700px){
 html.kb-open body.mode-assistant{position:fixed;left:0;right:0;top:var(--vv-top,0px);height:var(--app-h,100dvh);overflow:hidden}
 html.kb-open body.mode-assistant header,html.kb-open .mode-assistant .stage,html.kb-open .mode-assistant .timeline,html.kb-open .mode-assistant .chat-tabs{display:none!important}
 html.kb-open .mode-assistant .workspace{height:var(--app-h,100dvh);grid-template-rows:minmax(0,1fr)}
 html.kb-open .mode-assistant .chat-panel{grid-row:1;height:var(--app-h,100dvh)}
 html.kb-open .mode-assistant .chat-compose{margin-bottom:6px}
}

/* Credits pill: shows what's left and opens Plans. Visible on every screen size. */
.credits-pill{display:inline-flex;align-items:center;gap:6px;background:#1f1d17;border:1px solid #4a4130;color:#f1d79a;font-size:12px;white-space:nowrap;padding:7px 10px;border-radius:999px;cursor:pointer}
.credits-pill .credits-plus{color:#111213;background:#f1d79a;border-radius:999px;padding:2px 8px;font-weight:600;font-size:11px}
.credits-pill.low{border-color:#8a5a2b;color:#ffbf86}
.credits-pill.low .credits-plus{background:#ff8a4c}
.credits-pill:hover{filter:brightness(1.12)}
@media (max-width:700px){
 .credits-pill{padding:5px 6px 5px 8px;font-size:11px;gap:5px}
 .credits-pill .credits-word{display:none}
 .credits-pill .credits-plus{font-size:0;padding:0;width:18px;height:18px;display:inline-grid;place-items:center}
 .credits-pill .credits-plus::after{content:"+";font-size:14px;line-height:1}
 body:not(.view-gallery) .header-actions{display:flex;align-items:center;gap:6px}
}
@media (max-width:700px){
 /* Editor header is tight: just the count; the + appears only when credits run low. */
 body:not(.view-gallery) .credits-pill{padding:4px 7px;gap:3px;font-size:11px}
 body:not(.view-gallery) .credits-pill:not(.low) .credits-plus{display:none}
 body:not(.view-gallery) .header-actions{gap:5px}
 body:not(.view-gallery) .mode-tabs button{padding:5px 6px}
 body:not(.view-gallery) #export{padding:7px 9px}
}

/* ===== Tool bar (Timeline editor): every tool one tap away; swaps to clip tools when a clip is selected. ===== */
.tool-strip{display:none}
.mode-advanced .tool-strip{display:flex;grid-column:1;grid-row:1/4;flex-direction:column;align-items:stretch;gap:2px;padding:10px 6px;overflow-y:auto;overflow-x:hidden;background:#151617;border-right:1px solid var(--line);scrollbar-width:none;z-index:6}
.mode-advanced .tool-strip::-webkit-scrollbar{display:none}
.mode-advanced .rail{display:none!important}
.tool-strip .tool{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:5px;min-height:58px;padding:8px 2px;border:0;border-radius:12px;background:transparent;color:#c9cbd0;font-size:10.5px;font-weight:500;letter-spacing:.01em;cursor:pointer;transition:background .15s,color .15s}
.tool-strip .tool svg{width:22px;height:22px}
.tool-strip .tool:hover{background:#202225;color:#fff}
.tool-strip .tool:active{transform:scale(.96)}
.tool-strip .tool.danger{color:#ff9b86}
.tool-strip .tool.back{min-height:40px;color:#fff}
.tool-strip .tool-sep{height:1px;background:var(--line);margin:2px 8px 4px}
.tool-strip.clip-mode{background:linear-gradient(#1b1a19,#151617)}
.tool-strip.clip-mode .tool:not(.back) svg{color:var(--accent)}
.tool-flash{outline:2px solid var(--accent);outline-offset:4px;border-radius:8px;transition:outline-color 1s}
.sheet-done{display:none}
.ratio-pop{position:fixed;z-index:60;left:84px;top:50%;transform:translateY(-50%);display:flex;gap:8px;padding:10px;background:#1c1d1f;border:1px solid var(--line);border-radius:16px;box-shadow:0 20px 50px #000a}
.ratio-pop button{display:flex;flex-direction:column;align-items:center;gap:6px;min-width:72px;padding:10px 8px;border:1px solid transparent;border-radius:12px;background:#232527;color:#e6e7ea;font-size:12px;font-weight:600}
.ratio-pop button.selected{border-color:var(--accent);color:#fff}
.ratio-pop i{display:block;height:34px;border:2px solid currentColor;border-radius:4px}
.ratio-pop small{font-size:10px;font-weight:400;color:var(--muted)}

@media (max-width:700px){
 /* Phone: the tool bar runs along the bottom and scrolls sideways; tools open as a sheet over the timeline. */
 .mode-advanced .tool-strip{position:fixed;left:0;right:0;bottom:0;top:auto;z-index:40;flex-direction:row;align-items:stretch;gap:2px;padding:6px 8px calc(6px + env(safe-area-inset-bottom));overflow-x:auto;overflow-y:hidden;border-right:0;border-top:1px solid var(--line);background:rgba(17,18,19,.96);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}
 .tool-strip .tool{flex:0 0 auto;width:62px;min-height:54px;padding:6px 0;font-size:10px}
 .tool-strip .tool.back{width:40px}
 .tool-strip .tool-sep{width:1px;height:auto;margin:8px 2px}
 .mode-advanced .library{position:fixed!important;left:0;right:0;bottom:0;z-index:50;max-height:none!important;height:min(58dvh,520px);margin:0;border-radius:20px 20px 0 0;border:1px solid var(--line);border-bottom:0;background:#18191b;box-shadow:0 -18px 50px #000c;transform:translateY(105%);transition:transform .28s cubic-bezier(.2,.8,.2,1);overflow:auto;padding-bottom:calc(16px + env(safe-area-inset-bottom));grid-row:auto}
 body.sheet-open.mode-advanced .library{transform:none}
 .mode-advanced .library .panel-heading{position:sticky;top:0;z-index:2;background:#18191b;padding-top:18px}
 .mode-advanced .library .panel-heading::before{content:"";position:absolute;top:7px;left:50%;width:38px;height:4px;margin-left:-19px;border-radius:4px;background:#3a3c40}
 .mode-advanced .sheet-done{display:inline-flex;margin-left:auto;padding:6px 14px;border-radius:999px;border:0;background:var(--accent);color:#141414;font-weight:700;font-size:13px}
 .mode-advanced .library .device-note{display:none}
 .mode-advanced .workspace{padding-bottom:calc(76px + env(safe-area-inset-bottom))}
 .ratio-pop{left:50%;top:auto;bottom:calc(80px + env(safe-area-inset-bottom));transform:translateX(-50%)}
}
