/**
 * Base theme — TrainersMap brand tokens.
 * Ported from user-account `static/styles/base.css`; values are the TrainersMap palette.
 *
 * - `/theme-bootstrap.js` in `app.html` runs before these sheets (first paint matches persisted theme).
 * - Linked from `app.html` before `main.css` (static asset: `/styles/base.css`).
 * - `themeManager` (`lib/utility/settings/themes/manage.ts`) sets `data-theme`, `data-font-size`, `data-animation-speed`.
 * - THE ONLY PLACE BRAND COLORS ARE WRITTEN. Feature CSS uses `var(--app-*)`.
 * - Brand is red / white / black. `--app-fresh` is marketplace "New" only. Status colors (success, warning, error) and `--app-online` are not brand. Success stays green.
 */

/* Light (default) */
:root {
	color-scheme: light;

	--app-font-system:
		system-ui, -apple-system, blinkmacsystemfont, "Segoe UI", roboto,
		"Helvetica Neue", arial, sans-serif;
	--app-font-body:
		"Avenir Next", avenir, "Inter Variable", inter, ui-sans-serif, system-ui,
		-apple-system, "Segoe UI", roboto, sans-serif;

	/* Coolvetica Regular. Every heading. File: /fonts/coolvetica/Coolvetica Rg.otf */
	--app-font-coolvetica: coolvetica, var(--app-font-body);
	--app-font-heading: var(--app-font-coolvetica);

	/* Brand display face. The folded-rune font built from the fold-type specimen.
       Faces are generated into /styles/fonts.css by deck/open-slide/fonts/build.py. */
	--app-font-display: "TrainersMap", var(--app-font-heading);
	--app-font-digital:
		digital, ui-monospace, sfmono-regular, menlo, monaco, consolas, monospace;

	/* @ in username handles. Handle body stays --app-font-digital. Carlito is the metric Calibri stand-in on Linux. */
	--app-font-at: calibri, carlito, "Segoe UI", sans-serif;
	--app-bg: #f5f5f5;
	--app-surface: #fff;
	--app-bg-highlight: #eee;

	/* Chat bubbles. The same greys in both themes. Theirs is the lighter grey. */
	--app-bubble-mine: #808080;
	--app-on-bubble-mine: #111;
	--app-bubble-theirs: #c4c4c4;
	--app-on-bubble-theirs: #111;
	--app-text: #111;
	--app-text-dim: #6b6b6b;
	--app-media-alpha-1: color-mix(in srgb, var(--app-bg) 86%, var(--app-text));
	--app-media-alpha-2: color-mix(in srgb, var(--app-bg) 70%, var(--app-text));

	/* Inline <code> chip — wash of ink on paper, not --app-text-dim. */
	--app-code-bg: color-mix(in srgb, var(--app-text) 12%, var(--app-surface));

	/* Fenced code. White paper in light, black paper in dark. Same on every surface. */
	--app-code-block-bg: #fff;
	--app-on-code-block: #111;
	--app-code-block-dim: #6b6b6b;
	--app-code-block-border: rgb(0 0 0 / 14%);
	--app-font-mono:
		ui-monospace, sfmono-regular, menlo, monaco, consolas, "Liberation Mono",
		monospace;
	--app-accent: #111;
	--app-on-accent: #fff;
	--app-pin: #ef233c;
	--app-on-pin: #fff;
	--app-active: var(--app-pin);
	--app-brand-lime: var(--app-pin);

	/* Marketplace "New" badge. Not a brand color. */
	--app-fresh: #1a6fd4;
	--app-on-fresh: #f3f8ff;
	--app-border: #e0e0e0;

	/* Field chrome — charcoal (`--app-text` / dark-mode `--app-bg`). Dividers stay `--app-border`. */
	--app-input-border: var(--app-text);

	/* Status green. Same role as warning / error. Not brand. */
	--app-success: #2b8c69;

	/* Presence dot only. Not a brand color. */
	--app-online: #22c55e;
	--app-warning: #f3a925;
	--app-error: #c83838;
	--app-on-error: #fff;

	/* Leaflet canvas behind tiles + the "you are here" pin. Not brand. */
	--app-map-bg: #dce7ea;
	--app-map-you: #2078e8;

	/* Factory fact network: one hue per concept type. Lightness and chroma flip per theme and stay
       inside sRGB at every hue (checked: light 0.6 / 0.1, dark 0.76 / 0.11). Not brand. */
	--app-graph-l: 0.6;
	--app-graph-c: 0.1;
	--app-graph-1: oklch(var(--app-graph-l) var(--app-graph-c) 255deg);
	--app-graph-2: oklch(var(--app-graph-l) var(--app-graph-c) 75deg);
	--app-graph-3: oklch(var(--app-graph-l) var(--app-graph-c) 150deg);
	--app-graph-4: oklch(var(--app-graph-l) var(--app-graph-c) 300deg);
	--app-graph-5: oklch(var(--app-graph-l) var(--app-graph-c) 200deg);
	--app-graph-6: oklch(var(--app-graph-l) var(--app-graph-c) 345deg);
	--app-graph-7: oklch(var(--app-graph-l) var(--app-graph-c) 120deg);
	--app-graph-8: oklch(var(--app-graph-l) var(--app-graph-c) 40deg);
	--app-radius: 0.9rem;

	/* The tighter radius for dense surfaces and code blocks, where 0.9rem looks pillowed. */
	--app-radius-md: 8px;

	/* A fully rounded end: chips, pills, and capsule buttons. */
	--app-radius-pill: 999px;

	/* The spacing scale. The number is the step, not the pixel count.
	   Steps 0-55 are the two-pixel ruler: the number times 2px. Ace locked that step on 2026-10-29.
	   A missing number in that range is an unused step, not a free name.
	   Steps from 100 are fixed lengths off that ruler. The slot stays if the literal later changes.
	   Theme-invariant on purpose: spacing never changes per theme, so these live in :root only. */
	--app-space-0: 0px;
	--app-space-1: 2px;
	--app-space-2: 4px;
	--app-space-3: 6px;
	--app-space-4: 8px;
	--app-space-5: 10px;
	--app-space-6: 12px;
	--app-space-7: 14px;
	--app-space-8: 16px;
	--app-space-9: 18px;
	--app-space-10: 20px;
	--app-space-11: 22px;
	--app-space-12: 24px;
	--app-space-13: 26px;
	--app-space-14: 28px;
	--app-space-15: 30px;
	--app-space-16: 32px;
	--app-space-17: 34px;
	--app-space-18: 36px;
	--app-space-19: 38px;
	--app-space-20: 40px;
	--app-space-22: 44px;
	--app-space-24: 48px;
	--app-space-26: 52px;
	--app-space-28: 56px;
	--app-space-32: 64px;
	--app-space-36: 72px;
	--app-space-42: 84px;
	--app-space-46: 92px;
	--app-space-48: 96px;
	--app-space-55: 110px;
	--app-space-100: 1px;
	--app-space-101: 3px;
	--app-space-102: 5px;
	--app-space-103: 7px;
	--app-space-104: 9px;
	--app-space-105: 13px;
	--app-space-106: 19px;
	--app-space-107: -1px;
	--app-space-108: 0.1em;
	--app-space-109: 0.2em;
	--app-space-110: 0.25em;
	--app-space-111: 0.28em;
	--app-space-112: 0.3em;
	--app-space-113: 0.35em;
	--app-space-114: 0.45em;
	--app-space-115: 0.5em;
	--app-space-116: 0.55em;
	--app-space-117: 0.75em;
	--app-space-118: 0.78em;
	--app-space-119: 0.85em;
	--app-space-120: 0.88em;
	--app-space-121: 0.92em;
	--app-space-122: 0.95em;
	--app-space-123: 1em;
	--app-space-124: -0.08em;
	--app-space-125: 0.2rem;
	--app-space-126: 0.35rem;
	--app-space-127: 0.4rem;
	--app-space-128: 0.625rem;
	--app-space-129: 0.65rem;
	--app-space-130: 0.75rem;
	--app-space-131: 0.78rem;
	--app-space-132: 0.8rem;
	--app-space-133: 0.8125rem;
	--app-space-134: 0.85rem;
	--app-space-135: 0.875rem;
	--app-space-136: 0.92rem;
	--app-space-137: 0.95rem;
	--app-space-138: 1rem;
	--app-space-139: 1.1rem;
	--app-space-140: 1.125rem;
	--app-space-141: 1.2rem;
	--app-space-142: 1.25rem;
	--app-space-143: 1.5rem;
	--app-space-144: 1.625rem;
	--app-space-145: 1.75rem;
	--app-space-146: 1.875rem;
	--app-space-147: 4.5rem;
	--app-space-148: 12rem;
	--app-space-149: 12.5rem;
	--app-space-150: 16rem;
	--app-space-151: 18rem;
	--app-space-152: 1.9vw;
	--app-space-153: 2vw;
	--app-space-154: 2.4vw;
	--app-space-155: 2.4vh;
	--app-space-156: 3vw;
	--app-space-157: 4vw;
	--app-space-158: 6vw;
	--app-space-159: 6.4vw;
	--app-space-160: 9vw;
	--app-space-161: 11.5vw;
	--app-space-162: 50vw;
	--app-space-163: 1vh;
	--app-space-164: 5vh;
	--app-space-165: 6vh;
	--app-space-166: 8vh;
	--app-space-167: 50%;
	--app-space-168: 100%;
	--app-space-169: -8%;
	--app-space-170: 11px;
	--app-space-171: 15px;
	--app-space-172: 0.9rem;

	/* Fixed paints. Same literal in both themes. Not a second spelling of the hex. */
	--app-clear: transparent;
	--app-media-alpha-tile: 16px;
	--app-media-alpha-canvas: conic-gradient(
		var(--app-media-alpha-1) 25%,
		var(--app-media-alpha-2) 0 50%,
		var(--app-media-alpha-1) 0 75%,
		var(--app-media-alpha-2) 0
	);
	--app-ink: currentColor;
	--app-coal: black;
	--app-chalk: #fff;
	--app-on-media: white;
	--app-on-media-dim: color-mix(in srgb, white 75%, transparent);
	--app-stripe: #b22234;
	--app-canton: #3c3b6e;
	--app-azure: #2b7de9;
	--app-leaf: #0f9d58;
	--app-sand: #f4a261;
	--app-violet: #7b2cbf;
	--app-lagoon: #0096c7;
	--app-clay: #e07a5f;
	--app-slate: #3d405b;
	--app-wash: color-mix(in srgb, currentColor 28%, transparent);
	--app-glass: rgb(12 12 12 / 72%);
	--app-plate: rgb(20 20 20 / 0.92);
	--app-on-plate: rgb(255 255 255);
	--app-on-plate-faint: rgb(255 255 255 / 0.14);
	--app-on-plate-dim: rgb(255 255 255 / 0.45);
	--app-on-plate-mid: rgb(255 255 255 / 0.6);
	--app-on-plate-strong: rgb(255 255 255 / 0.85);
	--app-border-none: 0 solid transparent;
	--app-border-blank: 1px solid transparent;
	--app-border-open: 2px solid transparent;
	--app-caret: 6px solid transparent;
	--app-line-faint: 1px solid rgb(255 255 255 / 34%);
	--app-spinner-ring: 1.5px solid color-mix(in srgb, currentColor 28%, transparent);
	--app-focus-line: 2px solid rgb(255 255 255 / 0.7);
	--app-shadow-none: drop-shadow(0 0 0 transparent);
	--app-hairline: inset 0 0 0 1px rgb(255 255 255 / 0.1);
	--app-scrim: linear-gradient(transparent, rgb(0 0 0 / 70%));
	--app-mask-opaque: linear-gradient(currentcolor, currentcolor), linear-gradient(currentcolor, currentcolor), linear-gradient(currentcolor, currentcolor), linear-gradient(currentcolor, currentcolor);
	--app-quiet-underline: underline transparent;
	--app-flat: 0;
	--app-type-parent: inherit;

	/* Feed, history, profile posts, and post detail share one timeline column. */
	--app-post-timeline-measure: min(1180px, calc(100% - 40px));
	--app-overlay: rgb(0 0 0 / 45%);

	/* Full-screen photo lightbox: near-black in both themes, light glyphs on top. */
	--app-lightbox-bg: rgb(0 0 0 / 92%);
	--app-on-lightbox: #f4f4f4;
	--app-shadow-color: rgb(0 0 0 / 8%);
	--app-shadow-color-strong: rgb(0 0 0 / 25%);
	--app-shadow: 0 8px 24px var(--app-shadow-color);
	--app-focus-ring: 0 0 0 3px rgb(239 35 60 / 35%);

	/* Brand marks that should flip with theme */
	--logo-filter: none;

	/* Factory provider · Iconify logos:openrouter-icon */
	--app-brand-openrouter: #7624f4;

	/* Factory provider · Wikimedia DeepSeek-icon.svg */
	--app-brand-deepseek: #4d6bfe;
	--app-brand-xai: #111111;
	--app-brand-cursor: #555;
	--app-brand-pi-coral: #F09082;
	--app-brand-pi-blue: #4D9ABF;
	--app-brand-pi-gold: #F1BE58;

	/* Window chrome — duplicate in main.css; change both if you resize bars */
	--status-bar-height: 20px;
	--chrome-bar-height: 26px;

	/* One glyph size for both chrome navs (the top bar and the feed rail) so the two
       never drift. Cells are `--chrome-bar-height` square in both. */
	--nav-glyph-size: 15px;

	/* Reserved scrollbar gutter for a `scrollbar-gutter: stable` scrollport. Overlay scrollbars
       reserve nothing, so anything positioned against the viewport edge (the compose FAB) needs
       this to clear the bar instead of sitting 4px beside it. */
	--scrollbar-width: 16px;

	/* Home Screen bar: side clearance past the phone corners, and the top radius.
       Safari-in-browser ignores these. The bar itself sits on the glass. */
	--status-bar-tray-inset: 16px;
	--status-bar-tray-radius: 10px;
	--font-size-chrome-status-readout: 11px;
	--font-size-chrome-status-btn: 12px;

	/* Values a component sets at runtime or inside its own selector. Declared here so the
	   token gate can see them; each is the value the consuming CSS already falls back to. */

	/* Set inline by panelStackFrame.svelte from the persisted prototype split. */
	--prototype-stage-end: 48;
	--prototype-code-end: 72;

	/* Set by chat-thread.css on the thread element; the dock reserve and the air above it. */
	--chat-input-reserve: 120px;
	--chat-thread-gap: 0px;

	/* Set by custom-dialog.css on the dialog; the dismiss button's box and its centre line. */
	--profile-dialog-close-size: 1.75rem;
	--profile-dialog-close-mid: calc(
		var(--profile-dialog-close-top) + var(--profile-dialog-close-size) / 2
	);

	/* Dialog / sheet stacking above sticky site header (site-header.css z 100) and status bar (10040). */
	--app-dialog-overlay-z: 10060;
	--app-dialog-content-z: 10061;

	/* Landing hero — always dark, both themes. Red is `--app-pin`. */
	--app-hero-bg: #141414;
	--app-hero-text: #fff;
	--app-hero-text-dim: #9a9a9a;
	--app-hero-grid: rgb(255 255 255 / 4.5%);

	/* Above header (30) + status bar (10040); below the sidebar (10052), site notice (10058), and dialogs (10060). */
	--app-hero-z: 10045;

	/* The name is the layer. The number is the current level. */
	--app-raised-z: 1;
	--app-over-z: 2;
	--app-cover-z: 3;
	--app-float-z: 4;
	--app-pop-z: 5;
	--app-rail-z: 6;
	--app-below-header-z: 29;
	--app-header-z: 30;
	--app-above-header-z: 31;
	--app-drawer-z: 40;
	--app-menu-z: 80;
	--app-flow-z: auto;
	--app-dock-z: 10010;
	--app-sticky-z: 10030;
	--app-bottom-nav-z: 10035;
	--app-status-bar-z: 10040;
	--app-fab-z: 10050;
	--app-sidebar-z: 10052;
	--app-notice-z: 10058;

	/* Profile dialog photo. The agent figure body uses the same diameter. */
	--app-profile-photo: calc(112px * 1.2);
	/* Body radius 100 inside viewBox half 158. See mods/figure/repere.ts. */
	--agent-figure-scale: 1.58;
}

