/*
 * Colour, shadow and type tokens: the only place colour values live (S0, #167).
 * A source scan (tests/js/css-literals.test.js) fails on colour literals in any
 * other stylesheet, and tests/js/design-contrast.test.js checks every scheme.
 *
 * Lantern is the default (no data-scheme). Its values come from
 * Thiesi/ChitChat-Mobile @ e9eb5b452ba23c316e1962e7993fe09010ff9933,
 * docs/design/visual-vocabulary.md; shared values change only through paired
 * PRs. The other schemes are opt-in variants that re-tint the same roles;
 * semantic roles keep their meaning in all of them (honey = people, the unsure
 * line = uncertainty, rose = error, Dusk = stewardship). Dark is the base, as
 * before; theme.js sets data-theme and data-scheme before paint.
 *
 * Lantern Next (L0, #382; docs/design/lantern-next.md): the web leads Lantern
 * for this overhaul, so three values differ from that commit on purpose
 * (light --ground and --raised, dark --outgoing), and the type, shape, space,
 * elevation and motion scales further down are new. CCM adopts them from
 * lantern-next.md.
 */

@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/bricolage-grotesque-700.woff2") format("woff2");
}

@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("/assets/fonts/bricolage-grotesque-800.woff2") format("woff2");
}

/* Lantern, dark: Persimmon on Night ink. */
:root {
  /* Identity hues for people (pebbles) and rooms (lanterns), the same in every theme;
     index from identity-hue.js (shared with ChitChat Mobile). Text on them is --hue-ink. */
  --hue-0: #F7A072;
  --hue-1: #F5C451;
  --hue-2: #A8D672;
  --hue-3: #7FD1C1;
  --hue-4: #8DB8F5;
  --hue-5: #B7A3F5;
  --hue-6: #F29BC4;
  --hue-7: #D9B08C;
  --hue-ink: #14111C;
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display-font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  /* Bricolage is set tighter than body text, but less than the former serif needed. */
  --display-tracking: -0.02em;
  --ground: #14111C;
  --surface: #1C1826;
  --raised: #272233;
  --line: #3A3347;
  --field-line: #7D7490;
  --text: #F2EDF7;
  --text-muted: #A79FB4;
  --signature: #F06A3B;
  --on-signature: #14111C;
  --signature-text: #F06A3B;
  --signature-hover: #F5916D;
  --outgoing: #742F17;
  --on-outgoing: #F2EDF7;
  --presence: #FFB547;
  --presence-text: #FFB547;
  --unsure-line: #FFB547;
  /* Warning icons and text: the "attention, not danger" amber (#225, CCM's unsureLine alias). */
  --warning: var(--unsure-line);
  --presence-wash: #4A3A1C;
  --steward: #A9B6FF;
  --error: #FF8A9B;
  --shadow: 0 12px 36px rgb(0 0 0 / 0.24);
  --shadow-soft: rgb(0 0 0 / 0.12);
  --shadow-strong: rgb(0 0 0 / 0.35);
  --scrim: rgb(0 0 0 / 0.55);
  --scrim-strong: rgb(0 0 0 / 0.68);
}

/* Lantern, light: Persimmon on Paper. */
:root[data-theme="light"] {
  color-scheme: light;
  --ground: #F5F0E8;
  --surface: #FFFFFF;
  --raised: #F1EADF;
  --line: #E6DCCF;
  --field-line: #8C8299;
  --text: #14111C;
  --text-muted: #5E566B;
  --signature: #F06A3B;
  --on-signature: #14111C;
  --signature-text: #B5401A;
  --signature-hover: #F5916D;
  --outgoing: #FFD9C4;
  --on-outgoing: #14111C;
  --presence: #FFB547;
  --presence-text: #8F5B00;
  --unsure-line: #8F5B00;
  --presence-wash: #FFF0D2;
  --steward: #3D52C4;
  --error: #C4314B;
  --shadow: 0 12px 36px rgb(60 40 20 / 0.08);
  --shadow-soft: rgb(60 40 20 / 0.06);
  --shadow-strong: rgb(20 17 28 / 0.22);
  --scrim: rgb(20 17 28 / 0.45);
  --scrim-strong: rgb(20 17 28 / 0.62);
}

