/* Phone/WebView adaptation. Keep the product flow, photo geometry and blue
   palette unchanged. These rules intentionally follow all theme styles. */
:root {
  --mobile-gutter: clamp(16px, 4.4vw, 22px);
  --mobile-safe-top: env(safe-area-inset-top, 0px);
  --mobile-safe-right: env(safe-area-inset-right, 0px);
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-safe-left: env(safe-area-inset-left, 0px);
  --h5-shell-gap: 0px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-bottom: 160px;
}
html, body { min-width: 0; width: 100%; }
html, body, .h5-shell, .download-dialog { touch-action: pan-x pan-y; }
/* Native rubber-band strength is not configurable. Touch-only edge guards
   replace the large bounce with 20%-travel feedback, never moving the page. */
html[data-h5-edge-guard], html[data-h5-edge-guard] body,
html[data-h5-edge-guard] :is(.download-dialog, .payment-dialog, .session-dialog) {
  overscroll-behavior-y: none;
}
.h5-edge-feedback {
  position: fixed;
  z-index: 40;
  height: 16px;
  pointer-events: none;
  contain: strict;
  background: linear-gradient(to bottom, rgb(0 61 165 / 15%), rgb(0 61 165 / 0%));
  transform-origin: top;
  transform: scaleY(var(--h5-edge-scale, 0));
}
.h5-edge-feedback[data-edge='bottom'] {
  background: linear-gradient(to top, rgb(0 61 165 / 15%), rgb(0 61 165 / 0%));
  transform-origin: bottom;
}
@media (prefers-reduced-motion: reduce) { .h5-edge-feedback { display: none; } }
/* clip does not create a scroll container that would break sticky buttons. */
@supports (overflow-x: clip) { html, body { overflow-x: clip; } }
.h5-shell {
  min-height: calc(100vh - var(--h5-shell-gap) - var(--h5-shell-gap));
  min-height: calc(100dvh - var(--h5-shell-gap) - var(--h5-shell-gap));
  padding-left: var(--mobile-safe-left);
  padding-right: var(--mobile-safe-right);
}
/* The document must not remain Safari's scroll surface: a fixed body prevents
   large pale-blue root rubber bands. Only the finite shell scrolls; main and
   sections stay uncontained so their existing sticky docks retain their role. */