@media (width <= 480px) {
	:root {
		--app-profile-photo: var(--app-space-42);
	}
}

/* Dark */
[data-theme="dark"] {
	color-scheme: dark;
	scrollbar-color: var(--app-border) var(--app-bg);

	--app-bg: #111;
	--app-surface: #1a1a1a;
	--app-bg-highlight: #242424;
	--app-text: #f5f5f5;
	--app-text-dim: #9a9a9a;
	--app-code-block-bg: #000;
	--app-on-code-block: #fff;
	--app-code-block-dim: #9a9a9a;
	--app-code-block-border: rgb(255 255 255 / 18%);
	--app-media-alpha-1: color-mix(in srgb, var(--app-bg) 86%, var(--app-text));
	--app-media-alpha-2: color-mix(in srgb, var(--app-bg) 70%, var(--app-text));
	--app-accent: #fff;
	--app-on-accent: #111;
	--app-pin: #ef233c;
	--app-on-pin: #fff;
	--app-active: var(--app-pin);
	--app-brand-lime: var(--app-pin);

	/* Factory provider · Iconify logos:openrouter-icon-dark */
	--app-brand-openrouter: #c8ff00;
	--app-brand-deepseek: #4d6bfe;
	--app-fresh: #27456f;
	--app-on-fresh: #c5d8f2;
	--app-border: #2e2e2e;
	--app-input-border: var(--app-border);
	--app-success: #4fc48f;
	--app-online: #4ade80;
	--app-warning: #f5b43a;
	--app-error: #ff6b6b;
	--app-on-error: #fff;
	--app-map-bg: #1b2126;
	--app-map-you: #5b9cff;
	--app-graph-l: 0.76;
	--app-graph-c: 0.11;
	--app-overlay: rgb(0 0 0 / 65%);
	--app-shadow-color: rgb(0 0 0 / 50%);
	--app-shadow-color-strong: rgb(0 0 0 / 70%);
	--app-focus-ring: 0 0 0 3px rgb(239 35 60 / 30%);
	--logo-filter: none;
}