/* Lounge (the previous default), dark. */
:root[data-scheme="lounge"]:not([data-theme="light"]) {
  --ground: #111E22;
  --surface: #192B2F;
  --raised: #23383C;
  --line: #385054;
  --field-line: #677979;
  --text: #F2F3E9;
  --text-muted: #AFC1BD;
  --signature: #A8DBC5;
  --on-signature: #142F28;
  --signature-text: #C5EFDC;
  --signature-hover: #C5EFDC;
  --outgoing: #2E5047;
  --on-outgoing: #F2F3E9;
  --presence: #FFB547;
  --presence-text: #FFB547;
  --unsure-line: #FFB547;
  --presence-wash: #2E5047;
  --steward: #A9B6FF;
  --error: #FF8F8F;
}

/* Lounge (the previous default), light. */
:root[data-scheme="lounge"][data-theme="light"] {
  --ground: #F1EEE5;
  --surface: #FFFDF7;
  --raised: #E9EEE5;
  --line: #CCD5C9;
  --field-line: #79877F;
  --text: #213D38;
  --text-muted: #4F6259;
  --signature: #286454;
  --on-signature: #FFFFFF;
  --signature-text: #1B5344;
  --signature-hover: #1B5344;
  --outgoing: #DBEADE;
  --on-outgoing: #213D38;
  --presence: #FFB547;
  --presence-text: #8F5B00;
  --unsure-line: #8F5B00;
  --presence-wash: #DBEADE;
  --steward: #3D52C4;
  --error: #C0392B;
}

/* Dusk, dark. */
:root[data-scheme="dusk"]:not([data-theme="light"]) {
  --ground: #141729;
  --surface: #1C2038;
  --raised: #262B48;
  --line: #3A4066;
  --field-line: #6B6F8A;
  --text: #EEF0FB;
  --text-muted: #B3B8D6;
  --signature: #A9B4FF;
  --on-signature: #161A3A;
  --signature-text: #C9D0FF;
  --signature-hover: #C9D0FF;
  --outgoing: #333B6E;
  --on-outgoing: #EEF0FB;
  --presence: #FFB547;
  --presence-text: #FFB547;
  --unsure-line: #FFB547;
  --presence-wash: #333B6E;
  --steward: #A9B6FF;
  --error: #FF8F9A;
}

/* Dusk, light. */
:root[data-scheme="dusk"][data-theme="light"] {
  --ground: #EEF0F8;
  --surface: #FBFBFF;
  --raised: #E6E9F6;
  --line: #C9CDE4;
  --field-line: #80849F;
  --text: #22274A;
  --text-muted: #50567A;
  --signature: #3D4AA8;
  --on-signature: #FFFFFF;
  --signature-text: #2F3A8F;
  --signature-hover: #2F3A8F;
  --outgoing: #E1E5FB;
  --on-outgoing: #22274A;
  --presence: #FFB547;
  --presence-text: #8F5B00;
  --unsure-line: #8F5B00;
  --presence-wash: #E1E5FB;
  --steward: #3D52C4;
  --error: #BD3729; /* a shade deeper than Lounge's: 4.5:1 on this scheme's --raised too (L0) */
}

/* Ember, dark. */
:root[data-scheme="ember"]:not([data-theme="light"]) {
  --ground: #1D1612;
  --surface: #271E18;
  --raised: #33281F;
  --line: #4D3D30;
  --field-line: #7A6D61;
  --text: #F6EDE4;
  --text-muted: #C9B8A8;
  --signature: #F0A868;
  --on-signature: #2B1608;
  --signature-text: #FFC896;
  --signature-hover: #FFC896;
  --outgoing: #4A3322;
  --on-outgoing: #F6EDE4;
  --presence: #FFB547;
  --presence-text: #FFB547;
  --unsure-line: #FFB547;
  --warning: #FFD966; /* yellower: Ember's action colour is amber */
  --presence-wash: #4A3322;
  --steward: #A9B6FF;
  --error: #FF8F8F;
}

