@media (max-width: 720px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  body {
    font-size: 15px;
  }

  :is(h1, h2, h3, p, a, label, small, strong, span, code, dd) {
    overflow-wrap: anywhere;
  }

  :is(img, video) {
    max-width: 100%;
  }

  button,
  .result-link,
  .result-fields a:not(.result-link),
  .result-media a:not(.result-link),
  .storyboard-final-link {
    min-height: 44px;
  }

  .app-shell {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      calc(80px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .topbar {
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .topbar-intro {
    min-width: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .brand {
    min-width: 0;
    align-items: flex-start;
    gap: 10px;
  }

  .brand > :last-child {
    min-width: 0;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .brand h1 {
    font-size: 1.16rem;
    line-height: 1.28;
  }

  .brand p:last-child {
    font-size: 0.8rem;
    line-height: 1.5;
  }

  .topbar-actions {
    display: grid;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
  }

  .case-library-entry,
  .api-key-entry {
    width: 100%;
    max-width: none;
    min-width: 0;
    min-height: 48px;
    padding: 6px 8px;
    white-space: normal;
  }

  .case-library-entry span,
  .api-key-entry span {
    min-width: 0;
    font-size: 0.78rem;
    line-height: 1.2;
  }

  .step-tabs {
    display: grid;
    width: 100%;
    min-width: 0;
    grid-template-columns: none;
    grid-auto-columns: 108px;
    grid-auto-flow: column;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1px 1px 6px;
    scroll-padding-inline: 1px;
    scroll-snap-type: x mandatory;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .step-tabs::-webkit-scrollbar {
    display: none;
  }

  .step-tab {
    width: 108px;
    min-width: 108px;
    min-height: 52px;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }

  .workspace {
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding-top: 12px;
  }

  .input-panel,
  .result-panel,
  .campaign-form,
  .field,
  .voice-source-panel,
  .step-results,
  .step-result-card,
  .storyboard-workbench,
  .storyboard-item,
  .result-media,
  .result-fields {
    min-width: 0;
    max-width: 100%;
  }

  .panel-head,
  .campaign-form,
  .result-head,
  .progress-block,
  .endpoint-map {
    padding-right: 12px;
    padding-left: 12px;
  }

  .panel-head,
  .result-head {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .panel-head h2,
  .result-head h2,
  .endpoint-map h2 {
    font-size: 1.24rem;
  }

  .campaign-form {
    gap: 14px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .split-fields,
  .upload-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .upload-grid {
    gap: 10px;
  }

  input[type="text"],
  input[type="password"],
  select,
  textarea {
    min-height: 46px;
    font-size: 16px;
  }

  textarea {
    min-height: 108px;
  }

  #voice-sample {
    min-height: 48px;
    font-size: 0.76rem;
  }

  #voice-sample::file-selector-button {
    min-height: 36px;
  }

  .voice-mode-button,
  .clone-voice-button {
    min-height: 44px;
  }

  .voice-mode-button {
    padding-right: 6px;
    padding-left: 6px;
    font-size: 0.7rem;
  }

  .voice-preset-list {
    max-height: 264px;
    overflow-y: auto;
  }

  .voice-preset-list > span {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .voice-grid {
    gap: 6px;
    scroll-snap-type: x proximity;
  }

  .voice-option {
    width: 64px;
    min-width: 64px;
    min-height: 64px;
    scroll-snap-align: start;
  }

  .voice-preview-button {
    top: 2px;
    right: 2px;
    width: 24px;
    height: 24px;
    min-height: 24px;
  }

  .voice-preview-button::after {
    content: "";
    position: absolute;
    inset: -10px;
  }

  .dropzone {
    min-height: 152px;
  }

  .dropzone label {
    min-height: 150px;
    padding: 14px 10px;
  }

  #product-drop .preview-strip,
  #product-drop .preview-strip.has-preview {
    width: 100%;
    max-width: 344px;
    justify-self: center;
  }

  #model-drop .preview-strip,
  #model-drop .preview-strip.single,
  #model-drop .preview-strip.has-preview {
    width: min(100%, 210px);
    justify-self: center;
  }

  #model-drop .preview-card img,
  #model-drop .preview-strip > img {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
  }

  .range-field input[type="range"],
  .storyboard-count-field input[type="range"],
  input#storyboard-count {
    height: 44px;
  }

  .primary-action {
    width: 100%;
    min-height: 56px;
  }

  .progress-block {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .status-line {
    gap: 10px;
  }

  .status-line strong {
    min-width: 0;
  }

  .status-line span {
    min-width: 104px;
    min-height: 48px;
    flex: 0 0 auto;
    padding: 0 14px;
    font-size: 1.78rem;
  }

  .api-status {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    margin: 0 12px 12px;
    padding: 12px;
  }

  .api-status > span {
    width: fit-content;
  }

  .pipeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 0 12px 14px;
  }

  .pipeline-step {
    min-height: 88px;
    padding: 10px 10px 14px;
  }

  .pipeline-step h3 {
    margin: 7px 0 0;
    font-size: 0.9rem;
  }

  .pipeline-step p {
    display: none;
  }

  .pipeline-step:has(:is(.step-percent, .pipeline-percent, .step-result-percent)) {
    padding-right: 58px;
  }

  .pipeline-step :is(.step-percent, .pipeline-percent, .step-result-percent) {
    top: 9px;
    right: 8px;
  }

  .workflow-results,
  .step-results,
  .storyboard-workbench {
    gap: 10px;
    margin-right: 12px;
    margin-left: 12px;
    padding: 10px;
  }

  .step-result-card .storyboard-workbench {
    margin-right: 0;
    margin-left: 0;
  }

  .step-result-card,
  .step-result-card:has(.result-media > :only-child),
  .step-result-card:has(.result-media > :nth-child(2)):not(:has(.result-media > :nth-child(3))),
  .step-result-card:has(.result-media) {
    grid-template-columns: minmax(0, 1fr);
  }

  .step-result-card {
    gap: 10px;
    padding: 11px;
  }

  .step-result-card:has(:is(.step-percent, .pipeline-percent, .step-result-percent)) {
    padding-right: 11px;
  }

  .step-result-card > :is(.step-percent, .pipeline-percent, .step-result-percent) {
    right: 11px;
  }

  .step-result-card::after {
    top: auto;
    right: 11px;
    bottom: 11px;
  }

  .step-result-head {
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px;
  }

  .step-result-head > div:first-child {
    flex: 1 1 160px;
  }

  .step-result-status {
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .step-percent,
  .pipeline-percent,
  .step-result-percent {
    min-width: 54px;
    min-height: 32px;
    font-size: 0.82rem;
  }

  .result-media,
  .result-fields,
  .shot-gallery-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-media img,
  .result-media video {
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 68dvh;
    object-fit: contain;
  }

  .result-media.has-final-video {
    grid-template-columns: minmax(0, min(100%, 280px));
    justify-content: center;
  }

  .result-video-card,
  .result-video-card.is-final {
    width: min(100%, 280px);
    max-width: 280px;
    justify-self: center;
  }

  .result-video-player,
  .result-media.has-final-video video.result-video-player {
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: min(70dvh, 500px);
    aspect-ratio: 9 / 16;
    object-fit: contain;
  }

  .result-link,
  .result-fields a:not(.result-link),
  .result-media a:not(.result-link) {
    width: 100%;
    justify-content: space-between;
    white-space: normal;
  }

  .storyboard-workbench.is-script-only,
  .storyboard-workbench.has-inline-shots,
  .storyboard-workbench.has-inline-shots .storyboard-item,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(:is(.storyboard-shot-image, .storyboard-shot-empty, .storyboard-inline-preview, .storyboard-inline-empty, .storyboard-item-media)),
  .storyboard-item:has(:is(.storyboard-shot-image, .storyboard-shot-empty)) {
    grid-template-columns: minmax(0, 1fr);
  }

  .storyboard-workbench.has-inline-shots .storyboard-item,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(:is(.storyboard-shot-image, .storyboard-shot-empty, .storyboard-inline-preview, .storyboard-inline-empty, .storyboard-item-media)) {
    gap: 10px;
    padding: 10px;
  }

  .storyboard-workbench.has-inline-shots .storyboard-shot-title,
  .storyboard-workbench.has-inline-shots .storyboard-fields,
  .storyboard-workbench.has-inline-shots .storyboard-controls,
  .storyboard-workbench.has-inline-shots .storyboard-item-media,
  .storyboard-workbench.has-inline-shots .storyboard-item-video,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) .storyboard-shot-title,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) .storyboard-fields,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) .storyboard-controls,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) :is(.storyboard-shot-image, .storyboard-shot-empty, .storyboard-item-media),
  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) .storyboard-item-video,
  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) > :is(.storyboard-inline-preview, .storyboard-inline-empty, .storyboard-inline-actions, .storyboard-video-preview, .storyboard-video-empty, .storyboard-video-actions),
  .storyboard-workbench.has-inline-shots .storyboard-item > :is(.storyboard-inline-preview, .storyboard-inline-empty, .storyboard-inline-actions, .storyboard-video-preview, .storyboard-video-empty, .storyboard-video-actions),
  .storyboard-shot-image,
  .storyboard-shot-empty,
  .storyboard-flow-arrow,
  .storyboard-item-media,
  .storyboard-item-video {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .storyboard-shot-title {
    min-height: 32px;
    flex-wrap: wrap;
    white-space: normal;
  }

  .storyboard-shot-title .storyboard-progress-mini {
    flex: 1 1 100%;
  }

  .storyboard-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .storyboard-field:has(textarea) {
    grid-column: auto;
  }

  .storyboard-field textarea,
  .storyboard-field input {
    min-height: 44px;
    font-size: 16px;
  }

  .storyboard-field textarea,
  .storyboard-workbench.has-inline-shots .storyboard-field textarea {
    min-height: 96px;
  }

  .storyboard-actions,
  .storyboard-controls,
  .storyboard-inline-actions,
  .storyboard-video-actions,
  .storyboard-final-actions,
  .shot-gallery-actions {
    justify-content: flex-start;
  }

  .storyboard-button,
  .storyboard-button.primary,
  .storyboard-inline-actions .storyboard-button,
  .storyboard-video-actions .storyboard-button,
  .shot-gallery-actions .storyboard-button,
  .storyboard-final-link {
    min-height: 44px;
  }

  .storyboard-inline-actions,
  .storyboard-video-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .storyboard-flow-arrow {
    min-height: 38px;
  }

  .storyboard-workbench.has-inline-shots .storyboard-item:has(.storyboard-shot-title) .storyboard-flow-arrow {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .storyboard-flow-arrow::before {
    content: "\2193";
    width: 34px;
    height: 34px;
  }

  .storyboard-workbench.has-inline-shots .storyboard-shot-image,
  .storyboard-workbench.has-inline-shots .storyboard-shot-empty,
  .storyboard-workbench.has-inline-shots .storyboard-inline-preview,
  .storyboard-workbench.has-inline-shots .storyboard-video-preview,
  .storyboard-workbench.has-inline-shots .storyboard-inline-empty,
  .storyboard-workbench.has-inline-shots .storyboard-video-empty,
  .storyboard-workbench.has-inline-shots .storyboard-item-media,
  .storyboard-workbench.has-inline-shots .storyboard-item-video {
    width: min(100%, 250px);
    min-height: 0;
    justify-self: center;
  }

  .storyboard-workbench.has-inline-shots .storyboard-shot-image,
  .storyboard-workbench.has-inline-shots .storyboard-shot-empty,
  .storyboard-workbench.has-inline-shots .storyboard-inline-preview,
  .storyboard-workbench.has-inline-shots .storyboard-video-preview,
  .storyboard-workbench.has-inline-shots .storyboard-inline-empty,
  .storyboard-workbench.has-inline-shots .storyboard-video-empty,
  .storyboard-workbench.has-inline-shots img.storyboard-shot-image,
  .storyboard-workbench.has-inline-shots .storyboard-shot-image img,
  .storyboard-workbench.has-inline-shots img.storyboard-inline-preview,
  .storyboard-workbench.has-inline-shots .storyboard-inline-preview img,
  .storyboard-workbench.has-inline-shots video.storyboard-video-preview,
  .storyboard-workbench.has-inline-shots .storyboard-video-preview video {
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: min(70dvh, 445px);
    aspect-ratio: 9 / 16;
    object-fit: contain;
  }

  .storyboard-workbench.has-inline-shots .storyboard-inline-actions,
  .storyboard-workbench.has-inline-shots .storyboard-video-actions {
    width: min(100%, 250px);
    justify-self: center;
  }

  .shot-gallery-card :is(img, .storyboard-shot-image) {
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 68dvh;
    object-fit: contain;
  }

  .case-save-fab {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    min-height: 48px;
    max-width: calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    padding: 0 15px;
  }

  .case-library-overlay,
  .case-save-auth-overlay,
  .api-key-overlay {
    align-items: end;
    justify-items: stretch;
    padding:
      max(8px, env(safe-area-inset-top))
      env(safe-area-inset-right)
      0
      env(safe-area-inset-left);
  }

  .case-library-drawer,
  .case-save-auth-dialog,
  .api-key-dialog {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)));
    margin: 0;
    border-radius: 8px 8px 0 0;
  }

  .case-library-drawer {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .case-library-head,
  .case-library-actions,
  .case-library-body,
  .case-save-auth-head,
  .case-save-auth-form,
  .api-key-head,
  .api-key-form {
    padding-right: 12px;
    padding-left: 12px;
  }

  .case-library-head,
  .case-save-auth-head,
  .api-key-head {
    gap: 10px;
    padding-top: 14px;
    padding-bottom: 12px;
  }

  .case-library-close,
  .api-key-close,
  .image-lightbox-close {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .case-library-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .case-demo-button,
  .case-card button,
  .case-save-auth-actions button,
  .case-save-auth-form input,
  .api-key-save {
    min-height: 44px;
  }

  .case-library-body {
    min-height: 0;
    max-height: none;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .case-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .case-card-cover {
    width: min(100%, 220px);
    min-height: 0;
  }

  .case-save-auth-dialog,
  .api-key-dialog {
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .case-save-auth-form,
  .api-key-form {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .image-lightbox {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .image-lightbox-panel {
    width: 100%;
    max-height: calc(100dvh - max(20px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  }

  .image-lightbox img {
    width: 100%;
    height: auto;
    max-height: calc(100dvh - 110px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    object-fit: contain;
  }
}

@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .step-tabs,
  .voice-grid {
    scroll-behavior: auto;
  }

  .case-save-fab,
  .step-tab,
  .voice-option,
  .result-image-card,
  .storyboard-inline-preview,
  .storyboard-video-preview {
    transition: none;
  }
}
