.mobile-only { display: none; }

@media (max-width: 950px) {
  html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
  .mobile-only { display: flex; }
  .editor-header { height: calc(60px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; gap: 10px; }
  .editor-brand { gap: 6px; flex-shrink: 0; }
  .editor-brand img { width: 30px; height: 30px; }
  .editor-brand strong { display: none; }
  .header-divider, #save-state { display: none; }
  .project-heading { flex: 1; min-width: 0; }
  .project-heading input { width: 100%; min-width: 0; font-size: 16px; padding: 8px 4px; text-overflow: ellipsis; }
  .header-actions { margin-left: 0; gap: 6px; flex: 0 0 auto; }
  .header-actions > .icon-button { width: 44px; height: 44px; }
  .header-actions #export { min-width: 68px; min-height: 40px; padding: 8px; font-size: 11px; gap: 4px; }
  .header-actions #export svg { display: none; }
  .editor-workspace {
    height: calc(100dvh - 60px - env(safe-area-inset-top));
    width: 100%; min-width: 0;
    display: grid; grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(200px, 48%) minmax(0, 1fr) calc(76px + env(safe-area-inset-bottom));
    overflow: hidden;
  }
  .panel-resizer { display: none; }
  .viewer-panel { grid-column: 1; grid-row: 1; min-height: 0; min-width: 0; border: 0; }
  .viewer-toolbar { min-height: 40px; height: 40px; padding: 0 10px; }
  .viewer-toolbar > .section-label, .canvas-options > label, #preview-quality-field > .export-field-label { display: none; }
  .canvas-options { width: 100%; justify-content: flex-end; gap: 8px; min-width: 0; }
  #preview-quality-field { margin-right: auto; }
  .canvas-options .select-trigger, .aspect-trigger { height: 36px; min-height: 36px; padding: 6px 10px; font-size: 11px; }
  .aspect-trigger { max-width: 190px; }
  #aspect-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #fullscreen { width: 36px; height: 36px; }
  .aspect-menu { position: fixed; top: calc(100px + env(safe-area-inset-top)); left: auto; right: 12px; width: min(320px, calc(100vw - 24px)); max-height: 50dvh; overflow-y: auto; z-index: 100; }
  .stage { min-height: 0; padding: 4px 12px; }
  .canvas-empty { padding: 8px; gap: 6px; }
  .canvas-empty .empty-illustration { width: 240px; max-height: calc(100% - 56px); }
  .canvas-empty h2 { display: none; }
  .canvas-empty > span, .canvas-empty > p { display: none; }
  .canvas-empty .primary-button { min-height: 44px; }
  .playback-bar { height: 62px; min-height: 62px; padding: 0 12px; flex-shrink: 0; }
  .playback-bar .preview-note, .playback-bar .frame-rate { display: none; }
  .playback-bar .transport { position: static; transform: none; display: grid; grid-template-columns: 40px 44px 40px; grid-template-rows: 38px 18px; gap: 0 8px; margin: 0 auto; }
  .transport #back-start { right: auto; left: 12px; top: 4px; width: 40px; height: 40px; }
  .transport .play-button { width: 36px; height: 36px; justify-self: center; }
  .transport .icon-button { width: 40px; height: 38px; }
  .transport .timecode { position: static; transform: none; grid-row: 2; grid-column: 1 / 4; justify-content: center; font-size: 10px; gap: 6px; }
  .timeline-panel, .library-panel, .inspector-panel { grid-column: 1; grid-row: 2; min-width: 0; min-height: 0; border: 0; border-top: 1px solid var(--line-strong); }
  .library-panel, .inspector-panel { display: none; overflow-y: auto; overscroll-behavior: contain; }
  body[data-mobile-panel='library'] .library-panel { display: block; }
  body[data-mobile-panel='properties'] .inspector-panel { display: block; padding: 0 16px 20px; }
  body[data-mobile-panel='library'] .timeline-panel, body[data-mobile-panel='properties'] .timeline-panel { display: none; }
  .mobile-panel-heading { position: sticky; top: 0; z-index: 4; background: var(--panel); justify-content: space-between; align-items: center; padding: 4px 16px; border-bottom: 1px solid var(--line); min-height: 44px; color: var(--secondary); }
  .mobile-panel-heading button, .inspector-panel > .panel-heading button { width: 40px; height: 40px; }
  .inspector-panel > .panel-heading { position: sticky; top: 0; z-index: 4; background: var(--panel); margin: 0; min-height: 48px; }
  .inspector-panel > .panel-heading .tiny-dot { display: none; }
  .library-section { padding: 14px 16px 24px; }
  .library-footnote, #uploads-view > .local-import-notice:not(#compatibility-status) { display: none; }
  .panel-heading { margin-bottom: 12px; }
  .library-section .panel-heading h1 { font-size: 18px; }
  .library-caption, .panel-description, .property-hint { font-size: 12px; }
  .segmented button, .import-button, .link-import-button, .text-preset { min-height: 44px; }
  .media-card .media-add, .media-card .media-remove { opacity: 1; width: 36px; height: 36px; }
  .media-card .media-add { top: 46px; }
  #media-panel[data-view='list'] .media-card .media-add { top: auto; }
  .media-preview-popover { width: min(360px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; }
  .media-preview-popover .preview-player video, .media-preview-popover .preview-player img { max-height: 58dvh; }
  .timeline-toolbar { height: auto; min-height: 94px; display: flex; flex-direction: column; align-items: stretch; gap: 0; padding: 0; }
  .timeline-actions { flex: 0 0 48px; width: 100%; overflow-x: auto; padding: 0 8px; gap: 4px; scrollbar-width: none; touch-action: pan-x; }
  .timeline-actions > button { flex: 0 0 auto; min-width: 40px; min-height: 44px; }
  .timeline-actions .tool-button { font-size: 11px; }
  .timeline-actions .tool-button span { display: inline; }
  .timeline-actions .toolbar-divider { flex-shrink: 0; margin: 0 4px; }
  .timeline-zoom { height: 44px; padding: 0 10px; justify-content: flex-end; border-top: 1px solid var(--line); }
  .timeline-zoom .icon-button { width: 40px; height: 40px; }
  .timeline-zoom input { width: 110px; height: 40px; }
  #snap-toggle { margin-right: auto; }
  #mobile-multiselect[aria-pressed='true'] { background: var(--violet-soft); color: var(--violet); }
  .timeline-scroll { overscroll-behavior: contain; touch-action: pan-x pan-y; }
  .timeline-ruler, #playhead { touch-action: none; }
  .timeline-clip { touch-action: none; }
  .timeline-clip.selected .trim-handle { width: 16px; }
  .timeline-footer { min-height: 24px; padding: 4px 10px; }
  .timeline-footer > span:last-child { display: none; }
  .tool-rail { grid-column: 1; grid-row: 3; width: 100%; flex-direction: row; align-items: flex-start; justify-content: flex-start; gap: 4px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; border: 0; border-top: 1px solid var(--line-strong); background: var(--desk); }
  .tool-rail .rail-button { display: grid; width: 68px; min-width: 68px; height: 58px; flex: 0 0 68px; gap: 6px; padding: 6px 2px; border-radius: 10px; font-size: 11px; }
  .tool-rail .rail-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .tool-rail .rail-button .text-icon { font-size: 23px; line-height: 24px; }
  .tool-rail .rail-button.active { background: transparent; color: var(--secondary); }
  body[data-mobile-panel='library'] .tool-rail .rail-button.active, .tool-rail .rail-button[aria-pressed='true'] { background: var(--violet-soft); color: var(--violet); }
  #mobile-timeline { position: sticky; left: 0; z-index: 2; background: var(--desk); box-shadow: 6px 0 10px var(--desk); }
  #mobile-timeline[aria-pressed='true'] { background: var(--raised); }
  dialog { max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px; }
  dialog .dialog-heading { gap: 12px; }
  dialog .dialog-heading h2 { font-size: 20px; }
  dialog .icon-button { min-width: 40px; min-height: 40px; }
  dialog input:not([type='range']), dialog textarea, #inspector input:not([type='range']):not([type='checkbox']), #inspector textarea, #inspector select { font-size: 16px; }
  .modal-overlay { padding: 12px; }
  .modal-overlay .modal { width: min(480px, 100%); max-height: calc(100dvh - 24px); overflow-y: auto; }
  .modal-overlay .modal-header, .modal-overlay .modal-body, .modal-overlay .modal-footer { padding: 18px; }
  .modal-overlay .modal-footer { flex-wrap: wrap; gap: 8px; }
  .modal-overlay .btn { min-height: 44px; }
  #mobile-project-menu { width: min(430px, calc(100vw - 24px)); }
  #mobile-project-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
  #mobile-project-actions > button { min-width: 0; width: 100%; min-height: 46px; display: flex; justify-content: flex-start; align-items: center; gap: 12px; padding: 10px 12px; font-size: 14px; background: var(--raised); border-radius: 8px; }
  #mobile-project-actions .project-file-action span { display: inline; }
  #mobile-project-actions > button svg { width: 20px; height: 20px; }
  #mobile-secondary-actions { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
  #mobile-secondary-actions .rail-bottom { margin-top: 0; flex-direction: row; justify-content: space-between; }
  #mobile-secondary-actions .rail-button { display: flex; min-height: 44px; width: auto; height: 44px; flex-direction: row; gap: 10px; padding: 10px; }
  #mobile-secondary-actions #themeToggle { width: 44px; height: 44px; margin: 0; }
  .editor-toast { max-width: calc(100vw - 24px); bottom: calc(90px + env(safe-area-inset-bottom)); }
  .viewer-panel:fullscreen { padding: 0; }
  .viewer-panel:fullscreen .transport { grid-template-columns: 40px 44px 40px; }
}
@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .editor-header { height: 50px; padding-top: 0; }
  .editor-workspace { height: calc(100dvh - 50px); grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); grid-template-rows: minmax(0, 1fr) 66px; }
  .viewer-panel { grid-column: 1; grid-row: 1; }
  .timeline-panel, .library-panel, .inspector-panel { grid-column: 2; grid-row: 1; }
  .tool-rail { grid-column: 1 / 3; grid-row: 2; padding-block: 4px; }
  .canvas-empty h2 { display: none; }
  .aspect-trigger { max-width: 130px; }
  .timeline-toolbar { min-height: 88px; }
}
@media (max-width: 360px) {
  .editor-header { padding-inline: 8px; gap: 6px; }
}

