:root{
  /* Match FlexGrid vibe */
  --blue:#4c6fff;
  --blue2:#175d8c;
  --yellow:#ffdd55;
  --yellow2:#ffd22e;
  --text:#eef6ff;
  --outline: rgba(255,255,255,0.16);
}

html,
body {
  height: 100%;
  margin: 0;
  position: relative;
  --app-page-bg:
    radial-gradient(120% 120% at 20% 10%, rgba(109, 224, 255, 0.22), rgba(0, 0, 0, 0) 55%),
    radial-gradient(120% 120% at 85% 0%, rgba(255, 221, 85, 0.16), rgba(0, 0, 0, 0) 55%),
    linear-gradient(180deg, var(--blue), var(--blue2));
  background: var(--app-page-bg);
  color: var(--text);
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.hubBackBtn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 14px;
  font-weight: 900;
  font-size: clamp(13px, 3.6vw, 16px);
  letter-spacing: 0.03em;
  text-decoration: none;
  color: #1a1400;
  background: linear-gradient(180deg, var(--yellow), var(--yellow2));
  border: 0;
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

.hubBackBtn__icon {
  font-size: 1.15em;
  line-height: 1;
}

.hubBackBtn__text {
  white-space: nowrap;
}

.hubBackBtn:hover {
  filter: brightness(1.06);
}
.hubBackBtn:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.85);
  outline-offset: 3px;
}

.app {
  box-sizing: border-box;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0
    max(14px, env(safe-area-inset-left));
}

.appPoweredBy {
  margin-top: auto;
  width: 100%;
  max-width: min(720px, 100%);
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  text-align: center;
  box-sizing: border-box;
}

.appPoweredBy p {
  margin: 0;
  font-size: clamp(13px, 3.2vw, 15px);
  font-weight: 800;
  letter-spacing: 0.22em;
  color: rgba(238, 246, 255, 0.82);
}

.card {
  width: min(720px, 100%);
  max-width: 100%;
  box-sizing: border-box;
  border-radius: 18px;
  background: rgba(0,0,0,0.18);
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  padding: 12px 14px 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.header {
  margin: 0;
  padding: 0;
}

.brandRow {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2vw, 16px);
  margin: 4px 0 10px;
  width: 100%;
  max-width: 100%;
}

.brandLogoWrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  min-width: 0;
}

.brandLogo {
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.32));
}

/* LO slightly smaller; DDG ~2.5× taller — row flex-centers × between them */
#loLogoHeader.brandLogo,
.templatePickerBrandRow .templatePickerBrandLo {
  height: clamp(44px, 10.5vw, 68px);
  max-height: min(68px, 20vw);
}

#ddgLogoHeader.brandLogo,
.templatePickerBrandRow .templatePickerBrandDdg {
  height: clamp(110px, 27vw, 190px);
  max-height: min(190px, 52vw);
}

#loLogoFallback.brandLogoFallback {
  height: clamp(44px, 10.5vw, 68px);
  min-width: clamp(72px, 22vw, 100px);
  font-size: clamp(22px, 6vw, 34px);
  border-radius: 16px;
}

#ddgLogoFallback.brandLogoFallback {
  height: clamp(110px, 27vw, 190px);
  min-width: clamp(100px, 28vw, 160px);
  font-size: clamp(28px, 8vw, 52px);
  border-radius: 18px;
}

.brandLogoFallback {
  height: 96px;
  min-width: 150px;
  padding: 0 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-weight: 950;
  letter-spacing: 0.4px;
}

.brandX {
  flex: 0 0 auto;
  align-self: center;
  font-weight: 950;
  opacity: 0.78;
  font-size: clamp(22px, 5.5vw, 36px);
  line-height: 1;
  padding: 0 2px;
}

.header h1 {
  margin: 0;
  font-size: clamp(28px, 4.6vw, 40px);
  letter-spacing: -0.2px;
}

.sub {
  margin: 10px 0 0 0;
  opacity: 0.9;
  font-weight: 800;
}

.upload {
  margin-top: 18px;
  display: grid;
  gap: 10px;
  justify-items: start;
}

.hint {
  margin: 0;
  opacity: 0.65;
  font-weight: 600;
}

.btn {
  position: relative;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.2px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn.primary {
  background: linear-gradient(180deg, var(--yellow), var(--yellow2));
  color: #1a1400;
  box-shadow: 0 10px 18px rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.35);
}

.btn.primary.alt {
  background: linear-gradient(180deg, var(--yellow), var(--yellow2));
  color: #1a1400;
  border: 0;
  box-shadow: 0 10px 18px rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.35);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: #eaf0ff;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.btn.blue {
  background: linear-gradient(180deg, #6d9fff, var(--blue) 42%, #3d5fd4);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.22);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.btn.big {
  width: 100%;
  min-height: 56px;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 950;
}

.btn:active {
  transform: translateY(1px) scale(.99);
}

.btn:hover{ filter: brightness(1.05); }

