/* Phones and tablets (no hover). Figma: Website Design > Mobile - Home+ProjectSelection (439:1076,
   453:267), _menunav (453:205), mobile_header_expanded (453:192), Mobile - Contact (455:457).
   The frames are 402 wide; --mu is one Figma px at the current width (capped for tablets),
   so every size below reads straight from Figma: calc(<figma px> * var(--mu)).
   Desktop never sees any of this: everything that shows is inside @media (hover: none). */
.m-home, .m-logo, .m-menu { display: none; }

@media (hover: none) {
  :root { --mu: calc(min(100vw, 560px) / 402); }
  html, body { overflow-x: clip; }

  /* The desktop pieces step aside (their scripts also stop early on touch) */
  .hdr, #intro, #projects, #contact, body[data-page="home"] #csFoot, body[data-page="home"] #csFootSpace { display: none !important; }

  /* ---------- S-M logo button: sits at its Figma spot, then stays 12px under the top edge ---------- */
  .m-logo {
    display: block; position: fixed; z-index: 120; left: 50%;
    top: max(calc(12px + env(safe-area-inset-top, 0px)), calc(63 * var(--mu) - var(--m-scroll, 0px)));   /* Figma v2: y63 */
    width: calc(82 * var(--mu)); height: calc(50.9 * var(--mu)); margin-left: calc(-41 * var(--mu));
    padding: 0; border: 0; background: none; color: var(--on-accent); cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .m-logo svg { position: absolute; inset: 0; width: 100%; height: 100%; fill: var(--accent); }
  .m-logo span {
    position: relative; display: block; text-align: center;
    font-weight: 500; font-size: calc(36.07 * var(--mu)); letter-spacing: -0.1em; line-height: calc(50.9 * var(--mu));
    padding-bottom: calc(2 * var(--pill-lift)); padding-right: 0.08em;
  }
  .m-logo:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; border-radius: 12px; }

  /* ---------- Glass menu (mobile_header_expanded: 400 x 564, radius 50, at x1 y44) ---------- */
  .m-menu {
    display: block; position: fixed; z-index: 110; left: 50%; top: var(--m-panel-top, calc(44 * var(--mu)));
    width: calc(400 * var(--mu)); height: calc(564 * var(--mu)); margin-left: calc(-200 * var(--mu));
    visibility: hidden; pointer-events: none;
  }
  .m-menu.is-open { visibility: visible; pointer-events: auto; }
  .m-menu-glass {
    /* js/mobile-menu.js sizes this from the logo's pill to the full panel on springs (Liquid Glass
       morph). Nothing clips it, so the blur sees the page behind and the overshoot shows. */
    position: absolute; left: 0; top: 0; width: 100%; height: 100%; border-radius: calc(50 * var(--mu));
    background: var(--glass-fill);
    -webkit-backdrop-filter: blur(24px) saturate(1.4); backdrop-filter: blur(24px) saturate(1.4);
    box-shadow: inset 0 1.5px 0 var(--glass-rim), inset 0 18px 30px -18px var(--glass-glow),
      inset 1.5px 0 0 var(--glass-rim-soft), inset -1.5px 0 0 var(--glass-rim-soft);
  }
  .m-menu nav { position: absolute; inset: 0; }
  .m-menu a {
    position: absolute; left: 1.75%; right: 1.75%; display: block; text-align: center;
    font-weight: 500; font-size: calc(80 * var(--mu)); letter-spacing: -0.05em; line-height: 1.2;
    color: var(--fg); text-decoration: none; -webkit-tap-highlight-color: transparent;
  }
  .m-menu a:nth-child(1) { top: 14.72%; }
  .m-menu a:nth-child(2) { top: 34.04%; }
  .m-menu a:nth-child(3) { top: 53.37%; }
  .m-menu a:nth-child(4) { top: 72.7%; }
  .m-menu a:active { color: var(--accent); }
  .m-menu a:focus-visible { outline: 3px solid var(--blue); outline-offset: -2px; border-radius: 16px; }
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .m-menu-glass { background: var(--glass-solid); }
  }
  html.m-menu-open { overflow: hidden; }

  /* Theme toggle: top right, level with the logo, and it rides up with the logo as you scroll */
  .theme-toggle {
    --w: 52px; left: auto;
    top: calc(max(calc(12px + env(safe-area-inset-top, 0px)), calc(63 * var(--mu) - var(--m-scroll, 0px))) + 25.45 * var(--mu) - 12px);
    right: max(14px, env(safe-area-inset-right, 0px));
  }

  /* ---------- Home: one screen, a sideways carousel (Sam, Nov 19; Figma Mobile - Home+ProjectSelection_v2,
     402 x 821: 688:300 greeting, 633:684 / 688:229 / 688:258 projects). The 402 x 821 artboard sits on
     the bottom edge of the screen, so the glass, caption and name row land exactly; any extra height goes
     above, under the logo. Every y below is Figma px measured from the artboard's top:
     calc(100svh + (y - 821) * var(--mu)). Slide 1 = greeting, then one slide per project. ---------- */
  body[data-page="home"] { --mu: min(calc(min(100vw, 560px) / 402), calc(100svh / 821)); }
  html:has(body[data-page="home"]), body[data-page="home"] { overflow: hidden; height: 100%; overscroll-behavior: none; }
  .m-home { display: block; position: relative; width: 100%; height: 100svh; overflow: hidden; }
  .m-ps { position: absolute; inset: 0; touch-action: none; }   /* sideways = slides, up/down = turn the object (js/mobile-home.js) */
  .m-intro { position: absolute; inset: 0; will-change: transform; }
  .m-greet {
    position: absolute; left: calc(50% + (47 - 201) * var(--mu)); top: calc(100svh + (207 - 821) * var(--mu)); width: calc(315 * var(--mu)); margin: 0;
    text-align: center; font-weight: 500; font-size: calc(64 * var(--mu)); letter-spacing: -0.05em; line-height: 1.08;
    color: var(--fg); white-space: nowrap;
  }
  .m-greet .hl { color: var(--accent); }
  .m-greet .hl i { font-style: normal; color: var(--fg); }
  .m-pron {
    position: absolute; left: calc(50% + (312 - 201) * var(--mu)); top: calc(100svh + (216 - 821) * var(--mu)); margin: 0;
    font-weight: 300; font-size: calc(13 * var(--mu)); letter-spacing: -0.05em; line-height: 1.2; color: var(--fg);
  }
  /* Portrait: the same frame + cutout pair as the desktop intro (Figma "Portrait collage" 339 wide at x16 y318) */
  .m-photo { position: absolute; left: calc(50% + (16 - 201) * var(--mu)); top: calc(100svh + (318 - 821) * var(--mu)); width: calc(339 * var(--mu)); aspect-ratio: 650 / 387; }
  .m-photo img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
  .m-state {
    position: absolute; left: calc(50% + (24 - 201) * var(--mu)); top: calc(100svh + (580 - 821) * var(--mu)); width: calc(362 * var(--mu)); margin: 0;
    text-align: left; font-weight: 300; font-size: calc(26 * var(--mu)); letter-spacing: -0.05em; line-height: 1.3;
    color: var(--fg);
  }
  /* Word pop colour: accent fading into the text colour as --flash goes 1 -> 0 (js/mobile-home.js) */
  .mw { display: inline-block; --flash: 0; color: color-mix(in srgb, var(--accent) calc(var(--flash) * 100%), var(--fg)); }
  .m-greet .mw.hl { color: var(--accent); }

  /* Projects: the stills are free above the glass and cut off at the bottom of the screen. The glass
     (y581 to the bottom) arrives with the first project and stays; its caption swaps per project. */
  .m-track { position: absolute; inset: 0; }
  .m-card { position: absolute; inset: 0; display: block; color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
  .m-card:not([href]) { cursor: default; }
  .m-card:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
  .m-objs { position: absolute; z-index: 1; inset: 0; overflow: hidden; pointer-events: none; }
  .m-objs-in { position: absolute; inset: 0; }
  .m-still { position: absolute; display: block; max-width: none; will-change: transform; transform-origin: 50% 50%; }
  .m-glass, .m-fade, .m-cap { will-change: transform; }
  .m-glass {
    position: absolute; left: 0; right: 0; top: calc(100svh - 240 * var(--mu)); bottom: 0; z-index: 2; pointer-events: none;
    overflow: hidden; background: var(--bg); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36);
    border-radius: calc(50 * var(--mu)) calc(50 * var(--mu)) 0 0;   /* Figma "Glass caption surface": 50 on the top corners */
  }
  /* The glass holds its own copy of the stills (lined up with the real ones), enlarged 6% and blurred a
     little, so it reads as thick clear glass in every browser, iPhone included. */
  .m-glass-objs {
    position: absolute; left: 0; top: calc(-100svh + 240 * var(--mu)); width: 100%; height: 100svh;
    filter: blur(4px) saturate(180%) brightness(1.05); transform: scale(1.06);   /* clear glass, like desktop (was 9px) */ transform-origin: 50% calc(100svh - 120 * var(--mu));
  }
  .m-glass::after { content: ""; position: absolute; inset: 0; background: var(--glass-fill); }
  /* Dark mode: a light tint of black deeper in the glass, so the white title reads over a white render (Google Ads) */
  html:not([data-theme="light"]) .m-glass::after { background: linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.4) 60%), var(--glass-fill); }
  /* Progressive blur over the glass's top edge, so the still goes sharp to glassy */
  /* Off (Sam, Nov 19): this band softened the objects above the glass's edge. Objects stay sharp up to the glass now, like desktop. */
  .m-fade { display: none; }
  .m-fade-was { position: absolute; left: 0; right: 0; top: calc(100svh + (504 - 821) * var(--mu)); height: calc(137 * var(--mu)); z-index: 2; pointer-events: none; }
  .m-fade i { position: absolute; inset: 0; }
  .m-fade i:nth-child(1) {
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
    -webkit-mask: linear-gradient(transparent 0%, #000 35%, transparent 70%); mask: linear-gradient(transparent 0%, #000 35%, transparent 70%);
  }
  .m-fade i:nth-child(2) {
    -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
    -webkit-mask: linear-gradient(transparent 25%, #000 50%, transparent 80%); mask: linear-gradient(transparent 25%, #000 50%, transparent 80%);
  }
  .m-fade i:nth-child(3) { display: none; }
  .m-cap {
    position: absolute; z-index: 4; left: calc(50% + (39.25 - 201) * var(--mu)); top: calc(100svh + (596.4 - 821) * var(--mu)); width: calc(318.9 * var(--mu));
    display: flex; flex-direction: column; gap: calc(24.3 * var(--mu)); pointer-events: none;
  }
  .m-name {
    --flash: 0; margin: 0; text-align: center; white-space: nowrap;
    color: color-mix(in srgb, var(--accent) calc(var(--flash) * 100%), var(--fg));
    font-weight: 500; font-size: calc(56.88 * var(--mu)); letter-spacing: -0.05em; line-height: 1.1;
    text-shadow: 0 1px 12px color-mix(in srgb, var(--bg) 45%, transparent);
  }
  .m-tags { display: flex; justify-content: center; gap: calc(8.125 * var(--mu)); margin: 0; padding: 0; list-style: none; }
  .m-tags li {
    width: calc(100.55 * var(--mu)); height: calc(34.53 * var(--mu)); flex: none;
    display: flex; align-items: center; justify-content: center; white-space: nowrap;
    padding-bottom: calc(2 * var(--pill-lift));
    background: var(--accent); color: var(--on-accent); border: 1px solid var(--pill-rim); border-radius: calc(20.31 * var(--mu));
    font-weight: 300; font-size: calc(16.25 * var(--mu)); letter-spacing: -0.05em;
  }

  /* Position dots under the pills (Sam, Nov 19), like the desktop dots turned sideways: grey dots with
     a yellow bar that slides to the current project. 44px-tall tap row; sits between the pills and the name row. */
  .m-dots {
    --gap: 16px; position: absolute; z-index: 4; left: 50%; top: calc(100svh + (741 - 821) * var(--mu)); height: 28px; margin-top: -14px;
    display: flex; gap: 0; translate: -50% 0;
  }
  .m-dot { width: var(--gap); height: 28px; padding: 0; border: 0; background: none; display: grid; place-items: center; -webkit-tap-highlight-color: transparent; }
  .m-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--fg); opacity: 0.3; }
  .m-dot:focus-visible { outline: 2px solid var(--blue); outline-offset: -4px; border-radius: 50%; }
  .m-dots::after {
    content: ""; position: absolute; top: 50%; left: calc(var(--gap) / 2 + var(--i, 0) * var(--gap)); pointer-events: none;
    width: 16px; height: 6px; margin: -3px 0 0 -8px; border-radius: 3px; background: var(--accent);
    transition: left 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);   /* springs past and settles */
  }
  @media (prefers-reduced-motion: reduce) { .m-dots::after { transition: none; } }

  /* Closing slide (Sam, Nov 19): after the last project, the way to About and Contact even if the
     S-M menu is never found. Same type as the About page's "Let's work together" and the pills. */
  .m-end {
    position: absolute; z-index: 3; left: 50%; top: calc(100svh + (330 - 821) * var(--mu)); width: calc(318 * var(--mu)); margin-left: calc(-159 * var(--mu));
    display: flex; flex-direction: column; align-items: center; gap: calc(28 * var(--mu)); will-change: transform;
  }
  .m-end-line { margin: 0; text-align: center; font-weight: 500; font-size: calc(44 * var(--mu)); letter-spacing: -0.05em; line-height: 1.1; color: var(--fg); }
  .m-end-links { display: flex; gap: calc(12 * var(--mu)); margin: 0; padding: 0; list-style: none; }
  .m-end-links a {
    width: calc(120 * var(--mu)); height: 44px; display: flex; align-items: center; justify-content: center; text-decoration: none;
    padding-bottom: calc(2 * var(--pill-lift)); background: var(--accent); color: var(--on-accent); border: 1px solid var(--pill-rim); border-radius: 22px;
    font-weight: 300; font-size: 17px; letter-spacing: -0.05em; -webkit-tap-highlight-color: transparent;
  }
  .m-end-links a:active { scale: 0.96; }
  .m-end-links a:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

  /* Menu hint on the first visit (js/mobile-home.js): the logo flickers yellow / blue and bounces,
     and "Tap for menu" shows under it for a few seconds */
  .m-hint {
    position: fixed; z-index: 119; left: 0; right: 0; margin: 0; text-align: center; pointer-events: none;
    top: calc((63 + 50.9 + 10) * var(--mu));
    font-weight: 300; font-size: 14px; letter-spacing: -0.03em; color: var(--fg);
    opacity: 0; translate: 0 -6px; transition: opacity 0.4s ease-out, translate 0.4s ease-out;
  }
  .m-hint.is-on { opacity: 1; translate: 0 0; }
  .m-logo.is-hinting { animation: m-hint-bounce 1.2s ease-in-out 2; }
  .m-logo.is-hinting svg { animation: m-hint-flicker 0.6s steps(1) 4; }
  @keyframes m-hint-flicker { 0% { fill: var(--accent); } 50% { fill: var(--hint-alt, var(--blue)); } }
  html[data-theme="light"] .m-logo { --hint-alt: #EDFF21; }   /* the other logo colour in light mode */
  @keyframes m-hint-bounce { 0%, 100% { scale: 1; } 20% { scale: 1.12; } 40% { scale: 0.96; } 60% { scale: 1.04; } }

  /* Swipe-spin turntables (js/mobile-home.js): hidden until their frames have loaded, then they replace the stills */
  .m-spin { position: absolute; display: block; visibility: hidden; opacity: 0; will-change: transform; pointer-events: none; }
  .m-spin.is-ready { opacity: 1; }
  .m-still { transition: opacity 0.2s; }

  /* "Drag to turn" (js/mobile-home.js): a small glass pill just above the glass card, centred, shown on
     project slides until the visitor has turned an object once */
  .m-gesture {
    position: absolute; z-index: 5; left: 50%; top: calc(100svh + (548 - 821) * var(--mu)); margin: 0; translate: -50% 8px;
    display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px 0 9px; border-radius: 16px; pointer-events: none;
    background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255, 255, 255, 0.2); color: var(--fg);
    -webkit-backdrop-filter: blur(8px) saturate(1.5); backdrop-filter: blur(8px) saturate(1.5);
    font-weight: 300; font-size: 13px; letter-spacing: -0.03em; white-space: nowrap;
    opacity: 0; transition: opacity 0.35s ease-out, translate 0.35s ease-out;
  }
  html[data-theme="light"] .m-gesture { background: rgba(255, 255, 255, 0.55); border-color: rgba(0, 0, 0, 0.14); }
  .m-gesture.is-on { opacity: 1; translate: -50% 0; }
  .m-gesture svg { width: 16px; height: 16px; flex: none; }
  .m-gesture.is-on svg:first-child { animation: m-gesture-nudge 1.6s ease-in-out infinite; }
  @keyframes m-gesture-nudge { 0%, 100% { transform: translateY(0); } 30% { transform: translateY(-2px); } 60% { transform: translateY(2px); } }
  @media (prefers-reduced-motion: reduce) { .m-gesture.is-on svg:first-child { animation: none; } }

  /* Overlap transition into a case study: the sheet that grows up over the screen */
  .m-sheet {
    position: fixed; z-index: 300; left: 0; right: 0; bottom: 0; pointer-events: none;
    background: var(--bg); border-radius: calc(50 * var(--mu)) calc(50 * var(--mu)) 0 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36), 0 -20px 60px rgba(0, 0, 0, 0.35);
  }

  /* Name and role: fixed along the bottom on every slide (x39 / x228, y764), over the glass */
  .m-who {
    position: absolute; z-index: 5; left: calc(50% + (39 - 201) * var(--mu)); width: calc(318 * var(--mu)); top: calc(100svh + (764 - 821) * var(--mu));
    margin: 0; display: flex; justify-content: space-between; pointer-events: none;
    font-weight: 300; font-size: calc(16.25 * var(--mu)); letter-spacing: -0.05em; line-height: calc(23 * var(--mu)); color: var(--fg);
  }
  .m-who span:first-child { width: calc(100.55 * var(--mu)); text-align: center; }
  .m-who span:last-child { width: calc(129 * var(--mu)); text-align: center; }

  /* Carousel controls (Compass Layout > Carousel): round outlined previous / next buttons, here on the
     screen edges level with the objects. Glass behind the chevron so it reads over any render. A 44px
     tap area around a 36px button. Hidden at the ends (nothing before the greeting, nothing after the last project). */
  .m-arrow {
    position: absolute; z-index: 6; top: calc(100svh + (390 - 821) * var(--mu)); width: 44px; height: 44px; margin-top: -22px;
    display: grid; place-items: center; padding: 0; border: 0; background: none; color: var(--fg); cursor: pointer;
    -webkit-tap-highlight-color: transparent; transition: opacity 0.15s ease-out, scale 0.15s ease-out;
  }
  .m-arrow.is-prev { left: max(6px, env(safe-area-inset-left, 0px)); }
  .m-arrow.is-next { right: max(6px, env(safe-area-inset-right, 0px)); }
  .m-arrow::before {
    content: ""; position: absolute; width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(8px) saturate(1.5); backdrop-filter: blur(8px) saturate(1.5);
  }
  html[data-theme="light"] .m-arrow::before { border-color: rgba(0, 0, 0, 0.14); background: rgba(255, 255, 255, 0.55); }
  .m-arrow svg { position: relative; width: 18px; height: 18px; }
  .m-arrow:active { scale: 0.92; }
  .m-arrow[disabled] { opacity: 0; pointer-events: none; }
  .m-arrow:focus-visible { outline: none; }
  .m-arrow:focus-visible::before { outline: 2px solid var(--blue); outline-offset: 2px; }
  @media (prefers-reduced-motion: reduce) { .m-arrow { transition: none; } }

  /* ---------- Contact (Figma Mobile - Contact: three 80px links, centred, from y200) ---------- */
  body[data-page="case"] .ct { padding: calc(193 * var(--mu)) 0 0; text-align: center; min-height: calc(100svh - 96px); }
  body[data-page="case"] .ct-links a { font-size: calc(80 * var(--mu)); line-height: 1.4; }
  /* Case studies: clear the logo instead of the desktop header */
  body[data-page="case"] .cs { padding-top: calc(160 * var(--mu)); }
}

/* Arriving on the sheet (any page opened from the phone carousel): the content rises into place.
   html.sheet-in is set by the head script when sessionStorage has "sm-sheet". */
@media (hover: none) {
  html.sheet-in body > main { animation: m-sheet-in 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }
  @keyframes m-sheet-in { from { opacity: 0; transform: translateY(48px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) { html.sheet-in body > main { animation: none; } }