@media (max-width: 950px) and (orientation: portrait) {
  body[data-mobile-panel='library'] .editor-workspace, body[data-mobile-panel='properties'] .editor-workspace {
    grid-template-rows: minmax(150px, 36%) minmax(0, 1fr) calc(76px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 950px) {
  .header-actions #export { min-width: 60px; min-height: 32px; height: 32px; padding: 6px 9px; font-size: 10px; }
  .editor-workspace { grid-template-rows: minmax(200px, 62%) minmax(0, 1fr) calc(76px + env(safe-area-inset-bottom)); }
  .viewer-toolbar, .timeline-toolbar, .timeline-footer, #previous-frame, #next-frame, #back-start, #snap-toggle { display: none; }
  .stage { padding: 4px 10px; }
  .playback-bar { height: 48px; min-height: 48px; position: relative; }
  .playback-bar .transport { display: flex; gap: 8px; height: 44px; align-items: center; margin: auto; }
  .mobile-playback-tools { display: flex; align-items: center; gap: 2px; position: absolute; right: 8px; top: 2px; }
  .mobile-playback-tools #fullscreen { position: fixed; left: 10px; right: auto; top: auto; }
  .mobile-playback-tools .icon-button { width: 38px; height: 42px; }
  .mobile-timing { height: 28px; flex-shrink: 0; align-items: center; padding: 0 12px; }
  .mobile-timing .timecode { position: static; transform: none; display: flex; gap: 6px; font-size: 10px; }
  .tool-rail #mobile-properties, .tool-rail #mobile-timeline { display: none; }
  body:not([data-mobile-panel='timeline']) .tool-rail #mobile-timeline { display: grid; }
  body[data-mobile-selected='true'] .tool-rail { display: none; }
  .mobile-context-bar { display: none; grid-column: 1; grid-row: 3; overflow-x: auto; align-items: flex-start; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--desk); border-top: 1px solid var(--line); scrollbar-width: none; }
  body[data-mobile-selected='true'] .mobile-context-bar { display: flex; }
  .mobile-context-bar > button, .mobile-property-tools > button, .tool-rail #clear-timeline { display: grid; grid-template-rows: 24px auto; justify-items: center; align-content: start; flex: 0 0 68px; width: 68px; min-width: 68px; min-height: 58px; height: auto; padding: 4px 2px; gap: 5px; font-size: 10px; white-space: normal; background: transparent; color: var(--secondary); }
  .mobile-context-bar button span { display: block; font-size: 10px; line-height: 12px; max-width: 68px; overflow-wrap: anywhere; }
  .mobile-context-bar button svg { width: 22px; height: 22px; }
  .mobile-context-bar .mobile-context-back { position: sticky; left: 0; z-index: 2; flex-basis: 40px; min-width: 40px; width: 40px; display: grid; place-content: center; background: var(--raised); border-radius: 8px; box-shadow: 5px 0 8px var(--desk); }
  .mobile-property-tools { display: flex; gap: 6px; }
  .mobile-context-bar button:disabled { opacity: .3; }
  #mobile-secondary-actions .timeline-zoom { display: flex; border: 0; padding: 0; margin-top: 10px; justify-content: center; }
  #mobile-secondary-actions .timeline-zoom .toolbar-divider { display: none; }
}
@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .editor-workspace { grid-template-rows: minmax(0, 1fr) 66px; }
  .mobile-context-bar { grid-column: 1 / 3; grid-row: 2; padding-block: 4px; }
}
@media (max-width: 950px) and (orientation: portrait) {
  body[data-mobile-panel='library'] .editor-workspace, body[data-mobile-panel='properties'] .editor-workspace { grid-template-rows: minmax(150px, 48%) minmax(0, 1fr) calc(76px + env(safe-area-inset-bottom)); }
}
@media (max-width: 950px) {
  body[data-mobile-panel] .editor-workspace { grid-template-rows: minmax(200px, 62%) minmax(0, 1fr) calc(76px + env(safe-area-inset-bottom)); }
  body[data-mobile-panel] .timeline-panel { display: flex; }
  .editor-bottomsheet { background: var(--panel); color: var(--ink); max-height: 60dvh; }
  .editor-bottomsheet .bottomsheet-content { padding: 0 0 calc(12px + env(safe-area-inset-bottom)); }
  .editor-bottomsheet .bottomsheet-title { color: var(--ink); }
  .editor-bottomsheet .library-panel, .editor-bottomsheet .inspector-panel { display: block; border: 0; overflow: visible; }
  .editor-bottomsheet .library-section { min-height: 0; }
  .editor-bottomsheet .mobile-panel-heading, .editor-bottomsheet .inspector-panel > .panel-heading { display: none; }
  .editor-bottomsheet .aspect-menu { position: static; width: 100%; max-height: none; box-shadow: none; border: 0; }
  .editor-bottomsheet #inspector { padding: 0 16px; }
}
@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  body[data-mobile-panel] .editor-workspace { grid-template-rows: minmax(0, 1fr) 66px; }
  .editor-bottomsheet { max-height: 85dvh; }
}
@media (max-width: 950px) {
  .mobile-playback-tools { left: 8px; justify-content: flex-end; pointer-events: none; }
  .mobile-playback-tools button { pointer-events: auto; }
  .mobile-playback-tools #fullscreen { position: absolute; left: 0; top: 0; }
  /* Fullscreen keeps the left corner; undo, redo and the rest sit on the right */
  .mobile-playback-tools #undo { margin-left: auto; }
}
body:has(.editor-bottomsheet.open) .bottomsheet-overlay { backdrop-filter: none; background: #0002; }
@media (max-width: 950px) {
  .tool-rail, .mobile-context-bar { min-width: 0; max-width: 100%; overflow-y: hidden; overscroll-behavior-x: contain; touch-action: pan-x; }
  .mobile-context-bar > button, .mobile-property-tools > button, .tool-rail .rail-button, .tool-rail #clear-timeline { flex: 0 0 80px; width: 80px; min-width: 80px; height: 60px; min-height: 60px; padding: 2px; gap: 4px; grid-template-rows: 24px 24px; }
  .mobile-context-bar button span, .tool-rail .rail-button span, .tool-rail #clear-timeline span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 76px; height: 24px; line-height: 12px; white-space: normal; overflow-wrap: normal; hyphens: none; text-align: center; }
  .mobile-property-tools { flex-shrink: 0; }
  .mobile-context-bar .mobile-context-back { flex: 0 0 40px; width: 40px; min-width: 40px; grid-template-rows: auto; }
}
@media (max-width: 950px) {
  .timeline-ruler { margin-left: 44px; }
  .track-label { width: 44px; padding: 0; justify-content: center; }
  .track-label .track-name, .track-label [data-layer-action]:not([data-layer-action='mute']) { display: none; }
  .track-label .track-controls { margin: 0; }
  .track-label .track-controls button { width: 40px; height: 44px; }
  .track-row:not(:has(.timeline-clip.selected)) .track-controls { visibility: hidden; }
  .mobile-context-bar, .tool-rail { padding-top: 7px; padding-bottom: calc(7px + env(safe-area-inset-bottom)); }
}
@media (max-width: 950px) {
  #selection .selection-label { display: none; }
}
@media (max-width: 950px) {
  .media-card .media-add { display: none; }
  #media-panel[data-view='list'] .media-card { padding-right: 42px; }
}

@media (max-width: 950px) {
  #mobile-project-actions #userMenu { display: none; }
}

@media (max-width: 950px) {
  .editor-settings-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .editor-settings-actions .tool-button { width: 100%; min-height: 44px; justify-content: center; }
}

@media (max-width: 950px) {
  .header-actions { margin-left: auto; }
  #mobile-project-actions .project-heading { margin-bottom: 12px; }
  #mobile-project-actions .project-heading label { display: block; color: var(--secondary); font-size: 12px; margin-bottom: 8px; }
  #mobile-project-actions #project-name { width: 100%; padding: 10px 12px; min-height: 44px; background: var(--raised); border: 1px solid var(--line-strong); border-radius: 6px; text-align: left; }
  #mobile-project-actions #save-state { display: block; padding-top: 6px; }
}

@media (max-width: 950px) {
  #export-dialog .dialog-heading { padding: 16px 20px; }
  .export-dialog-body { padding: 0 20px 16px; }
  .export-dialog-footer { padding: 14px 20px max(16px, env(safe-area-inset-bottom)); }
}
