/* =========================================================================
   Ask Gianfranco — a personal AI app
   Hand-authored. OKLCH throughout. Warm paper stage, deep clay-red accent.
   base.css: tokens, stage, device, statusbar, liveact, os-switch, sys glyphs,
   mood overlays, navind, reduced-motion block, per-OS chrome skins.
   ========================================================================= */

:root {
  --stage:        oklch(0.915 0.014 83);  /* warm ecru page */
  --surface:      oklch(0.975 0.006 86);  /* app screen, warm white */
  --surface-2:    oklch(0.948 0.011 80);  /* incoming bubbles, panels */
  --surface-3:    oklch(0.918 0.014 78);  /* chips, inputs */
  --line:         oklch(0.85 0.015 76);
  --line-soft:    oklch(0.90 0.012 78);

  --text:         oklch(0.28 0.018 52);   /* warm charcoal ink */
  --text-muted:   oklch(0.46 0.020 50);
  --text-faint:   oklch(0.60 0.018 52);

  /* ----------------------------------------------------- seeded accent ----
     --seed is the single hue source for the whole OS accent. Settings writes
     it (hue only; L/C stay 0.47/0.155). Every seed-derived token is declared
     TWICE: a literal clay-red first (the permanent fallback for browsers
     without relative-color support), then the relative-color version that
     follows --seed. Browsers that don't understand `oklch(from ...)` ignore
     the second declaration and keep clay-red — so theming degrades cleanly.
     Neutrals (--stage/--surface/--line/--text), --mint, glass, the island
     near-black and AI transient colors NEVER re-seed: paper identity + text
     contrast are guaranteed regardless of the chosen hue. */
  --seed:         oklch(0.47 0.155 33);   /* deep clay red — the OS accent seed */

  --accent:       oklch(0.47 0.155 33);   /* deep clay red, AA on paper (fallback) */
  --accent:       oklch(from var(--seed) l c h);
  --accent-strong:oklch(0.41 0.160 32);                                   /* fallback */
  --accent-strong:oklch(from var(--seed) calc(l - 0.06) calc(c + 0.005) h);
  --accent-ink:   oklch(0.975 0.012 80);  /* paper text on accent fills (fallback) */
  --accent-ink:   oklch(from var(--seed) 0.975 0.012 h);
  --accent-soft:  oklch(0.47 0.155 33 / 0.13);                            /* fallback */
  --accent-soft:  oklch(from var(--seed) l c h / 0.13);
  --accent-line:  oklch(0.47 0.155 33 / 0.32);                            /* fallback */
  --accent-line:  oklch(from var(--seed) l c h / 0.32);
  --mint:         oklch(0.58 0.135 150);  /* online dot, deepened for light — FIXED */

  /* status-bar adaptation tokens (consumed by .statusbar; default = warm paper
     chrome). Dark apps (e.g. Terminal, later phases) override these per
     `body[data-app=...]` to flip the bar's ink + fill without touching the
     global accent. */
  --statusbar-ink: var(--text);
  --statusbar-bg:  color-mix(in oklch, var(--surface) 82%, transparent);

  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-ui:      "Schibsted Grotesk", system-ui, sans-serif;
  --font-mono:    "Geist Mono", ui-monospace, "SF Mono", monospace;
  --font-label:   "Schibsted Grotesk", system-ui, sans-serif; /* labels: sans, not mono */

  --ease:         cubic-bezier(0.16, 1, 0.3, 1);
  --col:          min(460px, 100vw);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--stage);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection { background: var(--accent-soft); color: var(--text); }

a { color: inherit; }

/* ----------------------------------------------------------------- stage */

.stage-grain,
.stage-glow { position: fixed; pointer-events: none; z-index: 0; }

/* a faint warm wash at the top of the paper, nothing more */
.stage-glow {
  inset: 0;
  background: radial-gradient(72vw 44vw at 50% -8%, oklch(0.72 0.07 45 / 0.12), transparent 60%);
  transition: opacity 1.2s var(--ease);
}

