/*
 * Phones. The same film in a portrait composition: the head-turner on top, the device the hero of the middle,
 * the segmented control at the bottom, inside the safe areas. The queries match main.js (PHONE_Q, SHORT_Q);
 * nothing here applies to a desktop window.
 */

/* phone-only parts, off by default */
.m-words, .hero-sub-m, .m-head { display: none; }
/* a tab's two names (desktop, phone): plain text inside the tab and inside its ink */
.seg-ink span span { display: inline; height: auto; padding: 0; }
.seg button .l-m, .seg-ink span .l-m { display: none; }
/* phones carry each chapter's tone on its own words (main.js), not on the body */
.ch[data-tone="dark"] {
  --ink: #f2f4fa;
  --ink-rgb: 242, 244, 250;
  --ink-2: rgba(var(--ink-rgb), 0.76);
  --ink-3: rgba(var(--ink-rgb), 0.64);
  --line: rgba(var(--ink-rgb), 0.16);
  --chip: rgba(var(--ink-rgb), 0.08);
  --thumb: #f2f4fa;
  --thumb-ink: #0b1120;
  color: var(--ink);
}
.ch[data-tone="dark"] .pt-ic { color: color-mix(in oklab, var(--acc) 55%, #fff); background: color-mix(in oklab, var(--acc) 24%, transparent); }


/* the short words (phones, and short landscape windows): a statement and two chips per segment */
@media (max-width: 599px), (max-aspect-ratio: 9/10), (max-height: 540px) and (min-aspect-ratio: 9/10) {
  .ch-head span, .ch-stmts, .ch-get { display: none; }

  .m-words { display: block; margin-top: 12px; align-self: stretch; }
  .m-stmts { position: relative; height: var(--mstmts-h, auto); }
  .mstmt {
    position: absolute; left: 0; right: 0; top: 0; visibility: hidden;
    font-size: clamp(31px, min(9.5vw, 5.2vh), 52px); font-weight: 830; font-stretch: 112%; line-height: 0.98; letter-spacing: -0.035em;
    text-wrap: balance;
  }
  .mstmt .w { display: inline-block; overflow: hidden; vertical-align: top; padding: 0.04em 0 0.1em; margin: -0.04em 0 -0.1em; }
  .mstmt .w > span { display: inline-block; will-change: transform, opacity; }

  /* chips: one pill each, morphing from segment to segment */
  .m-chips { display: flex; gap: 8px; margin-top: 14px; height: 30px; }
  .chip { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 8px; flex: none; transform-origin: 0 50%; }
  .chip-bg {
    position: absolute; inset: 0; border-radius: 999px;
    background: color-mix(in oklab, var(--acc) 13%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--acc) 24%, transparent);
  }
  .ch[data-tone="dark"] .chip-bg { background: color-mix(in oklab, var(--acc) 24%, transparent); }
  .chip-ic { position: relative; flex: none; width: 16px; height: 16px; color: var(--acc); }
  .ch[data-tone="dark"] .chip-ic { color: color-mix(in oklab, var(--acc) 55%, #fff); }
  .chip-ic > span { position: absolute; inset: 0; display: grid; place-items: center; visibility: hidden; }
  .chip-ic .i { width: 16px; height: 16px; }
  .chip-lb { position: relative; flex: 1 1 auto; min-width: 0; height: 30px; overflow: hidden; }
  .chip-lb > span { position: absolute; left: 0; top: 0; line-height: 30px; white-space: nowrap; font-size: 13.5px; font-weight: 650; letter-spacing: -0.005em; color: var(--ink); visibility: hidden; }

  .seg button .l-d, .seg-ink span .l-d { display: none; }
  .seg button .l-m, .seg-ink span .l-m { display: inline; }
}

@media (max-width: 599px), (max-aspect-ratio: 9/10) {
  .m-head { display: flex; }
  :root {
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --m-top: calc(var(--safe-t) + 70px);
  }
  html, body { overscroll-behavior-y: none; }
  body { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

  /* the stage keeps the large viewport's height while the browser bar slides; the words keep the small one */
  .stage { bottom: auto; height: var(--stage-h, 100lvh); }
  .words { bottom: auto; height: var(--vis-h, 100svh); }
  .curtain { bottom: auto; height: var(--vis-h, 100svh); }

  /* nav: the mark, the app, and the App Store, compact */
  .nav { height: calc(var(--safe-t) + 50px); padding: var(--safe-t) 14px 0 16px; gap: 8px; }
  .nav-mark { font-size: 0; gap: 0; }
  .nav-logo { width: 17px; height: 17px; }
  .nav-app { gap: 7px; padding: 4px 10px 4px 4px; font-size: 14.5px; }
  .nav-app img { width: 24px; height: 24px; border-radius: 6px; }
  .nav-app::before { height: 18px; margin: 0 6px 0 2px; }
  .nav-store { border-radius: 7px; }
  .nav-store img { width: 93px; height: 31px; }

  /* the rail: a slim row of chapter bars under the nav, each filling as you pass through it */
  .rail {
    top: calc(var(--safe-t) + 50px); bottom: auto; left: 16px; right: 16px; transform: none;
    gap: 4px; padding: 0; border-radius: 0;
  }
  .rail button { flex: 1 1 0; min-width: 0; height: 12px; padding: 0; font-size: 0; color: transparent; }
  .rail button::before { content: ""; position: absolute; left: 0; right: 0; bottom: 5px; height: 2px; border-radius: 1px; background: rgb(var(--rail-rgb)); opacity: 0.16; }
  .rail button i { bottom: 5px; opacity: 0.9; }

  /* a chapter's words */
  .ch {
    top: 0; bottom: auto; left: 0; right: 0; width: auto; height: var(--vis-h, 100svh);
    display: block; padding: var(--m-top) 20px 0;
  }
  .ch[data-side="right"] { left: 0; right: 0; }
  .ch-head { gap: 9px; visibility: hidden !important; }
  /* the one chapter header (mhead.js): it morphs from chapter to chapter instead of leaving */
  .m-head {
    --m-ink: 16, 20, 30;
    position: absolute; left: 20px; top: var(--m-top); z-index: 6; display: flex; align-items: center; gap: 9px; height: 26px;
    pointer-events: none; visibility: hidden; color: rgb(var(--m-ink));
  }
  .m-glyph { position: relative; flex: none; width: 26px; height: 26px; color: #fff; }
  .m-gbg { position: absolute; inset: 0; border-radius: 8px; background: var(--cobalt); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 3px 8px rgba(8, 14, 32, 0.18); }
  .m-glyph > span { position: absolute; inset: 0; display: grid; place-items: center; visibility: hidden; }
  .m-glyph .i { width: 14px; height: 14px; }
  .m-name { position: relative; height: 20px; overflow: hidden; }
  .m-name b { position: absolute; left: 0; top: 0; line-height: 20px; white-space: nowrap; font-size: 14.5px; font-weight: 720; letter-spacing: -0.01em; visibility: hidden; }
  .ch-glyph { width: 26px; height: 26px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 3px 8px rgba(8, 14, 32, 0.18); }
  .ch-glyph .i { width: 54%; height: 54%; }
  .ch-head b { font-size: 14.5px; font-weight: 720; }
  /* the control: bottom centre, inside the safe area */
  .seg {
    position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 16px); margin: 0 auto; width: max-content; max-width: calc(100% - 28px);
    --sh: 34px; --sp: 11px; --segf: 13px;
    background: color-mix(in oklab, var(--chip) 100%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  }

  /* the opening: the headline on top, the phone below it, the badge at the bottom */
  .hero-words {
    left: 20px; right: 20px; width: auto; top: calc(var(--safe-t) + 74px); bottom: calc(var(--safe-b) + 18px); transform: none;
    gap: 12px;
  }
  .hero-h1 { font-size: clamp(36px, min(12.6vw, 6.4vh), 64px); font-stretch: 100%; line-height: 0.92; letter-spacing: -0.042em; }
  .hero-sub-d { display: none; }
  .hero-sub-m { display: block; max-width: 28ch; font-size: clamp(15px, 4.1vw, 19px); line-height: 1.4; }
  .hero-get { margin-top: auto; justify-content: center; gap: 12px; }
  .hero-get .badge img { height: 44px; }
  .hero-get small { font-size: 12.5px; line-height: 1.35; }

  /* the close */
  .close { padding: calc(var(--safe-t) + 60px) 22px 0; }
  .close-icon { width: clamp(84px, 24vw, 112px); height: clamp(84px, 24vw, 112px); }
  .close h2 { font-size: clamp(40px, 12.4vw, 64px); font-stretch: 112%; }
  .close-sub { font-size: 15.5px; max-width: 30ch; line-height: 1.45; }
  .close-get { margin-top: 22px; }
  .close-get .badge img { height: 48px; }
  .foot {
    flex-direction: column; align-items: center; gap: 10px; text-align: center;
    padding: 18px 0 calc(var(--safe-b) + 18px); font-size: 12px; line-height: 1.5;
  }
  .foot nav { flex-wrap: wrap; justify-content: center; gap: 6px 16px; }
}

/* a phone's headline: one word per line (a portrait tablet keeps two lines) */
@media (max-width: 599px) {
  .hero-h1 span { white-space: normal; width: min-content; }
}

/* a phone on its side (or any short window): the desktop's side-by-side film with the short words, compact */
@media (max-height: 540px) and (min-aspect-ratio: 9/10) {
  .nav { height: 46px; padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); gap: 10px; }
  .nav-mark { font-size: 14px; gap: 7px; }
  .nav-logo { width: 15px; height: 15px; }
  .nav-app { font-size: 13.5px; padding: 3px 8px 3px 3px; gap: 7px; }
  .nav-app img { width: 22px; height: 22px; border-radius: 6px; }
  .nav-store img { width: 90px; height: 30px; }
  .ch { top: 50px; bottom: 38px; left: max(28px, env(safe-area-inset-left)); gap: 12px; }
  .ch-glyph { width: 28px; height: 28px; border-radius: 8px; }
  .ch-head b { font-size: 14px; }
  .mstmt { font-size: clamp(24px, 7.4vh, 36px); }
  .m-words { margin-top: 0; order: 1; }
  .ch .seg { order: 2; }
  .m-chips { margin-top: 10px; }
  .seg { --sh: 30px; --sp: 10px; --segf: 12px; }
  .rail { bottom: 6px; padding: 4px 12px; }
  .rail button { font-size: 11px; padding: 2px 0 5px; }
  .hero-words { top: 50%; gap: 12px; width: clamp(300px, 44vw, 460px); }
  .hero-h1 { font-size: clamp(30px, 9vh, 46px); }
  .hero-sub-d { display: none; }
  .hero-sub-m { display: block; max-width: 30ch; font-size: 14.5px; line-height: 1.4; }
  .hero-get .badge img { height: 38px; }
  .close-icon { width: 64px; height: 64px; }
  .close h2 { font-size: clamp(30px, 9vh, 48px); margin-top: 12px; }
  .close-sub { margin-top: 8px; font-size: 14px; }
  .close-get { margin-top: 12px; }
  .close-get .badge img { height: 40px; }
  .foot { padding: 10px 0 12px; font-size: 11.5px; }
}
