/* Token Lab. UI colors live here as variables; palette colors come only from app.js
   into swatches and previews. Layout follows the Figma frame "Token Lab · Desktop 1440". */

:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --ink: #141413;
  --ink-2: #3d3c38;
  --muted: #6e6d66;
  --line: #e3e1d9;
  --line-strong: #cfccc1;
  --chip: #ecebe6;
  --on-ink: #f4f3ef;
  --swatch-line: rgba(0, 0, 0, 0.06);
  --tag-bg: rgba(255, 255, 255, 0.9);
  --error: #b42318;

  --pass-bg: #e3f3e8;
  --pass: #17663a;
  --large-bg: #fbefd5;
  --large: #8a5a00;
  --fail-bg: #fde3df;
  --fail: #b42318;

  --focus: #141413;
  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: normal;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd {
  margin: 0;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

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

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
  cursor: pointer;
}

.btn-primary {
  height: 40px;
  padding: 6px 12px;
  border: 0;
  background: var(--ink);
  color: var(--on-ink);
}

.btn-primary:hover {
  background: var(--ink-2);
}

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

.btn-secondary {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.btn-secondary:hover {
  border-color: var(--ink);
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 64px;
  padding: 0 40px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.logo-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--sw);
}

.nav {
  display: flex;
  gap: 24px;
  margin-right: auto;
  font-size: 14px;
  color: var(--muted);
}

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

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  align-items: start;
}

/* ---------- panel ---------- */

.panel {
  align-self: stretch;
  border-right: 1px solid var(--line);
}

.panel-inner {
  position: sticky;
  top: 64px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 40px 32px 40px 40px;
}

