/* ============================================================
   ЯДРЁНЫЧ — design system
   Fonts: Unbounded (display) + Onest (UI/body)
   ============================================================ */

@import url('fonts/fonts.css');

:root {
  /* brand */
  --brand:        oklch(0.56 0.165 252);
  --brand-press:  oklch(0.48 0.165 252);
  --brand-soft:   oklch(0.95 0.045 252);
  --brand-ring:   oklch(0.56 0.165 252 / 0.30);
  --cyan:         oklch(0.70 0.12 205);
  --cyan-soft:    oklch(0.95 0.045 205);
  --grad-brand:   linear-gradient(135deg, var(--brand), var(--cyan));
  --grad-bar:     linear-gradient(90deg, var(--brand), var(--cyan));

  /* ai models */
  --alisa:        oklch(0.62 0.205 25);
  --alisa-soft:   oklch(0.955 0.04 25);
  --giga:         oklch(0.60 0.135 162);
  --giga-soft:    oklch(0.955 0.04 162);

  /* light theme surfaces */
  --bg:           oklch(0.985 0.004 250);
  --surface:      oklch(1 0 0);
  --surface-2:    oklch(0.975 0.006 250);
  --surface-3:    oklch(0.955 0.009 250);
  --border:       oklch(0.915 0.009 250);
  --border-strong:oklch(0.86 0.012 250);
  --text:         oklch(0.24 0.022 255);
  --text-muted:   oklch(0.52 0.022 255);
  --text-faint:   oklch(0.66 0.016 255);

  --pos:          oklch(0.60 0.14 150);
  --warn:         oklch(0.70 0.15 70);

  /* radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-pill: 999px;

  /* shadow */
  --shadow-sm: 0 1px 2px oklch(0.4 0.03 255 / 0.06), 0 1px 3px oklch(0.4 0.03 255 / 0.05);
  --shadow-md: 0 4px 14px oklch(0.4 0.03 255 / 0.07), 0 2px 6px oklch(0.4 0.03 255 / 0.05);
  --shadow-lg: 0 18px 48px oklch(0.4 0.05 255 / 0.12), 0 6px 18px oklch(0.4 0.04 255 / 0.08);
  --shadow-brand: 0 10px 30px var(--brand-ring);

  --font-display: 'Unbounded', system-ui, sans-serif;
  --font-ui: 'Onest', system-ui, sans-serif;
}

[data-theme="dark"] {
  --brand:        oklch(0.70 0.15 255);
  --brand-press:  oklch(0.77 0.15 255);
  --brand-soft:   oklch(0.34 0.095 255);
  --brand-ring:   oklch(0.70 0.15 255 / 0.32);
  --cyan:         oklch(0.74 0.11 205);
  --cyan-soft:    oklch(0.34 0.075 205);

  --alisa:        oklch(0.70 0.185 25);
  --alisa-soft:   oklch(0.34 0.10 25);
  --giga:         oklch(0.70 0.13 162);
  --giga-soft:    oklch(0.32 0.07 162);

  --bg:           oklch(0.18 0.018 258);
  --surface:      oklch(0.222 0.022 258);
  --surface-2:    oklch(0.252 0.025 258);
  --surface-3:    oklch(0.29 0.028 258);
  --border:       oklch(0.33 0.028 258);
  --border-strong:oklch(0.41 0.03 258);
  --text:         oklch(0.96 0.008 255);
  --text-muted:   oklch(0.74 0.02 255);
  --text-faint:   oklch(0.58 0.02 255);

  --pos:          oklch(0.72 0.15 150);
  --warn:         oklch(0.78 0.15 70);

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.30);
  --shadow-md: 0 4px 16px oklch(0 0 0 / 0.36);
  --shadow-lg: 0 22px 54px oklch(0 0 0 / 0.50), 0 6px 18px oklch(0 0 0 / 0.40);
  --shadow-brand: 0 12px 34px oklch(0.70 0.15 255 / 0.30);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .35s ease, color .35s ease;
}