/* oversized faint wordmark grounding the desktop stage (hidden on phones) */
.stage-mark { display: none; }
@media (min-width: 1080px) {
  .stage-mark {
    position: fixed;
    z-index: 0;
    pointer-events: none;
    top: 50%;
    right: calc(50% + var(--col) / 2 + 1.5vw);
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    text-align: right;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(3.5rem, 8.5vw, 7.5rem);
    line-height: 0.84;
    letter-spacing: -0.04em;
    color: oklch(0.30 0.02 50 / 0.07);
    white-space: nowrap;
  }
}
@media (min-width: 1320px) {
  .stage-mark { right: calc(50% + var(--col) / 2 + 3.5vw); }
}

/* subtle paper tooth */
.stage-grain {
  inset: 0;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
}

/* -------------------------------------- story mood: emotional temperature */
/* Overlays crossfade per story beat to shift the paper's temperature
   (Phillips arc). Subtle on light; opacity-only transitions keep it cheap. */
.mood { position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0; }
.mood-cool {
  background: radial-gradient(62vw 50vw at 50% -6%, oklch(0.62 0.05 242 / 0.13), transparent 62%);
  transition: opacity 1.2s var(--ease);
}
.mood-dim {
  background: oklch(0.55 0.012 60 / 0.12);
  mix-blend-mode: multiply;
  transition: opacity 1.3s var(--ease);
}
.mood-bloom {
  background: radial-gradient(72vw 50vw at 50% -6%, oklch(0.62 0.13 40 / 0.15), transparent 62%);
  transition: opacity 1.2s var(--ease);
}

body[data-mood="challenge"] .mood-cool { opacity: 1; }
body[data-mood="challenge"] .stage-glow { opacity: 0.4; }
body[data-mood="peak"] .mood-bloom { opacity: 0.55; }
body[data-mood="setback"] .mood-dim { opacity: 1; }
body[data-mood="setback"] .mood-cool { opacity: 0.4; }
body[data-mood="setback"] .stage-glow { opacity: 0.3; }
body[data-mood="payoff"] .mood-bloom { opacity: 1; animation: bloom 1.6s var(--ease); }
body[data-mood="payoff"] .stage-glow { opacity: 1; }

@keyframes bloom {
  0% { opacity: 0; transform: scale(0.97); }
  45% { opacity: 1; }
  100% { opacity: 1; transform: scale(1); }
}

/* the device surface also takes the temperature, so mood reads on mobile */
.device { transition: background-color 1.3s var(--ease); }
body[data-mood="challenge"] .device { background: oklch(0.965 0.006 92); }
body[data-mood="setback"] .device { background: oklch(0.945 0.007 72); }
body[data-mood="payoff"] .device { background: oklch(0.978 0.011 82); }

/* ---------------------------------------------------------------- device */

.device {
  position: relative;
  z-index: 1;
  width: var(--col);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow:
    0 0 0 1px var(--line),
    0 2rem 4.5rem -2rem oklch(0.4 0.03 50 / 0.28);
}

/* ------------------------------------------------------------- statusbar */

.statusbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: max(0.7rem, env(safe-area-inset-top)) 1.25rem 0.7rem;
  color: var(--statusbar-ink);
  background: var(--statusbar-bg);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line-soft);
}
.statusbar__time {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
/* Android clocks sit lighter and a touch smaller than iOS */
body[data-os="android"] .statusbar__time { font-weight: 500; font-size: 0.84rem; letter-spacing: 0; }
.statusbar__app {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.statusbar__sys { justify-self: end; display: inline-flex; align-items: center; gap: 0.4rem; color: var(--statusbar-ink); }
.statusbar__sys svg { fill: currentColor; }
/* per-OS status glyph clusters: only the active platform's set shows */
.sys { display: none; align-items: center; gap: 0.42rem; }
.sys--android { gap: 0.32rem; }
body[data-os="ios"] .sys--ios { display: inline-flex; }
body[data-os="android"] .sys--android { display: inline-flex; }
.sys-pct { font-family: var(--font-ui); font-weight: 600; font-size: 0.74rem; letter-spacing: -0.02em; color: currentColor; }

/* story progress: a hairline that fills as the narrative advances */
.story-progress {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--line-soft);
  overflow: hidden;
}
.story-progress__fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.9s var(--ease);
  box-shadow: 0 0 0.6rem var(--accent);
}

.dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; display: inline-block; }
.dot--live {
  background: var(--mint);
  box-shadow: 0 0 0 0 oklch(0.58 0.135 150 / 0.5);
  animation: pulse 2.6s var(--ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 oklch(0.58 0.135 150 / 0.45); }
  70%  { box-shadow: 0 0 0 0.5rem oklch(0.58 0.135 150 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(0.58 0.135 150 / 0); }
}

/* ------------------------------------------------------- reveal & motion */

.reveal { opacity: 0; transform: translateY(1.2rem); }
.reveal.in { opacity: 1; transform: none; transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }

/* ------------------------------------------------------------- desktop+  */

@media (min-width: 1080px) {
  body { padding: 3vh 0; align-items: flex-start; }
  .device {
    height: min(820px, calc(100dvh - 6vh));
    min-height: min(680px, calc(100dvh - 6vh));
    margin: auto;
    border-radius: 2.4rem;
    overflow: clip;
    max-height: none;
  }
  /* soft paper-cradle, a light bezel ring plus a long warm shadow */
  .device { box-shadow: 0 0 0 1px var(--line), 0 0 0 0.5rem oklch(0.97 0.006 86), 0 0 0 0.55rem var(--line), 0 2.5rem 5.5rem -1.5rem oklch(0.4 0.03 50 / 0.32); }
  /* the per-screen scroller (.app-body) owns scrolling now, not .thread */
  .statusbar { border-radius: 2.4rem 2.4rem 0 0; }
}

/* very small phones */
@media (max-width: 360px) {
  .thread { padding-inline: 0.9rem; }
  .bubble { font-size: 0.95rem; }
}

/* =========================================================================
   OS-FEATURE LAYER (overdrive)
   The device behaves like a real OS; each story beat fires a native feature
   of the selected platform. Chrome only: the chat content and the clay-red
   brand are untouched. Skinned by body[data-os="ios" | "android"].
   ========================================================================= */

/* ---- Material You tonal palette, seeded from --seed (authentic dynamic color)
   The whole tonal palette is generated from ONE hue (the seed). Each token
   keeps its hand-tuned L/C; only the hue follows --seed — this is exactly the
   Material You mechanic (a tonal palette derived from a single source color),
   so dragging the hue slider in Settings re-tints every Android surface live.
   Declared as a fallback pair (literal clay-red first, relative second) so
   non-supporting browsers keep the original clay palette. Applied to Android
   chrome only. The neutral surfaces carry a faint seed tint by design (Material
   surfaces are tinted toward the source color). */
body[data-os="android"] {
  --m3-primary:               oklch(0.47 0.155 33);                /* fallback */
  --m3-primary:               oklch(from var(--seed) 0.47 0.155 h);
  --m3-on-primary:            oklch(0.985 0.010 80);               /* fallback */
  --m3-on-primary:            oklch(from var(--seed) 0.985 0.010 h);
  --m3-primary-container:     oklch(0.885 0.052 42);              /* fallback */
  --m3-primary-container:     oklch(from var(--seed) 0.885 0.052 h);
  --m3-on-primary-container:  oklch(0.33 0.100 33);               /* fallback */
  --m3-on-primary-container:  oklch(from var(--seed) 0.33 0.100 h);
  --m3-surface:               oklch(0.975 0.006 70);              /* fallback */
  --m3-surface:               oklch(from var(--seed) 0.975 0.006 h);
  --m3-surface-container:     oklch(0.945 0.013 58);              /* fallback */
  --m3-surface-container:     oklch(from var(--seed) 0.945 0.013 h);
  --m3-surface-container-hi:  oklch(0.915 0.016 52);              /* fallback */
  --m3-surface-container-hi:  oklch(from var(--seed) 0.915 0.016 h);
  --m3-outline:               oklch(0.78 0.020 58);               /* fallback */
  --m3-outline:               oklch(from var(--seed) 0.78 0.020 h);
}
body[data-os="android"] .device { background: oklch(0.972 0.009 64); }

/* ------------------------------------------------------------- os-switch */
.os-switch {
  --switch-pad: 0.18rem;
  --switch-gap: 0.1rem;
  --switch-row: 2.75rem;
  position: relative;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--switch-gap);
  margin: 0 auto 0.5rem;
  padding: var(--switch-pad);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-label);
}
.os-switch__btn {
  position: relative;
  z-index: 1;
  flex: 1 1 0;              /* equal columns so the thumb aligns under either */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.34rem;
  min-width: 5.2rem;
  min-height: var(--switch-row);
  padding: 0.32rem 0.85rem;
  border: none;
  background: none;
  border-radius: 2rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.3s var(--ease);
}
.os-switch__btn[aria-pressed="true"] { color: var(--text); }
.os-switch__btn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.os-switch__glyph { opacity: 0.9; }
.os-switch__thumb {
  position: absolute;
  z-index: 0;
  top: var(--switch-pad); bottom: var(--switch-pad); left: var(--switch-pad);
  width: calc((100% - (var(--switch-pad) * 2) - var(--switch-gap)) / 2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 0.2rem 0.5rem -0.25rem oklch(0.4 0.03 50 / 0.3);
  transition: transform 0.42s var(--ease);
}
body[data-os="android"] .os-switch__thumb { transform: translateX(calc(100% + var(--switch-gap))); }

/* desktop: lift the STAGE selector out of the phone, onto the stage (mirrors the
   wordmark on the left). Stacks vertically; the thumb slides top/bottom. Scoped
   to .os-switch--stage so the relocated Settings instance keeps its compact
   horizontal segmented look on desktop too. */
@media (min-width: 1080px) {
  .os-switch--stage {
    --switch-pad: 0.24rem;
    --switch-gap: 0rem;
    --switch-row: 2.62rem;
    position: fixed;
    z-index: 6;
    top: 50%;
    left: calc(50% + var(--col) / 2 + 2.2vw);
    transform: translateY(-50%);
    margin: 0;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, var(--switch-row));
    min-width: 9.7rem;
    overflow: hidden;
    padding: 0;
    background: var(--surface);
    border-radius: 2.15rem;
    box-shadow: 0 0.6rem 1.6rem -0.5rem oklch(0.35 0.03 50 / 0.4);
  }
  .os-switch--stage .os-switch__btn { width: 100%; justify-content: flex-start; padding-inline: 1rem; }
  .os-switch--stage .os-switch__btn:focus-visible { outline-offset: -4px; }
  .os-switch--stage .os-switch__thumb {
    top: 0; left: 0; right: 0;
    bottom: auto;
    width: auto;
    height: var(--switch-row);
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 2.15rem 2.15rem 1.05rem 1.05rem;
    transition: transform 0.42s var(--ease);
  }
  body[data-os="android"] .os-switch--stage .os-switch__thumb {
    transform: translateY(var(--switch-row));
    border-top: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 1.05rem 1.05rem 2.15rem 2.15rem;
  }
}
@media (min-width: 1320px) {
  .os-switch--stage { left: calc(50% + var(--col) / 2 + 3.5vw); }
}

