.mobile-nav,
.mobile-video-play { 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; }
  .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; display: grid; }
  .brand-mark img { width: 22px; }
  .brand-copy { display: grid; }
  .brand-copy strong { max-width: 128px; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
  .brand-copy small { display: none; }
  .top-actions { margin-left: auto; gap: 4px; }
  #saveRecipeButton, #importRecipeButton, #batchButton { display: none; }
  .top-actions .button, .top-actions .icon-button { width: 34px; min-width: 34px; height: 34px; min-height: 34px; padding: 0; }
  .top-actions .button { gap: 0; font-size: 0; }
  .top-actions .button span { width: 100%; height: 100%; display: grid; place-items: center; font-size: 24px; line-height: 1; }
  .top-actions .icon-button { font-size: 18px; }

  .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;
    background: var(--mist);
  }
  .editor-toolbar { position: relative; z-index: 4; min-height: var(--mobile-toolbar); height: var(--mobile-toolbar); gap: 7px; padding: 5px 9px; }
  .media-info strong { max-width: 40vw; font-size: 11px; }
  .media-info span { display: none; }
  .editor-actions { gap: 4px; }
  .editor-actions .tool-button { min-height: 32px; height: 32px; padding: 0 9px; }
  #originalButton { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #removeButton { width: 32px; min-width: 32px; padding: 0; }
  body.has-video-media .mobile-video-play:not([hidden]) {
    width: 32px;
    min-width: 32px;
    display: grid;
    place-items: center;
    padding: 0;
    border-color: var(--gold-dark);
    background: color-mix(in srgb, var(--gold) 18%, var(--white));
  }
  .mobile-video-play span { display: block; font-size: 12px; line-height: 1; }

  .stage-wrap { position: relative; z-index: 1; align-self: start; width: 100%; height: calc(100% - var(--mobile-sheet-height)); min-height: 0; padding: 8px; overflow: hidden; }
  .dropzone { width: min(92%, 440px); min-height: 0; height: calc(100% - 4px); gap: 7px; padding: 22px 16px; border-radius: 14px; }
  .drop-icon { width: 46px; height: 46px; font-size: 24px; }
  .dropzone strong { font-size: 17px; text-align: center; }
  .dropzone small { max-width: 31ch; line-height: 1.4; text-align: center; }
  .canvas-shell { width: 100%; height: 100%; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; display: grid; place-items: center; overflow: hidden; box-shadow: none; }
  .canvas-shell[hidden] { display: none; }
  .canvas-shell canvas { width: auto; height: auto; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; }

  .video-controls {
    position: absolute;
    z-index: 5;
    left: 8px;
    right: 8px;
    bottom: calc(var(--mobile-sheet-height) + 8px);
    min-height: 40px;
    display: grid;
    grid-template-columns: auto minmax(80px, 1fr) auto;
    gap: 7px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--white) 92%, transparent);
    box-shadow: 0 8px 24px rgba(20, 30, 25, .15);
    backdrop-filter: blur(10px);
  }
  .video-controls .check-label { display: none; }
  .video-controls #playButton { width: 32px; min-width: 32px; height: 28px; min-height: 28px; padding: 0; }
  .video-controls #playLabel { display: none; }
  .video-controls #playIcon { display: block; font-size: 11px; line-height: 1; }
  .video-time { min-width: 72px; font-size: 9px; }

  .panel--left,
  .stack-section,
  .parameters-section,
  .keyframes-section {
    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);
    border-radius: 18px 18px 0 0;
    background: var(--white);
    box-shadow: 0 -12px 32px rgba(20, 30, 25, .18);
    overflow: auto;
  }
  .panel--left::before,
  .stack-section::before,
  .parameters-section::before,
  .keyframes-section::before {
    content: "";
    position: absolute;
    z-index: 5;
    top: 7px;
    left: 50%;
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    transform: translateX(-50%);
  }
  body:not([data-mobile-panel="effects"]) .panel--left,
  body:not([data-mobile-panel="stack"]) .stack-section,
  body:not([data-mobile-panel="controls"]) .parameters-section,
  body:not([data-mobile-panel="keyframes"]) .keyframes-section { display: none !important; }

  .panel--right { display: contents; }
  .panel--left { padding-top: 10px; }
  .panel--left .presets-section,
  .panel--left .library-section { padding: 12px; }
  .panel--left .presets-section { padding-top: 12px; }
  .panel--left .section-heading { margin-bottom: 8px; }
  .preset-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-wrap { height: 34px; margin-bottom: 8px; }
  .video-note { margin-bottom: 8px; padding: 6px 8px; }
  .effect-library { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 10px; }
  .effect-category + .effect-category { border-top: 0; padding-top: 0; }
  .effect-item { min-height: 46px; }

  .stack-section,
  .parameters-section,
  .keyframes-section { padding: 22px 14px 14px; }
  .stack-section .section-heading,
  .parameters-section > .section-heading,
  .keyframes-section > .section-heading {
    position: sticky;
    z-index: 3;
    top: -22px;
    margin: -22px -14px 10px;
    padding: 22px 14px 8px;
    background: var(--white);
  }
  .empty-parameters { min-height: 100px; }
  .effect-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stack-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stack-actions .tool-button:first-child { grid-column: auto; }
  .stack-actions .tool-button { min-width: 0; padding: 0 7px; font-size: 9px; }

  .statusbar { 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);
    background: var(--white);
  }
  .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(--text-3); font-size: 9px; font-weight: 750; }
  .mobile-nav-icon { font-size: 18px; line-height: 1; }
  .mobile-nav button[data-active="true"] { background: var(--petroleum); color: var(--gold); }
  body[data-theme="dark"] .mobile-nav button[data-active="true"] { background: var(--gold); color: #141e19; }
  .mobile-nav button:disabled { opacity: .32; }

  .notice { right: auto; left: 50%; bottom: calc(var(--mobile-nav-height) + var(--mobile-sheet-height) + 8px); width: max-content; max-width: calc(100vw - 32px); height: auto; transform: translate(-50%, 12px); text-align: center; white-space: nowrap; }
  .notice[data-visible="true"] { transform: translate(-50%, 0); }
}

@media (max-width: 560px) {
  :root { --mobile-sheet-height: clamp(216px, 35svh, 294px); }
  .topbar { padding: 8px; }
  .brand-copy strong { max-width: 110px; font-size: 14px; }
  .effect-library, .preset-library { grid-template-columns: 1fr; }
  .effect-stack { 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 strong { max-width: 96px; font-size: 13px; }
  .top-actions .button, .top-actions .icon-button { width: 32px; min-width: 32px; height: 32px; min-height: 32px; }
  .panel--left, .stack-section, .parameters-section, .keyframes-section { border-radius: 14px 14px 0 0; }
  #originalButton { max-width: 74px; }
}
