/* 网页版窄屏适配。桌面布局继续由 editor.css 控制。 */
.mobile-export-button {
  display: none;
}

.mobile-tool-sheet-close,
.mobile-inline-text-actions,
.mobile-edit-text-button,
.mobile-text-preview,
.mobile-canvas-actions {
  display: none;
}

@media (max-width: 720px) {
  html,
  body,
  .app-shell,
  .workspace {
    overscroll-behavior-x: none;
  }

  html,
  body {
    /* iOS may ignore user-scalable=no; manipulation independently disables
       double-tap page zoom while keeping ordinary one-finger scrolling. */
    touch-action: manipulation;
  }

  .canvas-pane,
  .canvas-viewport,
  .canvas-stage {
    overscroll-behavior: none;
    touch-action: none;
  }

  .toolrail,
  .inspector-scroll {
    overscroll-behavior-x: contain;
    touch-action: pan-x;
  }

  .activation-gate {
    min-width: 0;
    padding: 18px 12px;
  }

  .activation-card {
    padding: 24px 18px 20px;
    border-radius: 16px;
  }

  .activation-heading {
    margin: 24px 0;
  }

  .activation-heading h1 {
    font-size: 23px;
  }

  .activation-copy-row {
    grid-template-columns: 1fr;
  }

  .activation-secondary-button {
    min-height: 40px;
  }

  .activation-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .app-shell {
    height: 100dvh;
    min-width: 0;
    min-height: 0;
  }

  .topbar {
    display: grid;
    height: 108px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: 38px 42px;
    gap: 10px 8px;
    padding: 10px 12px 8px;
  }

  .brand {
    gap: 8px;
    min-width: 0;
  }

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

  .brand h1 {
    font-size: 15px;
  }

  .history-actions {
    display: flex;
    grid-column: 2;
    grid-row: 1;
    gap: 2px;
  }

  .history-actions .command-button {
    width: 32px;
    min-width: 32px;
    min-height: 32px;
    justify-content: center;
    padding: 0;
    border-radius: 6px;
    color: #777b82;
  }

  .history-actions .command-button svg {
    width: 20px;
    height: 20px;
  }

  .history-actions .command-button span,
  .history-actions .command-button kbd,
  .history-actions .command-divider,
  .history-actions #resetButton {
    display: none;
  }

  .mobile-export-button {
    display: inline-flex;
    min-width: 58px;
    min-height: 32px;
    grid-column: 3;
    grid-row: 1;
    align-items: center;
    justify-content: center;
    justify-self: end;
    padding: 0 14px;
    border: 0;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-export-button:disabled {
    background: #dadce0;
    color: #999da4;
  }

  .command-button {
    min-width: 34px;
    min-height: 34px;
  }

  .mode-switch {
    position: static;
    display: grid;
    width: 100%;
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0;
    transform: none;
  }

  .mode-choice {
    min-width: 0;
    padding: 0 5px;
    font-size: 11px;
  }

  .workspace {
    height: calc(100dvh - 108px);
    min-height: calc(100dvh - 108px);
  }

  .toolrail {
    order: 3;
    width: 100%;
    min-height: 74px;
    flex: 0 0 74px;
    gap: 4px;
    padding: 7px 8px;
    border-top: 1px solid var(--line);
    border-bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  #selectTool {
    order: -2;
  }

  #chooseTool {
    order: -3;
  }

  #blurTool {
    order: -1;
  }

  body.select-tool-active .inspector {
    display: none;
    min-height: 0;
    flex-basis: 0;
  }

  .tool-button {
    min-width: 72px;
    min-height: 58px;
    flex: 0 0 72px;
    flex-direction: column;
    gap: 3px;
    padding: 5px 4px;
    font-size: 10px;
  }

  .free-collage-controls {
    min-width: 150px;
    flex: 0 0 150px;
    padding: 5px 8px;
  }

  .canvas-pane {
    order: 1;
    min-height: 0;
    flex: 1 1 auto;
  }

  .canvas-viewport {
    background-color: #303133;
    background-image: none;
  }

  .canvas-stage {
    padding: 12px;
  }

  .empty-state {
    width: calc(100% - 24px);
    min-height: 270px;
    padding: 28px 18px;
    border-radius: 14px;
  }

  .empty-visual {
    width: 58px;
    height: 58px;
    margin-bottom: 17px;
  }

  .empty-state h2 {
    font-size: 18px;
  }

  .empty-state p {
    margin-bottom: 18px;
    font-size: 12px;
  }

  .zoom-bar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 3px;
    padding: 0 10px;
  }

  .annotation-status {
    display: none;
  }

  .zoom-controls button {
    width: 30px;
  }

  .zoom-controls .zoom-value {
    width: 48px;
  }

  .inspector {
    position: relative;
    order: 2;
    display: none;
    min-width: 0;
    flex-direction: column;
  }

  .inspector-scroll {
    display: block;
  }

  .inspector-section {
    border-right: 0;
    padding: 20px 18px;
  }

  .export-area,
  .collage-actions {
    min-height: 0;
    padding: 18px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .canvas-pane {
    flex-basis: 0;
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .inspector {
    display: flex;
    min-height: 0;
    max-height: min(34dvh, 270px);
    flex: 0 0 min(34dvh, 270px);
    border-top: 1px solid var(--line);
    border-left: 0;
    background: rgba(255, 255, 255, 0.98);
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .inspector-scroll {
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .inspector-scroll > .inspector-section:first-child,
  body.mobile-tool-options-open:not(.mobile-settings-open) .shortcut-section,
  body.mobile-tool-options-open:not(.mobile-settings-open) .export-area,
  body.mobile-tool-options-open:not(.mobile-settings-open) .collage-actions {
    display: none;
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .tool-settings:not(.is-hidden) {
    display: block;
    padding: 15px 52px 16px 16px;
    border: 0;
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .tool-settings h3 {
    margin-bottom: 9px;
    font-size: 13px;
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .tool-help {
    font-size: 10px;
    line-height: 1.5;
  }

  .mobile-tool-sheet-close {
    position: absolute;
    z-index: 3;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    color: #52565c;
    font-size: 20px;
    line-height: 1;
  }

  body.mobile-tool-options-open:not(.mobile-settings-open) .mobile-tool-sheet-close {
    display: inline-flex;
  }

  .mobile-edit-text-button {
    display: flex;
    width: 100%;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    margin-top: 12px;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-edit-text-button[disabled] {
    background: #eceef1;
    color: #969ba3;
  }

  body:not(.mobile-settings-open) {
    height: 100dvh;
    overflow: hidden;
  }

  body.mobile-settings-open {
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.mobile-settings-open .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  body.mobile-settings-open .workspace {
    display: block;
    height: auto;
    min-height: calc(100dvh - 108px);
  }

  body.mobile-settings-open .toolrail,
  body.mobile-settings-open .canvas-pane {
    display: none;
  }

  body.mobile-settings-open .inspector {
    display: flex;
    min-height: calc(100dvh - 108px);
    max-height: none;
  }

  #editorCanvas.is-touch-gesturing {
    cursor: grabbing;
  }

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

  /* 手机编辑器采用“参数条 + 主工具条”两排固定底栏，画布占满剩余空间。 */
  .topbar {
    height: 88px;
    grid-template-rows: 32px 34px;
    gap: 4px 8px;
    padding: 7px 10px 6px;
  }

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

  .history-actions {
    gap: 2px;
  }

  .command-button {
    min-width: 32px;
    min-height: 32px;
  }

  .mode-choice {
    min-height: 34px;
    font-size: 10px;
  }

  .workspace {
    height: calc(100dvh - 88px);
    min-height: calc(100dvh - 88px);
  }

  .canvas-pane,
  body.mobile-tool-options-open:not(.mobile-settings-open) .canvas-pane {
    order: 1;
    min-height: 0;
    flex: 1 1 auto;
    grid-template-rows: minmax(0, 1fr);
  }

  .canvas-pane.has-batch {
    grid-template-rows: 92px minmax(0, 1fr);
  }

  .canvas-stage {
    padding: 8px;
  }

  .zoom-bar {
    position: absolute;
    z-index: 8;
    right: 8px;
    bottom: 8px;
    left: 8px;
    height: 36px;
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  .file-status {
    display: none;
  }

  #fileStatus {
    display: none;
  }

  .zoom-controls {
    position: absolute;
    right: 112px;
    bottom: 44px;
    pointer-events: auto;
  }

  .zoom-controls #zoomOutButton,
  .zoom-controls #zoomInButton,
  .zoom-controls #fitButton {
    display: none;
  }

  .zoom-controls .zoom-value {
    width: auto;
    min-width: 44px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px;
    background: rgba(20, 21, 23, 0.8);
    color: #fff;
    font-size: 10px;
    backdrop-filter: blur(8px);
  }

  body:not(.mobile-settings-open) .inspector,
  body.mobile-tool-options-open:not(.mobile-settings-open) .inspector {
    position: relative;
    order: 2;
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 62px;
    max-height: 62px;
    flex: 0 0 62px;
    overflow: hidden;
    border-top: 1px solid var(--line);
    border-left: 0;
    background: rgba(255, 255, 255, 0.98);
  }

  body:not(.mobile-settings-open) .inspector-scroll,
  body.mobile-tool-options-open:not(.mobile-settings-open) .inspector-scroll {
    display: block;
    width: 100%;
    height: 62px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  body:not(.mobile-settings-open) .inspector-scroll::-webkit-scrollbar {
    display: none;
  }

  body:not(.mobile-settings-open) .inspector-scroll > .inspector-section:first-child,
  body:not(.mobile-settings-open) .shortcut-section,
  body:not(.mobile-settings-open) .export-area,
  body:not(.mobile-settings-open) .collage-actions,
  body:not(.mobile-settings-open) .mobile-tool-sheet-close,
  body.mobile-tool-options-open:not(.mobile-settings-open) .inspector-scroll > .inspector-section:first-child,
  body.mobile-tool-options-open:not(.mobile-settings-open) .shortcut-section,
  body.mobile-tool-options-open:not(.mobile-settings-open) .export-area,
  body.mobile-tool-options-open:not(.mobile-settings-open) .collage-actions,
  body.mobile-tool-options-open:not(.mobile-settings-open) .mobile-tool-sheet-close {
    display: none;
  }

  body:not(.mobile-settings-open) .tool-settings:not(.is-hidden),
  body.mobile-tool-options-open:not(.mobile-settings-open) .tool-settings:not(.is-hidden) {
    box-sizing: border-box;
    display: flex;
    width: max-content;
    min-width: 100%;
    height: 62px;
    align-items: center;
    gap: 9px;
    padding: 6px 9px;
    border: 0;
    white-space: nowrap;
  }

  body:not(.mobile-settings-open) .tool-settings h3,
  body:not(.mobile-settings-open) .tool-help,
  body.mobile-tool-options-open:not(.mobile-settings-open) .tool-settings h3,
  body.mobile-tool-options-open:not(.mobile-settings-open) .tool-help,
  body:not(.mobile-settings-open) .highlight-control-label,
  body:not(.mobile-settings-open) .privacy-control-label,
  body:not(.mobile-settings-open) .arrow-preview {
    display: none;
  }

  body:not(.mobile-settings-open) .highlight-control-group,
  body:not(.mobile-settings-open) .privacy-control-group,
  body:not(.mobile-settings-open) .text-style-control,
  body:not(.mobile-settings-open) .highlight-style-grid,
  body:not(.mobile-settings-open) .arrow-style-grid,
  body:not(.mobile-settings-open) .text-style-grid,
  body:not(.mobile-settings-open) .privacy-choice-grid,
  body:not(.mobile-settings-open) .highlight-color-grid,
  body:not(.mobile-settings-open) .crop-presets,
  body:not(.mobile-settings-open) .crop-actions {
    display: flex;
    width: max-content;
    align-items: center;
    gap: 6px;
    margin: 0;
  }

  body:not(.mobile-settings-open) .highlight-color-grid {
    padding: 0 4px;
  }

  body:not(.mobile-settings-open) .highlight-color-choice {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
  }

  body:not(.mobile-settings-open) .highlight-style-choice,
  body:not(.mobile-settings-open) .text-style-choice {
    min-width: 48px;
    min-height: 48px;
    flex: 0 0 48px;
    gap: 2px;
    padding: 3px 2px;
    border: 0;
    border-radius: 8px;
    font-size: 8px;
  }

  body:not(.mobile-settings-open) .highlight-style-choice i {
    width: 27px;
    height: 18px;
  }

  body:not(.mobile-settings-open) .arrow-style-choice {
    min-width: 66px;
    min-height: 48px;
    flex: 0 0 66px;
    gap: 1px;
    padding: 3px 2px;
    border: 0;
    border-radius: 8px;
    font-size: 8px;
  }

  body:not(.mobile-settings-open) .arrow-style-choice svg {
    width: 56px;
    height: 24px;
  }

  body:not(.mobile-settings-open) .privacy-choice {
    min-width: 68px;
    min-height: 42px;
    flex: 0 0 auto;
    border-radius: 8px;
    font-size: 9px;
  }

  body:not(.mobile-settings-open) .privacy-effect-choice {
    width: 58px;
    min-width: 58px;
    min-height: 50px;
    flex: 0 0 58px;
    gap: 2px;
    padding: 2px 3px;
  }

  body:not(.mobile-settings-open) .privacy-effect-choice img {
    width: 34px;
    height: 34px;
    border-radius: 5px;
  }

  body:not(.mobile-settings-open) .privacy-effect-choice span {
    font-size: 7px;
    line-height: 1;
  }

  body:not(.mobile-settings-open) .range-field {
    display: grid;
    width: 142px;
    min-width: 142px;
    grid-template-columns: 45px 92px;
    align-items: center;
    gap: 5px;
    margin: 0;
  }

  body:not(.mobile-settings-open) .range-field > span {
    display: block;
    margin: 0;
    font-size: 8px;
    line-height: 1.25;
  }

  body:not(.mobile-settings-open) .range-field b,
  body:not(.mobile-settings-open) .range-field output {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body:not(.mobile-settings-open) .range-field input[type="range"] {
    width: 92px;
    min-height: 34px;
  }

  body:not(.mobile-settings-open) .mobile-mask-opacity-field {
    display: grid;
    width: 178px;
    min-width: 178px;
    grid-template-columns: 72px 100px;
    order: -1;
  }

  body:not(.mobile-settings-open) .mobile-mask-opacity-field input[type="range"] {
    width: 100px;
  }

  /* 高亮框手机参数条：遮罩 → 框类型 → 颜色 → 线条粗细。 */
  body:not(.mobile-settings-open) #highlightSettings > .mobile-mask-opacity-field {
    order: -3;
  }

  body:not(.mobile-settings-open) #highlightSettings > .highlight-style-grid {
    order: -2;
  }

  body:not(.mobile-settings-open) #highlightSettings > .highlight-control-group {
    order: -1;
  }

  body:not(.mobile-settings-open) .mobile-edit-text-button,
  body:not(.mobile-settings-open) .arrow-straighten-button,
  body:not(.mobile-settings-open) .crop-reset-button,
  body:not(.mobile-settings-open) .crop-actions button,
  body:not(.mobile-settings-open) .note-step,
  body:not(.mobile-settings-open) .crop-readout {
    width: auto;
    min-width: 74px;
    min-height: 42px;
    flex: 0 0 auto;
    margin: 0;
    padding: 0 8px;
    border-radius: 8px;
    font-size: 9px;
  }

  .toolrail {
    order: 3;
    width: 100%;
    min-height: calc(62px + env(safe-area-inset-bottom, 0px));
    flex: 0 0 calc(62px + env(safe-area-inset-bottom, 0px));
    gap: 2px;
    padding: 4px 4px env(safe-area-inset-bottom, 0px);
    border-top: 1px solid var(--line);
    border-bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .toolrail::-webkit-scrollbar {
    display: none;
  }

  .tool-button {
    min-width: 56px;
    min-height: 54px;
    flex: 0 0 56px;
    scroll-snap-align: start;
    flex-direction: column;
    gap: 2px;
    padding: 4px 2px;
    border-radius: 9px;
    font-size: 9px;
  }

  .tool-button.is-active {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .tool-icon,
  .tool-icon svg {
    width: 22px;
    height: 22px;
  }

  .mobile-canvas-actions {
    position: absolute;
    z-index: 9;
    right: 12px;
    bottom: 52px;
    display: flex;
    gap: 7px;
  }

  .mobile-canvas-actions button {
    min-width: 44px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px;
    background: rgba(20, 21, 23, 0.8);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    backdrop-filter: blur(8px);
  }

  .mobile-canvas-actions button:disabled {
    opacity: 0.32;
  }

  #mobileDeleteButton:not(:disabled) {
    background: rgba(255, 57, 65, 0.9);
  }

  body.select-tool-active:not(.mobile-settings-open) .inspector {
    display: none !important;
    min-height: 0;
    flex: 0 0 0;
    border: 0;
  }
}
body.apple-photo-save-open {
  overflow: hidden;
}

.apple-photo-save-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: rgba(18, 19, 21, 0.98);
  color: #fff;
}

.apple-photo-save-header,
.apple-photo-save-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(29, 30, 33, 0.98);
}

.apple-photo-save-header strong {
  display: block;
  font-size: 18px;
}

.apple-photo-save-header p,
.apple-photo-save-footer span {
  margin: 4px 0 0;
  color: #b8bbc2;
  font-size: 12px;
}

.apple-photo-save-header button,
.apple-photo-save-actions button {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: #ff3941;
  color: #fff;
  font: inherit;
  font-weight: 700;
}

.apple-photo-save-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
}

.apple-photo-save-actions .apple-photo-download-button {
  background: #3a3b40;
  font-size: 13px;
}

.apple-photo-save-actions .apple-photo-share-button {
  background: #ff3941;
}

.apple-photo-save-stage {
  display: grid;
  min-height: 0;
  padding: 18px;
  place-items: center;
  overflow: auto;
  overscroll-behavior: contain;
}

.apple-photo-save-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.42);
  touch-action: auto;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

@media (max-width: 720px) {
  .apple-photo-save-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .apple-photo-save-footer span {
    margin: 0;
    text-align: center;
  }

  .apple-photo-save-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
