/* Sky Map design tokens: the Night Atlas. See public/app/DESIGN.md for the reasoning behind every value.
 *
 * Themes are attributes on <html>: data-theme="night" (default) | "red"; data-text="large"; data-posture=
 * "phone" | "tablet" | "laptop" | "wall"; data-layout="compact" | "compact-landscape" | "regular" | "wall".
 * --dim (0.15 to 1) is the dimmer: every light-emitting token (text, icons, accents, lines) is multiplied by it, so
 * dimming is a token change, never a page filter.
 */

:root {
  color-scheme: dark;
  --dim: 1;

  /* ---------------------------------------------------------------- night ink: surfaces (blue-black, never grey) */
  --ink-0: #030409;                       /* page, behind the sky */
  --ink-1: #06080e;                       /* sunk wells (inputs) */
  --ink-2: #0a0d15;                       /* surfaces */
  --ink-3: #10141e;                       /* controls at rest */
  --ink-4: #171c29;                       /* controls hovered or pressed */
  /* smoked ink: surfaces over the sky. No backdrop blur (a full-screen blur costs a GPU pass per frame on phones). */
  --smoke-1: rgb(4 6 11 / 0.74);          /* top line and dock over the sky */
  --smoke-2: rgb(6 8 14 / 0.95);          /* sheets and side panels: a breath of the sky, never its labels */
  --smoke-3: rgb(7 9 15 / 0.97);          /* dialogs, the command palette */
  --scrim: rgb(1 2 5 / 0.55);             /* behind modal dialogs */
  --bezel-fade: linear-gradient(to top, rgb(3 4 9 / 0.92), rgb(3 4 9 / 0.55) 55%, rgb(3 4 9 / 0));

  /* ---------------------------------------------------------------- starlight: text and icons (warm, never white) */
  --star-1: rgb(calc(216 * var(--dim)) calc(209 * var(--dim)) calc(194 * var(--dim)));   /* L 0.64: names, values */
  --star-2: rgb(calc(160 * var(--dim)) calc(155 * var(--dim)) calc(145 * var(--dim)));   /* L 0.33: secondary */
  --star-3: rgb(calc(128 * var(--dim)) calc(124 * var(--dim)) calc(116 * var(--dim)));   /* L 0.20: labels, hints (4.6:1) */
  --star-4: rgb(calc(86 * var(--dim)) calc(83 * var(--dim)) calc(78 * var(--dim)));      /* L 0.09: disabled, decoration */

  /* ---------------------------------------------------------------- the one warm accent: a brass observing lamp */
  --accent: rgb(calc(222 * var(--dim)) calc(166 * var(--dim)) calc(104 * var(--dim)));   /* L 0.44 */
  --accent-hi: rgb(calc(238 * var(--dim)) calc(194 * var(--dim)) calc(140 * var(--dim))); /* pressed, focus */
  --accent-wash: rgb(calc(222 * var(--dim)) calc(166 * var(--dim)) calc(104 * var(--dim)) / 0.14); /* selected fill */
  --accent-rule: rgb(calc(222 * var(--dim)) calc(166 * var(--dim)) calc(104 * var(--dim)) / 0.42);
  --on-accent: #170e05;

  /* ---------------------------------------------------------------- engraved rules (hairlines) */
  --rule: rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.09);
  --rule-2: rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.16);
  --wash: rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.05);    /* hover fill */
  --wash-2: rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.09);  /* pressed fill */

  /* ---------------------------------------------------------------- status: colour-blind safe, always with icon + word */
  --go: rgb(calc(92 * var(--dim)) calc(190 * var(--dim)) calc(160 * var(--dim)));        /* bluish green */
  --maybe: rgb(calc(226 * var(--dim)) calc(180 * var(--dim)) calc(82 * var(--dim)));     /* amber */
  --skip: rgb(calc(224 * var(--dim)) calc(122 * var(--dim)) calc(96 * var(--dim)));      /* vermilion */
  --go-wash: rgb(calc(92 * var(--dim)) calc(190 * var(--dim)) calc(160 * var(--dim)) / 0.12);
  --maybe-wash: rgb(calc(226 * var(--dim)) calc(180 * var(--dim)) calc(82 * var(--dim)) / 0.12);
  --skip-wash: rgb(calc(224 * var(--dim)) calc(122 * var(--dim)) calc(96 * var(--dim)) / 0.12);
  --live: var(--go);

  /* ---------------------------------------------------------------- the sky's own palette (raw "r g b / a" triplets)
     core/theme.js passes these to sky.setTheme(); the renderer makes them red-only itself in night mode, so they are
     not overridden by the red theme. UI legends use them as rgb(var(--sky-line-ecliptic)). */
  --sky-line-constellations: 142 166 222 / 0.3;
  --sky-line-boundaries: 166 140 112 / 0.24;
  --sky-line-azimuthalGrid: 118 170 142 / 0.22;
  --sky-line-equatorialGrid: 104 138 222 / 0.22;
  --sky-line-ecliptic: 228 188 112 / 0.44;
  --sky-line-equator: 112 158 238 / 0.38;
  --sky-line-meridian: 186 186 192 / 0.3;
  --sky-line-galactic: 186 146 222 / 0.32;
  --sky-line-zodiac: 230 189 117 / 0.3;
  --sky-line-lunarMansions: 153 204 219 / 0.28;
  --sky-line-horizonLine: 228 170 122 / 0.55;
  --sky-line-satellitePath: 240 202 132 / 0.62;
  --sky-line-annotations: 222 166 104 / 0.8;
  --sky-label-constellation: 150 168 214 / 0.64;
  --sky-label-star: 214 218 230 / 0.92;
  --sky-label-starDim: 178 188 214 / 0.72;
  --sky-label-bayer: 176 188 220 / 0.8;
  --sky-label-flamsteed: 160 172 206 / 0.6;
  --sky-label-planet: 236 206 156 / 0.95;
  --sky-label-sunMoon: 244 232 206 / 0.95;
  --sky-label-deepSky: 150 196 180 / 0.82;
  --sky-label-satellite: 240 202 132 / 0.92;
  --sky-label-cardinal: 222 166 104 / 0.95;
  --sky-label-cardinalMinor: 222 166 104 / 0.6;
  --sky-label-grid: 160 178 210 / 0.62;
  --sky-label-radiant: 206 172 236 / 0.85;
  --sky-label-selection: 236 228 210 / 0.98;
  --sky-label-annotation: 236 228 210 / 0.94;
  --sky-label-annotationMuted: 200 200 210 / 0.72;
  --sky-label-landmark: 214 204 186 / 0.78;
  --sky-label-landmarkWater: 160 184 222 / 0.8;
  --sky-symbol-deepSky: 150 196 180 / 0.55;
  --sky-symbol-radiant: 206 172 236 / 0.8;
  --sky-symbol-selection: 236 228 210 / 0.92;
  --sky-symbol-pointer: 222 166 104 / 0.95;
  --sky-symbol-panel: 6 8 14 / 0.8;
  --sky-symbol-panelBorder: 216 205 184 / 0.2;
  --sky-symbol-landmark: 214 196 160 / 0.5;
  --sky-halo: 2 3 7 / 0.66;

  /* ---------------------------------------------------------------- the location picker's map (an engraved chart at night)
     Sea and lakes in the page's ink, land a breath of starlight, water lines a quiet blue, roads in the brass lamp's
     colour, borders dashed. Canvas reads them through app.theme.color(). */
  --map-sea: var(--ink-1);
  --map-land: rgb(calc(216 * var(--dim)) calc(209 * var(--dim)) calc(194 * var(--dim)) / 0.14);
  --map-coast: rgb(calc(216 * var(--dim)) calc(209 * var(--dim)) calc(194 * var(--dim)) / 0.34);
  --map-water: rgb(calc(118 * var(--dim)) calc(150 * var(--dim)) calc(206 * var(--dim)) / 0.55);
  --map-water-label: rgb(calc(146 * var(--dim)) calc(172 * var(--dim)) calc(214 * var(--dim)) / 0.85);
  --map-border: rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.42);
  --map-border-2: rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.2);
  --map-road: rgb(calc(222 * var(--dim)) calc(166 * var(--dim)) calc(104 * var(--dim)) / 0.5);
  --map-road-2: rgb(calc(222 * var(--dim)) calc(166 * var(--dim)) calc(104 * var(--dim)) / 0.28);
  --map-label: var(--star-1);
  --map-label-2: var(--star-2);
  --map-label-3: var(--star-3);
  --map-halo: rgb(6 8 14 / 0.85);

  /* ---------------------------------------------------------------- deep-sky hues (atlas convention) */
  --dso-galaxy: rgb(calc(222 * var(--dim)) calc(152 * var(--dim)) calc(150 * var(--dim)));     /* rose ellipse */
  --dso-open: rgb(calc(218 * var(--dim)) calc(196 * var(--dim)) calc(128 * var(--dim)));       /* straw, dotted circle */
  --dso-globular: rgb(calc(224 * var(--dim)) calc(176 * var(--dim)) calc(110 * var(--dim)));   /* amber, circle + cross */
  --dso-nebula: rgb(calc(130 * var(--dim)) calc(196 * var(--dim)) calc(160 * var(--dim)));     /* sage, square */
  --dso-planetary: rgb(calc(122 * var(--dim)) calc(196 * var(--dim)) calc(192 * var(--dim)));  /* teal, disc with rays */
  --dso-other: rgb(calc(160 * var(--dim)) calc(168 * var(--dim)) calc(190 * var(--dim)));

  /* ---------------------------------------------------------------- sky object hues (UI references to sky labels) */
  --obj-star: rgb(calc(206 * var(--dim)) calc(212 * var(--dim)) calc(226 * var(--dim)));
  --obj-planet: rgb(calc(232 * var(--dim)) calc(200 * var(--dim)) calc(150 * var(--dim)));
  --obj-moon: rgb(calc(230 * var(--dim)) calc(218 * var(--dim)) calc(190 * var(--dim)));   /* L 0.71: under the 0.72 cap */
  --obj-satellite: rgb(calc(240 * var(--dim)) calc(202 * var(--dim)) calc(132 * var(--dim)));
  --moon-lit: rgb(calc(226 * var(--dim)) calc(218 * var(--dim)) calc(196 * var(--dim)));
  --moon-dark: #161a24;

  /* ---------------------------------------------------------------- typography */
  --font-serif: 'Sky Map Serif', 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Noto Serif', Georgia, serif;
  --font-sans: 'Sky Map Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
  --fs-2xs: 0.6875rem;   /* 11: eyebrows, keycaps */
  --fs-xs: 0.75rem;      /* 12: hints, units */
  --fs-sm: 0.8125rem;    /* 13: secondary text */
  --fs-md: 0.9375rem;    /* 15: interface text */
  --fs-lg: 1.0625rem;    /* 17: row titles, captions */
  --fs-xl: 1.375rem;     /* 22: serif sheet titles */
  --fs-2xl: 1.875rem;    /* 30: serif object names */
  --fs-3xl: 2.75rem;     /* 44: wall headings */
  --fs-4xl: 4.5rem;      /* 72: wall clock */
  --lh-tight: 1.12;
  --lh-snug: 1.28;
  --lh-body: 1.45;
  --track-caps: 0.14em;          /* sans eyebrows */
  --track-atlas: 0.24em;         /* serif roman capitals, the constellation voice */
  --w-regular: 400;
  --w-medium: 500;
  --w-strong: 600;

  /* ---------------------------------------------------------------- space, size, radii (rem: large text scales them) */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem; --sp-5: 1.25rem; --sp-6: 1.5rem; --sp-8: 2rem; --sp-10: 2.5rem; --sp-12: 3rem;
  --hit: 2.75rem;                /* 44 px: minimum touch target */
  --hit-lg: 3rem;                /* 48 px: dock targets, for cold fingers and gloves */
  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;
  --hairline: 1px;
  --panel-w: 23.5rem;            /* side panels on laptop and wall */
  --gutter: 0.75rem;             /* distance of floating chrome from the screen edge */

  /* ---------------------------------------------------------------- elevation: dark shadows, a plate-edge highlight */
  --edge: inset 0 1px 0 rgb(calc(216 * var(--dim)) calc(205 * var(--dim)) calc(184 * var(--dim)) / 0.06);
  --elev-1: var(--edge), 0 6px 20px rgb(0 0 0 / 0.32);
  --elev-2: var(--edge), 0 14px 40px rgb(0 0 0 / 0.48);
  --elev-3: var(--edge), 0 28px 72px rgb(0 0 0 / 0.6);

  /* ---------------------------------------------------------------- motion */
  --dur-1: 90ms;        /* press, hover */
  --dur-2: 160ms;       /* fades, chips, tooltips */
  --dur-3: 260ms;       /* toasts, panels' content */
  --dur-4: 380ms;       /* sheets and side panels */
  --dur-5: 700ms;       /* house lights down */
  --dur-6: 1600ms;      /* the sky fading in as the eyes adapt */
  --ease-paper: cubic-bezier(0.22, 0.9, 0.26, 1);   /* a sheet of paper sliding to rest: quick start, long settle, no bounce */
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
  --ease-inout: cubic-bezier(0.65, 0, 0.35, 1);     /* projector swings */
  --ease-dawn: cubic-bezier(0.3, 0, 0.2, 1);        /* eyes adapting */

  /* ---------------------------------------------------------------- safe areas */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  /* The same by writing direction, for logical insets and paddings (inset-inline-start, padding-inline-end…): a
     physical safe area on a logical side is wrong in right-to-left, where the start edge is the right one */
  --safe-start: var(--safe-l);
  --safe-end: var(--safe-r);
}
:root[dir='rtl'] { --safe-start: var(--safe-r); --safe-end: var(--safe-l); }

