/* Design tokens. Grouped surfaces, labels, fills and system colours follow Apple's iOS UI kit
   (the palette the pai Mini App was checked against): Grouped Primary/Secondary #F2F2F7/#FFFFFF
   light, #000000/#1C1C1E dark; Body 17/22, Subheadline 15/20, Footnote 13/18.
   Text colours that carry meaning are shaded until they pass WCAG AA on their surface. */

:root {
	color-scheme: light;

	--bg: #f2f2f7;
	--card: #ffffff;
	--elevated: #ffffff;
	--sidebar: #f5f5f7;
	--chat-bg: #ffffff;
	--text: #000000;
	--muted: #3c3c43c4;
	--faint: #3c3c4399;
	--line: #3c3c4329;
	--line-strong: #c6c6c8;
	--input-line: #8e8e93;
	--soft: #7676801f;
	--soft-strong: #76768033;
	--press: #0000000f;

	--system-blue: #0088ff;
	--system-green: #34c759;
	--system-orange: #ff8d28;
	--system-red: #ff383c;
	--system-yellow: #ffcc00;
	--system-purple: #af52de;
	--system-teal: #00c3d0;
	--system-gray: #8e8e93;

	--accent: #005db9; /* text and icons on light surfaces, 6.6:1 on white */
	--accent-strong: #004b96;
	--on-accent: #ffffff;
	--fill: #0a6fd8; /* filled buttons: white text 4.9:1 in both schemes */
	--fill-strong: #005bb8;
	--tint-fill: #e3f0ff;
	--danger: #c4161c;
	--danger-fill: #ffe5e6;
	--success: #116434;
	--success-fill: #e3f7e8;
	--warning: #80500f;
	--warning-fill: #ffefdc;

	--bubble-mine: #0a6fd8; /* white text 4.9:1 */
	--bubble-mine-text: #ffffff;
	--bubble-other: #e9e9eb;
	--bubble-other-text: #000000;
	--code-bg: #f5f5f7;

	--bar: #f9f9fbd1; /* translucent material */
	--bar-solid: #f9f9fb;
	--glass: #ffffffb8;
	--glass-line: #ffffff99;
	--glass-shadow: 0 8px 32px #0000001f, 0 1px 3px #00000014;
	--sheet-backdrop: #00000052;
	--sheet-bg: #f2f2f7;
	--sheet-card: #ffffff;
	--shadow-card: 0 1px 2px #0000000d, 0 4px 16px #0000000a;
	--loader-halo: #c9ccff;

	/* Type, in rem so text scales with the reader's setting. */
	--font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
	--text-large-title: 2.125rem; /* 34 */
	--text-title1: 1.75rem; /* 28 */
	--text-title2: 1.375rem; /* 22 */
	--text-title3: 1.25rem; /* 20 */
	--text-headline: 1.0625rem; /* 17 semibold */
	--text-body: 1.0625rem; /* 17 */
	--text-callout: 1rem; /* 16 */
	--text-subheadline: 0.9375rem; /* 15 */
	--text-footnote: 0.8125rem; /* 13 */
	--text-caption: 0.75rem; /* 12 */
	--text-caption2: 0.6875rem; /* 11 */
	--leading-body: 1.2941;
	--leading-sub: 1.3333;
	--leading-foot: 1.3846;

	/* Layout */
	--page-inset: 16px;
	--row-inset: 16px;
	--section-gap: 28px;
	--touch: 44px;
	--group-radius: 16px;
	--control-radius: 12px;
	--sheet-radius: 22px;
	--row-height: 52px;
	--icon-slot: 30px;
	--navbar-height: 52px;
	--tabbar-height: 64px;
	--content-max: 720px;
	--chat-max: 760px;
	--ease: cubic-bezier(0.2, 0.8, 0.2, 1);
	--ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);
	--fast: 160ms;
	--medium: 260ms;

	/* Safe areas: the browser's, or Telegram's device and content insets, whichever is larger. */
	--safe-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
	--safe-right: max(env(safe-area-inset-right, 0px), calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)));
	--safe-bottom: max(env(safe-area-inset-bottom, 0px), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
	--safe-left: max(env(safe-area-inset-left, 0px), calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
}

/* Dark values, written twice: for the system setting and for an explicit choice. */
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #000000;
	--card: #1c1c1e;
	--elevated: #2c2c2e;
	--sidebar: #111113;
	--chat-bg: #000000;
	--text: #ffffff;
	--muted: #ebebf5b3;
	--faint: #ebebf580;
	--line: #54545899;
	--line-strong: #38383a;
	--input-line: #636366;
	--soft: #7676803d;
	--soft-strong: #7676805c;
	--press: #ffffff14;
	--system-blue: #0091ff;
	--system-green: #30d158;
	--system-orange: #ff9230;
	--system-red: #ff4245;
	--system-yellow: #ffd600;
	--system-purple: #bf5af2;
	--system-teal: #00d2e0;
	--accent: #5cb2ff;
	--accent-strong: #8ac8ff;
	--on-accent: #ffffff;
	--fill: #0a6fd8;
	--fill-strong: #1a7ee6;
	--tint-fill: #0f2a44;
	--danger: #ff7a7d;
	--danger-fill: #3a1d1f;
	--success: #6fe28f;
	--success-fill: #16301f;
	--warning: #ffbd7a;
	--warning-fill: #3a2a17;
	--bubble-mine: #0a6fd8;
	--bubble-other: #262628;
	--bubble-other-text: #ffffff;
	--code-bg: #161618;
	--bar: #161618cc;
	--bar-solid: #161618;
	--glass: #2c2c2eb3;
	--glass-line: #ffffff1f;
	--glass-shadow: 0 8px 32px #00000080, 0 1px 2px #0000004d;
	--sheet-backdrop: #0000008a;
	--sheet-bg: #1c1c1e;
	--sheet-card: #2c2c2e;
	--shadow-card: none;
	--loader-halo: #161b38;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #000000;
		--card: #1c1c1e;
		--elevated: #2c2c2e;
		--sidebar: #111113;
		--chat-bg: #000000;
		--text: #ffffff;
		--muted: #ebebf5b3;
		--faint: #ebebf580;
		--line: #54545899;
		--line-strong: #38383a;
		--input-line: #636366;
		--soft: #7676803d;
		--soft-strong: #7676805c;
		--press: #ffffff14;
		--system-blue: #0091ff;
		--system-green: #30d158;
		--system-orange: #ff9230;
		--system-red: #ff4245;
		--system-yellow: #ffd600;
		--system-purple: #bf5af2;
		--system-teal: #00d2e0;
		--accent: #5cb2ff;
		--accent-strong: #8ac8ff;
		--on-accent: #ffffff;
		--fill: #0a6fd8;
		--fill-strong: #1a7ee6;
		--tint-fill: #0f2a44;
		--danger: #ff7a7d;
		--danger-fill: #3a1d1f;
		--success: #6fe28f;
		--success-fill: #16301f;
		--warning: #ffbd7a;
		--warning-fill: #3a2a17;
		--bubble-mine: #0a6fd8;
		--bubble-other: #262628;
		--bubble-other-text: #ffffff;
		--code-bg: #161618;
		--bar: #161618cc;
		--bar-solid: #161618;
		--glass: #2c2c2eb3;
		--glass-line: #ffffff1f;
		--glass-shadow: 0 8px 32px #00000080, 0 1px 2px #0000004d;
		--sheet-backdrop: #0000008a;
		--sheet-bg: #1c1c1e;
		--sheet-card: #2c2c2e;
		--shadow-card: none;
		--loader-halo: #161b38;
	}
}

/* Larger screens: denser type, like a desktop chat app, same language. */
@media (min-width: 960px) {
	:root {
		--text-body: 1rem;
		--text-headline: 1rem;
		--text-subheadline: 0.875rem;
		--text-large-title: 1.875rem;
		--row-height: 46px;
		--page-inset: 32px;
	}
}

@media (prefers-contrast: more) {
	:root:root {
		--muted: var(--text);
		--faint: var(--text);
		--line: var(--input-line);
	}
}