/* Ember, light. */
:root[data-scheme="ember"][data-theme="light"] {
  --ground: #F6EFE6;
  --surface: #FFFAF4;
  --raised: #F1E6D8;
  --line: #DFCDB9;
  --field-line: #948173;
  --text: #3A2618;
  --text-muted: #6B5241;
  --signature: #A8521C;
  --on-signature: #FFFFFF;
  --signature-text: #8A4214;
  --signature-hover: #8A4214;
  --outgoing: #F6DFC8;
  --on-outgoing: #3A2618;
  --presence: #FFB547;
  --presence-text: #8F5B00;
  --unsure-line: #8F5B00;
  --warning: #6F5A00; /* yellower: Ember's action colour is amber */
  --presence-wash: #F6DFC8;
  --steward: #3D52C4;
  --error: #B42318;
}

/* Rosé, dark. */
:root[data-scheme="rose"]:not([data-theme="light"]) {
  --ground: #1D1419;
  --surface: #281B22;
  --raised: #34242D;
  --line: #503745;
  --field-line: #7C6A73;
  --text: #F8EEF2;
  --text-muted: #CDB5C1;
  --signature: #F0A6C4;
  --on-signature: #3A1226;
  --signature-text: #FFC9DE;
  --signature-hover: #FFC9DE;
  --outgoing: #4D2C3C;
  --on-outgoing: #F8EEF2;
  --presence: #FFB547;
  --presence-text: #FFB547;
  --unsure-line: #FFB547;
  --presence-wash: #4D2C3C;
  --steward: #A9B6FF;
  --error: #FF9A8F;
}

/* Rosé, light. */
:root[data-scheme="rose"][data-theme="light"] {
  --ground: #F7EEF1;
  --surface: #FFFAFB;
  --raised: #F2E4EA;
  --line: #E0C9D3;
  --field-line: #977E89;
  --text: #3B1F2C;
  --text-muted: #6C4C5B;
  --signature: #A23B6A;
  --on-signature: #FFFFFF;
  --signature-text: #852D56;
  --signature-hover: #852D56;
  --outgoing: #F7DBE7;
  --on-outgoing: #3B1F2C;
  --presence: #FFB547;
  --presence-text: #8F5B00;
  --unsure-line: #8F5B00;
  --presence-wash: #F7DBE7;
  --steward: #3D52C4;
  --error: #B42318;
}

/* High contrast, dark: the accessibility palette. */
:root[data-scheme="contrast"]:not([data-theme="light"]) {
  --ground: #000000;
  --surface: #0A0A0A;
  --raised: #1C1C1C;
  --line: #FFFFFF;
  --field-line: #FFFFFF;
  --text: #FFFFFF;
  --text-muted: #E6E6E6;
  --signature: #FFD60A;
  --on-signature: #000000;
  --signature-text: #FFE45C;
  --signature-hover: #FFE45C;
  --outgoing: #1C1C1C;
  --on-outgoing: #FFFFFF;
  --presence: #FFD60A;
  --presence-text: #FFD60A;
  --unsure-line: #FFD60A;
  --warning: #FF9F1C; /* orange: this scheme's unsure line is its yellow action colour */
  --presence-wash: #333300;
  --steward: #9CB4FF;
  --error: #FF7B7B;
  --shadow: none;
}

/* High contrast, light. */
:root[data-scheme="contrast"][data-theme="light"] {
  --ground: #FFFFFF;
  --surface: #FFFFFF;
  --raised: #EEEEEE;
  --line: #000000;
  --field-line: #000000;
  --text: #000000;
  --text-muted: #1F1F1F;
  --signature: #0033CC;
  --on-signature: #FFFFFF;
  --signature-text: #002299;
  --signature-hover: #002299;
  --outgoing: #DFE6FF;
  --on-outgoing: #000000;
  --presence: #6B4E00;
  --presence-text: #6B4E00;
  --unsure-line: #6B4E00;
  --presence-wash: #FFF3B0;
  --steward: #0033CC;
  --error: #B00000;
  --shadow: none;
}

:root[data-scheme="contrast"] a:not([class]) { text-decoration: underline; }

/* Midnight, dark only: CC's own true-black scheme on CCM's AMOLED values.
   Never presented as Lantern's dark mode or as "Pure black". Light mode is Lantern light. */
