.app-story {
  margin: clamp(2rem, 7vw, 5rem) 0;
  --app-story-progress: 0;
  --app-story-local: 0;
  /* ~iPhone 17 Pro Max class logical viewport (440×956 pt); decorative handset only */
  --device-pt-w: 440;
  --device-pt-h: 956;
  --phone-r-outer: clamp(2.65rem, 10.85vmin, 3.42rem);
  --phone-r-inner: clamp(2.02rem, 8.95vmin, 2.82rem);
  /* Slightly less aggressive rounding so top category rail is not clipped by the mask */
  --phone-r-glass: clamp(1.52rem, 6.85vmin, 2.26rem);
  /* Orange anodized-style frame (promotional, not a device asset) */
  --metal-1: #ffe4c8;
  --metal-2: #f0ae78;
  --metal-3: #d9783a;
  --metal-4: #b65524;
  --metal-5: #7a3818;
}

.app-story__intro {
  max-width: 44rem;
  margin: 0 auto clamp(1rem, 3.5vw, 1.75rem);
  text-align: center;
}

.app-story__lead {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.02rem;
  line-height: 1.6;
}

.app-story__inline-code {
  font-size: 0.88em;
}

/* Longer pin so scroll-linked motion has room */
.app-story__pin {
  min-height: calc(3.35 * 100dvh);
  min-height: calc(3.35 * 100svh);
  position: relative;
}

.app-story__sticky {
  position: sticky;
  top: calc(5.5rem + env(safe-area-inset-top, 0px));
  padding: 0 0 clamp(1rem, 3vw, 1.75rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Phone centered; copy on both rails */
.app-story__layout {
  width: min(1280px, 98vw);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: clamp(0.75rem, 2vw, 2rem);
  align-items: center;
}

.app-story__col h3 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--text);
}

.app-story__col-text {
  margin: 0;
  color: var(--text-muted);
  font-size: clamp(0.86rem, 1.65vw, 0.94rem);
  line-height: 1.56;
}

.app-story__col--left {
  text-align: right;
  justify-self: end;
  max-width: 22rem;
}

.app-story__col--right {
  text-align: left;
  justify-self: start;
  max-width: 22rem;
}

.app-story__phone-wrap {
  position: relative;
  flex-shrink: 0;
  /* Side keys protrude slightly past the shell */
  padding-inline: clamp(6px, 2vw, 14px);
}

/* Grounding: diffuse + tighter contact shadow */
.app-story__phone-wrap::before {
  content: "";
  position: absolute;
  inset: auto 14% -7% 14%;
  height: 16%;
  background: radial-gradient(
    ellipse 90% 100% at 50% 0%,
    rgba(180, 90, 40, 0.22),
    transparent 72%
  );
  filter: blur(26px);
  pointer-events: none;
}

.app-story__phone-wrap::after {
  content: "";
  position: absolute;
  inset: auto 22% -3% 22%;
  height: 10%;
  background: radial-gradient(
    ellipse 100% 100% at 50% 40%,
    rgba(80, 40, 18, 0.32),
    transparent 68%
  );
  filter: blur(14px);
  pointer-events: none;
}

/*
 * Handset: orange frame + hardware keys + OLED stack + light glare (no faux camera island)
 */
.app-phone {
  position: relative;
  /* vmin scales up cleanly on tall 4K / ultrawide while staying height-bounded */
  width: min(
    clamp(470px, 26vmin, 620px),
    calc(88dvh * var(--device-pt-w) / var(--device-pt-h))
  );
  max-width: min(620px, 96vw);
  transform-origin: center center;
  transform: none;
  z-index: 1;
}

.app-phone__keys {
  pointer-events: none;
  position: absolute;
  inset: 0;
}

.app-phone__key {
  position: absolute;
  width: clamp(3px, 0.82vw, 4px);
  border-radius: 2px;
  background: linear-gradient(
    165deg,
    var(--metal-2) 0%,
    var(--metal-4) 52%,
    var(--metal-5) 100%
  );
  box-shadow:
    inset 1px 0 0 rgba(255, 255, 255, 0.35),
    inset -1px 0 1px rgba(0, 0, 0, 0.22),
    0 2px 4px rgba(0, 0, 0, 0.12);
}

.app-phone__key--action {
  left: -2px;
  top: calc(18% + 6px);
  height: clamp(48px, 12.5vmin, 60px);
  border-radius: 2px 0 0 2px;
}

.app-phone__key--vol-up {
  left: -2px;
  top: calc(27% + 10px);
  height: clamp(56px, 14vmin, 68px);
  border-radius: 2px 0 0 2px;
}

.app-phone__key--vol-down {
  left: -2px;
  top: calc(36% + 14px);
  height: clamp(56px, 14vmin, 68px);
  border-radius: 2px 0 0 2px;
}

.app-phone__key--power {
  right: -2px;
  top: calc(28% + 8px);
  height: clamp(78px, 18vmin, 92px);
  border-radius: 0 2px 2px 0;
  background: linear-gradient(
    -165deg,
    var(--metal-2) 0%,
    var(--metal-4) 52%,
    var(--metal-5) 100%
  );
  box-shadow:
    inset -1px 0 0 rgba(255, 255, 255, 0.35),
    inset 1px 0 1px rgba(0, 0, 0, 0.22),
    0 2px 4px rgba(0, 0, 0, 0.12);
}