html[data-h5-scroll-root] {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
html[data-h5-scroll-root] body {
  position: fixed;
  inset: 0;
  top: var(--h5-viewport-top, 0px);
  bottom: auto;
  height: var(--h5-viewport-height, 100%);
  min-height: 0;
  overflow: hidden;
}
html[data-h5-scroll-root] .h5-shell {
  height: calc(100% - var(--h5-shell-gap) - var(--h5-shell-gap));
  min-height: 0;
  margin: var(--h5-shell-gap) auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 160px;
}
html[data-h5-scroll-root][data-h5-modal-open] .h5-shell { overflow-y: hidden; }
/* Stationary brand and a real body-level action portal. A fixed descendant of
   overflow:clip may have valid geometry but fail to paint/hit-test in Safari. */
html[data-h5-fixed-chrome] .h5-shell {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: var(--h5-dock-height, 0px);
}
html[data-h5-fixed-chrome] .site-header { flex: 0 0 auto; }
html[data-h5-fixed-chrome] .h5-scrollport {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding: 16px 0;
}
html[data-h5-fixed-chrome][data-h5-modal-open] .h5-scrollport { overflow-y: hidden; }
html[data-h5-fixed-chrome] .h5-scroll-content {
  /* Clip transformed visual overflow, without translating a fixed ancestor. */
  overflow: hidden;
  overflow: clip;
}
html[data-h5-fixed-chrome] .h5-fixed-dock-host {
  position: fixed;
  left: var(--h5-dock-left, var(--mobile-gutter));
  top: var(--h5-dock-top, auto);
  bottom: auto;
  width: var(--h5-dock-width, calc(100% - 2 * var(--mobile-gutter)));
  margin: 0;
  padding: 0;
  border: 0;
  min-height: 0;
  background: transparent;
  overflow: visible;
  transform: none;
  translate: none;
  animation: none;
  transition: none;
  contain: none;
  will-change: auto;
  z-index: 45;
}
html[data-h5-fixed-chrome] .h5-fixed-dock-host > .h5-dock {
  position: relative;
  inset: auto;
  width: 100%;
  margin: 0;
  padding-top: 12px;
  z-index: auto;
}
html[data-h5-fixed-chrome] main .h5-screen[data-screen]:not([hidden]) > :not(.h5-dock),
html[data-h5-fixed-chrome] .h5-scroll-content > .h5-steps {
  translate: 0 var(--h5-pull-offset, 0px);
  transition: none;
}
html[data-h5-fixed-chrome][data-h5-pull-releasing] main .h5-screen[data-screen]:not([hidden]) > :not(.h5-dock),
html[data-h5-fixed-chrome][data-h5-pull-releasing] .h5-scroll-content > .h5-steps {
  transition: translate 180ms cubic-bezier(.2, .7, .3, 1);
}
@media (prefers-reduced-motion: reduce) {
  html[data-h5-fixed-chrome] main .h5-screen[data-screen]:not([hidden]) > :not(.h5-dock),
  html[data-h5-fixed-chrome] .h5-scroll-content > .h5-steps { translate: none; transition: none !important; }
}
html[data-h5-scroll-root] :is(.download-dialog, .payment-dialog, .session-dialog) {
  max-height: calc(var(--h5-viewport-height, 100dvh) - 24px - var(--mobile-safe-top) - var(--mobile-safe-bottom));
}
@media (min-width: 600px) { :root { --h5-shell-gap: 20px; } }
.site-header {
  height: auto;
  min-height: calc(78px + var(--mobile-safe-top));
  padding: calc(12px + var(--mobile-safe-top)) var(--mobile-gutter) 12px;
  gap: 12px;
}
.brand, .brand > span:last-child { min-width: 0; }
.h5-brand-mark { flex-shrink: 0; }
.h5-header-tag { flex-shrink: 0; }
.h5-steps { padding-left: var(--mobile-gutter); padding-right: var(--mobile-gutter); }
.h5-screen { min-width: 0; padding-left: var(--mobile-gutter); padding-right: var(--mobile-gutter); }
.h5-screen fieldset, .h5-surface, .h5-screen .card-fields, .h5-screen .card-fields label { min-width: 0; }
.h5-page-heading h1 { font-size: clamp(25px, 7vw, 29px); overflow-wrap: anywhere; }
.h5-page-heading p, .h5-screen .service-notice, .h5-preview-status,
.h5-screen .translation-help, .h5-final-note, .h5-watermark-note { overflow-wrap: anywhere; }
.h5-screen legend { gap: 8px; }
.h5-screen legend > small { flex-shrink: 0; }
.h5-style-options .h5-style-art { height: auto; aspect-ratio: 3 / 4; }
.h5-style-options button > span:not(.h5-style-art), .h5-style-options button > small { overflow-wrap: anywhere; }
.h5-surface { padding: clamp(14px, 4vw, 18px); }
.h5-style-settings .swatches { gap: 6px; }
.h5-style-settings .swatches button { min-width: 40px; min-height: 58px; }
.h5-outfit > span { min-width: 0; }
.h5-outfit select { max-width: 100%; flex-shrink: 0; }
.h5-promise { flex-wrap: wrap; }

/* 16px prevents iOS focus-to-zoom; do not scale the input down with transform. */
.h5-screen input:not([type='checkbox']):not([type='range']),
.h5-screen select, .h5-screen textarea,
.download-dialog input:not([type='radio']):not([type='checkbox']),
.download-dialog select, .download-dialog textarea {
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  font-size: 16px;
  line-height: 1.4;
  scroll-margin: 80px 0 160px;
}
.h5-screen .toggle-row { gap: 12px; }
.h5-screen .toggle-row > div { min-width: 0; }
.h5-english-details summary { gap: 10px; flex-wrap: wrap; }
.h5-screen .range-field input, .h5-result-screen .compare-control input {
  min-width: 0;
  min-height: 44px;
  touch-action: pan-y;
}
.h5-screen .size-options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.h5-screen .size-options button { min-height: 62px; }
.h5-screen .file-summary {
  height: auto;
  min-height: 98px;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  gap: 10px;
}
.h5-screen .file-summary > div { min-width: 0; }
.h5-screen .file-summary strong, .h5-screen .file-summary span { max-width: 100%; }
.h5-screen .file-summary button { min-height: 44px; padding: 6px; }
.h5-photo-guide > div { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.h5-photo-guide span { min-width: 0; }
.h5-photo-guide strong, .h5-photo-guide small { overflow-wrap: anywhere; }
.h5-dock { padding-bottom: max(12px, var(--mobile-safe-bottom)); }
.h5-primary { height: auto; min-height: 49px; padding-top: 12px; padding-bottom: 12px; }
.h5-dock .button-label { min-width: 0; min-height: 0; }
/* The measured fixed dock follows visualViewport changes, including keyboards;
   do not switch it back into document flow while a field is being edited. */

.h5-result-screen .preview-topbar { flex-wrap: wrap; gap: 10px; padding-left: 14px; padding-right: 14px; }
.h5-result-screen .preview-topbar > div { min-width: 0; }
.h5-result-screen .preview-topbar p { overflow-wrap: anywhere; }
.h5-result-screen .mode-badge { flex-shrink: 0; }
.h5-result-screen .view-toolbar { flex-wrap: wrap; }
.h5-result-screen .view-toolbar button { min-width: 0; min-height: 44px; flex: 1; padding: 8px 4px; }
.h5-result-screen .preview-stage { min-height: clamp(280px, 80vw, 380px); padding: clamp(14px, 4.4vw, 22px); }
.h5-result-screen .compare-frame, .h5-result-screen .compare-control { max-width: 100%; }
.h5-result-screen .photo-guides { height: auto; min-height: 44px; flex-wrap: wrap; gap: 8px 12px; }
.h5-result-screen .generation-progress { padding: 18px; overflow: auto; }
.h5-result-screen .result-actions {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  padding-bottom: max(12px, var(--mobile-safe-bottom));
}
.h5-result-screen .result-actions button { min-width: 0; padding-left: 8px; padding-right: 8px; }
footer.h5-footer {
  gap: 12px;
  flex-wrap: wrap;
  padding-left: var(--mobile-gutter);
  padding-right: var(--mobile-gutter);
  padding-bottom: max(25px, var(--mobile-safe-bottom));
}
.toast { bottom: max(90px, calc(70px + var(--mobile-safe-bottom))); overflow-wrap: anywhere; }

/* A scrollable phone-sized sheet in portrait, landscape and embedded WeChat.
   Keep the existing sticky 12px-blurred purchase dock and free layouts. */
.download-dialog {
  width: min(450px, calc(100vw - 20px - var(--mobile-safe-left) - var(--mobile-safe-right)));
  max-width: 100%;
  max-height: calc(100vh - 24px - var(--mobile-safe-top) - var(--mobile-safe-bottom));
  max-height: calc(100dvh - 24px - var(--mobile-safe-top) - var(--mobile-safe-bottom));
  scroll-padding-bottom: calc(112px + var(--mobile-safe-bottom));
  -webkit-overflow-scrolling: touch;
}
.download-sheet { min-width: 0; padding: 22px 16px; }
.download-heading { gap: 12px; }
.download-heading > div { min-width: 0; }
.download-heading h2 { font-size: clamp(20px, 5.6vw, 22px); overflow-wrap: anywhere; }
.download-close { width: 44px; height: 44px; }
.download-form { min-width: 0; display: block; }
.download-choice, .download-choice-content, .download-summary > div { min-width: 0; }
.download-preview-stage { min-height: 150px; height: clamp(150px, 25svh, 190px); }
.download-summary { gap: 10px; padding: 14px; }
.download-selection, .download-selection-note, .download-price-note, .download-status, .download-footnote { overflow-wrap: anywhere; }
.download-actions button { min-height: 48px; font-size: 14px; white-space: normal; }

@media (max-width: 370px) {
  .h5-outfit select { width: 100%; }
  .h5-style-options { gap: 7px; }
  .h5-screen .size-options { gap: 6px; }
  .h5-screen .file-summary { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; }
  .h5-screen .file-thumb { width: 52px; height: 64px; }
  .download-layout-choice .download-choice-content { padding-left: 7px; padding-right: 7px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  :root { --h5-shell-gap: 0px; }
  .h5-shell { margin-top: 0; margin-bottom: 0; border-radius: 0; }
  .site-header { min-height: calc(66px + var(--mobile-safe-top)); border-radius: 0; }
  .h5-screen { padding-top: 16px; }
  .h5-page-heading { margin-bottom: 18px; }
  .download-dialog {
    max-height: calc(100vh - 16px - var(--mobile-safe-top) - var(--mobile-safe-bottom));
    max-height: calc(100dvh - 16px - var(--mobile-safe-top) - var(--mobile-safe-bottom));
  }
}
@media (hover: none) {
  .h5-screen .upload-zone:hover, .h5-primary:hover:not(:disabled) { transform: none; }
}

/* Driven by visualViewport (including an open keyboard), not just @media.
   The brand and actual actions stay visible. Secondary copy remains available
   to assistive technology and returns visually when the keyboard closes. */
html[data-h5-fixed-chrome][data-h5-compact-chrome] .site-header {
  min-height: calc(54px + var(--mobile-safe-top));
  padding-top: calc(6px + var(--mobile-safe-top));
  padding-bottom: 6px;
}
html[data-h5-fixed-chrome][data-h5-compact-chrome] .h5-screen > .h5-dock {
  min-height: 0;
  padding-top: 6px;
  padding-bottom: 6px;
}
html[data-h5-fixed-chrome][data-h5-compact-chrome] .h5-dock > p,
html[data-h5-fixed-chrome][data-h5-compact-chrome] .h5-dock > .result-note {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
html[data-h5-fixed-chrome][data-h5-compact-chrome] .h5-scrollport { scroll-padding: 8px 0; }
html[data-h5-fixed-chrome][data-h5-compact-chrome] .h5-screen :is(input, select, textarea) { scroll-margin: 4px 0; }
