/* ═══════════════════════════════════════════════════════════════
   FMISIEL — дизайн-токены
   Уровни: primitive → semantic → component. Компоненты используют
   только semantic/component-токены. Документация: docs/design-system.md
   ═══════════════════════════════════════════════════════════════ */

/* ── 0. ШРИФТЫ ───────────────────────────────────────────────────
   Bebas Neue Cyrillic (Dharma Type / Ryoichi Tsunekawa), SIL OFL 1.1.
   Одно начертание 400, только прописные. Файл — подмножество
   (латиница, кириллица, пунктуация) в WOFF2. */
@font-face {
  font-family: 'Bebas Neue Cyrillic';
  src: url('/fonts/bebas-neue-cyrillic.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ── 1. PRIMITIVE ─────────────────────────────────────────────── */
:root {
  /* Нейтральные */
  --neutral-0: #ffffff;
  --neutral-50: #fafafa;
  --neutral-100: #f2f2f2;
  --neutral-200: #e5e5e5;
  --neutral-300: #d4d4d4;
  --neutral-400: #a3a3a3;
  --neutral-500: #8f8f8f;
  --neutral-600: #6b6b6b;
  --neutral-700: #5c5c5c;
  --neutral-800: #262626;
  --neutral-900: #141414;
  --neutral-950: #0a0a0a;
  --neutral-dark-950: #121015;
  --neutral-dark-900: #1b1820;
  --neutral-dark-800: #24212a;
  --neutral-dark-700: #3a3640;
  --neutral-dark-100: #ececec;

  /* Акцент — Pantone 2635 C ≈ #C5B4E3 (ступень 300). Остальные ступени выведены
     от него по светлоте (assumption, см. design-system.md) */
  --lavender-50: #f7f4fc;
  --lavender-100: #efe9f8;
  --lavender-200: #ddd2f0;
  --lavender-300: #c5b4e3;
  --lavender-400: #a991d3;
  --lavender-500: #8d6fc1;
  --lavender-600: #7255a8;
  --lavender-700: #5b4389;
  --lavender-800: #44336a;
  --lavender-900: #2d2247;

  --red-700: #b3261e;
  --red-200: #f2b8b5;
  --green-700: #2e7d32;
  --green-200: #81c995;

  /* Типографика */
  /* Узкий акцидентный: заголовки, меню, кнопки, метки. Oswald — близкий по ширине запасной */
  --font-family-display: 'Bebas Neue Cyrillic', 'Oswald', 'Arial Narrow', sans-serif;
  /* Системный — только поля ввода и служебный текст редакции */
  --font-family-ui: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-family-serif: 'PT Serif', Georgia, 'Times New Roman', serif;
  --font-family-mono: 'Roboto Mono', 'Courier New', monospace;

  --font-size-xs: 0.75rem;   /* 12 — минимум для текста */
  --font-size-sm: 0.875rem;  /* 14 */
  --font-size-md: 1rem;      /* 16 */
  --font-size-lg: 1.125rem;  /* 18 — основной текст статьи */
  --font-size-xl: 1.375rem;  /* 22 */
  --font-size-2xl: 1.75rem;  /* 28 */
  --font-size-3xl: 2.25rem;  /* 36 */
  --font-size-4xl: clamp(2rem, 5vw, 3.25rem); /* 32–52 */
  /* Дисплейная шкала для узкого Bebas Neue: на вид он заметно мельче обычного гротеска */
  --display-xs: 1.25rem;   /* 20 — метки, кнопки, меню, даты */
  --display-sm: 1.875rem;  /* 30 — h3, подзаголовки */
  --display-md: 2.25rem;   /* 36 — заголовки карточек, h2 */
  --display-lg: 3.5rem;    /* 56 — заголовок раздела */
  --display-xl: clamp(2.5rem, 6vw, 4.5rem); /* 40–72 — заголовок статьи */
  --font-size-label: var(--display-xs);

  --font-weight-light: 300;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --font-weight-thin: 200;

  --line-height-tight: 1.15;
  --line-height-snug: 1.35;
  --line-height-normal: 1.6;
  --line-height-relaxed: 1.8;

  --letter-spacing-tight: 0.01em;
  --letter-spacing-normal: 0.03em;
  --letter-spacing-wide: 0.05em;

  /* Отступы — сетка 4px */
  --space-0: 0;
  --space-1: 0.25rem;  /* 4 */
  --space-2: 0.5rem;   /* 8 */
  --space-3: 0.75rem;  /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.25rem;  /* 20 */
  --space-6: 1.5rem;   /* 24 */
  --space-8: 2rem;     /* 32 */
  --space-10: 2.5rem;  /* 40 */
  --space-12: 3rem;    /* 48 */
  --space-16: 4rem;    /* 64 */
  --space-20: 5rem;    /* 80 */
  --space-24: 6rem;    /* 96 */

  /* Радиусы — айдентика строгая, почти без скруглений */
  --radius-none: 0;
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Границы */
  --border-width-thin: 1px;
  --border-width-thick: 2px;

  /* Breakpoints — справочно: CSS-переменные нельзя использовать в @media,
     в коде те же значения записаны числами */
  --bp-sm: 400px;
  --bp-md: 700px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;
  --bp-2xl: 1440px;

  /* Слои */
  --z-base: 0;
  --z-dropdown: 50;
  --z-sticky: 100;
  --z-modal: 900;
  --z-toast: 950;
  --z-tooltip: 1000;

  /* Движение */
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-emphasized: cubic-bezier(0.3, 0, 0, 1.2);
  --ease-decelerate: cubic-bezier(0, 0, 0, 1);

  /* Размеры */
  --size-touch: 44px;
  --size-control-sm: 32px;
  --size-control-md: 40px;
  --container-max: 860px;
}

/* ── 2. SEMANTIC — светлая тема (по умолчанию) ───────────────── */
:root,
[data-theme="light"] {
  color-scheme: light;
  --color-bg-default: var(--neutral-50);
  --color-bg-inverse: var(--neutral-950);
  --color-bg-overlay: rgb(10 10 10 / 0.92);
  --color-surface-default: var(--neutral-0);
  --color-surface-muted: var(--neutral-100);
  --color-surface-subtle: var(--neutral-200);
  --color-surface-accent: var(--lavender-100);
  --color-surface-header: rgb(250 250 250 / 0.92);

  --color-border-default: var(--neutral-950);
  --color-border-muted: var(--neutral-300);

  --color-text-default: var(--neutral-950);
  --color-text-muted: var(--neutral-700);    /* 6.4:1 */
  --color-text-subtle: var(--neutral-600);   /* 5.1:1 */
  --color-text-inverse: var(--neutral-50);
  --color-text-accent: var(--lavender-700);  /* 7.7:1 */

  --color-accent-brand: var(--lavender-300);
  --color-accent-strong: var(--lavender-600);
  --color-focus-ring: var(--lavender-600);   /* 5.6:1 к фону */
  --color-selection: var(--lavender-200);

  --color-danger: var(--red-700);
  --color-success: var(--green-700);

  --shadow-xs: 0 1px 2px rgb(10 10 10 / 0.06);
  --shadow-sm: 0 2px 6px rgb(10 10 10 / 0.08);
  --shadow-md: 0 6px 16px rgb(10 10 10 / 0.10);
  --shadow-lg: 0 12px 32px rgb(10 10 10 / 0.14);
  --shadow-xl: 0 24px 60px rgb(10 10 10 / 0.30);
}

/* ── 2b. SEMANTIC — тёмная тема ──────────────────────────────── */
[data-theme="dark"] {
  color-scheme: dark;
  --color-bg-default: var(--neutral-dark-950);
  --color-bg-inverse: var(--neutral-dark-100);
  --color-bg-overlay: rgb(5 4 8 / 0.94);
  --color-surface-default: var(--neutral-dark-900);
  --color-surface-muted: var(--neutral-dark-800);
  --color-surface-subtle: var(--neutral-dark-700);
  --color-surface-accent: var(--lavender-900);
  --color-surface-header: rgb(18 16 21 / 0.9);

  --color-border-default: var(--neutral-dark-100);
  --color-border-muted: var(--neutral-dark-700);

  --color-text-default: var(--neutral-dark-100);
  --color-text-muted: var(--neutral-400);    /* 7.5:1 */
  --color-text-subtle: var(--neutral-500);   /* 5.9:1 */
  --color-text-inverse: var(--neutral-dark-950);
  --color-text-accent: var(--lavender-300);  /* 9.9:1 */

  --color-accent-brand: var(--lavender-300);
  --color-accent-strong: var(--lavender-400);
  --color-focus-ring: var(--lavender-400);
  --color-selection: var(--lavender-800);

  --color-danger: var(--red-200);
  --color-success: var(--green-200);

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-sm: 0 2px 6px rgb(0 0 0 / 0.45);
  --shadow-md: 0 6px 16px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.55);
  --shadow-xl: 0 24px 60px rgb(0 0 0 / 0.7);
}

/* ── 3. COMPONENT ─────────────────────────────────────────────── */
:root {
  --btn-height-sm: var(--size-control-sm);
  --btn-height-md: var(--size-control-md);
  --btn-padding-x-sm: var(--space-3);
  --btn-padding-x-md: var(--space-4);
  --btn-font-size: var(--font-size-label);
  --btn-letter-spacing: var(--letter-spacing-wide);
  --btn-border: var(--border-width-thin) solid var(--color-border-default);
  --btn-radius: var(--radius-none);

  --input-height: var(--size-control-md);
  --input-padding-x: var(--space-3);
  --input-border: var(--border-width-thin) solid var(--color-border-default);
  --input-radius: var(--radius-none);

  --card-padding-y: var(--space-8);
  --card-gap: var(--space-8);
  --card-media-ratio: 4 / 3;

  --focus-ring: var(--border-width-thick) solid var(--color-focus-ring);
  --focus-offset: 2px;

  --heading-font: var(--font-family-display);
  --heading-weight: var(--font-weight-regular); /* у Bebas одно начертание — без синтетического жирного */
  --body-font: var(--font-family-serif);
  --label-font: var(--font-family-display);
  --label-weight: var(--font-weight-regular);
  --ui-font: var(--font-family-ui);
}

/* Глобальные правила, общие для сайта и редакции */
::selection { background: var(--color-selection); color: var(--color-text-default); }

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Шрифты для выделенного текста (редактор) ── */
.ff-bebas { font-family: 'Bebas Neue Cyrillic', 'Oswald', sans-serif; }
.ff-helvetica { font-family: 'Helvetica Neue', Arial, sans-serif; }
.ff-montserrat { font-family: 'Montserrat', sans-serif; }
.ff-oswald { font-family: 'Oswald', sans-serif; }
.ff-unbounded { font-family: 'Unbounded', sans-serif; }
.ff-playfair { font-family: 'Playfair Display', serif; }
.ff-cormorant { font-family: 'Cormorant Garamond', serif; }
.ff-ptserif { font-family: 'PT Serif', serif; }
.ff-mono { font-family: 'Roboto Mono', monospace; }
.ff-caveat { font-family: 'Caveat', cursive; }
.ff-base { font-family: var(--body-font); }
h1 .ff-base, h2 .ff-base, h3 .ff-base, h4 .ff-base { font-family: var(--heading-font); }