/* =========================================================================
   Live Activity: iOS Dynamic Island / Android Live Update status chip
   ========================================================================= */
.liveact {
  position: relative;
  justify-self: center;
  display: inline-flex;
  align-items: center;
  height: 1.9rem;
  max-width: min(72vw, 320px);
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.liveact__goo { position: absolute; inset: 0; z-index: 0; }
.liveact__bg {
  position: absolute; inset: 0;
  border-radius: 1.2rem;
  transition: background 0.45s var(--ease), border-radius 0.45s var(--ease);
  touch-action: manipulation;
}
.liveact:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 4px; }
.liveact__blob {
  position: absolute; top: 50%; left: 0;
  width: 1.2rem; height: 1.2rem;
  border-radius: 50%;
  transform: translate(-30%, -50%) scale(0);
  opacity: 0;
}
.liveact__content {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; gap: 0.42rem;
  height: 100%; padding: 0 0.72rem;
  white-space: nowrap;
}
.liveact__lead { display: inline-flex; align-items: center; }
.liveact__dot { width: 0.5rem; height: 0.5rem; }
.liveact__ic { display: none; }
.liveact__text { display: inline-flex; flex-direction: column; justify-content: center; line-height: 1.05; min-width: 0; }
.liveact__title { font-weight: 600; font-size: 0.8rem; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; }
.liveact__sub { font-family: var(--font-label); font-size: 0.64rem; opacity: 0.82; overflow: hidden; text-overflow: ellipsis; }
.liveact__trail { display: inline-flex; align-items: center; }
.liveact__ring { display: none; }
.liveact__ringtrack { stroke: currentColor; opacity: 0.28; }
.liveact__ringfill {
  stroke: var(--accent);
  stroke-dasharray: 100;
  stroke-dashoffset: calc(100 - var(--prog, 0) * 100);
  transform: rotate(-90deg); transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.85s var(--ease);
}
.liveact__bar { display: none; width: 2.4rem; height: 0.32rem; border-radius: 1rem; background: currentColor; opacity: 0.3; overflow: hidden; }
.liveact__barfill { display: block; height: 100%; width: calc(var(--prog, 0) * 100%); background: var(--accent); border-radius: inherit; transition: width 0.85s var(--ease); }

