/* Cryptosystems Meet design tokens.
   Three themes, Day, Night and Matrix, selected by [data-theme] on
   <html> (theme-boot.js: saved choice, else prefers-color-scheme, which
   only ever picks Day or Night; Matrix is an explicit choice).
   RULE: theme blocks below hold colour / shadow custom properties ONLY
   and all three define the exact same keys (qa/test-ui-foundation.py). Anything that
   affects size or position lives in the theme-independent :root block,
   so switching theme can never move a pixel of layout.
   Palette is the Cryptosystems brand (branding/brand.css --cs-*):
   ink #f8f5fa / #000, page #08060c / #f5f5f5, plum surfaces, lavender
   muted #a89ab8, brand danger. Calm, low-chroma, Tesla-like. */

/* Self-hosted fonts (no third-party request). Files in fonts/ come from
   the official Google Fonts distribution (Plus Jakarta Sans v12, Fragment Mono
   v6), latin + latin-ext subsets only; other scripts fall back to the
   system stack via unicode-range. Licence: SIL OFL 1.1, see
   fonts/OFL-PlusJakartaSans.txt and fonts/OFL-FragmentMono.txt.
   Plus Jakarta Sans is one variable file per subset covering the weights
   the UI uses (400, 500, 600). */
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/plus-jakarta-sans-latin-wght.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/plus-jakarta-sans-latin-ext-wght.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Fragment Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/fragment-mono-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fragment Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/fragment-mono-latin-ext-400.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}


/* ---------- Theme-independent ---------- */
:root {
  /* Type */
  --font-sans: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Fragment Mono", ui-monospace, monospace;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 22px;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --tracking-tight: -0.01em;
  --tracking-caps: 0.06em;

  /* Space (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Shape */
  --radius-card: 20px;
  --radius-field: 12px;
  --radius-pill: 999px;
  --radius-chip: 10px;

  /* Controls */
  --size-control: 40px;
  --size-control-lg: 48px;
  --size-icon: 18px;
  --meter-height: 6px;

  /* Focus / press / disabled (shared button state system) */
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  --press-ring-width: 2px;
  --press-scale: 0.97;
  --opacity-disabled: 0.45;

  /* Motion: calm. Zeroed for prefers-reduced-motion below. */
  --motion-fast: 120ms;
  --motion-base: 200ms;
  --motion-slow: 320ms;
  --ease-standard: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-fast: 0.01ms;
    --motion-base: 0.01ms;
    --motion-slow: 0.01ms;
    --press-scale: 1;
  }
}