.app-phone__shell {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  aspect-ratio: 440 / 956;
  margin-inline: auto;
  padding: clamp(11px, 2.75vw, 15px);
  border-radius: var(--phone-r-outer);
  background:
    linear-gradient(
      168deg,
      var(--metal-1) 0%,
      var(--metal-2) 24%,
      var(--metal-3) 58%,
      var(--metal-4) 88%,
      var(--metal-5) 100%
    );
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 235, 0.55),
    inset 1px 0 1px rgba(255, 235, 210, 0.35),
    inset -1px 0 2px rgba(60, 25, 8, 0.12),
    inset 0 -10px 28px rgba(55, 28, 10, 0.38),
    0 1px 0 rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  filter: drop-shadow(0 28px 52px rgba(120, 45, 12, 0.28))
    drop-shadow(0 10px 22px rgba(60, 28, 12, 0.16));
}

/* Brushed specular + edge line (no external assets) */
.app-phone__shell::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.app-phone__shell::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: calc(var(--phone-r-outer) - 1px);
  pointer-events: none;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    inset 0 0 0 2px rgba(0, 0, 0, 0.06);
}

.app-phone__shell-inner {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  border-radius: var(--phone-r-inner);
  background: linear-gradient(180deg, #121316 0%, #0e0f12 100%);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.5),
    inset 0 0 0 2px rgba(255, 255, 255, 0.06),
    inset 0 1px 2px rgba(255, 255, 255, 0.06);
}

.app-phone__viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border-radius: var(--phone-r-glass);
  overflow: hidden;
  /* Match light Home shell — avoids black “frame” bleeding around the iframe edges */
  background: #fafafa;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    inset 0 0 0 2px rgba(15, 23, 42, 0.12);
}

.app-phone__viewport--flutter {
  display: block;
}

/* Width/height set in px by app-story.js; inset 0 avoids a visible bezel gutter around Flutter */
.app-story__flutter-frame {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  border: 0;
  display: block;
  background: #fafafa;
  z-index: 1;
}

/*
 * IMPORTANT: Never use display:flex/display:block on [hidden] without overriding —
 * author display wins over the hidden attribute and the banner would stay on screen.
 */
.app-story__flutter-fallback[hidden] {
  display: none !important;
}

/* Shown only when bundle probe fails; sits *under* handset, not over the iframe */
.app-story__flutter-fallback:not([hidden]) {
  display: block;
  margin: 0.9rem auto 0;
  padding: 0.7rem 1rem;
  max-width: min(32rem, 94vw);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text);
  text-align: center;
  border-radius: 12px;
  border: 1px solid rgba(234, 88, 12, 0.28);
  background: rgba(255, 247, 237, 0.95);
  box-shadow: var(--shadow-soft, 0 4px 24px rgba(15, 23, 42, 0.06));
}

.app-story__flutter-fallback code {
  font-size: 0.82em;
  word-break: normal;
  overflow-wrap: anywhere;
}

.app-phone__sim-chrome {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  overflow: hidden;
}

.app-phone__home-bar {
  position: absolute;
  bottom: 1.35%;
  left: 50%;
  transform: translateX(-50%);
  width: min(38%, 196px);
  height: clamp(5px, 1.05vmin, 6px);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.34);
  box-shadow:
    0 0 0 0.5px rgba(255, 255, 255, 0.12),
    0 3px 8px rgba(0, 0, 0, 0.35);
}

@media (max-width: 1024px) {
  .app-story__layout {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 1rem;
  }

  .app-story__col--left,
  .app-story__col--right {
    text-align: center;
    justify-self: center;
    max-width: 36rem;
  }

  .app-story__col--left {
    order: 1;
  }

  .app-story__phone-wrap {
    order: 2;
  }

  .app-story__col--right {
    order: 3;
  }

  .app-phone {
    width: min(
      clamp(400px, 88vw, 520px),
      calc(78dvh * var(--device-pt-w) / var(--device-pt-h))
    );
    max-width: 96vw;
  }

  .app-story__sticky {
    top: calc(4.85rem + env(safe-area-inset-top, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-phone {
    transform: none !important;
  }
}

/* ── Premium App Story overrides ── */
body.landing-v2 .app-story__intro h2 {
  font-size: clamp(1.85rem, 4.2vw, 3.25rem) !important;
  font-weight: 800 !important;
  letter-spacing: -0.03em !important;
}

/* Upgrade iPhone frame to match Electric Blue brand */
body.landing-v2 .app-story {
  --metal-1: #c8d4f0;
  --metal-2: #a0b4e8;
  --metal-3: #7090d8;
  --metal-4: #4466b8;
  --metal-5: #2244a0;
}

body.landing-v2 .app-phone__shell {
  box-shadow:
    0 0 0 1px rgba(59, 111, 255, 0.18),
    0 12px 40px rgba(59, 111, 255, 0.18),
    0 40px 100px rgba(15, 23, 42, 0.16) !important;
}

body.landing-v2 .app-story__col h3 {
  font-size: clamp(1.1rem, 2.2vw, 1.35rem) !important;
  font-weight: 800 !important;
  letter-spacing: -0.03em !important;
  background: var(--sn-accent-gradient, linear-gradient(135deg, #3b6fff, #7c3aed));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.landing-v2 .app-story__col-text {
  font-size: clamp(0.9rem, 1.6vw, 1rem) !important;
  line-height: 1.65 !important;
  color: var(--sn-text-secondary) !important;
}