/* progress mode: glyph + progress replace the simple app dot */
.liveact--progress .liveact__dot { display: none; }
.liveact--progress .liveact__ic  { display: inline-flex; }
.liveact--progress .liveact__sub { display: inline; }

/* iOS Dynamic Island skin */
body[data-os="ios"] .liveact { color: oklch(0.97 0.005 80); }
body[data-os="ios"] .liveact__goo { filter: url(#goo); }
body[data-os="ios"] .liveact__bg,
body[data-os="ios"] .liveact__blob { background: oklch(0.16 0.010 60); }
body[data-os="ios"] .liveact__ringtrack { stroke: oklch(0.55 0.01 60); }
body[data-os="ios"] .liveact--progress .liveact__ring { display: inline-block; }

/* Android Live Update status chip skin */
body[data-os="android"] .liveact { color: var(--m3-on-primary-container); height: 1.72rem; }
body[data-os="android"] .liveact__goo { filter: none; }
body[data-os="android"] .liveact__bg { background: var(--m3-primary-container); border-radius: 0.95rem; }
body[data-os="android"] .liveact__blob { display: none; }
body[data-os="android"] .liveact--progress .liveact__bar { display: inline-block; }

/* wake (hero): the activity comes alive */
@keyframes liveact-wake {
  0% { transform: scale(0.55); opacity: 0; }
  55% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.liveact--wake .liveact__goo { animation: liveact-wake 0.7s var(--ease); transform-origin: center; }

/* iOS goo: a blob detaches and re-merges when the state updates */
@keyframes liveact-pop {
  0%   { transform: translate(-20%, -50%) scale(0); }
  45%  { transform: translate(-135%, -50%) scale(1); }
  100% { transform: translate(-20%, -50%) scale(0); }
}
body[data-os="ios"] .liveact--pulse .liveact__blob { opacity: 1; animation: liveact-pop 0.7s var(--ease); }

/* expanded (build beat): a detail card spawns from the island/status chip */
.liveact__expand {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 50%;
  width: min(80vw, 320px);
  padding: 0.75rem 0.85rem;
  text-align: left;
  border-radius: 1.15rem;
  opacity: 0;
  transform: translateX(-50%) translateY(-0.4rem) scale(0.96);
  transform-origin: top center;
  pointer-events: none;
  z-index: 60;     /* above app-screen (30) + navind (40); shell layering */
  transition: opacity 0.35s var(--ease), transform 0.42s var(--ease);
}
.liveact--expanded .liveact__expand {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}
body[data-os="ios"] .liveact__expand { background: oklch(0.16 0.010 60); color: oklch(0.96 0.005 80); box-shadow: 0 1rem 2.4rem -0.8rem oklch(0 0 0 / 0.6); }
body[data-os="android"] .liveact__expand { background: var(--m3-surface-container-hi); color: var(--text); border: 1px solid var(--m3-outline); box-shadow: 0 0.8rem 2rem -0.8rem oklch(0.3 0.03 50 / 0.4); }
.liveact__ehead { font-family: var(--font-label); font-size: 0.64rem; opacity: 0.7; margin-bottom: 0.45rem; display: flex; justify-content: space-between; }
.liveact__erow { display: flex; align-items: baseline; justify-content: space-between; gap: 0.7rem; font-size: 0.8rem; }
.liveact__erow + .liveact__erow { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px solid currentColor; border-color: color-mix(in oklch, currentColor 16%, transparent); }
.liveact__ev { font-weight: 600; }
.liveact__es { opacity: 0.7; font-family: var(--font-label); font-size: 0.7rem; }

/* Focus / Do Not Disturb (setback) */
body.is-focus .mood-dim { opacity: 1; }
body.is-focus .device { filter: saturate(0.9) brightness(0.985); transition: filter 0.9s var(--ease); }
.sysfocus { display: inline-flex; align-items: center; color: var(--text-muted); }
.sysfocus svg { width: 0.95rem; height: 0.95rem; }

/* =========================================================================
   OS FIDELITY PASS
   Liquid Glass (iOS 26) vs Material 3 Expressive (Android): translucent
   refractive chrome for iOS, tonal springy surfaces for Android. Plus a
   per-OS wallpaper that crossfades on switch, gesture-nav indicators, and
   platform corner radii.
   ========================================================================= */

/* ---- per-OS design tokens ---------------------------------------------- */
body[data-os="ios"] {
  --glass-bg:     oklch(0.985 0.006 250 / 0.5);
  --glass-stroke: oklch(1 0 0 / 0.55);
  --glass-hi:     oklch(1 0 0 / 0.7);
  --glass-shadow: 0 0.7rem 2rem -0.7rem oklch(0.32 0.04 255 / 0.4);
  --radius-device: 3rem;
}
body[data-os="android"] {
  --radius-device: 2rem;
}

/* ---- per-OS wallpaper behind the phone (animated crossfade) ------------- */
.stage-os { position: fixed; inset: 0; z-index: 0; opacity: 0; pointer-events: none; transition: opacity 0.8s var(--ease); }
.stage-os--ios {
  background:
    radial-gradient(120vw 75vh at 74% -12%, oklch(0.85 0.07 255 / 0.55), transparent 55%),
    radial-gradient(95vw 70vh at 8% 112%, oklch(0.87 0.06 200 / 0.5), transparent 55%),
    linear-gradient(160deg, oklch(0.95 0.02 255), oklch(0.93 0.02 285));
}
/* Android wallpaper is the warm/clay one — it follows the seed hue (the stops
   fan ~+12/-greek around the seed to keep the gradient's tonal spread). iOS's
   cool-blue wallpaper above is FIXED art direction and never re-seeds.
   Fallback pair: literal clay hues first, relative (seed-following) second. */
.stage-os--android {
  background:
    radial-gradient(115vw 78vh at 86% -8%, oklch(0.86 0.10 45 / 0.6), transparent 55%),
    radial-gradient(92vw 70vh at 4% 108%, oklch(0.88 0.08 75 / 0.52), transparent 55%),
    linear-gradient(160deg, oklch(0.93 0.035 60), oklch(0.92 0.03 38));
  background:
    radial-gradient(115vw 78vh at 86% -8%, oklch(from var(--seed) 0.86 0.10 calc(h + 12) / 0.6), transparent 55%),
    radial-gradient(92vw 70vh at 4% 108%, oklch(from var(--seed) 0.88 0.08 calc(h + 42) / 0.52), transparent 55%),
    linear-gradient(160deg, oklch(from var(--seed) 0.93 0.035 calc(h + 27)), oklch(from var(--seed) 0.92 0.03 calc(h + 5)));
}
body[data-os="ios"] .stage-os--ios { opacity: 1; }
body[data-os="android"] .stage-os--android { opacity: 1; }
/* dial back the warm grain so the OS wallpaper reads */
.stage-grain { opacity: 0.12; }

/* ---- device: platform corner radius + smooth morph on switch ----------- */
.device { transition: background-color 1.3s var(--ease), border-radius 0.6s var(--ease); }
@media (min-width: 1080px) {
  .device { border-radius: var(--radius-device); }
  .statusbar { border-radius: var(--radius-device) var(--radius-device) 0 0; }
}

/* ---- gesture nav indicator: iOS home bar / Android handle ----------------
   The .navind interactive styling lives in shell.css now (it is a working Home
   control, moved out of the composer to device level). The per-OS handle look
   is defined there too. */

/* ---- composer: Liquid Glass (iOS) / Material surface (Android) ---------- */
/* The glass lives on a ::before layer, NOT the composer itself: a
   backdrop-filter on .composer would make it a containing block and trap the
   fixed desktop OS-switch inside it. The pseudo keeps the composer filter-free. */
.composer { background: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.composer::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  border-top: 1px solid transparent;
  transition: background 0.6s var(--ease), border-color 0.6s var(--ease);
}
body[data-os="ios"] .composer::before {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(1.8);
          backdrop-filter: blur(22px) saturate(1.8);
  border-top: 1px solid var(--glass-stroke);
  box-shadow: inset 0 1px 0 var(--glass-hi);
}
body[data-os="android"] .composer::before {
  background: color-mix(in oklch, var(--m3-surface-container) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  border-top: 1px solid var(--m3-outline);
}

/* ---- suggest chips: scroll-snap + platform skins ----------------------- */
.suggest { scroll-snap-type: x proximity; }
.chip { scroll-snap-align: center; transition: background 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.25s var(--ease); }
body[data-os="ios"] .chip {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(14px) saturate(1.6);
          backdrop-filter: blur(14px) saturate(1.6);
  border: 1px solid var(--glass-stroke);
}
body[data-os="android"] .chip { background: var(--m3-surface-container-hi); border-color: transparent; border-radius: 1.25rem; }
body[data-os="android"] .chip:hover { background: var(--m3-primary-container); transform: none; }

/* ---- Live Activity polish ---------------------------------------------- */
/* iOS compact Live Activities live around the TrueDepth camera, not inside it.
   The center sensor stays blank; compact leading/trailing carry the state. */
body[data-os="ios"] .liveact {
  width: 10.3rem;
  max-width: none;
  height: 2rem;
}
body[data-os="ios"] .liveact::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 4.7rem;
  height: 1.48rem;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: oklch(0.10 0.006 60);
  box-shadow: inset 0 0.04rem 0 oklch(1 0 0 / 0.05), 0 0.18rem 0.45rem -0.18rem oklch(0 0 0 / 0.9);
}
body[data-os="ios"] .liveact__goo { display: none; }
body[data-os="ios"] .liveact__content {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  padding: 0;
}
body[data-os="ios"] .liveact__text { display: none; }
body[data-os="ios"] .liveact__lead,
body[data-os="ios"] .liveact__trail {
  position: absolute;
  top: 50%;
  height: 1.48rem;
  border-radius: 999px;
  transform: translateY(-50%);
  background: oklch(0.10 0.006 60);
  color: oklch(0.97 0.005 80);
  display: grid;
  place-items: center;
  box-shadow: inset 0 0.04rem 0 oklch(1 0 0 / 0.05), 0 0.18rem 0.45rem -0.18rem oklch(0 0 0 / 0.9);
}
body[data-os="ios"] .liveact__lead {
  left: 0.14rem;
  width: 2.08rem;
}
body[data-os="ios"] .liveact__trail {
  right: 0.14rem;
  width: 2.32rem;
}
body[data-os="ios"] .liveact__trail[hidden] { display: none !important; }
body[data-os="ios"] .liveact--progress .liveact__ic {
  display: inline-flex;
  width: 0.92rem;
  height: 0.92rem;
}
body[data-os="ios"] .liveact--progress .liveact__ring {
  display: block;
  width: 1.08rem;
  height: 1.08rem;
}
body[data-os="ios"] .liveact--wake::before,
body[data-os="ios"] .liveact--wake .liveact__lead,
body[data-os="ios"] .liveact--wake .liveact__trail {
  animation: liveact-wake 0.7s var(--ease);
}
body[data-os="ios"] .liveact--pulse .liveact__lead {
  animation: island-nudge 0.64s var(--ease);
}
@keyframes island-nudge {
  0%, 100% { transform: translateY(-50%) scale(1); }
  42% { transform: translateY(-50%) translateX(-0.16rem) scale(1.06); }
}

/* Android uses the platform's promoted Live Update status chip pattern:
   short critical text in the status bar, fuller context in the card. */
body[data-os="android"] .liveact {
  height: 1.58rem;
  max-width: 6rem;
}
body[data-os="android"] .liveact__content {
  gap: 0.28rem;
  padding: 0 0.48rem;
}
body[data-os="android"] .liveact__text {
  display: inline-flex;
  min-width: 0;
}
body[data-os="android"] .liveact__title {
  max-width: 2.25rem;
  font-size: 0.72rem;
  line-height: 1;
}
body[data-os="android"] .liveact__sub { display: none !important; }
body[data-os="android"] .liveact__ic {
  width: 0.82rem;
  height: 0.82rem;
}
body[data-os="android"] .liveact__bar {
  width: 1.42rem;
  height: 0.23rem;
}
body[data-os="android"] .liveact__trail[hidden] { display: none !important; }

/* iOS expanded island reads as dark liquid glass */
body[data-os="ios"] .liveact__expand {
  background: oklch(0.18 0.012 60 / 0.72);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
          backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid oklch(1 0 0 / 0.12);
}
/* Android status chip gains a hair of elevation */
body[data-os="android"] .liveact__bg { box-shadow: 0 0.18rem 0.5rem -0.22rem oklch(0.3 0.03 50 / 0.4); }
body[data-os="android"] .liveact__expand {
  width: min(19rem, calc(100vw - 2rem));
  padding: 0.9rem 0.95rem;
  border-radius: 1.45rem;
}
.liveact__etitle {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.15;
  margin-bottom: 0.16rem;
}
.liveact__estate {
  font-family: var(--font-label);
  font-size: 0.72rem;
  opacity: 0.78;
  margin-bottom: 0.58rem;
}
.liveact__etrack {
  position: relative;
  height: 0.42rem;
  border-radius: 999px;
  margin-bottom: 0.7rem;
  background: color-mix(in oklch, currentColor 18%, transparent);
  overflow: hidden;
}
.liveact__etrack span {
  display: block;
  width: var(--pct, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.liveact__etrack::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0.12rem;
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 50%;
  transform: translateY(-50%);
  background: oklch(0.975 0.006 86);
}

/* ---- notifications: glass (iOS) with a specular top edge ---------------- */
.notif { position: relative; }
body[data-os="ios"] .notif {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(1.7);
          backdrop-filter: blur(22px) saturate(1.7);
  border: 1px solid var(--glass-stroke);
  box-shadow: var(--glass-shadow);
}
body[data-os="ios"] .notif::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 1px 0 var(--glass-hi);
}
body[data-os="android"] .poster { box-shadow: 0 0.6rem 1.6rem -0.8rem oklch(0.3 0.03 50 / 0.4); }

/* ---- knowledge card spacing ------------------------------------------- */
.profile { gap: 0.9rem; padding: 0.12rem 0 1rem; margin: 0.02rem 0 0.95rem; }
.profile__id { gap: 0.16rem; }
.profile__role { margin-bottom: 0; }
.profile__link { margin-top: 0.38rem; }
.glance { gap: 1.1rem; }

/* =========================================================================
   prefers-reduced-motion — kept complete in base.css as one block so the
   cascade order is preserved (chat element rules included intentionally).
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
  .stream-cursor { display: none; }
  /* OS-feature components rest in their final, visible state */
  .notif, .gemini, .poster { opacity: 1; transform: none; }
  .ai-glow, .ai-label { display: none; }
}