/* ------------------------------------------------------------------ red night mode: a true red-only theme.
   Every light token keeps green and blue at exactly 0, and --dim scales the red. Hierarchy is carried by size and
   weight more than by brightness, because pure red tops out at 5.3:1 contrast on black. */
:root[data-theme='red'] {
  --dim: 0.8;
  --ink-0: #030000; --ink-1: #060000; --ink-2: #0a0000; --ink-3: #120000; --ink-4: #1b0000;
  --smoke-1: rgb(4 0 0 / 0.8);
  --smoke-2: rgb(6 0 0 / 0.95);
  --smoke-3: rgb(7 0 0 / 0.97);
  --scrim: rgb(2 0 0 / 0.6);
  --bezel-fade: linear-gradient(to top, rgb(3 0 0 / 0.94), rgb(3 0 0 / 0.55) 55%, rgb(3 0 0 / 0));
  /* Text sits near the top of the red range (contrast is what red can spare; rules, washes and the sky stay dim):
     at the default 80 % primary text is 3.6 : 1 and secondary about 3 : 1; the dimmer takes primary to 5.3 : 1. */
  --star-1: rgb(calc(255 * var(--dim)) 0 0);
  --star-2: rgb(calc(238 * var(--dim)) 0 0);
  --star-3: rgb(calc(222 * var(--dim)) 0 0);
  --star-4: rgb(calc(150 * var(--dim)) 0 0);
  --accent: rgb(calc(255 * var(--dim)) 0 0);
  --accent-hi: rgb(calc(255 * var(--dim)) 0 0);
  --accent-wash: rgb(calc(255 * var(--dim)) 0 0 / 0.16);
  --accent-rule: rgb(calc(255 * var(--dim)) 0 0 / 0.5);
  --on-accent: #000;
  --rule: rgb(calc(220 * var(--dim)) 0 0 / 0.16);
  --rule-2: rgb(calc(220 * var(--dim)) 0 0 / 0.26);
  --wash: rgb(calc(220 * var(--dim)) 0 0 / 0.07);
  --wash-2: rgb(calc(220 * var(--dim)) 0 0 / 0.12);
  --go: rgb(calc(242 * var(--dim)) 0 0);
  --maybe: rgb(calc(200 * var(--dim)) 0 0);
  --skip: rgb(calc(158 * var(--dim)) 0 0);
  --go-wash: rgb(calc(242 * var(--dim)) 0 0 / 0.12);
  --maybe-wash: rgb(calc(200 * var(--dim)) 0 0 / 0.1);
  --skip-wash: rgb(calc(158 * var(--dim)) 0 0 / 0.08);
  --dso-galaxy: rgb(calc(214 * var(--dim)) 0 0);
  --dso-open: rgb(calc(214 * var(--dim)) 0 0);
  --dso-globular: rgb(calc(214 * var(--dim)) 0 0);
  --dso-nebula: rgb(calc(190 * var(--dim)) 0 0);
  --dso-planetary: rgb(calc(190 * var(--dim)) 0 0);
  --dso-other: rgb(calc(170 * var(--dim)) 0 0);
  --obj-star: rgb(calc(220 * var(--dim)) 0 0);
  --obj-planet: rgb(calc(240 * var(--dim)) 0 0);
  --obj-moon: rgb(calc(240 * var(--dim)) 0 0);
  --obj-satellite: rgb(calc(230 * var(--dim)) 0 0);
  --moon-lit: rgb(calc(220 * var(--dim)) 0 0);
  --moon-dark: #140000;
  --edge: inset 0 1px 0 rgb(calc(220 * var(--dim)) 0 0 / 0.08);
  --map-sea: var(--ink-1);
  --map-land: rgb(calc(220 * var(--dim)) 0 0 / 0.15);
  --map-coast: rgb(calc(230 * var(--dim)) 0 0 / 0.4);
  --map-water: rgb(calc(170 * var(--dim)) 0 0 / 0.55);
  --map-water-label: rgb(calc(200 * var(--dim)) 0 0 / 0.85);
  --map-border: rgb(calc(220 * var(--dim)) 0 0 / 0.45);
  --map-border-2: rgb(calc(220 * var(--dim)) 0 0 / 0.24);
  --map-road: rgb(calc(240 * var(--dim)) 0 0 / 0.5);
  --map-road-2: rgb(calc(240 * var(--dim)) 0 0 / 0.3);
  --map-halo: rgb(6 0 0 / 0.85);
}

/* ------------------------------------------------------------------ large text: the whole interface is in rem */
:root[data-text='large'] { font-size: 125%; }

/* ------------------------------------------------------------------ wall screen: a ten-foot interface */
:root[data-posture='wall'] { font-size: clamp(18px, 1.35vw, 56px); --gutter: 2.5vw; --panel-w: 30rem; }   /* the same proportions at 4K */
:root[data-posture='wall'][data-text='large'] { font-size: clamp(22px, 1.7vw, 68px); }

/* ------------------------------------------------------------------ reduced motion: crossfades only, no travel */
@media (prefers-reduced-motion: reduce) {
  :root { --dur-3: 120ms; --dur-4: 120ms; --dur-5: 200ms; --dur-6: 300ms; }
}
:root[data-motion='reduced'] { --dur-3: 120ms; --dur-4: 120ms; --dur-5: 200ms; --dur-6: 300ms; }