/* ---------- Night (default) ---------- */
:root,
[data-theme="night"] {
  --color-bg: #08060c;
  --color-bg-wash: #100b18;
  --color-surface: #16101e;
  --color-surface-raised: #1e1728;
  --color-surface-sunken: #0f0b15;
  --color-surface-glass: rgba(22, 16, 30, 0.92);
  --color-dock: rgba(22, 16, 30, 0.72);
  --color-fg: #f8f5fa;
  --color-fg-muted: #a89ab8;
  --color-fg-faint: rgba(248, 245, 250, 0.56);
  --color-border: rgba(248, 245, 250, 0.10);
  --color-border-strong: rgba(248, 245, 250, 0.18);
  --color-accent: #c4b6d4;
  --color-accent-fg: #08060c;
  --color-accent-soft: rgba(196, 182, 212, 0.16);
  --color-accent-glow: rgba(196, 182, 212, 0.55);
  --color-danger: #ea4335;
  --color-danger-strong: #8a2a2a;
  --color-danger-fg: #ffffff;
  --color-danger-soft: rgba(234, 67, 53, 0.16);
  --color-danger-text: #ff8a80;
  --color-success: #7fd1a8;
  --color-meter-track: rgba(248, 245, 250, 0.10);
  --color-meter-fill: #c4b6d4;
  --color-meter-peak: #7fd1a8;
  --color-focus-ring: #c4b6d4;
  --color-scrim: rgba(8, 6, 12, 0.46);
  --color-preview-bg: #121018;
  --color-preview-fg: rgba(248, 245, 250, 0.72);
  --color-preview-chip: rgba(8, 6, 12, 0.66);
  --color-avatar-bg: #2a2236;
  --color-avatar-fg: #f8f5fa;
  --color-tile: #1e1728;
  --color-tile-on: #2a2236;
  --color-dock-tile: rgba(255, 255, 255, 0.04);

  /* Button variants (consumed by buttons.css) */
  --btn-neutral-bg: #1e1728;
  --btn-neutral-fg: #f8f5fa;
  --btn-neutral-hover: #261e31;
  --btn-neutral-press: #31283e;
  --btn-selected-bg: #2a2236;
  --btn-selected-hover: #32293f;
  --btn-off-bg: rgba(234, 67, 53, 0.16);
  --btn-off-fg: #ff8a80;
  --btn-off-hover: rgba(234, 67, 53, 0.24);
  --btn-off-press: rgba(234, 67, 53, 0.32);
  --btn-primary-bg: #e9e3ef;
  --btn-primary-fg: #08060c;
  --btn-primary-hover: #f8f5fa;
  --btn-primary-press: #d6cce0;
  --btn-danger-bg: #8a2a2a;
  --btn-danger-fg: #ffffff;
  --btn-danger-hover: #9c3232;
  --btn-danger-press: #ae3a3a;
  --btn-ghost-bg: transparent;
  --btn-ghost-fg: #a89ab8;
  --btn-ghost-hover: rgba(248, 245, 250, 0.06);
  --btn-ghost-press: rgba(248, 245, 250, 0.12);
  --btn-press-ring: rgba(196, 182, 212, 0.55);

  --shadow-card: 0 0 0 1px rgba(248, 245, 250, 0.08), 0 18px 40px rgba(0, 0, 0, 0.35);
  --shadow-raised: 0 0 0 1px rgba(248, 245, 250, 0.06), 0 8px 24px rgba(0, 0, 0, 0.30);
  --glass: url(#lg-dark) saturate(1.2) blur(18px);
  --icon-chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%23a89ab8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/></svg>");
  --scheme: dark;
}

/* ---------- Day ---------- */
[data-theme="day"] {
  --color-bg: #f5f5f5;
  --color-bg-wash: #ffffff;
  --color-surface: #ffffff;
  --color-surface-raised: #f5f5f5;
  --color-surface-sunken: #ececec;
  --color-surface-glass: rgba(255, 255, 255, 0.92);
  --color-dock: rgba(255, 255, 255, 0.55);
  --color-fg: #000000;
  --color-fg-muted: rgba(0, 0, 0, 0.55);
  --color-fg-faint: rgba(0, 0, 0, 0.40);
  --color-border: rgba(0, 0, 0, 0.08);
  --color-border-strong: rgba(0, 0, 0, 0.14);
  --color-accent: #3a2438;
  --color-accent-fg: #ffffff;
  --color-accent-soft: rgba(58, 36, 56, 0.10);
  --color-accent-glow: rgba(58, 36, 56, 0.38);
  --color-danger: #ea4335;
  --color-danger-strong: #8a2a2a;
  --color-danger-fg: #ffffff;
  --color-danger-soft: rgba(234, 67, 53, 0.10);
  --color-danger-text: #b3261e;
  --color-success: #1e7a4f;
  --color-meter-track: rgba(0, 0, 0, 0.08);
  --color-meter-fill: #3a2438;
  --color-meter-peak: #1e7a4f;
  --color-focus-ring: #3a2438;
  --color-scrim: rgba(0, 0, 0, 0.28);
  --color-preview-bg: #1a1820;
  --color-preview-fg: rgba(255, 255, 255, 0.78);
  --color-preview-chip: rgba(12, 12, 12, 0.62);
  --color-avatar-bg: #2a2a2a;
  --color-avatar-fg: #f5f5f5;
  --color-tile: #f5f5f5;
  --color-tile-on: #ececec;
  --color-dock-tile: transparent;

  --btn-neutral-bg: #f2f2f2;
  --btn-neutral-fg: #000000;
  --btn-neutral-hover: #e9e9e9;
  --btn-neutral-press: #dedede;
  --btn-selected-bg: #e6e6e6;
  --btn-selected-hover: #dcdcdc;
  --btn-off-bg: rgba(234, 67, 53, 0.10);
  --btn-off-fg: #b3261e;
  --btn-off-hover: rgba(234, 67, 53, 0.16);
  --btn-off-press: rgba(234, 67, 53, 0.24);
  --btn-primary-bg: #111111;
  --btn-primary-fg: #ffffff;
  --btn-primary-hover: #262626;
  --btn-primary-press: #3a3a3a;
  --btn-danger-bg: #8a2a2a;
  --btn-danger-fg: #ffffff;
  --btn-danger-hover: #9c3232;
  --btn-danger-press: #ae3a3a;
  --btn-ghost-bg: transparent;
  --btn-ghost-fg: rgba(0, 0, 0, 0.55);
  --btn-ghost-hover: rgba(0, 0, 0, 0.05);
  --btn-ghost-press: rgba(0, 0, 0, 0.10);
  --btn-press-ring: rgba(58, 36, 56, 0.45);

  --shadow-card:
    0 0.71px 0.71px -0.54px rgba(0, 0, 0, 0.10),
    0 1.81px 1.81px -1.08px rgba(0, 0, 0, 0.09),
    0 3.62px 3.62px -1.63px rgba(0, 0, 0, 0.09),
    0 6.87px 6.87px -2.17px rgba(0, 0, 0, 0.09),
    0 13.65px 13.65px -2.71px rgba(0, 0, 0, 0.08),
    0 30px 30px -3.25px rgba(0, 0, 0, 0.05),
    inset 0 3px 1px #fff;
  --shadow-raised: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.08);
  --glass: url(#lg-day) saturate(1.35) blur(16px);
  --icon-chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='rgba(0,0,0,0.45)' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/></svg>");
  --scheme: light;
}

/* ---------- Matrix ----------
   Phosphor green on black, same keys as Day / Night. Colour and shadow
   only: radius, type, spacing and motion stay shared, so Matrix never
   moves layout (the old html.matrix overrides with 2px radii are gone).
   Contrast on #000: fg 17:1, muted 10:1, focus ring 15:1, primary
   button label #000 on #00c850 10:1. */
[data-theme="matrix"] {
  --color-bg: #000000;
  --color-bg-wash: #020a05;
  --color-surface: #04100a;
  --color-surface-raised: #08180e;
  --color-surface-sunken: #020804;
  --color-surface-glass: rgba(4, 16, 10, 0.94);
  --color-dock: rgba(2, 10, 5, 0.86);
  --color-fg: #b6ffd0;
  --color-fg-muted: #4fd88a;
  --color-fg-faint: rgba(182, 255, 208, 0.52);
  --color-border: rgba(0, 255, 102, 0.16);
  --color-border-strong: rgba(0, 255, 102, 0.30);
  --color-accent: #00ff66;
  --color-accent-fg: #000000;
  --color-accent-soft: rgba(0, 255, 102, 0.12);
  --color-accent-glow: rgba(0, 255, 102, 0.55);
  --color-danger: #ff4d4d;
  --color-danger-strong: #8a2a2a;
  --color-danger-fg: #ffffff;
  --color-danger-soft: rgba(255, 77, 77, 0.16);
  --color-danger-text: #ff8a80;
  --color-success: #00ff66;
  --color-meter-track: rgba(0, 255, 102, 0.12);
  --color-meter-fill: #00c850;
  --color-meter-peak: #b6ffd0;
  --color-focus-ring: #00ff66;
  --color-scrim: rgba(0, 0, 0, 0.62);
  --color-preview-bg: #000c05;
  --color-preview-fg: rgba(182, 255, 208, 0.78);
  --color-preview-chip: rgba(0, 0, 0, 0.74);
  --color-avatar-bg: #002b12;
  --color-avatar-fg: #00ff66;
  --color-tile: #07140b;
  --color-tile-on: #0c2414;
  --color-dock-tile: rgba(0, 255, 102, 0.05);

  --btn-neutral-bg: #08180e;
  --btn-neutral-fg: #b6ffd0;
  --btn-neutral-hover: #0d2215;
  --btn-neutral-press: #133020;
  --btn-selected-bg: #0f3a1f;
  --btn-selected-hover: #144626;
  --btn-off-bg: rgba(255, 77, 77, 0.16);
  --btn-off-fg: #ff8a80;
  --btn-off-hover: rgba(255, 77, 77, 0.24);
  --btn-off-press: rgba(255, 77, 77, 0.32);
  --btn-primary-bg: #00c850;
  --btn-primary-fg: #000000;
  --btn-primary-hover: #00e05a;
  --btn-primary-press: #00a843;
  --btn-danger-bg: #8a2a2a;
  --btn-danger-fg: #ffffff;
  --btn-danger-hover: #9c3232;
  --btn-danger-press: #ae3a3a;
  --btn-ghost-bg: transparent;
  --btn-ghost-fg: #4fd88a;
  --btn-ghost-hover: rgba(0, 255, 102, 0.07);
  --btn-ghost-press: rgba(0, 255, 102, 0.14);
  --btn-press-ring: rgba(0, 255, 102, 0.60);

  --shadow-card: 0 0 0 1px rgba(0, 255, 102, 0.22), 0 18px 40px rgba(0, 0, 0, 0.6);
  --shadow-raised: 0 0 0 1px rgba(0, 255, 102, 0.18), 0 8px 24px rgba(0, 0, 0, 0.5);
  --glass: none;
  --icon-chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%2300c850' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/></svg>");
  --scheme: dark;
}
