/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0d;
  --surface:   #161616;
  --surface2:  #1f1f1f;
  --border:    #2a2a2a;
  --text:      #e8e8e8;
  --text-muted:#6b6b6b;
  --accent:    #ffffff;

  --aaa:   #3ecf8e;
  --aa:    #4d9ef5;
  --large: #f5a623;
  --fail:  #e84f4f;

  --radius: 8px;
  --radius-sm: 5px;
  --cell: 88px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.logo-icon { font-size: 1.4rem; opacity: .9; }
.logo-text { color: var(--text-muted); }
.logo-text strong { color: var(--text); }
.tagline {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Main ── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

/* ── Section label ── */
.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Guide section ── */
.guide-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 40px;
}
.guide-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: start;
}
.guide-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  line-height: 1.25;
}
.guide-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.7;
}
.guide-desc abbr {
  text-decoration: underline dotted;
  cursor: help;
}
.guide-steps {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.guide-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.step-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 1px;
}
.guide-step strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 3px;
}
.guide-step p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.inline-badge {
  display: inline-flex;
  align-items: center;
  height: 17px;
  padding: 0 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: .04em;
  vertical-align: middle;
}

@media (max-width: 700px) {
  .guide-inner { grid-template-columns: 1fr; gap: 24px; }
}

/* ── Palette section ── */
.palette-section {}
.palette-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.color-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Color chip */
.color-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  height: 44px;
  transition: border-color .15s;
}
.color-chip:hover { border-color: #444; }

.chip-swatch {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: filter .15s;
}
.chip-swatch:hover { filter: brightness(1.12); }

.chip-input {
  width: 84px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  padding: 0 8px;
  text-transform: uppercase;
}

.chip-remove {
  width: 32px;
  height: 44px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: color .15s, background .15s;
}
.chip-remove:hover { color: var(--fail); background: rgba(232,79,79,.08); }

/* Add button */
.btn-add {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-add:hover { color: var(--text); border-color: #555; }
.btn-add-icon { font-size: 1.1rem; line-height: 1; }

/* Palette actions */
.palette-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.btn-secondary {
  height: 34px;
  padding: 0 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-secondary:hover { color: var(--text); border-color: #555; background: #252525; }

/* ── Legend ── */
.legend-section {}
.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.legend-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-right: 16px;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-aaa      { background: rgba(62,207,142,.18); color: var(--aaa); }
.badge-aa       { background: rgba(77,158,245,.18); color: var(--aa); }
.badge-aa-large { background: rgba(245,166,35,.18);  color: var(--large); }
.badge-fail     { background: rgba(232,79,79,.18);   color: var(--fail); }

/* ── Grid section ── */
.grid-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 0;
}
.grid-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.grid-scroll {
  margin: 16px auto 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
  max-width: 100%;
}

/* Grid table */
.contrast-grid {
  border-collapse: collapse;
  table-layout: fixed;
}
.contrast-grid th,
.contrast-grid td {
  border: 1px solid var(--border);
}

/* Corner cell */
.grid-corner {
  width: 96px;
  min-width: 96px;
  background: var(--surface);
}

/* Column header */
.col-header {
  width: var(--cell);
  min-width: var(--cell);
  padding: 10px 8px 8px;
  background: var(--surface);
  text-align: center;
  vertical-align: bottom;
  position: sticky;
  top: 0;
  z-index: 2;
}
.col-header-swatch {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  margin: 0 auto 6px;
  border: 2px solid rgba(255,255,255,.1);
}
.col-header-hex {
  display: block;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Row header */
.row-header {
  width: 96px;
  min-width: 96px;
  padding: 8px 10px;
  background: var(--surface);
  position: sticky;
  left: 0;
  z-index: 1;
}
.row-header-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}
.row-header-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.1);
}
.row-header-hex {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Grid cells */
.grid-cell {
  width: var(--cell);
  min-width: var(--cell);
  height: 88px;
  padding: 10px 8px 8px;
  vertical-align: top;
  cursor: default;
  transition: filter .12s;
}
.grid-cell:hover { filter: brightness(1.12); }

.cell-same {
  background: var(--surface2);
  position: relative;
}
.cell-same::after {
  content: '—';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
  font-size: 1.1rem;
}

.cell-ratio {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}
.cell-badges {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cell-badges .badge {
  width: 100%;
  justify-content: center;
}

/* Aa sample text */
.cell-sample {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.empty-state-icon { font-size: 2.5rem; display: block; margin-bottom: 12px; opacity: .4; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 480px;
  max-width: calc(100vw - 32px);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }
.modal-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.import-textarea {
  width: 100%;
  height: 96px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.82rem;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.import-textarea:focus { border-color: #555; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.btn-primary {
  height: 36px;
  padding: 0 18px;
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: var(--radius-sm);
  color: var(--bg);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }

/* ── Custom color picker ── */
.color-picker-popup {
  position: fixed;
  width: 232px;
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,.7);
  z-index: 300;
  flex-direction: column;
  gap: 10px;
  display: none;
}
.color-picker-popup.is-open { display: flex; }

.picker-gradient {
  width: 100%;
  height: 152px;
  border-radius: 6px;
  position: relative;
  cursor: crosshair;
  user-select: none;
  overflow: hidden;
  background:
    linear-gradient(to bottom, transparent, #000),
    linear-gradient(to right, #fff, transparent),
    hsl(var(--ph, 0), 100%, 50%);
}

.picker-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.picker-hue {
  width: 100%;
  height: 12px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 6px;
  background: linear-gradient(to right,
    #f00 0%, #ff0 16.67%, #0f0 33.33%,
    #0ff 50%, #00f 66.67%, #f0f 83.33%, #f00 100%
  );
  outline: none;
  cursor: pointer;
  border: none;
  display: block;
}
.picker-hue::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0,0,0,.25);
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
  cursor: grab;
}
.picker-hue::-webkit-slider-thumb:active { cursor: grabbing; }
.picker-hue::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0,0,0,.25);
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
  cursor: grab;
  border: none;
}

.picker-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
}
.picker-preview {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.1);
  box-shadow: 0 0 0 1px rgba(0,0,0,.4);
}
.picker-hex-input {
  flex: 1;
  background: #252525;
  border: 1px solid #383838;
  border-radius: 5px;
  color: #e8e8e8;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  padding: 6px 10px;
  outline: none;
  text-transform: uppercase;
  transition: border-color .15s;
}
.picker-hex-input:focus { border-color: #555; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 4px; }
  main { padding: 28px 16px 60px; }
  :root { --cell: 78px; }
}