/* Light (explicit) */
[data-theme="light"] {
	color-scheme: light;
	scrollbar-color: var(--app-border) var(--app-bg);
}

/* Font size steps */
:root,
[data-font-size="medium"] {
	--font-size-base: 15px;
	--font-size-small: 13px;
	--font-size-large: 17px;
	--font-size-h1: 30px;
	--font-size-h2: 22px;
	--font-size-h3: 18px;
	--font-size-h4: 15px;
	--font-size-h5: 14px;
	--font-size-h6: 13px;
	--font-size-button: 14px;
	--font-size-label: 13px;
	--font-size-caption: 12px;
	--font-size-table: 14px;
	--font-size-modal: 16px;
	--font-size-status: 13px;
}

[data-font-size="small"] {
	--font-size-base: 13px;
	--font-size-small: 11px;
	--font-size-large: 15px;
	--font-size-h1: 26px;
	--font-size-h2: 19px;
	--font-size-h3: 16px;
	--font-size-h4: 13px;
	--font-size-h5: 12px;
	--font-size-h6: 11px;
	--font-size-button: 12px;
	--font-size-label: 11px;
	--font-size-caption: 10px;
	--font-size-table: 12px;
	--font-size-modal: 14px;
	--font-size-status: 11px;
}

[data-font-size="large"] {
	--font-size-base: 17px;
	--font-size-small: 15px;
	--font-size-large: 19px;
	--font-size-h1: 34px;
	--font-size-h2: 25px;
	--font-size-h3: 20px;
	--font-size-h4: 17px;
	--font-size-h5: 16px;
	--font-size-h6: 15px;
	--font-size-button: 16px;
	--font-size-label: 15px;
	--font-size-caption: 14px;
	--font-size-table: 16px;
	--font-size-modal: 18px;
	--font-size-status: 15px;
}