:root[data-scheme="midnight"]:not([data-theme="light"]) {
  --ground: #000000;
  --surface: #110E17;
  --raised: #1F1B29;
  --line: #2E2938;
  --shadow: none;
}

/* Web-only tokens for stewardship (S6, #172), derived from each scheme's own
   --steward and neutrals: no new colours. They are not part of the shared
   Lantern vocabulary (the app has no stewardship UI); if a scheme ever needs a
   value these can't produce, it becomes a paired change with CCM. Checked in
   tests/js/design-contrast.test.js against the A-01/A-02 floors.
   - --on-steward: labels on a filled --steward button (the page's ground in
     dark, where --steward is light; the card surface in light, where it's dark).
   - --steward-hover: hover and press move the fill towards --text, away from the label.
   - --steward-wash: a selected row or the current tab, under --text. */
:root {
  --on-steward: var(--ground);
  --steward-hover: color-mix(in srgb, var(--steward) 80%, var(--text));
  --steward-wash: color-mix(in srgb, var(--steward) 14%, var(--surface));
}
:root[data-theme="light"] { --on-steward: var(--surface); }

/* ---- Lantern Next scales (L0, #382) ----
   One rhythm for every screen: seven type roles, six radii, a 4px spacing
   scale, three elevations and three durations. Slices L1 onwards replace the
   one-off values in the other stylesheets with these; nothing here changes a
   screen by itself. Old and new values, with reasons: docs/design/lantern-next.md. */
:root {
  /* Type. Display roles use --display-font, the rest the system stack. Sizes
     are rem, so browser font settings and zoom apply. Nothing readable is set
     below --type-caption (12px at the default size). */
  --type-display-l: clamp(2rem, 1.2rem + 3vw, 3.25rem);
  --type-display-m: 1.625rem;
  --type-title: 1.1875rem;
  --type-message: 1rem;
  --type-body: 0.9375rem;
  --type-label: 0.8125rem;
  --type-caption: 0.75rem;
  --leading-display: 1.1;
  --leading-text: 1.45;
  --leading-tight: 1.3;
  /* Titles sit a little looser than the installation name (Display L keeps --display-tracking). */
  --title-tracking: -0.015em;

  /* Shape. Rooms stay 33% squircles and people circles: identity shapes, not tokens. */
  --radius-1: 0.5rem;        /* chips, menu items, code */
  --radius-2: 0.75rem;       /* icon buttons, small tiles */
  --radius-field: 1rem;      /* fields, list rows, cards, popovers */
  --radius-bubble: 1.25rem;  /* bubbles */
  --radius-sheet: 1.75rem;   /* sheets, dialogs, the stage */
  --radius-pill: 999px;      /* buttons, badges, the composer, segmented controls */

  /* Space: a 4px scale. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-7: 2rem;
  --space-8: 3rem;

  /* Targets: 44px, 48px for coarse pointers (below). */
  --target-min: 2.75rem;

  /* Motion. Only transform and opacity move, and nothing loops. Under
     prefers-reduced-motion the three durations are cut to nothing below, in
     this file, because every page loads it (accessibility.css, which also
     cuts every animation and transition, isn't loaded by all of them). */
  --motion-fast: 120ms;   /* hover, press, toggles, menus */
  --motion-base: 200ms;   /* dialogs, toasts, the segmented thumb */
  --motion-slow: 280ms;   /* sheets, panes */
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  /* Derived colour roles: no new hues, each from the scheme's own values.
     Dark is the base and the light values follow. Their pairs are checked in
     tests/js/design-contrast.test.js. */
  --signature-wash: color-mix(in srgb, var(--signature) 18%, var(--surface)); /* the current tab's pill */
  --stage: var(--surface);     /* the conversation's own background (Midnight: below) */
  --selected: var(--raised);   /* the selected list row */
  --field: var(--ground);      /* field fill */
  --toast: var(--raised);
  --on-toast: var(--text);

  /* Elevation, dark: tone and a fine edge carry depth; shadow only under floating layers. */
  --line-soft: color-mix(in srgb, var(--line) 70%, var(--ground));
  --elev-1: 0 0 0 1px var(--line-soft);                             /* resting: the stage, a selected row */
  --elev-2: 0 0 0 1px var(--line), 0 14px 34px rgb(0 0 0 / 0.5);    /* floating: menus, pickers, toasts */
  --elev-3: 0 0 0 1px var(--line), 0 32px 72px rgb(0 0 0 / 0.65);   /* in front: dialogs, sheets */
}
:root[data-theme="light"] {
  --selected: var(--surface);
  --field: var(--surface);
  --toast: var(--text);
  --on-toast: var(--ground);
  --elev-1: 0 1px 2px rgb(60 40 20 / 0.07), 0 0 0 1px rgb(60 40 20 / 0.05);
  --elev-2: 0 2px 6px rgb(60 40 20 / 0.07), 0 14px 34px -8px rgb(60 40 20 / 0.2);
  --elev-3: 0 8px 20px rgb(20 17 28 / 0.1), 0 32px 72px -16px rgb(20 17 28 / 0.34);
}
/* Midnight keeps its large areas true black (CCM's AMOLED rule), the conversation included. */
:root[data-scheme="midnight"]:not([data-theme="light"]) { --stage: var(--ground); }
/* High contrast and Midnight: edges, never shadows. */
:root[data-scheme="contrast"],
:root[data-scheme="midnight"]:not([data-theme="light"]) {
  --elev-1: 0 0 0 1px var(--line);
  --elev-2: 0 0 0 1px var(--field-line);
  --elev-3: 0 0 0 1px var(--field-line);
}
@media (any-pointer: coarse) {
  :root { --target-min: 3rem; }
}
/* Reduced motion: whatever is timed with these tokens becomes an instant cut, on every
   page (tests/js/motion-tokens.test.js). 0.01ms, not 0, so transitionend still fires. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-fast: 0.01ms;
    --motion-base: 0.01ms;
    --motion-slow: 0.01ms;
  }
  /* And whatever is timed with a literal instead (older rules), on every page too (Lantern
     Next L9): accessibility.css says the same, but the stewardship and status pages don't
     load it. Page-to-page view transitions are cut the same way, should a page use them. */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation-duration: 0.01ms !important;
  }
}

