/* ── depth3.chat brand design tokens ───────────────────────────────────────── */
:root {
	--bg-depth:                  lab(2.47544% -.0863299 .309634);
	--bg-base:                   lab(3.64792% -.117965 .422665);
	--bg-primary:                lab(5.40508% -.153907 .550512);
	--bg-secondary:              lab(7.70799% -.19557 .698656);
	--bg-tertiary:               lab(11.6832% -.201508 .728655);
	--bg-quaternary:             lab(15.5692% -.201941 .728303);
	--bg-accent:                 #9333ea;
	--bg-accent-translucent:     rgba(147, 51, 234, .18);
	--gradient-accent:           linear-gradient(135deg, #4f46e5 0%, #7c3aed 30%, #db2777 65%, #ea580c 100%);
	--bg-destructive:            lab(49.6786% 69.526 48.442);
	--bg-destructive-translucent:lab(49.6786% 69.526 48.442 / .18);
	--bg-positive:               lab(48.9452% -41.3464 51.1223);
	--bg-positive-translucent:   lab(48.9452% -41.3464 51.1223 / .18);
	--bg-attention:              lab(49.7965% 52.6911 61.1861);
	--bg-translucent:            lab(49.8943% -.875205 3.29613 / .15);
	--bg-muted:                  lab(49.8943% -.875205 3.29613 / .07);
	--bg-overlay:                rgba(0, 0, 0, .6);   /* modal/sheet backdrop */
	--hero-glow-opacity:         .38;                 /* start screen's gradient glow */

	--fg-on-accent:              #ffffff; /* always white — for text/icons ON --bg-accent */
	--fg-primary:                lab(100% 0 0);
	--fg-secondary:              lab(91.6306% -.204355 .72664);
	--fg-tertiary:               lab(64.5098% -.204027 .726879);
	--fg-quaternary:             lab(44.2098% -.20358 .727201);
	--fg-accent:                 lab(64.8421% 4.78992 -49.8068);
	--fg-positive:               lab(70.3504% -38.3783 42.6767);
	--fg-destructive:            lab(70.8432% 48.5363 29.4891);

	--border-depth:              lab(11.8507% -.395551 1.46293);
	--border-base:               lab(14.0896% -.396654 1.46207);
	--border-primary:            lab(16.6765% -.397772 1.46123);
	--border-secondary:          lab(19.3213% -.398725 1.4605);
	--border-accent:             #9333ea;
	--border-translucent:        lab(47.8174% -.203669 .727129 / .28);
}

/* ── Light theme overrides ──────────────────────────────────────────────────── */
[data-theme="light"] {
	--bg-depth:                  #ebebf5;
	--bg-base:                   #ffffff;
	--bg-primary:                #f8f8fc;
	--bg-secondary:              #f0f0f8;
	--bg-tertiary:               #e8e8f2;
	--bg-quaternary:             #e0e0ec;
	--bg-accent:                 #9333ea;
	--bg-accent-translucent:     rgba(147, 51, 234, .10);
	--gradient-accent:           linear-gradient(135deg, #4f46e5 0%, #7c3aed 30%, #db2777 65%, #ea580c 100%);
	--bg-destructive:            lab(49.6786% 69.526 48.442);
	--bg-destructive-translucent:lab(49.6786% 69.526 48.442 / .12);
	--bg-positive:               lab(48.9452% -41.3464 51.1223);
	--bg-positive-translucent:   lab(48.9452% -41.3464 51.1223 / .12);
	--bg-attention:              lab(49.7965% 52.6911 61.1861);
	--bg-translucent:            lab(20% 0 0 / .06);
	--bg-muted:                  lab(20% 0 0 / .04);
	--bg-overlay:                rgba(20, 20, 40, .45);
	--hero-glow-opacity:         .22;

	--fg-on-accent:              #ffffff; /* always white — for text/icons ON --bg-accent */
	--fg-primary:                #09090e;
	--fg-secondary:              #1a1a28;
	--fg-tertiary:               #5c5c7a;
	--fg-quaternary:             #8888a8;
	--fg-accent:                 lab(35% 22 -65);
	--fg-positive:               lab(35% -30 36);
	--fg-destructive:            lab(40% 55 35);

	--border-depth:              #d4d4e8;
	--border-base:               #e2e2f0;
	--border-primary:            #d8d8ec;
	--border-secondary:          #cccce0;
	--border-accent:             #9333ea;
	--border-translucent:        lab(20% 0 0 / .10);
}

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
.chat-messages::-webkit-scrollbar       { width: 3px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
	background: var(--border-primary);
	border-radius: 9999px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: var(--border-secondary); }

/* ── App shell — always exactly the visible part of the screen ─────────────────
 * Never size the app with 100vh / h-screen: on iPhone that is the height *without*
 * Safari's toolbar, so the bottom of the app (the message input) hides behind it.
 * The shell is fixed to the viewport; once JS knows window.visualViewport it
 * follows that instead (.vv-sized), which also shrinks it above the on-screen
 * keyboard, so the header and the input both stay visible while typing. */
html, body {
	height: 100%;
	overflow: hidden;
	overscroll-behavior: none;
}
.app-shell {
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
}
.app-shell.vv-sized {
	bottom: auto;
	top: var(--vv-top, 0px);
	height: var(--vv-height, 100%);
}

/* The plain-HTML start copy in index.html is for crawlers and no-script clients.
 * A browser that runs the app never sees it: the inline script in <head> sets
 * data-app before the first paint, and the app replaces #root. */
[data-app] #root > [data-static] {
	display: none;
}

/* ── iOS safe area — push content below notch/Dynamic Island and home bar ───── */
.safe-top {
	/* Used on fixed header: keeps content below the status bar / Dynamic Island */
	padding-top: env(safe-area-inset-top);
}
.safe-bottom {
	/* Used on footer: keeps input above the home indicator */
	padding-bottom: max(env(safe-area-inset-bottom), 8px);
}

/* ── Mobile scroll — native-feel touch scrolling ───────────────────────────── */
.chat-messages {
	-webkit-overflow-scrolling: touch; /* momentum scroll on iOS */
	overscroll-behavior: contain;      /* prevent scroll chaining to body */
	touch-action: pan-y;               /* only vertical pan, no accidental zoom */
}

/* ── Prevent iOS/Android zoom on input focus (font-size must be ≥ 16px) ────── */
.chat-input {
	font-size: 16px;
}
@media (min-width: 640px) {
	.chat-input { font-size: 14px; } /* restore smaller size on desktop */
}

/* ── Motion ─────────────────────────────────────────────────────────────────────
 * Timing tokens: the same in both themes (they aren't colours), so :root only.
 * Rules (CLAUDE.md → Motion): animate opacity and transform only, plus grid
 * rows for a height change (.expand); only live things animate in, never
 * history; reduced motion is always honoured (the block at the end). Entrances
 * fill "backwards" so nothing (a transform, a stacking context) lingers after
 * them; exits fill "both" and hold their end state until the element unmounts. */
:root {
	--dur-fast:    140ms;  /* exits, small state changes */
	--dur-base:    200ms;  /* entrances */
	--dur-slow:    320ms;  /* sheets, theme cross-fade */
	--ease-out:    cubic-bezier(.22, 1, .36, 1);
	--ease-in:     cubic-bezier(.55, 0, 1, .45);
	--ease-in-out: cubic-bezier(.65, 0, .35, 1);
	--ease-spring: cubic-bezier(.34, 1.56, .64, 1);
	--ease-sheet:  cubic-bezier(.32, .72, 0, 1);
}

@keyframes msg-in        { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes pop-in        { from { opacity: 0; transform: translateY(6px) scale(.96); } }
@keyframes pop-out       { to   { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes fade-in       { from { opacity: 0; } }
@keyframes fade-out      { to   { opacity: 0; } }
@keyframes sheet-in      { from { transform: translateY(100%); } }
@keyframes sheet-out     { to   { transform: translateY(100%); } }
@keyframes expand-in     { from { grid-template-rows: 0fr; opacity: 0; } to { grid-template-rows: 1fr; opacity: 1; } }
@keyframes expand-out    { from { grid-template-rows: 1fr; opacity: 1; } to { grid-template-rows: 0fr; opacity: 0; } }
@keyframes chip-pop      { from { opacity: 0; transform: scale(.5); } }
@keyframes count-bump    { from { opacity: 0; transform: translateY(-45%); } }
@keyframes dot-wave      { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-3px); opacity: 1; } }
@keyframes sheen         { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes breathe       { 50% { opacity: .75; } }
@keyframes send-fly      { 45% { transform: translate(14px, -14px); opacity: 0; } 46% { transform: translate(-14px, 14px); opacity: 0; } }
@keyframes skeleton-pulse { 50% { opacity: .5; } }
/* The hero layers only move: a scale or rotate changes a blurred layer's size or
 * angle, and the browser may then redo the blur every frame. */
@keyframes glow-drift {
	from { transform: translateX(-50%) translateY(0); }
	50%  { transform: translateX(-47%) translateY(24px); }
	to   { transform: translateX(-53%) translateY(-8px); }
}
/* The start screen's lower layer: mirrored (scale -1 on x, the same in every
 * frame), so its warm end sits bottom left. */
@keyframes field-drift {
	from { transform: translateX(-50%) translateY(0)     scale(-1, 1); }
	50%  { transform: translateX(-54%) translateY(-28px) scale(-1, 1); }
	to   { transform: translateX(-46%) translateY(18px)  scale(-1, 1); }
}

/* A message that arrives while the room is open. Put it on the full-width row
 * with origin-bottom-right (own) / origin-bottom-left (others): the row's
 * corner is the bubble's corner, so it grows from there with no sideways drift. */
.msg-in { animation: msg-in var(--dur-base) var(--ease-out) backwards; }
/* One after another: set --stagger on each (the start screen's templates). After .msg-in, which resets the delay. */
.stagger { animation-delay: var(--stagger, 0ms); }
/* Soft arrival on mount (a status line, the empty state). */
.fade-in { animation: fade-in var(--dur-base) var(--ease-out) backwards; }
/* Shows only if it is still there after --delay (default 600ms): "sending…",
 * "reconnecting…" and other states that are usually over before they'd flash. */
.fade-in-late { animation: fade-in var(--dur-base) var(--ease-out) var(--delay, 600ms) backwards; }

/* Enter + exit, driven by data-state="open" | "closed" (usePresence keeps the
 * element mounted through "closed"). .pop: popovers and dialog cards; give it
 * an origin-* utility pointing at what opened it. .fade: backdrops. .sheet:
 * a bottom sheet on phones, a card from sm up. */
.pop[data-state="open"]    { animation: pop-in var(--dur-base) var(--ease-out) backwards; }
.pop[data-state="closed"]  { animation: pop-out var(--dur-fast) var(--ease-in) both; pointer-events: none; }
.fade[data-state="open"]   { animation: fade-in var(--dur-base) var(--ease-out) backwards; }
.fade[data-state="closed"] { animation: fade-out var(--dur-fast) var(--ease-in) both; pointer-events: none; }
/* .sheet: a dialog that is a bottom sheet on phones (it slides like Settings)
 * and a centred card from sm up (it pops). Unmount it after --dur-slow. */
.sheet[data-state="open"]   { animation: sheet-in var(--dur-slow) var(--ease-sheet) backwards; }
.sheet[data-state="closed"] { animation: sheet-out var(--dur-slow) var(--ease-sheet) both; pointer-events: none; }
@media (min-width: 640px) {
	.sheet[data-state="open"]   { animation: pop-in var(--dur-base) var(--ease-out) backwards; }
	.sheet[data-state="closed"] { animation: pop-out var(--dur-fast) var(--ease-in) both; }
}

/* A block that would push the layout (a banner, an in-flow panel) grows and
 * shrinks instead: grid rows 0fr ↔ 1fr, so the list's bottom pin follows it
 * frame by frame. The direct child must have no padding, border or margin, or
 * 0fr can't reach 0 — put them on the grandchild. Use <Expand> in index.tsx.
 * (Never call a class "collapse": that is a Tailwind utility, visibility:collapse.) */
.expand { display: grid; grid-template-rows: 1fr; }
.expand > * { min-height: 0; overflow: hidden; }
.expand[data-state="open"]   { animation: expand-in var(--dur-base) var(--ease-out) backwards; }
.expand[data-state="closed"] { animation: expand-out var(--dur-fast) var(--ease-in) both; pointer-events: none; }

/* A reaction chip that wasn't there before; a count that changed. */
.chip-pop   { animation: chip-pop 260ms var(--ease-spring) backwards; }
.count-bump { display: inline-block; animation: count-bump var(--dur-fast) var(--ease-out) backwards; }

/* Fathom at work: three brand-gradient dots (plain spans, not icons) … */
.thinking-dots { display: inline-flex; align-items: center; gap: 4px; }
.thinking-dots > span {
	width: 6px;
	height: 6px;
	border-radius: 9999px;
	background: var(--gradient-accent);
	background-size: 300% 100%;
	animation: dot-wave 1.2s var(--ease-in-out) infinite;
}
.thinking-dots > span:nth-child(2) { background-position: 50% 0;  animation-delay: .15s; }
.thinking-dots > span:nth-child(3) { background-position: 100% 0; animation-delay: .3s; }
/* … a sheen along the bottom of the bubble while it's live … */
.fathom-live { position: relative; overflow: hidden; }
.fathom-live::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 2px;
	background: var(--gradient-accent);
	animation: sheen 1.6s var(--ease-in-out) infinite;
}
/* … and the logo breathing. Needs a stacking context around it (the header is relative z-20). */
.logo-live { position: relative; }
.logo-live::before {
	content: "";
	position: absolute;
	inset: -4px;
	border-radius: inherit;
	background: var(--gradient-accent);
	filter: blur(8px);
	opacity: 0;
	z-index: -1;
	animation: breathe 1.8s var(--ease-in-out) infinite;
}

/* The paper plane on send: key the icon so the animation replays. */
.send-fly { animation: send-fly 360ms var(--ease-out); }

/* Placeholder while the first page of messages is on its way; invisible on a fast connect. */
.skeleton { animation: fade-in var(--dur-base) var(--ease-out) 350ms backwards; }
.skeleton > * { background: var(--bg-secondary); animation: skeleton-pulse 1.4s var(--ease-in-out) infinite; }

/* Theme switch as one cross-fade (switchTheme in index.tsx): per-element
 * transitions are off for the switch, the View Transition fades the whole page. */
[data-theme-switching] *,
[data-theme-switching] *::before,
[data-theme-switching] *::after { transition: none !important; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: var(--dur-slow); animation-timing-function: var(--ease-in-out); }

/* ── Message hover toolbar (desktop) ───────────────────────────────────────────
 * Beside the bubble: right of others' and Fathom's, left of your own (the
 * smiley nearest the bubble). Only with a real pointer; phones tap the message,
 * or the add-reaction chip. Hover is keyed on the full-width .msg-row, so the
 * way from the bubble to the toolbar never leaves it. */
.msg-tools { display: none; }
@media (hover: hover) and (pointer: fine) {
	.msg-tools {
		position: absolute;
		/* Centred on the bubble: a name line above it (~20px) moves the centre down by half. */
		top: calc(50% + var(--msg-tools-shift, 0px));
		left: 100%;
		z-index: 10;
		display: flex;
		align-items: center;
		gap: 2px;
		padding-left: 6px;
		opacity: 0;
		pointer-events: none;
		transform: translate(-4px, -50%);
		transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
	}
	.msg-tools-mine {
		left: auto;
		right: 100%;
		padding-left: 0;
		padding-right: 6px;
		flex-direction: row-reverse;
		transform: translate(4px, -50%);
	}
	.msg-tools-named { --msg-tools-shift: 10px; }
	.msg-row:hover .msg-tools,
	[data-open] > .msg-tools {
		opacity: 1;
		pointer-events: auto;
		transform: translate(0, -50%);
	}
	.msg-tool {
		width: 28px;
		height: 28px;
		border-radius: 9999px;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14px;
		color: var(--fg-tertiary);
		background: var(--bg-primary);
		border: 1px solid var(--border-base);
		transition: color var(--dur-fast), background-color var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast);
	}
	.msg-tool:hover,
	.msg-tool[aria-expanded="true"] { color: var(--fg-accent); background: var(--bg-tertiary); border-color: var(--border-primary); }
	.msg-tool:active { transform: scale(.92); }
	.msg-tool:focus-visible { outline: 2px solid var(--border-accent); outline-offset: 1px; }
}

/* ── Accent glow helpers ────────────────────────────────────────────────────── */
.glow-accent {
	box-shadow: 0 0 28px rgba(219, 39, 119, .40), 0 0 12px rgba(124, 58, 237, .30);
}
.glow-accent-sm {
	box-shadow: 0 0 14px rgba(219, 39, 119, .30), 0 0 6px rgba(124, 58, 237, .20);
}

/* ── Start screen hero — the brand gradient as a soft glow behind the title ── */
.hero-glow {
	position: absolute;
	left: 50%;
	top: -140px;
	width: min(900px, 140vw);
	height: 520px;
	transform: translateX(-50%);
	background: var(--gradient-accent);
	border-radius: 9999px;
	filter: blur(90px);
	opacity: var(--hero-glow-opacity);
	pointer-events: none;
	/* Drifts slowly, like a gradient field. Translate only (see glow-drift): the
	 * layer keeps its size, so the blurred result can be reused as it moves.
	 * Still on touch screens (below). */
	animation: glow-drift 18s var(--ease-in-out) infinite alternate;
	will-change: transform;
}
/* A second, wider layer lower down, on its own slower clock (and started
 * part-way, so the two never move in step): together they read as a field
 * that flows, like UI-examples. Fainter than the glow; same rules. */
.hero-field {
	position: absolute;
	left: 50%;
	top: 220px;
	width: min(1200px, 190vw);
	height: 640px;
	transform: translateX(-50%) scale(-1, 1);
	background: var(--gradient-accent);
	border-radius: 9999px;
	filter: blur(120px);
	opacity: calc(var(--hero-glow-opacity) * .55);
	pointer-events: none;
	animation: field-drift 26s var(--ease-in-out) -9s infinite alternate;
	will-change: transform;
}
/* Phones and tablets: two large blurred layers moving for as long as the page
 * is open cost a small GPU and its battery too much. The same field, standing still. */
@media (hover: none) {
	.hero-glow,
	.hero-field { animation: none; will-change: auto; }
}

/* ── Reduced motion: always honoured ───────────────────────────────────────────
 * Everything still opens, closes and unmounts, just at once. Delays stay: they
 * decide *whether* something shows (a skeleton, "sending…"), not how it moves.
 * Loops that exist only to move are switched off. */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 1ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 1ms !important;
	}
	.hero-glow,
	.hero-field,
	.thinking-dots > span,
	.fathom-live::after,
	.logo-live::before,
	.skeleton > * { animation: none !important; }
	/* A stagger only orders motion; without motion it would just hold things back. */
	.stagger { animation-delay: 0ms !important; }
	::view-transition-group(*),
	::view-transition-old(*),
	::view-transition-new(*) { animation: none !important; }
}

/* ── Connection state ──────────────────────────────────────────────────────────
 * Header: the presence count and "Reconnecting…" share one grid cell. The
 * count fades out only after the socket has been down for --delay, the same
 * wait .fade-in-late gives "Reconnecting…" (both read it from the cell), so a
 * blip changes nothing; once connected again the count fades straight back. */
.conn-presence { transition: opacity var(--dur-base) var(--ease-out); }
.conn-presence.conn-stale { opacity: 0; transition-delay: var(--delay, 600ms); }