label.btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.stage {
  margin-top: 8px;
  display: grid;
  gap: 10px;
  padding-inline: clamp(0px, 1.2vw, 6px);
  box-sizing: border-box;
}

.canvasWrap {
  position: relative;
  width: 100%;
  /* JS sets aspect-ratio from template; fallback matches DDG PNG ~2048×2385 */
  aspect-ratio: 2048 / 2385;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
}

canvas#canvas {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Wrapped in <a download> so “Save link / Download linked file” can use a real .jpg name (Safari). */
.canvasExportMirrorLink {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  cursor: default;
  text-decoration: none;
  color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.canvasExportMirror {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.frameHint {
  position: absolute;
  left: var(--fx, 20%);
  top: var(--fy, 18%);
  width: var(--fw, 60%);
  height: var(--fh, 60%);
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.frameHintInner {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(6px, 1.8vmin, 11px);
  /* Extra bottom inset lifts logo + UPLOAD DDG above the Polaroid gutter */
  padding: clamp(6px, 2vmin, 14px) clamp(10px, 3vmin, 18px)
    clamp(14%, min(10rem, 20vmin));
  box-sizing: border-box;
  border-radius: 16px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.frameLogo {
  width: min(88%, min(496px));
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 25px rgba(0, 0, 0, 0.35));
}

.frameLogoFallback {
  width: min(88%, min(496px));
  min-height: clamp(140px, 32vmin, 220px);
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-weight: 950;
  font-size: clamp(28px, 9vw, 56px);
  letter-spacing: 0.05em;
}

.frameHintText {
  font-weight: 900;
  letter-spacing: 0.2px;
  opacity: 0.92;
  text-align: center;
  padding: 0 14px;
}

/* Override .btn.big { width: 100% } — keep upload pill compact */
.frameUploadBtn.btn.big {
  width: auto;
  max-width: min(68%, 220px);
  min-width: 0;
}

.frameUploadBtn {
  pointer-events: auto; /* frameHint is non-interactive by default */
  margin: 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 52px;
  padding: 11px clamp(14px, 4vw, 20px);
  box-sizing: border-box;
}

.frameLogo.spin {
  animation: spin 2.6s linear infinite;
}

.frameUploadBtn .btnText{
  flex: 0 1 auto;
  width: 100%;
  font-size: clamp(17px, 4.8vw, 22px);
  letter-spacing: 0.045em;
  text-align: center;
  display: inline-block;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-wrap: nowrap;
  padding-inline: clamp(0px, 1.2vw, 6px);
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

/* --- Processing + shutter + flash --- */
.processingOverlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
}

.processingOverlay.show {
  animation: overlayIn 380ms ease forwards;
}

@keyframes overlayIn {
  to {
    opacity: 1;
  }
}

.scanText {
  font-weight: 900;
  font-size: clamp(18px, 3.4vw, 24px);
  text-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.shutter {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.shutterBar {
  position: absolute;
  left: 0;
  width: 100%;
  height: 52%;
  background: rgba(0, 0, 0, 0.92);
}

.shutterBar.top {
  top: -52%;
}
.shutterBar.bottom {
  bottom: -52%;
}

.shutter.play .shutterBar.top {
  animation: shutterTop 220ms ease-in forwards, shutterTopOut 240ms ease-out 240ms forwards;
}
.shutter.play .shutterBar.bottom {
  animation: shutterBottom 220ms ease-in forwards, shutterBottomOut 240ms ease-out 240ms forwards;
}

@keyframes shutterTop {
  to {
    top: 0%;
  }
}
@keyframes shutterBottom {
  to {
    bottom: 0%;
  }
}
@keyframes shutterTopOut {
  to {
    top: -52%;
  }
}
@keyframes shutterBottomOut {
  to {
    bottom: -52%;
  }
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: white;
  opacity: 0;
  pointer-events: none;
}

.flash.play {
  animation: flash 260ms ease-out;
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  30% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
  }
}

/* Canvas reveal */
.canvasWrap.reveal {
  animation: reveal 420ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes reveal {
  0% {
    transform: scale(0.95);
    filter: saturate(0.9) contrast(0.96);
  }
  100% {
    transform: scale(1);
    filter: saturate(1) contrast(1);
  }
}

.canvasWrap.shake {
  animation: shake 220ms ease-out;
}

@keyframes shake {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-2px, 1px);
  }
  55% {
    transform: translate(2px, -1px);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* First paint — spin + label while template / logos load */
.bootLoading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom)
    max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  background:
    radial-gradient(120% 120% at 20% 10%, rgba(109, 224, 255, 0.22), rgba(0, 0, 0, 0) 55%),
    radial-gradient(120% 120% at 85% 0%, rgba(255, 221, 85, 0.12), rgba(0, 0, 0, 0) 55%),
    linear-gradient(180deg, var(--blue), var(--blue2));
  transition: opacity 0.32s ease, visibility 0.32s ease;
}

.bootLoading--done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.bootLoading__inner {
  display: grid;
  place-items: center;
  gap: 16px;
  text-align: center;
}

.bootLoading__logo {
  width: min(44vw, 168px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.4));
  animation: spin 1.35s linear infinite;
}

.bootLoading__text {
  margin: 0;
  font-weight: 900;
  font-size: clamp(17px, 4vw, 21px);
  letter-spacing: 0.06em;
  color: rgba(238, 246, 255, 0.92);
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .processingOverlay.show,
  .flash.play,
  .canvasWrap.reveal,
  .canvasWrap.shake,
  .shutter.play .shutterBar.top,
  .shutter.play .shutterBar.bottom {
    animation: none !important;
  }

  .bootLoading__logo {
    animation: none;
  }
}

/* Phones: breathing room at sides of canvas + buttons */
@media (max-width: 540px) {
  .app {
    /* Clear fixed back control (arrow) so it never sits on the logo row */
    padding-top: calc(env(safe-area-inset-top) + 58px);
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .hubBackBtn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 50%;
    gap: 0;
  }

  .hubBackBtn__icon {
    font-size: 24px;
    line-height: 1;
  }

  .hubBackBtn__text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .card {
    padding: 10px 8px 12px;
  }

  .stage {
    padding-inline: 10px;
  }

  .actions {
    padding-inline: 10px;
    padding-bottom: 2px;
  }

  /* Keep LO × DDG on one row without clipping */
  #loLogoHeader.brandLogo,
  .templatePickerBrandRow .templatePickerBrandLo {
    height: clamp(40px, 9.5vw, 60px);
    max-height: min(60px, 18vw);
  }

  #ddgLogoHeader.brandLogo,
  .templatePickerBrandRow .templatePickerBrandDdg {
    height: clamp(92px, 24vw, 150px);
    max-height: min(150px, 46vw);
  }

  #loLogoFallback.brandLogoFallback {
    height: clamp(40px, 9.5vw, 60px);
    min-width: 64px;
    font-size: clamp(18px, 5.5vw, 28px);
  }

  #ddgLogoFallback.brandLogoFallback {
    height: clamp(92px, 24vw, 150px);
    min-width: 88px;
    font-size: clamp(22px, 7vw, 40px);
  }

  .brandX {
    font-size: clamp(18px, 5vw, 28px);
  }

  /* Stack logo → UPLOAD from top of hole; less bottom padding so pill isn’t pushed too low */
  .frameHintInner {
    align-content: start;
    justify-items: center;
    padding-top: clamp(7%, 9vmin, 13%);
    padding-bottom: clamp(5%, 7vmin, 11%);
    padding-left: clamp(8px, 2.5vmin, 14px);
    padding-right: clamp(8px, 2.5vmin, 14px);
    gap: clamp(6px, 2vmin, 10px);
  }

  .frameUploadBtn {
    margin-top: 2px;
  }

  .templatePickerOptionFrame,
  .templatePickerOption img {
    max-height: min(42vh, 420px);
  }
}

