/* Touch controls also apply to tablets that retain the desktop layout. */
@media (pointer: coarse), (max-width: 800px) {
  button, summary, .photo { touch-action: manipulation; }
  .primary, .tabs button, .button-row button, .template, .add-more,
  .selection-tools button, .editor-bar button, .close, summary { min-height: 44px; }
  .editor-bar button, .close { min-width: 44px; }
  .tabs button, .button-row button, .template, .selection-tools button { font-size: 13px; }
  .photo input { width: 44px; height: 44px; top: 4px; left: 4px; appearance: none; border: 0; background: transparent; cursor: pointer; }
  .photo input::before { content: ''; position: absolute; inset: 10px; border: 2px solid #607353; border-radius: 5px; background: #fff; }
  .photo input:checked::before { background: #365744; border-color: #365744; }
  .photo input:checked::after { content: '✓'; position: absolute; inset: 10px; color: white; text-align: center; line-height: 24px; font-size: 18px; }
  .photo .remove { opacity: 1; width: 44px; height: 44px; top: 4px; right: 4px; font-size: 24px; background: #fffffff2; }
  input[type=range] { appearance: none; -webkit-appearance: none; height: 44px; margin: 4px 0 0; background: transparent; touch-action: pan-y; }
  input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 8px; background: #dce5d3; }
  input[type=range]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 28px; height: 28px; margin-top: -11px; border-radius: 50%; background: #365744; border: 3px solid white; box-shadow: 0 1px 5px #263d2740; }
  input[type=range]::-moz-range-track { height: 6px; border-radius: 8px; background: #dce5d3; }
  input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #365744; border: 3px solid white; }
  .slider-label, .control-heading { font-size: 14px; }
  .slider-label output, .control-heading small, .range-ends, .hint { font-size: 12px; }
  input[type=text], select { font-size: 16px; min-height: 48px; }
  .template small { font-size: 12px; }
  .preset { font-size: 13px; padding-bottom: 6px; }
}
@media (max-width: 800px) {
  .library, .settings, .editor, .intro > div, #controls { min-width: 0; }
  .selection-tools { position: static; gap: 8px; margin: 8px 0 0; justify-content: flex-start; flex-wrap: wrap; }
  .selection-tools button { padding: 8px 12px; background: #f0f3eb; border-radius: 6px; color: #526548; }
  #photos { margin-top: 12px; padding-bottom: 7px; scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
  .photo { flex: 0 0 150px; scroll-snap-align: start; }
  .photo img { height: 90px; }
  .photo-caption { font-size: 12px; display: block; }
  .photo-caption span { display: block; max-width: 132px; }
  .photo small { display: block; margin-top: 4px; font-size: 11px; }
  .editor-bar { height: auto; min-height: 58px; flex-wrap: wrap; padding: 7px 12px; gap: 3px; }
  .editor-bar > span { max-width: 100%; font-size: 12px; }
  .editor-bar > div { gap: 3px; flex-wrap: wrap; }
  .editor-bar button { font-size: 12px; }
  .divider { margin: 0 2px; }
  .section-title { font-size: 14px; }
  .batch-bar strong { font-size: 12px; }
  .batch-bar p { font-size: 12px; line-height: 1.5; }
  .canvas-footer { gap: 8px; flex-wrap: wrap; font-size: 11px; }
  .settings-bottom { font-size: 12px; }
  .about-editor p, .editor-faq details p { font-size: 14px; }
  .editor-faq summary { font-size: 14px; line-height: 1.5; padding: 10px 0; }
  #toast { max-width: calc(100vw - 28px); width: max-content; bottom: max(18px, env(safe-area-inset-bottom)); text-align: center; }
  dialog { max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; }
  dialog .close { margin: -12px -12px 8px 8px; }
  dialog p, dialog label { font-size: 14px; }
  dialog .export-note { font-size: 12px !important; }
}
@media (max-width: 680px) {
  header { position: sticky; top: 0; z-index: 10; background: #f7f8f5f5; height: 72px; padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); }
  .brand { font-size: 23px; }
  .brand-icon { font-size: 32px; margin-right: 5px; }
  .brand sup { display: none; }
  .primary { min-height: 46px; font-size: 12px; padding: 10px 12px; gap: 10px; }
  main { padding: 0 max(12px, env(safe-area-inset-left)); }
  .intro { display: block; padding: 24px 3px; }
  .intro p { font-size: 14px; line-height: 1.6; max-width: none; }
  .eyebrow { font-size: 10px; letter-spacing: 1.1px; }
  h1 { font-size: clamp(28px, 7vw, 38px); }
  .upload { width: 100%; height: auto; min-height: 54px; margin-top: 18px; padding: 12px 16px; font-size: 15px; text-align: center; }
  .upload > span { font-size: 23px; margin-right: 8px; }
  .upload small { display: block; margin: 4px 0 0; font-size: 11px; }
  .workspace { display: flex; flex-direction: column; }
  .editor { min-height: 0; }
  .editor-bar > span { flex-basis: 100%; }
  .editor-bar > div { width: 100%; justify-content: space-between; }
  .stage { min-height: 180px; padding: 16px 14px; }
  .stage canvas { max-height: 44vh; max-height: 44svh; }
  .image-label { left: 22px; bottom: 22px; }
  .settings { border-left: 0; border-top: 1px solid var(--line); padding: 18px 14px; min-height: 0; }
  .tabs { margin: 16px 0 22px; }
  .tabs button { min-height: 48px; }
  .presets { gap: 16px 10px; }
  .preset img { height: clamp(62px, 20vw, 110px); }
  .button-row { flex-wrap: wrap; }
  .button-row button { min-width: 110px; }
  footer { flex-wrap: wrap; gap: 12px; font-size: 11px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
