@layer reset, tokens, base, components, surfaces, utilities;

/* ==========================================================================
   Nova Link design tokens ("ember" dark theme)
   --------------------------------------------------------------------------
   One global namespace: --nv-*. Every surface (landing, dashboard, dialogs,
   admin, legal) reads these. Never add per-surface palettes; add a token here.

   Layer order (declared above, must stay the first statement of the first
   stylesheet): reset < tokens < base < components < surfaces < utilities.
   Surfaces win over components without !important; utilities ([hidden],
   .sr-only, reduced motion) win over everything.

   r181 (unslop): a dark room at night lit by a screen and one warm ember.
   The chrome is quiet: one warm near-black ramp, hairlines at 6-10%, depth
   from surface steps (no black card shadows, no inner highlights), solid
   bars (no glass), one accent (#ff7a1a, dark text on it) and one accent ink.
   Rich colour lives only in the moments: live profile renders, badge medals,
   the editor preview, the main chart and the world map.
   Retired effects keep their names so nothing breaks, but resolve to quiet
   values: --nv-grad-* are solid, --nv-glow* and --nv-shadow-1 draw nothing,
   --nv-ember is none, --nv-ease-spring is the one easing curve, the heavy
   weights are 500, eyebrow tracking is 0, --nv-r-pill is the control radius.

   Contrast (WCAG 2.x, measured on --nv-surface-1 #1b1a18):
     text 14.4:1 · text-2 7.7:1 · text-3 6.1:1 (4.6:1 on surface-3)
     accent 6.7:1 · accent-text 8.3:1 · on-accent on accent 7.3:1

   JS-owned CSS variables (public API, keep names verbatim, never define
   them here):
     --nb-size --nb-light --nb-deep --nb-glow --nb-i   .nb-medal (badge-icons-runtime.js)
     --badge-a --badge-b --badge-glow                  admin badge builder (admin-badges.js)
     --preset-bg --preset-accent                       editor theme presets (studio.js)
     --tag-color + previewStyle() string               discover cards (discover.js)
     --heat                                            country map rows (app.js)
     --rx --ry                                         landing card tilt (app.js initMotion)
     --c                                               colour swatches (app.js)
   The public profile (profile-frame.html) has its own --accent/--text/--bg
   namespace and does not load these files.
   ========================================================================== */