/* Animation speed. Out for an entrance. In-out for a move that returns. */
:root,
[data-animation-speed="normal"] {
	--animation-duration-fast: 0.15s;
	--animation-duration-normal: 0.3s;
	--animation-duration-slow: 0.5s;
	--app-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
	--app-ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

[data-animation-speed="fast"] {
	--animation-duration-fast: 0.1s;
	--animation-duration-normal: 0.2s;
	--animation-duration-slow: 0.3s;
}

[data-animation-speed="slow"] {
	--animation-duration-fast: 0.25s;
	--animation-duration-normal: 0.5s;
	--animation-duration-slow: 0.8s;
}

/*
 * Theme flip (`themeManager.applySettings` => `crossfadeTheme`). The fade is one View Transitions
 * screenshot crossfade: `crossfadeTheme` snapshots the old palette, commits the new one, and the
 * browser dissolves the two page images on the compositor. One animation for the whole page, so
 * thousands of elements do not run per-element transitions on the main thread (that was slow and
 * glitchy) and un-animatable paints (logo swap, scrollbars) fade too.
 *
 * The `data-theme-transition` window covers only the commit frame. The "new" snapshot is captured
 * right after `commit`; an element still running its own transition in that frame (pressed buttons'
 * `transition-all`, the split grip's background, input `transition-colors`) is photographed with a
 * stale color and visibly trails the crossfade. Under the marker, transitions are OFF so the
 * snapshot lands on final values; it clears one frame later and normal hover/press fades return.
 * Reduced motion never calls `startViewTransition`, so this never applies.
 */
html[data-theme-transition] *,
html[data-theme-transition] *::before,
html[data-theme-transition] *::after {
	transition: none !important;
}

/*
 * View Transitions crossfade
 */
::view-transition-old(root),
::view-transition-new(root) {
	animation-duration: 0.25s;
	animation-timing-function: ease;
}

/* The root snapshot already carries the whole page; the default group animation would double it. */
::view-transition-group(root) {
	animation-duration: 0.25s;
}

/*
 * Shadcn subtree bridge: semantic vars inherit from `--app-*` on a wrapper when a portal
 * needs a coherent subtree. Global defaults map in `lib/tailwind.css` (`:root`).
 */
.app-shadcn-surface {
	--background: var(--app-bg);
	--foreground: var(--app-text);
	--card: var(--app-surface);
	--card-foreground: var(--app-text);
	--popover: var(--app-surface);
	--popover-foreground: var(--app-text);
	--primary: var(--app-accent);
	--primary-foreground: var(--app-on-accent);
	--secondary: var(--app-bg-highlight);
	--secondary-foreground: var(--app-text);
	--muted: var(--app-bg-highlight);
	--muted-foreground: var(--app-text-dim);
	--accent: var(--app-bg-highlight);
	--accent-foreground: var(--app-text);
	--destructive: var(--app-error);
	--destructive-foreground: var(--app-surface);
	--border: var(--app-border);
	--input: var(--app-input-border);
	--ring: var(--app-active);
}