::selection { background: var(--brand-soft); color: var(--brand-press); }

/* scrollbar */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- typography helpers ---------- */
.display { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em; line-height: 1.04; }
.tnum { font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-faint);
}
.field-hint {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; flex: none;
  border: 1px solid var(--text-faint); border-radius: 50%;
  background: var(--surface); color: var(--text-faint); font-size: 11px; font-weight: 700;
  line-height: 1; letter-spacing: 0; text-transform: none;
  cursor: help; user-select: none;
}
.field-hint:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }
.field-hint-tooltip {
  position: fixed; z-index: 10000;
  width: min(320px, calc(100vw - 32px)); padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-md); font-size: 12px; font-weight: 400;
  line-height: 1.4; letter-spacing: normal; text-transform: none;
  white-space: normal; text-align: left;
  pointer-events: none;
}
.region-picker { position: relative; }
.region-options {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  max-height: 260px; overflow-y: auto; padding: 4px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); box-shadow: var(--shadow-md);
}
.region-option {
  display: block; width: 100%; padding: 8px 9px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; font-size: 12.5px;
  line-height: 1.3; text-align: left; cursor: pointer;
}
.region-option:hover, .region-option[aria-selected="true"] { background: var(--surface-2); }
.region-options-empty { padding: 8px 9px; color: var(--text-faint); font-size: 12px; }
.region-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.minus-picker { position: relative; }
.minus-options {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  max-height: 260px; overflow-y: auto; padding: 4px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); box-shadow: var(--shadow-md);
}
.minus-option {
  display: block; width: 100%; padding: 8px 9px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; font-size: 12.5px;
  line-height: 1.3; text-align: left; cursor: pointer;
}
.minus-option:hover, .minus-option[aria-selected="true"] { background: var(--surface-2); }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-ui);
  font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r-pill);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease, border-color .2s ease, color .2s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-brand); }
