.download-dialog {
  width: min(890px, calc(100vw - 32px));
  max-height: min(880px, calc(100dvh - 48px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--ui-border, #dce5f1);
  border-radius: 22px;
  background: #fff;
  color: var(--ui-ink, #132c50);
  box-shadow: 0 28px 90px #132c5052;
  overflow: auto;
  overscroll-behavior: contain;
  /* Keep focused options above the floating purchase dock when tabbing. */
  scroll-padding: 20px 0 calc(112px + env(safe-area-inset-bottom, 0px));
}
.download-dialog::backdrop { background: #132c50aa; backdrop-filter: blur(5px); }
.download-sheet { padding: 30px; }
.download-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.download-eyebrow { margin: 0 0 10px; color: var(--brand-blue, #003da5); font-size: 11px; font-weight: 650; letter-spacing: .12em; }
.download-heading h2 { margin: 0; font-size: 25px; font-weight: 650; line-height: 1.4; letter-spacing: -.035em; }
.download-close { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--ui-border, #dce5f1); background: var(--ui-surface, #f4f7fc); border-radius: 50%; color: var(--ui-muted, #526784); cursor: pointer; }
.download-close span { font-size: 27px; font-weight: 300; line-height: 1; }
.download-close:hover:not(:disabled) { background: #eef4ff; color: var(--brand-blue, #003da5); }
.download-intro { margin: 14px 0 26px; color: var(--ui-muted, #526784); font-size: 13px; line-height: 1.8; }
.download-group { min-width: 0; padding: 0; margin: 0 0 24px; border: 0; }
.download-group legend { padding: 0; margin-bottom: 12px; color: var(--brand-blue, #003da5); font-size: 11px; font-weight: 650; }
.download-group legend span { margin-left: 7px; color: var(--ui-ink, #132c50); font-size: 13px; }
.download-tier-list,.download-layout-list { display: grid; gap: 10px; }
.download-tier-list { grid-template-columns: repeat(2, minmax(0,1fr)); }
.download-layout-list { grid-template-columns: repeat(3, minmax(0,1fr)); }
.download-free-badge { display: inline-block; margin-left: 8px; padding: 2px 7px; border-radius: 5px; background: #eef4ff; color: #1a59b6; font-size: 11px; font-weight: 500; line-height: 1.5; vertical-align: middle; }
.download-choice { position: relative; cursor: pointer; }
.download-choice input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; overflow: hidden; }
.download-choice-content { display: flex; height: 100%; min-height: 148px; flex-direction: column; padding: 16px 13px; border: 1px solid var(--ui-border, #dce5f1); border-radius: 12px; background: var(--ui-surface, #f4f7fc); transition: border-color .15s, background .15s, box-shadow .15s; }
.download-choice:hover .download-choice-content { border-color: #1a59b6; }
.download-choice input:checked + .download-choice-content { background: #eef4ff; border-color: var(--brand-blue, #003da5); box-shadow: inset 0 0 0 1px var(--brand-blue, #003da5); }
.download-choice input:focus-visible + .download-choice-content { outline: 3px solid #1a59b6; outline-offset: 3px; }
.download-choice input:disabled + .download-choice-content { opacity: .55; cursor: wait; }
.download-choice-content strong { font-size: 14px; line-height: 1.5; font-weight: 650; }
.download-choice-content small { display: block; margin-top: 6px; color: var(--ui-muted, #526784); font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
.download-tier-price { display: block; margin-top: auto; padding-top: 16px; color: var(--brand-blue, #003da5); font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.download-layout-choice .download-choice-content { min-height: 134px; padding-top: 15px; }
.download-layout-choice .download-choice-content strong { font-size: 12px; }
.download-layout-choice .download-choice-content small { font-size: 10px; margin-top: 3px; }
.download-layout-icon { height: 32px; width: 30px; display: grid; gap: 3px; margin-bottom: 12px; grid-template-columns: 1fr; }
.download-layout-icon i { display: block; border: 1px solid #526784; background: #dce5f1; border-radius: 2px; }
.download-layout-single { width: 25px; }
.download-layout-2x2 { grid-template-columns: repeat(2,1fr); }
.download-layout-3x3 { grid-template-columns: repeat(3,1fr); }
.download-choice input:checked + .download-choice-content .download-layout-icon i { border-color: var(--brand-blue, #003da5); background: #c7daff; }
.download-info-option { position: relative; display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--ui-border, #dce5f1); border-radius: 12px; background: var(--ui-surface, #f4f7fc); cursor: pointer; }
.download-info-option > span:first-child { min-width: 0; flex: 1; }
.download-info-option strong { display: block; font-size: 13px; line-height: 1.6; font-weight: 650; }
.download-info-option small { display: block; margin-top: 4px; color: var(--ui-muted, #526784); font-size: 11px; line-height: 1.7; }
.download-info-toggle { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.download-info-switch { position: relative; flex: 0 0 42px; width: 42px; height: 25px; border: 1px solid #9caec7; border-radius: 20px; background: #9caec7; transition: background .15s, border-color .15s; }
.download-info-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #132c5026; transition: transform .15s; }
.download-info-toggle:checked + .download-info-switch { background: var(--brand-blue, #003da5); border-color: var(--brand-blue, #003da5); }
.download-info-toggle:checked + .download-info-switch::after { transform: translateX(17px); }
.download-info-toggle:focus-visible + .download-info-switch { outline: 3px solid #1a59b6; outline-offset: 3px; }
.download-info-toggle:disabled + .download-info-switch { opacity: .45; cursor: not-allowed; }
.download-preview { margin: 0 0 20px; border: 1px solid var(--ui-border, #dce5f1); border-radius: 12px; overflow: hidden; }
.download-preview-stage { min-height: 170px; height: 220px; padding: 13px; display: flex; align-items: center; justify-content: center; background: var(--ui-surface, #f4f7fc); }
.download-preview-image { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; box-shadow: 0 3px 12px #132c5021; }
.download-preview-placeholder { padding: 15px; color: var(--ui-muted, #526784); font-size: 12px; text-align: center; line-height: 1.8; }
.download-preview figcaption { padding: 10px 12px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 5px 14px; font-size: 10px; line-height: 1.6; }
.download-preview-caption { color: var(--ui-ink, #132c50); }
.download-preview-status { color: var(--ui-muted, #526784); }
.download-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; background: #eef4ff; border-radius: 10px; }
.download-selection { display: block; font-size: 13px; line-height: 1.6; }
.download-selection-note { display: block; margin-top: 4px; color: var(--ui-muted, #526784); font-size: 11px; }
.download-total { flex-shrink: 0; color: var(--brand-blue, #003da5); font-size: 24px; font-variant-numeric: tabular-nums; font-weight: 650; }
.download-price-note { margin: 11px 0 0; color: #1a59b6; font-size: 11px; line-height: 1.7; }
.download-status { margin: 12px 0 0; color: var(--ui-muted, #526784); font-size: 12px; line-height: 1.7; }
.download-status:empty,.download-price-note:empty { display: none; }
.download-error { margin: 13px 0 0; padding: 10px 12px; color: #9a402e; border: 1px solid #ebcbbc; border-radius: 8px; background: #fff5ef; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.download-actions {
  position: sticky;
  bottom: 12px;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 22px;
  padding: 10px;
  border: 1px solid #dce5f1;
  border-radius: 16px;
  /* Opaque fallback keeps the button readable without backdrop-filter. */
  background: var(--ui-surface, #f4f7fc);
  box-shadow: 0 8px 24px #132c501a, 0 -2px 12px #132c5008;
}
@supports ((backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px))) {
  .download-actions {
    background: #f4f7fcd6;
    border-color: #ffffffb3;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
}
.download-actions button { min-height: 46px; padding: 11px 12px; border-radius: 9px; font-size: 12px; font-weight: 600; cursor: pointer; line-height: 1.6; }
.download-purchase { border: 1px solid var(--brand-blue, #003da5); background: var(--brand-blue, #003da5); color: #fff; box-shadow: 0 3px 9px #003da51f; }
.download-purchase:focus-visible { outline: 3px solid #1a59b6; outline-offset: 3px; }
.download-purchase:hover:not(:disabled) { border-color: var(--brand-blue-hover, #002f7f); background: var(--brand-blue-hover, #002f7f); }
.download-actions button:disabled { opacity: .5; cursor: wait; }
.download-footnote { margin: 12px 0 0; color: var(--ui-muted, #526784); font-size: 10px; line-height: 1.8; }
@media(min-width:740px) {
  .download-form { display: grid; grid-template-columns: minmax(0,1fr) 230px; column-gap: 24px; }
  .download-quality-group { grid-column: 1; grid-row: 1; }
  .download-layout-group { grid-column: 1; grid-row: 2; }
  .download-info-group { grid-column: 1; grid-row: 3; }
  .download-preview { grid-column: 2; grid-row: 1 / 4; display: flex; flex-direction: column; }
  .download-preview-stage { flex: 1; min-height: 0; height: auto; }
  .download-preview-image { max-height: 340px; }
  .download-preview figcaption { flex-direction: column; }
  .download-summary,.download-price-note,.download-status,.download-error,.download-actions,.download-footnote { grid-column: 1 / -1; }
}
@media(max-width:540px) {
  .download-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 24px); border-radius: 17px; }
  .download-sheet { padding: 22px 17px; }
  .download-heading h2 { font-size: 22px; }
  .download-intro { font-size: 12px; margin-bottom: 22px; }
  .download-tier-list,.download-layout-list { gap: 7px; }
  .download-choice-content { padding: 13px 9px; min-height: 155px; }
  .download-choice-content strong { font-size: 13px; }
  .download-choice-content small { font-size: 10px; }
  .download-tier-price { font-size: 19px; }
  .download-layout-choice .download-choice-content { min-height: 140px; }
  .download-preview-stage { height: 190px; }
  .download-actions { grid-template-columns: 1fr; gap: 9px; }
  .download-purchase { grid-row: 1; }
  .download-actions button { min-height: 46px; }
  .download-total { font-size: 22px; }
  .download-selection { font-size: 12px; }
}
@media(prefers-reduced-motion:reduce) { .download-dialog * { transition: none !important; } }