.intro {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.intro h1 {
  font-size: 34px;
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.intro p {
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.hex-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 12px 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
}

.hex-field:focus-within {
  border-color: var(--ink);
}

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

.picker {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

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

.picker-fill {
  position: absolute;
  inset: 0;
  background: var(--sw);
}

.picker input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.hex-hash,
.hex-input {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
}

.hex-hash {
  color: var(--muted);
}

.hex-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-transform: uppercase;
  outline: none;
}

.hex-input::placeholder {
  color: var(--line-strong);
}

.field-error {
  font-size: 13px;
  line-height: 1.4;
  color: var(--error);
}

.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.preset:hover {
  border-color: var(--line-strong);
}

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

.preset-dot {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--sw);
}

.facts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 120px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

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

.facts dd {
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
}

/* ---------- main ---------- */

.main {
  min-width: 0;
  padding: 0 40px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 40px 0;
  border-bottom: 1px solid var(--line);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
}

.section-head h2 {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-note {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- scale ---------- */

.scales {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.scale-row {
  display: flex;
  gap: 16px;
}

.scale-name {
  flex: none;
  width: 72px;
  font-size: 13px;
  font-weight: 500;
}

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

.swatch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.swatch-color {
  display: block;
  height: 88px;
  padding: 8px;
  border: 1px solid var(--swatch-line);
  border-radius: 6px;
  background: var(--sw);
  transition: transform 0.15s;
}

.swatch:hover .swatch-color {
  transform: translateY(-2px);
}

.swatch-tag {
  display: block;
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--tag-bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
}

.swatch-step {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
}

.swatch-hex {
  margin-top: -6px;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-overflow: ellipsis;
}

/* ---------- tokens ---------- */

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

.tokens-table th {
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  color: var(--muted);
}

.tokens-table th:first-child {
  width: 30%;
}

.tokens-table td {
  height: 41px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.token-name {
  font-family: var(--mono);
  font-size: 12px;
}

.token-value {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.token-ref {
  font-size: 12px;
}

.token-hex {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

/* ---------- contrast ---------- */

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

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.preview-title {
  font-size: 13px;
  font-weight: 600;
}

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

/* Inside the canvas only palette tokens (--t-*) are used. */
.pv-canvas {
  padding: 24px;
  background: var(--t-bg);
  color: var(--t-text);
}

.pv-card {
  padding: 20px;
  border: 1px solid var(--t-border);
  border-radius: 10px;
  background: var(--t-surface);
}

.pv-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pv-top {
  justify-content: space-between;
}

.pv-eyebrow {
  font-size: 12px;
  color: var(--t-text-muted);
}

.pv-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--t-success);
}

.pv-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pv-title {
  margin-top: 12px;
  font-size: 16px;
  font-weight: 600;
}

.pv-text {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--t-text-muted);
}

.pv-label {
  display: block;
  margin-top: 16px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
}

.pv-input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--t-danger);
  border-radius: 6px;
  background: var(--t-surface);
  color: var(--t-text);
  font-size: 13px;
}

.pv-input:focus-visible {
  outline: 2px solid var(--t-accent);
  outline-offset: 1px;
}

.pv-error {
  margin-top: 8px;
  font-size: 12px;
  color: var(--t-danger);
}

.pv-buttons {
  margin-top: 16px;
}

.pv-button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--t-accent);
  color: var(--t-on-accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.pv-button:hover,
.pv-button.is-hover {
  background: var(--t-accent-hover);
}

.pv-button.is-ghost {
  border-color: var(--t-border);
  background: var(--t-surface);
  color: var(--t-text);
}

.pv-button:focus-visible {
  outline: 2px solid var(--t-text);
  outline-offset: 2px;
}

.pv-meta {
  margin-top: 12px;
  font-size: 12px;
  color: var(--t-text-muted);
}

.mini-badge {
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
}

.pairs {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pair {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 41px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
}

.pair-sample {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 18px;
  border: 1px solid var(--swatch-line);
  border-radius: 4px;
  background: var(--t-bg);
  color: var(--t-fg);
  font-size: 11px;
  font-weight: 600;
}

.pair-label {
  flex: 1;
  min-width: 0;
  font-size: 12px;
}

.pair-label span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.pair-ratio {
  font-family: var(--mono);
  font-size: 12px;
}

.pair .mini-badge {
  min-width: 34px;
  text-align: center;
}

[data-level='pass'] {
  background: var(--pass-bg);
  color: var(--pass);
}

[data-level='large'] {
  background: var(--large-bg);
  color: var(--large);
}

[data-level='fail'] {
  background: var(--fail-bg);
  color: var(--fail);
}

/* ---------- export ---------- */

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

.export-tabs {
  display: flex;
  gap: 2px;
}

.export-tab {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

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

.export-tab[aria-selected='true'] {
  background: var(--chip);
  color: var(--ink);
  font-weight: 500;
}

.code {
  margin: 0;
  max-height: 380px;
  padding: 16px 20px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.footer {
  padding: 40px 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}

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

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .previews {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel-inner {
    position: static;
    padding: 32px 24px;
  }

  .facts {
    margin-top: 0;
  }

  .main {
    padding: 0 24px;
  }

  .topbar {
    padding: 0 24px;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 16px;
  }

  .nav {
    display: none;
  }

  .logo {
    margin-right: auto;
  }

  .panel-inner {
    padding: 24px 16px;
  }

  .intro h1 {
    font-size: 28px;
  }

  .main {
    padding: 0 16px;
  }

  .section {
    padding: 32px 0;
  }

  .scale-row {
    flex-direction: column;
    gap: 10px;
  }

  .swatches {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    row-gap: 14px;
  }

  .swatch-color {
    height: 56px;
    padding: 4px;
  }

  .swatch-tag {
    padding: 2px 3px;
    font-size: 9px;
  }

  .swatch-hex {
    font-size: 10px;
  }

  .tokens-table thead {
    display: none;
  }

  .tokens-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px 12px;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
  }

  .tokens-table tbody tr:first-child {
    border-top: 0;
  }

  .tokens-table td {
    height: auto;
    padding: 0;
    border: 0;
  }

  .tokens-table td:first-child {
    grid-column: 1 / -1;
  }

  .tokens-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .token-value {
    flex-wrap: wrap;
    row-gap: 2px;
  }

  .pv-canvas {
    padding: 14px;
  }

  .pv-card {
    padding: 14px;
  }

  .pair {
    flex-wrap: wrap;
    padding: 8px 12px;
  }

  .pair-label {
    flex-basis: calc(100% - 34px);
  }

  .pair-ratio {
    margin-left: 34px;
    margin-right: auto;
  }

  .export-bar {
    flex-wrap: wrap;
  }

  .code {
    padding: 14px;
    font-size: 11px;
  }
}

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

  .swatch-color,
  .toast {
    transition: none;
  }
}