.btn-primary:hover { background: var(--brand-press); }
[data-theme="dark"] .btn-primary { color: oklch(0.16 0.02 255); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn-soft { background: var(--brand-soft); color: var(--brand-press); }
[data-theme="dark"] .btn-soft { color: var(--brand); }
.btn-soft:hover { filter: brightness(0.97); }
.btn-outline { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn-outline:hover { background: var(--brand-soft); }
[data-theme="dark"] .btn-outline { color: var(--cyan); border-color: var(--cyan); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 13px 22px; font-size: 15px; }
.btn-icon {
  width: 38px; height: 38px; padding: 0; justify-content: center;
  border-radius: var(--r-md); background: transparent; color: var(--text-muted);
  border: 1px solid transparent; cursor: pointer; transition: background .2s, color .2s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500;
  padding: 5px 11px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em;
  padding: 3px 9px; border-radius: var(--r-pill);
}
.badge-brand { background: var(--brand-soft); color: var(--brand-press); }
[data-theme="dark"] .badge-brand { color: var(--brand); }
.badge-alisa { background: var(--alisa-soft); color: var(--alisa); }
.badge-giga  { background: var(--giga-soft);  color: var(--giga); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ---------- inputs ---------- */
.input {
  font-family: var(--font-ui); font-size: 14px;
  width: 100%; padding: 11px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color .18s, box-shadow .18s;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
input[type="checkbox"] { width: 17px; height: 17px; margin: 0; accent-color: var(--brand); cursor: pointer; }
input[type="checkbox"]:disabled { cursor: wait; }

.keyword-row .keyword-delete { opacity: 0; pointer-events: none; }
.keyword-row:hover .keyword-delete, .keyword-row:focus-within .keyword-delete { opacity: 1; pointer-events: auto; }
@media (hover: none) {
  .keyword-row .keyword-delete { opacity: 1; pointer-events: auto; }
}
.result-card:hover { border-color: var(--brand); }
.result-card.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.result-card:disabled { opacity: .62; cursor: wait; }
.page-button[aria-current="page"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.cluster-workspace { container-type: inline-size; }
.cluster-workspace-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.cluster-map { min-width: 0; overflow: hidden; }
.cluster-map-toolbar {
  position: relative; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--border);
}
.cluster-map-summary { display: flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--text-muted); }
.cluster-map-summary strong { font-size: 17px; color: var(--text); }
.cluster-map-summary > span:first-of-type { margin: 0 3px; color: var(--border-strong); }
.cluster-map-search { position: relative; display: flex; align-items: center; width: 210px; min-width: 0; }
.cluster-map-search > svg { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--text-faint); pointer-events: none; }
.cluster-map-search input {
  width: 100%; min-width: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); padding: 9px 10px 9px 34px; font: inherit; font-size: 13px;
}
.cluster-map-search input:focus { outline: 2px solid var(--brand-ring); outline-offset: 1px; }
.cluster-map-search-options {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 10;
  width: min(330px, 100cqw - 40px); max-height: 250px; overflow-y: auto;
  padding: 5px; border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-lg); overscroll-behavior: contain;
}
.cluster-map-search-options button {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.cluster-map-search-options button:hover, .cluster-map-search-options button[aria-selected="true"] { background: var(--surface-2); }
.cluster-map-search-options button > span:nth-child(2) { flex: 1; overflow-wrap: anywhere; }
.cluster-map-search-options small { color: var(--text-muted); }
.cluster-map-search-empty { padding: 14px 10px; color: var(--text-muted); font-size: 13px; }
.cluster-map-viewport {
  position: relative; height: clamp(440px, 62vh, 620px); overflow: hidden;
  background-color: var(--surface-2);
  background-image: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--brand) 4%, transparent), transparent 70%), radial-gradient(var(--border) .65px, transparent .65px);
  background-size: 100% 100%, 22px 22px; cursor: grab; touch-action: none; user-select: none;
}
.cluster-map-viewport:focus-visible { outline: 2px solid var(--brand); outline-offset: -3px; }
.cluster-map-viewport.is-dragging, .cluster-map-viewport.is-dragging .cluster-bubble { cursor: grabbing; }
.cluster-map-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.cluster-bubble {
  position: absolute; display: flex; align-items: center; justify-content: center;
  padding: 0; border-radius: 50%; border: var(--bubble-border) solid color-mix(in srgb, var(--bubble-color) 65%, var(--border));
  background: radial-gradient(circle at 32% 25%, color-mix(in srgb, var(--bubble-color) 5%, var(--surface)), color-mix(in srgb, var(--bubble-color) 20%, var(--surface)));
  color: var(--text); font: inherit; text-align: center; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.cluster-bubble:hover { z-index: 1; border-color: var(--bubble-color); box-shadow: 0 6px 20px color-mix(in srgb, var(--bubble-color) 16%, transparent); }
.cluster-bubble[aria-pressed="true"] {
  z-index: 2; border-color: var(--bubble-color);
  background: radial-gradient(circle at 32% 25%, color-mix(in srgb, var(--bubble-color) 18%, var(--surface)), color-mix(in srgb, var(--bubble-color) 35%, var(--surface)));
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--bubble-color) 12%, transparent), 0 10px 28px color-mix(in srgb, var(--bubble-color) 16%, transparent);
}
.cluster-bubble:focus-visible { outline: 3px solid var(--text); outline-offset: 5px; z-index: 3; }
.cluster-bubble.is-dimmed { opacity: .18; }
.cluster-bubble-content { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 77%; pointer-events: none; }
.cluster-bubble-count { font-size: var(--bubble-count-size); line-height: 1.1; color: color-mix(in srgb, var(--bubble-color) 80%, var(--text)); }
.cluster-bubble-title {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  max-width: 100%; font-size: var(--bubble-title-size); font-weight: 600; line-height: 1.23; overflow-wrap: anywhere;
}
.cluster-map-tooltip {
  position: absolute; z-index: 4; display: grid; gap: 7px; width: 244px; max-width: calc(100% - 20px);
  padding: 13px 15px; border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-lg); font-size: 12px; pointer-events: none;
}
.cluster-map-tooltip strong { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.cluster-map-tooltip > span { color: var(--text-muted); }
.cluster-map-tooltip-intent { display: flex; gap: 6px; align-items: center; }
.cluster-map-navigation { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 18px; }
.cluster-map-size-key { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }
.cluster-map-size-key i { width: 6px; height: 6px; border: 1px solid var(--text-faint); border-radius: 50%; }
.cluster-map-size-key i:nth-child(2) { width: 10px; height: 10px; }
.cluster-map-size-key i:nth-child(3) { width: 15px; height: 15px; margin-right: 4px; }
.cluster-map-zoom { display: flex; align-items: center; padding: 3px; border: 1px solid var(--border); border-radius: 12px; }
.cluster-map-zoom button {
  display: flex; align-items: center; justify-content: center; width: 34px; height: 32px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; font: inherit; font-size: 20px;
}
.cluster-map-zoom button:hover { background: var(--surface-2); }
.cluster-map-zoom button:disabled { color: var(--text-faint); cursor: default; }
.cluster-map-zoom button:focus-visible { outline: 2px solid var(--brand); }
.cluster-map-zoom output { min-width: 45px; padding: 0 3px; color: var(--text-muted); font-size: 11px; text-align: center; }
.cluster-map-zoom .cluster-map-fit { width: auto; gap: 5px; padding: 0 10px; margin-left: 5px; border-left: 1px solid var(--border); border-radius: 0 8px 8px 0; font-size: 12px; }
.cluster-map-fit svg { width: 16px; height: 16px; }
.cluster-map-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; padding: 14px 20px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 11px; }
.cluster-map-legend > span { display: inline-flex; gap: 6px; align-items: center; }
.cluster-detail { min-width: 0; overflow: hidden; }
.cluster-detail-heading { padding: 20px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bubble-color) 5%, var(--surface)); }
.cluster-detail-heading h3 { overflow-wrap: anywhere; line-height: 1.25; }
.cluster-detail-intent { display: flex; align-items: center; gap: 7px; margin-top: 12px; font-size: 12px; color: var(--text-muted); }
.cluster-detail-intent .dot { background: var(--bubble-color); }
.cluster-detail-stats { display: flex; gap: 28px; margin-top: 20px; }
.cluster-detail-stats > div { display: grid; gap: 4px; }
.cluster-detail-stats strong { font-size: 23px; font-weight: 600; }
.cluster-detail-stats span { color: var(--text-muted); font-size: 11px; }
.cluster-detail-members { max-height: 350px; overflow-y: auto; padding: 8px 20px 14px; }
@container (min-width: 1060px) {
  .cluster-workspace-body { grid-template-columns: minmax(0, 1fr) 310px; }
}
@container (max-width: 520px) {
  .cluster-map-toolbar { padding: 14px; gap: 10px; }
  .cluster-map-search { width: 100%; }
  .cluster-map-viewport { height: 440px; }
  .cluster-map-navigation { padding: 10px; gap: 8px; }
  .cluster-map-zoom button { width: 38px; height: 38px; }
  .cluster-map-zoom .cluster-map-fit { width: 38px; padding: 0; }
  .cluster-map-fit span { display: none; }
  .cluster-map-legend { padding: 13px 14px; gap: 10px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .cluster-bubble { transition: none !important; }
}

/* animations */
@keyframes floatUp { from { transform: translateY(10px); } to { transform: none; } }
@keyframes pulseRing { 0% { box-shadow: 0 0 0 0 var(--brand-ring); } 70% { box-shadow: 0 0 0 14px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes mascotWave { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-22deg); } }
@keyframes mascotBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* Visible state is the BASE — opacity is NEVER animated, so a stuck/
   play-pending entrance animation (which can freeze at currentTime:0)
   can never hide content. Only transform is animated, and only when
   motion is welcome. */
.fade-up { opacity: 1; transform: none; }
@media (prefers-reduced-motion: no-preference) {
  .fade-up { animation: floatUp .5s cubic-bezier(.2,.7,.3,1) both; }
}
