:root {
  --ink: #1b1b1b;
  --muted: #6b6b6b;
  --line: #e3e1dc;
  --bg: #fbfaf8;
  --card: #fff;
  --accent: #1b1b1b;
}

* { box-sizing: border-box; }

html {
  /* полоса прокрутки есть всегда: при переключении страниц ширина не меняется */
  overflow-y: scroll;
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  z-index: 10;
}

.top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.brand {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
}
.brand-sub {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  padding-left: 2px;
}
.brand-sub:hover { color: var(--ink); text-decoration: underline; }
.nav-current { color: var(--ink); font-weight: 600; }
.tag { color: var(--muted); font-size: 12px; }
.top-nav { margin-left: auto; font-size: 12px; display: flex; align-items: center; gap: 14px; }
.top-nav a { color: var(--muted); text-decoration: none; }
.top-nav a:hover { color: var(--ink); text-decoration: underline; }

main { padding: 24px 20px 40px; max-width: 1240px; margin: 0 auto; }

.foot {
  padding: 18px 20px 32px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

h1 { font-size: 22px; margin: 0 0 6px; font-weight: 600; }
h2 { font-size: 15px; margin: 28px 0 10px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 6px; }

.intro {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 380px);
  gap: 6px 20px;
  align-items: baseline;
  margin-bottom: 12px;
}
.intro h1 { margin: 0; font-size: 17px; }
.intro h1 .meta { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.intro .search { margin: 0; }
.intro .search label { display: none; }
.intro .hint, .intro .results { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .intro { grid-template-columns: 1fr; }
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #f2f0ec;
  padding: 1px 4px;
  border-radius: 2px;
}

.search { margin: 16px 0 8px; }
.search label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.search input {
  width: 100%;
  padding: 9px 11px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  color: var(--ink);
}
.search input:focus { outline: 2px solid #c9c3b6; outline-offset: 1px; }
/* пример-подсказка мельче вводимого текста */
.search input::placeholder { font-size: 8px; opacity: 1; color: #8a8a90; }
.search input::-webkit-input-placeholder { font-size: 8px; color: #8a8a90; }

.hint { color: var(--muted); font-size: 11px; margin: 3px 0; line-height: 1.0; }
.hits { margin: 0 0 6px; }
.hits:empty { display: none; }
.hint code { font-size: 11px; }

/* выдача поиска: одна колонка и окно со скроллом 180 px */
.results {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: max-content; gap: 6px;
  /* окно по ширине текста, по центру панели */
  width: max-content; max-width: 100%; margin: 0 auto;
  max-height: 180px; overflow-y: auto; overscroll-behavior: contain;
  padding-right: 4px;
}
.res {
  -webkit-user-drag: none; user-select: text;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px 4px 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  text-decoration: none;
  color: var(--ink);
  font-size: 12px;
}
.res:hover { border-color: #c9c3b6; }
.res .sw { width: 18px; height: 18px; border-radius: 2px; }
.res-t { white-space: nowrap; }

/* ---- стена кластеров ---- */

.wall {
  display: grid;
  align-items: start;
  /* карточка подстраивается под число столбцов: 8 × 14 px + 7 зазоров по 2 px + отступы */
  grid-template-columns: repeat(var(--cluster-cols, 7), 138px);
  gap: 8px;
  /* именно start: при center содержимое шире контейнера уходит за левый край,
     и до него нельзя долистать — правый край доступен, левый нет */
  justify-content: start;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c9c3b6 transparent;
}
.wall::-webkit-scrollbar { height: 8px; }
.wall::-webkit-scrollbar-thumb { background: #c9c3b6; border-radius: 4px; }
.wall::-webkit-scrollbar-track { background: transparent; }

/* на широком экране стена помещается целиком — центрируем */
@media (min-width: 1040px) {
  .wall { justify-content: center; padding-bottom: 2px; }
}

/* подсказка о прокрутке — только там, где стена не помещается */
.scroll-hint {
  display: none;
  margin: 2px 0 10px;
  font-size: 12px;
  color: var(--muted);
}
@media (max-width: 1039px) {
  .scroll-hint { display: block; }
}

.card {
  /* ширина = столбцы × 16 px + зазоры 2 px + отступы и рамка */
  width: calc(var(--cols, 7) * 14px + (var(--cols, 7) - 1) * 2px + 12px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 4px 5px 3px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.card-title {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
  text-decoration: none;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-title:hover { text-decoration: underline; }
.card-meta { margin: 0; max-width: 100%; font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- сетки ---- */

.grid { display: grid; gap: 2px; }
/* явные размеры: строки и столбцы целые, зазоры не гуляют от округления */
.grid.mini { grid-template-columns: repeat(var(--cols), 14px); grid-auto-rows: 14px; gap: 2px; align-content: start; }
/* Мини-стена: ячейка ровно 14×14, чтобы вся палитра влезала на экран целиком. */
.cell.mini { width: 14px; height: 14px; aspect-ratio: auto; }
/* целая ширина ячейки: 8 × 92 px + 7 зазоров по 3 px = 757 px, без дробей */
.grid.big { grid-template-columns: repeat(var(--cols), 92px); grid-auto-rows: 92px; gap: 3px; max-width: 760px; align-content: start; }

.cell {
  display: block;
  touch-action: manipulation;
  background: var(--c);
  border-radius: 1px;
  aspect-ratio: 1 / 1;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.cell.big { border-radius: 2px; }
.cell.empty { background: transparent; }

.cell:hover, .cell:focus-visible {
  transform: scale(1.08);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  position: relative;
  z-index: 2;
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  .cell { transition: none; }
  .cell:hover, .cell:focus-visible { transform: none; }
}

.big-grid { margin-bottom: 8px; }

/* ---- таблица цветов ---- */

.table-wrap { overflow-x: auto; }
.colors { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.colors th, .colors td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
.colors th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.colors a { color: var(--ink); }

/* ---- страница цвета ---- */

.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }

.color-page { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.swatch {
  width: 260px;
  height: 260px;
  border-radius: 4px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.details { min-width: 260px; flex: 1; }

.coords {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 12px;
  margin: 14px 0 18px;
  font-size: 13px;
}
.coords dt { color: var(--muted); }
.coords dd { margin: 0; font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.copy {
  font: inherit;
  font-size: 12px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 3px;
  cursor: pointer;
  color: var(--ink);
}
.copy:hover { border-color: #c9c3b6; }

.neigh { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0; flex-wrap: wrap; }
.neigh-link {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  text-decoration: none;
  color: var(--ink);
  font-size: 12px;
}
.neigh-link .sw { width: 24px; height: 24px; border-radius: 2px; }
.neigh-link .de { color: var(--muted); font-variant-numeric: tabular-nums; }

.legend { color: var(--muted); font-size: 12px; margin-top: 22px; max-width: 720px; }

/* ---- подсказка у ячейки ---- */

.tip {
  position: fixed;
  z-index: 50;
  /* display у .tip перебивает браузерное [hidden] → скрываем явно */
  display: flex;
  gap: 9px;
  align-items: flex-start;
  max-width: 260px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  animation: tip-in 110ms ease-out;
}
.tip-sw { width: 34px; height: 34px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0, 0, 0, 0.08); }
.tip-text { display: flex; flex-direction: column; gap: 1px; font-size: 11.5px; line-height: 1.3; }
.tip-text b { font-weight: 600; }
.tip-prov {
  display: block;
  font-size: 11px;
  opacity: .75;
  margin-top: 2px;
}
.tip-text code { background: none; padding: 0; color: var(--muted); font-size: 11px; }

@keyframes tip-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* ---- появление страницы ---- */

main { animation: page-in 180ms ease-out; }
@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tip, main { animation: none; }
}

/* служебные метки проверки замером (для разработки) */
.cell { position: relative; }
.dot {
  position: absolute; right: 2px; bottom: 2px;
  width: 6px; height: 6px; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,.85);
  pointer-events: none;
}
.dot-good { background: #17a34a; }
.dot-mid  { background: #eab308; }
.dot-bad  { background: #dc2626; }

/* служебные данные: видны только при включённом переключателе Dev */
html:not(.dev) .dev-only { display: none !important; }
.dev-toggle {
  margin-left: 10px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid currentColor; background: none; color: inherit;
  font: inherit; font-size: 12px; cursor: pointer; opacity: .6;
}
.dev-toggle[aria-pressed="true"] { opacity: 1; font-weight: 600; }

/* окно проверки цвета */
.measure { border: 0; border-radius: 14px; padding: 0; max-width: 392px; width: 92vw; max-height: 92vh; }
.measure[open] { display: block; }
.measure::backdrop { background: rgba(20, 20, 22, .45); }
.measure-form { display: grid; gap: 10px; padding: 18px; }
.measure-form h2 { margin: 0; font-size: 17px; }
.measure-row { display: grid; grid-template-columns: repeat(3, 88px); gap: 8px; }
.measure-mode { display: flex; gap: 16px; align-items: center; margin: 2px 0; }
.measure-mode label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.measure-wall, .measure-source { display: grid; gap: 6px; }
.measure-form label { display: grid; gap: 4px; font-size: 12px; color: #555; }
.measure-form input { padding: 6px 9px; border: 1px solid #ccc; border-radius: 8px; font: inherit; width: 100%; min-width: 0; }
.measure-actions { display: flex; gap: 8px; }
.measure-send { padding: 8px 14px; border-radius: 8px; border: 0; background: #1d4ed8; color: #fff; font: inherit; cursor: pointer; }
.measure-close { padding: 8px 14px; border-radius: 8px; border: 1px solid #ccc; background: none; font: inherit; cursor: pointer; }
.measure-result { margin: 0; font-size: 13px; min-height: 18px; }
.measure-open { margin-left: 8px; padding: 3px 9px; border-radius: 999px; border: 1px solid currentColor; background: none; color: inherit; font: inherit; font-size: 12px; cursor: pointer; }

/* служебный блок на странице цвета */
.dev-block { margin: 14px 0; padding: 10px 12px; border: 1px dashed #c9c9cf; border-radius: 10px; background: #fafafa; }
.dev-block p { margin: 0 0 4px; font-size: 13px; line-height: 1.45; }
.dev-block b { font-weight: 600; }

/* страница матчинга */
.match-layout { position: relative; }
.match-layout .wall { overflow: visible; padding-bottom: 0; }

/* статистика живёт справа поверх свободного поля и не сдвигает стену */
.match-stats {
  position: fixed; right: 16px; top: 84px; width: 208px; z-index: 5;
  max-height: calc(100vh - 110px); overflow: auto;
  border: 1px solid #e2e2e6; border-radius: 12px; padding: 12px 14px; background: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,.08);
}
/* на узком экране панель сжимается, но остаётся поверх — высота страницы не меняется */
@media (max-width: 1240px) {
  .match-stats { width: 168px; font-size: 12px; }
}
.match-stats h2 { margin: 0 0 8px; font-size: 15px; }
.match-stats h3 { margin: 12px 0 6px; font-size: 13px; color: #555; }
.match-stats dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; margin: 0; font-size: 13px; }
.match-stats dt { color: #555; }
.match-stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.match-stats .legend { margin-top: 10px; font-size: 11px; color: #777; line-height: 1.4; }

/* средняя цена по кластерам — в две колонки, без длинной прокрутки */
.cluster-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.cluster-grid dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; margin: 0; font-size: 12px; }
.cluster-grid dt { color: #555; }
.cluster-grid dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* результаты поиска: цвета стены в зелёной рамке, из источников — в серой */
.res { display: flex; align-items: center; gap: 8px; }
.res-wall { border-left: 3px solid #17a34a; }
.res-src { border-left: 3px solid #b4b4bb; }
.res-de { margin-left: auto; color: #555; font-variant-numeric: tabular-nums; }
.res-body { display: grid; gap: 1px; min-width: 0; }
.res-lab { font-size: 11px; color: #7a7a82; font-variant-numeric: tabular-nums; }
/* стена-строка длиннее прежней: на узком экране переносим её, а не прокручиваем вбок */
@media (max-width: 900px) {
  .results { width: 100%; grid-template-columns: minmax(0, 1fr); }
  .res-lab { overflow-wrap: anywhere; }
}
.res-ver { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 999px;
  background: #e6f4ea; color: #17703a; font-size: 10px; line-height: 16px; }

/* подтверждение исключения оттенка */
.confirm { border: 0; border-radius: 14px; padding: 0; max-width: 340px; width: 92vw; }
.confirm::backdrop { background: rgba(20, 20, 22, .45); }
.confirm-form { display: grid; gap: 8px; padding: 18px; }
.confirm-form h2 { margin: 0; font-size: 16px; }
.confirm-form p { margin: 0; font-size: 13px; }
.confirm-paint { font-size: 12px; }
.confirm-actions { display: flex; gap: 8px; margin-top: 6px; }
.confirm-yes { padding: 8px 16px; border-radius: 8px; border: 0; background: #b42318; color: #fff; font: inherit; cursor: pointer; }
.confirm-no { padding: 8px 16px; border-radius: 8px; border: 1px solid #ccc; background: none; font: inherit; cursor: pointer; }

/* ручная расстановка названий: панель с квадратиками и перетаскивание */
.name-panel {
  position: fixed; left: 16px; top: 84px; width: 240px; z-index: 5;
  max-height: calc(100vh - 110px); overflow: auto;
  border: 1px solid #e2e2e6; border-radius: 12px; padding: 12px 14px; background: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,.08);
}
.name-panel h2 { margin: 0 0 6px; font-size: 15px; }
.name-panel h4 { margin: 10px 0 3px; font-size: 11px; font-weight: 600; color: #555; }
.name-panel .legend { font-size: 10px; color: #777; margin: 0 0 8px; line-height: 1.35; }
.chip {
  display: inline-block; margin: 2px 3px 2px 0; padding: 3px 8px; border-radius: 999px;
  background: #f1f0ee; font-size: 11px; cursor: grab; user-select: none;
}
.chip:active { cursor: grabbing; }
.chip.taken { opacity: .35; }
.name-clear { margin-top: 10px; font-size: 11px; padding: 4px 8px; border-radius: 8px; border: 1px solid #ccc; background: none; cursor: pointer; }
.name-status { font-size: 11px; color: #555; min-height: 14px; margin: 6px 0 0; }
.cell.drop { outline: 2px solid #1d4ed8; outline-offset: -2px; }
.cell.named { cursor: grab; }
.cell.named:active { cursor: grabbing; }
.cell.named:hover { outline: 2px solid #17a34a; outline-offset: -2px; }
.cell.named { position: relative; }
.name-x {
  display: none; position: absolute; top: -4px; right: -4px; width: 12px; height: 12px;
  border-radius: 50%; background: #b42318; color: #fff; font-size: 10px; line-height: 12px;
  text-align: center; cursor: pointer; z-index: 3;
}
.cell.named:hover .name-x { display: block; }

.tip[hidden] { display: none; }

/* ВРЕМЕННО: крупное значение оттенка во всплывающей подсказке */
.tip-hue { display: block; font-size: 30px; line-height: 1; font-weight: 700; }

/* окно насыщенности: 0 — зелёный, 50 — жёлтый, 100 — красный */
.sat-window {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 260px;
  padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); box-shadow: 0 6px 24px rgba(0,0,0,.12);
}
.sat-window h2 { margin: 0 0 8px; font-size: 13px; }
.sat-scale {
  height: 16px; border-radius: 3px;
  background: linear-gradient(90deg, #2e9e4f 0%, #9ec400 25%, #ffe000 50%, #f08a00 75%, #d02a20 100%);
}
.sat-ticks { display: flex; justify-content: space-between; margin-top: 4px; font-size: 10px; color: var(--muted); }
.sat-ticks span:nth-child(2) { text-align: center; }
.sat-hint { margin: 8px 0 0; font-size: 10px; color: var(--muted); line-height: 1.35; }

/* плашка с формулой колеровки в результатах поиска */
.rec-tip {
  position: fixed; z-index: 200; pointer-events: none;
  background: #fff; border: 1px solid #d8d4ca; border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
  padding: 8px 10px; font-size: 12px; color: #111; min-width: 150px;
}
.rec-tip .t { font-weight: 600; margin-bottom: 6px; font-size: 12px; }
.rec-tip table { border-collapse: collapse; width: 100%; }
.rec-tip td { padding: 2px 0; }
.rec-tip td.c { font-family: ui-monospace, monospace; color: #444; padding-right: 14px; }
.rec-tip td.g { text-align: right; font-variant-numeric: tabular-nums; }
