/* Token Lab - стилі застосунку.
   Усі кольори UI - тільки через змінні в :root. Колір палітри приходить
   з JS через inline custom properties (--c, --t-*). */

:root {
  --bg: #0a0a0b;
  --surface: #111113;
  --surface-2: #18181b;
  --line: #27272b;
  --line-control: #71717a;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --btn-bg: #f4f4f5;
  --btn-bg-hover: #ffffff;
  --btn-text: #0a0a0b;
  --danger: #f87171;
  --ok: #4ade80;
  --warn: #facc15;
  --focus: #f4f4f5;

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --maxw: 1440px;
  --gutter: 16px;
  --radius: 6px;
  --tap: 44px;

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, ul, ol, figure, pre {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

code, pre, .mono {
  font-family: var(--font-mono);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 20;
  padding: 10px 14px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border-radius: var(--radius);
  text-decoration: none;
}

.skip-link:focus {
  top: 8px;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn:hover {
  border-color: var(--text-muted);
}

.btn--primary {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-text);
}

.btn--primary:hover {
  background: var(--btn-bg-hover);
  border-color: var(--btn-bg-hover);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ---------- Шапка ---------- */

.site-header {
  border-bottom: 1px solid var(--line);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px var(--gutter);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.logo__mark {
  flex: none;
}

.site-header__share {
  margin-left: auto;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  order: 3;
  width: 100%;
  margin: 0 -8px;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 12px;
  color: var(--text-muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--text);
}

.share-bar {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.share-bar__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px var(--gutter);
}

.share-bar__label {
  color: var(--text-muted);
  font-size: 13px;
}

.share-bar__link {
  font-family: var(--font-mono);
  font-size: 13px;
  min-width: 0;
}

.notice {
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.notice__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 4px var(--gutter);
}

.notice__text {
  font-size: 13px;
  min-width: 0;
}

.notice__close {
  flex: none;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: transparent;
  font-size: 13px;
}

.notice__close:hover {
  border-color: var(--text-muted);
}

/* ---------- Каркас ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px var(--gutter) 48px;
}

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
}

.eyebrow,
.block__title,
.presets__label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel__title {
  margin-top: 12px;
  font-size: 30px;
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.panel__lead {
  margin-top: 12px;
  color: var(--text-muted);
}

/* ---------- Поле hex ---------- */

.field {
  margin-top: 24px;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
}

.field__row {
  display: flex;
  gap: 8px;
}

.hex-box {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  min-height: var(--tap);
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--bg);
}

.hex-box:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hex-box__prefix {
  padding-left: 14px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.hex-box__input {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  padding: 0 14px 0 4px;
  border: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 16px;
  text-transform: uppercase;
  outline: none;
}

.field.is-invalid .hex-box {
  border-color: var(--danger);
}

.field__hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.field.is-invalid .field__hint {
  display: none;
}

.field__error {
  margin-top: 6px;
  font-size: 13px;
  color: var(--danger);
}

.picker {
  position: relative;
  flex: none;
  width: var(--tap);
  height: var(--tap);
}

.picker__input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.picker__chip {
  position: absolute;
  inset: 0;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--c);
}

.picker__input:focus-visible + .picker__chip {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Пресети ---------- */

.presets {
  margin-top: 24px;
}

.presets__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.preset {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 6px 10px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: left;
  min-width: 0;
}

.preset:hover {
  border-color: var(--text-muted);
}

.preset[aria-pressed="true"] {
  border-color: var(--text);
}

.preset__dot {
  flex: none;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line-control);
  border-radius: 50%;
  background: var(--c);
}

.preset__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.preset__name {
  font-size: 13px;
  font-weight: 500;
}

.preset__hex {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Зведення ---------- */

.summary {
  margin-top: 24px;
  border-top: 1px solid var(--line);
}

.summary__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.summary__row dt {
  color: var(--text-muted);
  font-size: 13px;
}

.summary__row dd {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
}

.chip {
  flex: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line-control);
  border-radius: 3px;
  background: var(--c);
}

/* ---------- Контент ---------- */

.content {
  min-width: 0;
}

.block {
  padding: 24px 0;
  border-top: 1px solid var(--line);
  scroll-margin-top: 8px;
}

.block:first-child {
  padding-top: 0;
  border-top: 0;
}

.block__lead {
  margin: 8px 0 20px;
  color: var(--text-muted);
  max-width: 62ch;
}

/* ---------- Шкала ---------- */

.scale-row + .scale-row {
  margin-top: 24px;
}

.scale-row__title {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
}

.scale-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px 6px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.swatch__chip {
  display: block;
  height: 56px;
  border: 1px solid var(--line-control);
  border-radius: 4px;
  background: var(--c);
}

.swatch:hover .swatch__chip {
  border-color: var(--text);
}

.swatch.is-user .swatch__chip {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.swatch__step {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
}

.swatch__hex {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-muted);
}

.swatch__tag {
  align-self: flex-start;
  min-height: 16px;
  padding: 0 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 16px;
}

.swatch.is-user .swatch__tag {
  background: var(--btn-bg);
  color: var(--btn-text);
}

/* ---------- Таблиця токенів ---------- */

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.tokens-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.tokens-table th,
.tokens-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.tokens-table tbody tr:last-child > * {
  border-bottom: 0;
}

.tokens-table thead th {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tokens-table tbody th {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.tok-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tok-cell__ref {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.tok-cell__hex {
  padding-left: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Контраст ---------- */

.pv-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.pv {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.pv__head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.pv__stage {
  padding: 16px;
  background: var(--t-bg);
  color: var(--t-text);
}

.pv__card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--t-border);
  border-radius: 8px;
  background: var(--t-surface);
  color: var(--t-text);
}

.pv__title {
  font-size: 16px;
  font-weight: 600;
}

.pv__muted {
  font-size: 13px;
  color: var(--t-text-muted);
}

.pv__input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--t-border);
  border-radius: var(--radius);
  background: var(--t-bg);
  color: var(--t-text);
}

.pv__input::placeholder {
  color: var(--t-text-muted);
  opacity: 1;
}

.pv__input:focus-visible,
.pv__btn:focus-visible {
  outline: 2px solid var(--t-text);
  outline-offset: 2px;
}

.pv__btn {
  min-height: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--t-accent);
  color: var(--t-on-accent);
  font-weight: 500;
}

.pv__btn:hover {
  background: var(--t-accent-hover);
}

.pv__status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 13px;
}

.pv__status-danger {
  color: var(--t-danger);
}

.pv__status-success {
  color: var(--t-success);
}

.checks {
  border-top: 1px solid var(--line);
}

.checks__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-height: 48px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.checks__item:last-child {
  border-bottom: 0;
}

.checks__name {
  flex: 1;
  min-width: 80px;
  font-size: 13px;
}

.checks__ratio {
  font-family: var(--font-mono);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-width: 72px;
  justify-content: center;
  padding: 2px 8px;
  border: 1px solid var(--line-control);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge--ok {
  border-color: var(--ok);
  color: var(--ok);
}

.badge--warn {
  border-color: var(--warn);
  color: var(--warn);
}

.badge--fail {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- Експорт ---------- */

.export {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.export__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tab {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 13px;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected="true"] {
  border-color: var(--line-control);
  background: var(--surface-2);
  color: var(--text);
}

.tabpanel[hidden] {
  display: none;
}

.code {
  max-height: 420px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
  tab-size: 2;
}

.code code {
  font-family: inherit;
  white-space: pre;
}

/* ---------- Підвал, тост ---------- */

.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px var(--gutter) 40px;
  border-top: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-text);
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s, transform 0.18s;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast:empty {
  display: none;
}

/* ---------- Адаптив ---------- */

@media (min-width: 640px) {
  :root {
    --gutter: 24px;
  }

  .pv-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .presets__list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .preset {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .scale-grid {
    grid-template-columns: repeat(11, minmax(0, 1fr));
    gap: 8px 6px;
  }
}

@media (min-width: 860px) {
  .site-nav {
    order: 0;
    width: auto;
    margin: 0 0 0 16px;
  }

  .tokens-table th,
  .tokens-table td {
    padding: 12px 16px;
  }

  .tokens-table tbody th,
  .tok-cell__ref {
    font-size: 13px;
  }

  .tok-cell__hex {
    font-size: 12px;
  }
}

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 32px;
    align-items: start;
    padding-top: 32px;
  }

  .panel {
    padding: 24px;
  }

  .presets__list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .preset {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .scale-grid {
    gap: 8px 4px;
  }

}

@media (min-width: 1024px) and (min-height: 760px) {
  .panel {
    position: sticky;
    top: 16px;
  }
}

@media (min-width: 1280px) {
  .layout {
    gap: 48px;
  }

  .swatch__hex {
    font-size: 12px;
  }

  .swatch__chip {
    height: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