@layer tokens {
  :root {
    color-scheme: dark;

    /* ---- Canvas & surfaces (warm near-black, lightest last) ------------- */
    /* Depth is these steps plus a hairline: a card is one step above the canvas, a row or field
       inside it one step above the card. No black shadows under cards, no inner top highlights. */
    --nv-bg: #0a0a09;            /* page canvas, <body>, theme-color */
    --nv-bg-deep: #070706;       /* below the canvas: sidebars, wells, code */
    --nv-surface-1: #1b1a18;     /* cards, panels, dialogs, menus */
    --nv-surface-2: #262422;     /* raised inside a card: inputs, rows, tiles, chips, active rows */
    --nv-surface-3: #312f2c;     /* hover / pressed of surface-2, selected rows */
    --nv-surface-4: #3c3936;     /* hover of surface-3, tooltips, kbd */
    --nv-glass: var(--nv-bg);    /* r181: bars are solid (the canvas + a hairline); the name stays for old rules */
    --nv-scrim: rgba(5, 4, 3, .72);      /* dialog / sheet backdrop (no blur) */

    /* ---- Lines: the primary text colour at 6-10% ------------------------ */
    --nv-line: rgb(239 233 227 / 8%);         /* default 1px border on any surface */
    --nv-line-strong: rgb(239 233 227 / 10%); /* inputs, buttons, hovered cards, dividers that must read */
    --nv-line-soft: rgb(239 233 227 / 6%);    /* row separators inside cards */
    --nv-highlight: transparent;              /* r181: retired inner top highlight (composes as nothing) */

    /* ---- Text: three roles ---------------------------------------------- */
    --nv-text: #efe9e3;          /* primary: headings, values, active labels */
    --nv-text-2: #b3aba2;        /* secondary: labels, descriptions, nav (>=5.8:1 up to surface-3) */
    --nv-text-3: #a0978d;        /* muted: meta, captions, placeholders, icons (>=4.6:1 up to surface-3) */
    --nv-text-disabled: #6b645d; /* disabled labels only (not for body copy) */
    --nv-text-inverse: #1a0e05;  /* text on light/amber fills */

    /* ---- Accent (Nova orange): the primary action, the selection, the one figure that matters */
    --nv-accent: #ff7a1a;        /* primary buttons (solid, dark text), focus of fields, the main chart line */
    --nv-accent-hover: #ff8d3c;  /* hover of accent fills */
    --nv-accent-press: #e8650a;  /* :active of accent fills */
    --nv-accent-text: #ff9a4d;   /* THE accent ink: accent-coloured text, links, Premium (8.3:1) */
    --nv-accent-soft: rgba(255, 122, 26, .1);    /* tinted fills: selected chip, soft button */
    --nv-accent-soft-2: rgba(255, 122, 26, .16); /* hover of soft fills */
    --nv-accent-line: rgba(255, 122, 26, .3);    /* borders of selected / accent-soft elements */
    --nv-on-accent: #1a0e05;     /* text & icons on accent fills (dark on orange, 7.3:1) */
    --nv-amber: #ffb27a;         /* data viz second tone only (second series, map highlight); never chrome ink */
    --nv-amber-soft: var(--nv-accent-soft);
    /* r181: retired gradients resolve to the solid accent / solid text (single-colour images, valid anywhere). */
    --nv-grad-accent: linear-gradient(var(--nv-accent), var(--nv-accent));
    --nv-grad-ember: linear-gradient(var(--nv-accent), var(--nv-accent));
    --nv-grad-text: linear-gradient(var(--nv-text), var(--nv-text)); /* background-clip:text now paints solid primary text */

    /* ---- Status: meaning only, toned to sit in the ramp ----------------- */
    --nv-success: #4cc38a;
    --nv-success-soft: rgba(76, 195, 138, .12);
    --nv-success-line: rgba(76, 195, 138, .3);
    --nv-warning: #e6ad4c;
    --nv-warning-soft: rgba(230, 173, 76, .12);
    --nv-warning-line: rgba(230, 173, 76, .3);
    --nv-danger: #ff6b61;        /* danger text/icons on dark (6.2:1) */
    --nv-danger-fill: #d93a30;   /* solid danger fill with white text (4.6:1) */
    --nv-danger-soft: rgba(255, 107, 97, .12);
    --nv-danger-line: rgba(255, 107, 97, .3);
    --nv-info: #7cb0e8;
    --nv-info-soft: rgba(124, 176, 232, .12);
    --nv-info-line: rgba(124, 176, 232, .3);
    --nv-premium: var(--nv-accent-text); /* r181: Premium speaks in the one accent ink, not a second yellow */

    /* ---- Field (inputs, selects, textareas) ---------------------------- */
    --nv-field: #0f0e0d;                /* input fill: a well, darker than the card it sits on */
    --nv-field-hover: #141311;
    --nv-field-line: rgb(239 233 227 / 10%);
    --nv-field-line-hover: rgb(239 233 227 / 16%);

    /* ---- Radius: by size, nothing is a pill ---------------------------- */
    --nv-r-xs: 6px;      /* keycaps, tags, chips, small badges */
    --nv-r-sm: 10px;     /* controls: buttons, inputs, selects, segmented wells, menu rows */
    --nv-r-control: var(--nv-r-sm);
    --nv-r-md: 12px;     /* list rows, cards inside cards, popovers, menus */
    --nv-r-lg: 16px;     /* cards, panels */
    --nv-r-xl: 20px;     /* dialogs, sheets, hero frames */
    --nv-r-pill: var(--nv-r-control); /* r181: old pill users (buttons, chips, fields) get the control radius */
    --nv-r-round: 999px; /* fully round ends: switch tracks, thin progress bars, scrollbars, dots */

    /* ---- Spacing (4px grid). Use for padding, gaps and margins. --------- */
    --nv-space-0: 0;
    --nv-space-1: 4px;
    --nv-space-2: 8px;
    --nv-space-3: 12px;
    --nv-space-4: 16px;
    --nv-space-5: 20px;
    --nv-space-6: 24px;
    --nv-space-7: 28px;
    --nv-space-8: 32px;
    --nv-space-10: 40px;
    --nv-space-12: 48px;
    --nv-space-14: 56px;
    --nv-space-16: 64px;
    --nv-space-20: 80px;
    --nv-space-24: 96px;
    --nv-space-section: clamp(72px, 10vw, 136px); /* vertical rhythm between landing sections */

    /* ---- Typography ---------------------------------------------------- */
    /* Onest for the interface. Two weights: 400 and 500. Hierarchy comes from size and colour, not weight.
       Sentence case everywhere.
       One rule for figures (r181): amounts people read as numbers (prices, totals, views and clicks, quotas
       in МБ/дней, KPI values, counts) use --nv-font-figure = Onest with tabular-nums, so «$3.99», «1 778»
       and «365 дней» keep their normal period, thousands space and units. JetBrains Mono is only for the
       address signature, IDs and codes, and small meta (times, dates, axis labels, ranks, «560 px» chips). */
    --nv-font-sans: "Onest", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --nv-font-display: var(--nv-font-sans);
    --nv-font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
    --nv-font-figure: var(--nv-font-sans);

    --nv-fs-11: 11px;   /* the five tab-bar labels and kbd only */
    --nv-fs-12: 12px;   /* meta, captions, table heads, section labels (the floor) */
    --nv-fs-13: 13px;   /* secondary UI, labels, small buttons */
    --nv-fs-14: 14px;   /* default UI text, buttons, inputs on desktop */
    --nv-fs-16: 16px;   /* body copy, inputs on touch (prevents iOS zoom) */
    --nv-fs-18: 18px;   /* lead text, card titles */
    --nv-fs-22: 22px;   /* h3, dialog titles */
    --nv-fs-28: 28px;   /* h2, page titles */
    --nv-fs-36: 36px;   /* h1 in app, section titles on landing */
    --nv-fs-48: 48px;   /* big numbers, landing h2 on desktop */
    --nv-fs-display: clamp(40px, 6.2vw, 80px); /* landing hero only */
    --nv-fs-eyebrow: 12px; /* r181: section labels are sentence case at the 12px floor */

    --nv-fw-regular: 400;
    --nv-fw-medium: 500;
    --nv-fw-semibold: 500;  /* r181: was 600 */
    --nv-fw-bold: 500;      /* r181: was 700 */
    --nv-fw-heavy: 500;     /* r181: was 800 */
    --nv-fw-strong: 600;    /* rare emphasis only: at most one figure or word per view */

    --nv-lh-tight: 1.1;   /* display, big numbers */
    --nv-lh-snug: 1.25;   /* headings */
    --nv-lh-ui: 1.4;      /* controls, labels */
    --nv-lh-body: 1.6;    /* paragraphs */

    --nv-tracking-tight: -.01em;   /* headings 22-36px; 0 below 16px */
    --nv-tracking-display: -.03em; /* display text from 56px */
    --nv-tracking-eyebrow: 0;      /* r181: no tracked uppercase labels */

    /* ---- Control sizes -------------------------------------------------- */
    --nv-h-sm: 32px;   /* compact buttons, chips, table actions */
    --nv-h-md: 40px;   /* default buttons and inputs */
    --nv-h-lg: 48px;   /* hero CTAs, touch-primary actions */
    --nv-hit: 44px;    /* minimum touch target on coarse pointers */
    --nv-h-nav: 36px;  /* r181: desktop navigation rows (sidebar, rail); touch keeps --nv-hit */

    /* ---- Elevation: surface steps first; shadows only for things that float */
    --nv-shadow-1: 0 0 #0000;                          /* cards: none (surface step + hairline) */
    --nv-shadow-2: 0 12px 32px -12px rgb(0 0 0 / 55%);  /* floating: popovers, menus, toasts */
    --nv-shadow-3: 0 24px 64px -24px rgb(0 0 0 / 65%);  /* dialogs, sheets, the drawer */

    /* ---- Glow: retired (r181). Names kept; they draw nothing. ----------- */
    --nv-glow-sm: 0 0 #0000;
    --nv-glow: 0 0 #0000;
    --nv-glow-lg: 0 0 #0000;
    --nv-ember: none;          /* was a radial orange wash behind heroes / headers */

    /* ---- Focus ring (two-tone: dark gap + light amber ring) ------------ */
    --nv-focus: #ffb27a;          /* outer ring colour: 11:1 on canvas */
    --nv-focus-gap: #0a0a09;      /* inner gap: separates the ring from orange fills */
    --nv-focus-ring: 0 0 0 2px var(--nv-focus-gap), 0 0 0 4px var(--nv-focus); /* box-shadow form for clipped contexts */
    --nv-field-ring: 0 0 0 3px rgba(255, 122, 26, .16); /* focused input halo (with accent border) */

    /* ---- Signature: an address is mono, the host dim, the name bright -- */
    /* nova-link.lol/name wherever an address is shown (claim field, overview hero, URL chip,
       share sheet, leaderboard rows) and nowhere else. Markup: .nv-address > .nv-address-host + .nv-address-name */
    --nv-address-font: var(--nv-font-mono);
    --nv-address-host: var(--nv-text-3);
    --nv-address-name: var(--nv-text);

    /* ---- Z-index scale -------------------------------------------------- */
    --nv-z-raised: 1;      /* overlapping siblings */
    --nv-z-sticky: 20;     /* sticky table heads, sticky toolbars */
    --nv-z-header: 30;     /* app top bar, landing nav */
    --nv-z-sidebar: 40;    /* off-canvas sidebar + its backdrop */
    --nv-z-dropdown: 50;   /* menus, popovers, selects */
    --nv-z-overlay: 60;    /* non-dialog overlays (public profile host) */
    --nv-z-toast: 80;      /* #toast (dialogs live in the top layer above all of this) */
    --nv-z-tooltip: 90;
    --nv-z-boot: 100;      /* #novaBootSplash */

    /* ---- Motion: one curve, a few durations ----------------------------- */
    /* Transition colour, background, border, opacity and transform only. No hover lift or scale;
       a press is scale(var(--nv-press-scale)). Never animate width, height, top, left or blurs. */
    --nv-dur-1: 120ms;   /* hover colour, press */
    --nv-dur-2: 180ms;   /* small movement: switch knob, chip, menus */
    --nv-dur-3: 260ms;   /* panels, popovers, toasts */
    --nv-dur-4: 420ms;   /* page / section reveals, sheets */
    --nv-ease: cubic-bezier(.22, 1, .36, 1);  /* the one easing curve */
    --nv-ease-out: var(--nv-ease);
    --nv-ease-in-out: var(--nv-ease);   /* r181: same curve */
    --nv-ease-spring: var(--nv-ease);   /* r181: retired overshoot */
    --nv-press-scale: .98;

    /* ---- Layout --------------------------------------------------------- */
    --nv-w-prose: 720px;     /* reading width (legal, FAQ) */
    --nv-w-narrow: 480px;    /* forms, auth */
    --nv-w-content: 1200px;  /* landing sections, app pages */
    --nv-w-wide: 1360px;     /* landing hero / showcase */
    --nv-gutter: max(clamp(16px, 4vw, 32px), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)); /* page side padding (16px on phones); r180: never inside a landscape notch (viewport-fit=cover) */
    --nv-sidebar-w: 256px;   /* dashboard sidebar */
    --nv-rail-w: 72px;       /* collapsed icon rail (901-1279px) */
    --nv-topbar-h: 56px;     /* app top bar */
    --nv-nav-h: 64px;        /* landing nav */
    --nv-bp-mobile: 640px;   /* reference only: media queries cannot read vars */
    --nv-bp-tablet: 900px;
    --nv-bp-desktop: 1280px;
  }

  /* ---- Phones (≤640px): a denser scale on the same 4px grid ------------
     One ramp, one accent and the same quiet effects everywhere (r181); phones only
     tighten spacing and the type scale, and keep thumb-sized controls. */
  @media (max-width: 640px) {
    :root {
      --nv-space-5: 16px;
      --nv-space-6: 20px;
      --nv-space-7: 24px;
      --nv-space-8: 24px;
      --nv-space-10: 32px;
      --nv-space-12: 36px;
      --nv-space-14: 40px;
      --nv-space-16: 48px;
      --nv-space-20: 56px;
      --nv-space-24: 64px;
      --nv-space-section: 56px;

      --nv-fs-18: 17px;
      --nv-fs-22: 20px;
      --nv-fs-28: 24px;
      --nv-fs-36: 28px;
      --nv-fs-48: 32px;
      --nv-fs-display: clamp(30px, 8.8vw, 36px);

      --nv-h-lg: 46px;
      --nv-h-sm: 36px;   /* r166 (G3): compact buttons stay thumb-sized */
      --nv-h-md: 44px;   /* r166 (G3): default buttons and inputs = the 44px touch target */

      --nv-gutter: max(16px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
      --nv-topbar-h: 52px;
      --nv-nav-h: 56px;
    }
  }

  /* r180: touch sizes follow the pointer, not the width, so landscape phones and tablets get the same
     thumb-sized controls as portrait phones (≤640px above). */
  @media (pointer: coarse) {
    :root {
      --nv-h-sm: 36px;
      --nv-h-md: 44px;
    }
  }
}
