.mobile-nav { display: none; }
.mobile-time-panel { display: contents; }
.mobile-video-play { display: none; }
.mobile-video-timeline { display: none; }

@media (max-width: 820px) {
  :root {
    --mobile-topbar: 58px;
    --mobile-toolbar: 46px;
    --mobile-nav-height: 68px;
    --mobile-sheet-height: clamp(220px, 36svh, 320px);
  }

  html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body { background: var(--graphite-green); }

  .app-shell {
    height: 100svh;
    min-height: 0;
    display: grid;
    grid-template-rows: var(--mobile-topbar) minmax(0, 1fr) var(--mobile-nav-height);
  }

  .topbar {
    position: relative;
    z-index: 30;
    top: auto;
    min-height: var(--mobile-topbar);
    height: var(--mobile-topbar);
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }

  .brand { gap: 8px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-mark svg { width: 22px; }
  .brand-copy h1 { max-width: 132px; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
  .brand-copy p { display: none; }
  .top-actions { margin-left: auto; gap: 4px; }
  .top-actions .button { width: 34px; min-height: 34px; padding: 0; }
  .top-actions .button span { display: none; }
  .top-actions .button i { font-size: 18px; }
  #shortcutsButton, #surpriseButton, #presetButton { display: none; }

  .workspace {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: block;
    overflow: hidden;
  }

  .editor {
    position: absolute;
    inset: 0;
    z-index: 1;
    height: auto;
    min-height: 0;
    display: grid;
    grid-template-rows: var(--mobile-toolbar) minmax(0, 1fr);
    border: 0;
    box-shadow: none;
  }

  body.has-media .editor {
    position: absolute;
    top: 0;
    height: auto;
    border: 0;
    box-shadow: none;
  }

  .editor-toolbar {
    position: relative;
    z-index: 2;
    top: auto;
    min-height: var(--mobile-toolbar);
    height: var(--mobile-toolbar);
    padding: 5px 9px;
  }

  .image-meta strong { max-width: 43vw; font-size: 11px; }
  .image-meta span { display: none; }
  .canvas-tools { gap: 3px; }
  .tool-button { min-height: 32px; height: 32px; padding: 0 8px; }
  #fitButton { width: 54px; display: grid; place-items: center; padding: 0; }
  #fitButton span { display: none; }
  #fitButton i { display: block; font-size: 17px; line-height: 1; }
  body.has-video-media .mobile-video-play:not([hidden]) { display: grid; place-items: center; }
  .mobile-video-play i { display: block; line-height: 1; }
  .zoom-value { display: none; }

  .canvas-area {
    position: relative;
    z-index: 1;
    align-self: start;
    width: 100%;
    height: calc(100% - var(--mobile-sheet-height));
    min-height: 0;
    overflow: hidden;
  }

  .dropzone, .webgl-error { inset: 8px; border-radius: 14px; }
  .dropzone { gap: 9px; padding: 24px 16px; }
  .dropzone h2 { font-size: 18px; }
  .dropzone .drop-icon { width: 46px; height: 46px; }
  .format-list { max-width: 32ch; line-height: 1.4; text-align: center; }

  .canvas-view, .canvas-scroller { width: 100%; height: 100%; min-width: 0; min-height: 0; }
  .canvas-scroller,
  body.has-image-media .canvas-scroller,
  body.has-video-media .canvas-scroller { padding: 8px; overflow: hidden; }
  .canvas-stage { max-width: 100%; max-height: 100%; }
  .canvas-scroller canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
  .original-button { bottom: 10px; min-height: 32px; padding: 0 10px; font-size: 10px; }
  body.has-video-media .original-button { bottom: 56px; }
  body.has-video-media .mobile-video-timeline:not([hidden]) {
    position: absolute;
    z-index: 9;
    left: 8px;
    right: 8px;
    bottom: 8px;
    min-height: 40px;
    display: grid;
    grid-template-columns: auto minmax(80px, 1fr) auto;
    align-items: center;
    gap: 7px;
    padding: 6px 8px;
    border: 1px solid var(--line-on-light);
    border-radius: 12px;
    background: color-mix(in srgb, var(--white) 92%, transparent);
    box-shadow: 0 8px 24px rgba(20, 30, 25, .16);
    backdrop-filter: blur(10px);
  }
  body[data-theme="dark"].has-video-media .mobile-video-timeline { border-color: var(--line-on-dark); background: color-mix(in srgb, var(--graphite-green) 92%, transparent); }
  .mobile-timeline-play { width: 30px; min-width: 30px; height: 28px; min-height: 28px; padding: 0; }
  .mobile-timeline-play i { display: block; line-height: 1; }
  .mobile-video-timeline input[type="range"] { width: 100%; min-width: 0; margin: 0; accent-color: var(--moss-green); }
  .mobile-video-timeline .video-time { min-width: 70px; font-size: 9px; }
  .hand-indicator, .point-target { display: none; }

  .panel--left,
  .panel-section--layers,
  .panel-section--parameters,
  .mobile-time-panel {
    position: fixed;
    z-index: 24;
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-height);
    top: auto;
    width: 100%;
    height: var(--mobile-sheet-height);
    max-height: none;
    margin: 0;
    border: 0;
    border-top: 1px solid var(--line-on-light);
    border-radius: 18px 18px 0 0;
    background: var(--white);
    box-shadow: 0 -12px 32px rgba(20, 30, 25, .18);
    overflow: hidden;
  }

  body[data-theme="dark"] .panel--left,
  body[data-theme="dark"] .panel-section--layers,
  body[data-theme="dark"] .panel-section--parameters,
  body[data-theme="dark"] .mobile-time-panel {
    border-color: var(--line-on-dark);
    background: var(--graphite-green);
  }

  .panel--left::before,
  .panel-section--layers::before,
  .panel-section--parameters::before,
  .mobile-time-panel::before {
    content: "";
    position: absolute;
    z-index: 5;
    top: 7px;
    left: 50%;
    width: 38px;
    height: 4px;
    border-radius: var(--r-pill);
    background: var(--line-on-light);
    transform: translateX(-50%);
  }

  body[data-theme="dark"] .panel--left::before,
  body[data-theme="dark"] .panel-section--layers::before,
  body[data-theme="dark"] .panel-section--parameters::before,
  body[data-theme="dark"] .mobile-time-panel::before { background: var(--line-on-dark); }

  body:not([data-mobile-panel="effects"]) .panel--left,
  body:not([data-mobile-panel="layers"]) .panel-section--layers,
  body:not([data-mobile-panel="controls"]) .panel-section--parameters,
  body:not([data-mobile-panel="timeline"]) .mobile-time-panel { display: none !important; }

  .panel { overflow: hidden; }
  .panel--right { display: contents; }
  body.has-media .panel--right { display: contents; }
  body.has-media .panel--left { grid-row: auto; }
  body.has-media .panel-section--layers,
  body.has-media .panel-section--parameters { position: fixed; top: auto; z-index: 24; max-height: none; }

  .panel--left > .panel-section {
    height: 100%;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    padding: 20px 12px 10px;
  }
  .panel--left .section-heading { margin-bottom: 8px; }
  .effect-search { height: 34px; margin-bottom: 8px; }
  .effect-library { min-height: 0; padding-right: 3px; overflow-y: auto; }
  .effect-item { min-height: 46px; }

  .panel-section--layers,
  .panel-section--parameters { min-height: 0; padding: 22px 14px 14px; overflow-y: auto; }
  body.has-media .panel-section--layers { padding: 22px 14px 14px; box-shadow: 0 -12px 32px rgba(20, 30, 25, .18); }
  .panel-section--layers .section-heading,
  .panel-section--parameters > .section-heading {
    position: sticky;
    z-index: 3;
    top: -22px;
    margin: -22px -14px 10px;
    padding: 22px 14px 8px;
    background: var(--white);
  }
  body[data-theme="dark"] .panel-section--layers .section-heading,
  body[data-theme="dark"] .panel-section--parameters > .section-heading { background: var(--graphite-green); }
  .layer-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layer-row { min-width: 0; }
  .empty-panel { min-height: 88px; padding: 14px 10px; }

  .mobile-time-panel {
    display: grid;
    align-content: start;
    gap: 10px;
    padding: 22px 12px 12px;
    overflow-y: auto;
  }
  .mobile-time-panel .keyframe-timeline,
  .mobile-time-panel .video-controls {
    position: static;
    left: auto;
    bottom: auto;
    width: 100%;
    transform: none;
    backdrop-filter: none;
    box-shadow: none;
  }
  .mobile-time-panel .keyframe-timeline { grid-template-columns: auto minmax(80px, 1fr) auto; }
  .mobile-time-panel .timeline-actions { grid-column: 1; grid-row: 1; }
  .mobile-time-panel .timeline-track { grid-column: 2; grid-row: 1; }
  .mobile-time-panel .timeline-time { grid-column: 3; grid-row: 1; min-width: 70px; font-size: 9px; }
  .mobile-time-panel .timeline-duration { grid-column: 1 / -1; grid-row: 2; justify-self: end; }
  .mobile-time-panel .video-controls { grid-template-columns: auto minmax(80px, 1fr) auto; }
  .mobile-time-panel .video-options { gap: 6px; }
  .mobile-time-panel .video-options .video-speed-control { margin-left: 0; }
  .mobile-time-panel .video-range { margin-left: 0; }

  .privacy-footer { display: none; }
  .mobile-nav {
    position: relative;
    z-index: 31;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: var(--mobile-nav-height);
    padding: 5px max(5px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(5px, env(safe-area-inset-left));
    border-top: 1px solid var(--line-on-light);
    background: var(--white);
  }
  body[data-theme="dark"] .mobile-nav { border-color: var(--line-on-dark); background: var(--petroleum-green); }
  .mobile-nav button {
    min-width: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    border: 0;
    border-radius: 10px;
    padding: 3px;
    background: transparent;
    color: var(--fg3);
    font-size: 9px;
    font-weight: 750;
  }
  .mobile-nav button i { font-size: 20px; }
  .mobile-nav button[data-active="true"] { background: var(--graphite-green); color: var(--golden-yellow); }
  body[data-theme="dark"] .mobile-nav button[data-active="true"] { background: var(--golden-yellow); color: var(--graphite-green); }
  .mobile-nav button:disabled { opacity: .32; }

  .notice {
    top: auto;
    bottom: calc(var(--mobile-nav-height) + var(--mobile-sheet-height) + 8px);
    width: max-content;
    height: auto;
    white-space: nowrap;
  }
}

@media (max-width: 560px) {
  :root { --mobile-sheet-height: clamp(216px, 35svh, 294px); }
  .topbar { padding: 8px; }
  .brand-copy h1 { max-width: 112px; font-size: 14px; }
  .layer-list { grid-template-columns: 1fr; }
}

@media (max-width: 370px), (max-height: 690px) {
  :root {
    --mobile-topbar: 54px;
    --mobile-toolbar: 42px;
    --mobile-nav-height: 62px;
    --mobile-sheet-height: 234px;
  }
  .brand-mark { width: 31px; height: 31px; }
  .brand-copy h1 { max-width: 100px; font-size: 13px; }
  .top-actions .button { width: 32px; min-height: 32px; }
  .panel--left,
  .panel-section--layers,
  .panel-section--parameters,
  .mobile-time-panel { border-radius: 14px 14px 0 0; }
}