/* Scheme picker swatches: each shows its scheme's action colour on its dark ground. */
.scheme-swatch[data-swatch="lantern"] { background: linear-gradient(135deg, #F06A3B 50%, #14111C 50%); }
.scheme-swatch[data-swatch="lounge"] { background: linear-gradient(135deg, #A8DBC5 50%, #111E22 50%); }
.scheme-swatch[data-swatch="dusk"] { background: linear-gradient(135deg, #A9B4FF 50%, #141729 50%); }
.scheme-swatch[data-swatch="ember"] { background: linear-gradient(135deg, #F0A868 50%, #1D1612 50%); }
.scheme-swatch[data-swatch="rose"] { background: linear-gradient(135deg, #F0A6C4 50%, #1D1419 50%); }
.scheme-swatch[data-swatch="midnight"] { background: linear-gradient(135deg, #F06A3B 50%, #000000 50%); }
.scheme-swatch[data-swatch="contrast"] { background: linear-gradient(135deg, #FFD60A 50%, #000000 50%); }

/* Installation icon (#211): the two fixed background choices (Lantern Night
   and Paper) and stand-ins for light and dark browser tabs, the same in every
   scheme and theme because they show other software's colours. */
.icon-swatch-chip[data-swatch="night"] { background: #14111C; }
.icon-swatch-chip[data-swatch="paper"] { background: #FBF7F1; }
.icon-tab-light { background: #F1ECE4; color: #1D1A24; }
.icon-tab-dark { background: #24202E; color: #F3EFE8; }
/* Page to page (Lantern Next L10): going from one page to another is a short cross-fade of
   the whole page instead of a hard cut, in browsers that can do it between documents; the
   others cut as before. The rail has a name of its own (shell.css), so it holds still while
   the page changes behind it. Only where motion is welcome: with reduced motion there is no
   transition at all, and the cut above would end one at once in any case. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 150ms; }
}

/* Authenticator setup (#204): a QR code scans reliably only as dark modules
   on a light ground with a quiet zone, so it keeps black on white in every
   scheme and theme. */
.totp-qr { background: #FFFFFF; }
.totp-qr path { fill: #000000; }
