/* See 4 Me — mobile & touch.
 * -----------------------------------------------------------------------
 * Mobile first. This file is about the physical device: notches, home
 * indicators, browsers that steal taps, long-press menus that fire a context
 * menu instead, and fingers that are bigger than the targets.
 *
 * TWO VIEWS, NOT TWO LAYOUTS
 * The landing page and the live view are both `position: fixed; inset: 0`, so
 * they are the same layout at every size. Only the padding differs, and only
 * for the safe area — the hardware's own reserved edges.
 */

/* ── the page itself ────────────────────────────────────────────────── */

html, body {
  /* dvh, not vh: on mobile browsers vh is the height with the address bar
     hidden, so a vh-sized element is taller than the visible screen and the
     bottom gets hidden behind the browser chrome. dvh tracks the real visible
     height and updates as the bar slides away. The vh lines are the fallback
     for older Safari. */
  height: 100vh;
  height: 100dvh;
  height: 100svh;

  /* Stop the whole page from rubber-banding when a drag starts near an edge.
     Without this, swiping near the screen edge scrolls the page and a tap can
     be swallowed — which for this user means the tap that starts Anna silently
     does nothing. */
  overscroll-behavior: none;

  /* NOTE: html/body are NOT position:fixed. Doing that made the root element
     collapse to its content height, so #tap (which is position:fixed inset:0)
     resolved against a 419px viewport instead of the full screen and every
     element below the fold landed at y≈1700. #tap and #live do the fixed
     positioning themselves. */

  /* Never let the page itself pan or zoom. The user CAN still pinch-zoom the
     text — the viewport no longer forbids it — but a stray drag cannot move
     the page out from under the tap target. */
  touch-action: manipulation;

  /* Stop iOS calling a number a phone number, which would open the dialler. */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* Kills the grey flash and the text inflation Android applies when a page
     has a lot of text on a narrow screen. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── the safe area ──────────────────────────────────────────────────────
   Every fixed, full-screen surface has to respect the notch, the status bar
   and the home indicator. `viewport-fit=cover` is what makes these insets
   non-zero; without it they resolve to 0 and the layout hides under the
   hardware. `env(..., 0px)` supplies the fallback where env() is unsupported. */

#tap, #live {
  padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  padding-left: calc(1.5rem + env(safe-area-inset-left, 0px));
  padding-right: calc(1.5rem + env(safe-area-inset-right, 0px));
}

/* The stop button sits at the very bottom, so it needs the home-indicator
   inset added or the home bar swallows the tap target. */
#stop {
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  padding-top: calc(1rem + env(safe-area-inset-top, 0px));
}

/* ── touch targets ────────────────────────────────────────────────────
   44x44 CSS px is the platform minimum (Apple HIG and WCAG 2.5.5 both land
   here). A full-screen button is obviously past it; #stop is a real button
   and has to be sized deliberately rather than by its text. */

#stop {
  min-height: 44px;
  min-width: 44px;
}

/* ── no text selection, no callout, no long-press menu ──────────────────
   A long press opens a context menu on both platforms. The menu is opened by
   LONG PRESS in this app, so the browser's own long-press menu would fire at
   the same moment and cover the options the user is trying to hear.

   This must be on the tap surface itself, not just on body — Safari only
   applies -webkit-touch-callout to the element that was actually touched. */

#tap, #live {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* Prevents the iOS text magnifier (the loupe) appearing on a double-tap. */
  -webkit-tap-highlight-color: transparent;
}

/* The stop button's own label stays selectable-free too. */
#stop {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* Both platforms give a little slop around a button's own tap area. */
  touch-action: manipulation;
}

/* ── the pulsing indicator ─────────────────────────────────────────────
   motion is the only "animation" in this app, and it indicates that Anna is
   listening. Someone with a vestibular disorder or photosensitivity cannot
   have a 2.4-second pulse. The listening state is also carried by the text
   and by the sound, so honouring this setting loses nothing. */

@media (prefers-reduced-motion: reduce) {
  #live.listening .pulse {
    animation: none;
  }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ── very small phones ────────────────────────────────────────────────
   The title and the start button are the largest elements now that the emoji
   is gone. On a short screen (an iPhone SE at 320x568, or a phone with a large
   system font) they would push the start hint off the bottom, and the start
   hint is the one thing a new user has to be able to read. */

@media (max-height: 660px) {
  h1 { font-size: 1.75rem; }
  .sub { font-size: 1.05rem; }
  .hint { font-size: 1rem; margin-top: 0; }
  #tap, #live { gap: 0.7rem; }
  .cta { padding: 0.75rem 1.5rem; font-size: 1.15rem; }
}

@media (max-height: 600px) {
  .cta { padding: 0.7rem 1.4rem; font-size: 1.15rem; }
  #live { gap: 0.75rem; }
}

/* The shortest screens still in use — an iPhone SE is 568px, a small Android
   with a large system font can be shorter than that. The start instruction must
   never be pushed off the bottom, because it is the one thing a new user has to
   read to know the app can be started at all. */
@media (max-height: 540px) {
  html { font-size: 19px; }
  h1 { font-size: 1.6rem; }
  .sub { font-size: 1rem; }
  .hint { font-size: 1rem; margin-top: 0; }
  #tap, #live { gap: 0.6rem; }
}

/* Landscape phone: height is the scarce dimension, so trim harder. */
@media (orientation: landscape) and (max-height: 500px) {
  h1 { font-size: 1.5rem; }
  .hint { display: none; }   /* the button says it, and height is critical */
  #tap { gap: 0.5rem; }
}

/* ── text scaling from the OS ──────────────────────────────────────────
   If the user has raised the system font size, respect it. Everything is in
   rem off a rem root, so this works. */

html {
  /* The base every rem size derives from. */
  font-size: 22px;
}

/* The eye is decoration, so it is the one thing allowed to grow with the
   viewport instead of with the system text size — capped at 30% of the screen
   height so it can never crowd out the start instruction. Every piece of real
   text scales fully with the user's font setting. */