/* --- Template picker (CHANGE TEMPLATE) --- */
.templatePickerOverlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: var(--app-page-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-sizing: border-box;
}

.templatePickerOverlay.hidden {
  display: none !important;
}

.templatePickerModal {
  width: min(640px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--app-page-bg);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 14px 16px;
  box-sizing: border-box;
}

.templatePickerHeader {
  margin: 0 0 10px;
  padding: 0 0 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.templatePickerBrandRow {
  margin: 2px 0 0;
}

.templatePickerHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.templatePickerTitle {
  margin: 0;
  font-size: clamp(22px, 4.2vw, 28px);
  font-weight: 950;
  letter-spacing: -0.15px;
  color: #fff;
  line-height: 1.15;
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.templatePickerClose {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.templatePickerClose:hover {
  filter: brightness(1.12);
  border-color: rgba(255, 221, 85, 0.45);
}

.templatePickerSub {
  margin: 0 0 14px;
  font-size: clamp(14px, 3.4vw, 17px);
  font-weight: 600;
  line-height: 1.35;
}

.templatePickerList {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.templatePickerOption {
  position: relative;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 8px;
  margin: 0;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.22);
  overflow: visible;
  display: block;
  width: 100%;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}

.templatePickerOption:hover {
  border-color: rgba(255, 221, 85, 0.45);
}

.templatePickerOption:active {
  transform: scale(0.99);
}

.templatePickerOption.isSelected {
  border-color: rgba(255, 221, 85, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 221, 85, 0.25), 0 8px 20px rgba(0, 0, 0, 0.35);
}

.templatePickerOptionFrame {
  width: 100%;
  max-height: min(52vh, 560px);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  overflow: hidden;
  box-sizing: border-box;
}

.templatePickerOption img {
  display: block;
  max-width: 100%;
  max-height: min(52vh, 560px);
  width: auto;
  height: auto;
  object-fit: contain;
}

.templatePickerOption .templatePickerOptionBadge {
  position: absolute;
  left: 14px;
  bottom: 14px;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: clamp(12px, 3vw, 14px);
  font-weight: 900;
  display: grid;
  place-items: center;
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

