:root {
  --bg: #0c0d10;
  --panel: #16171d;
  --line: rgba(255, 255, 255, .10);
  --line-strong: rgba(255, 255, 255, .20);
  --text: #f4f4f7;
  --muted: #9b9ca8;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* The tool owns the first screen; the reading content sits below it. */
.app {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

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

/* Keyboard focus must be visible on every control, not just the swatch ones. */
.btn:focus-visible,
select:focus-visible,
.brand:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn:has(:focus-visible) { outline: 2px solid var(--text); outline-offset: 2px; }
.stepper button:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
.fmt:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.pick:has(:focus-visible) { outline: 2px solid var(--fg); outline-offset: 2px; opacity: 1; }

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 22px;
  padding: 13px clamp(16px, 3vw, 30px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(16px) saturate(150%);
  border-bottom: 1px solid var(--line);
}

.brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.brand-mark {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #ff5d5d, #ffd23f, #4ade80, #38bdf8, #a78bfa, #ff5d5d);
  box-shadow: inset 0 0 0 3px var(--bg);
}

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tool-group { display: inline-flex; flex-wrap: wrap; gap: 8px; }

.field { display: inline-flex; align-items: center; gap: 8px; }
.field > label, .field-label { font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }

.select-wrap { position: relative; }
.select-wrap::after {
  content: "▾";
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--muted); font-size: 11px;
}
select {
  appearance: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 30px 9px 12px;
  font-size: 14px;
  cursor: pointer;
}
select:hover { border-color: var(--line-strong); }

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.stepper button { background: none; border: none; padding: 7px 14px; font-size: 17px; line-height: 1; cursor: pointer; color: var(--muted); }
.stepper button:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
#count { min-width: 1.6ch; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { background: #fff; transform: translateY(-1px); box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
.btn-primary kbd {
  font: 600 11px var(--mono);
  background: rgba(0, 0, 0, .14); border-radius: 5px; padding: 2px 6px;
}
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, .05); }

/* ---------- palette ---------- */

.palette {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 14px clamp(14px, 3vw, 30px) 24px;
}

.swatch {
  position: relative;
  flex: 1 1 0;
  min-height: 360px;
  border-radius: var(--radius);
  background: var(--c);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 18px;
  cursor: pointer;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.swatch:hover { transform: translateY(-4px); box-shadow: 0 16px 44px rgba(0, 0, 0, .42); z-index: 1; }

.sw-actions {
  position: absolute; inset: 14px 14px auto 14px;
  display: flex; justify-content: space-between; gap: 8px;
}
.sw-right { display: flex; gap: 8px; }
.icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: none; border-radius: 10px;
  background: rgba(127, 127, 127, .28);
  background: color-mix(in srgb, var(--fg) 16%, transparent);
  color: var(--fg);
  font-size: 15px; line-height: 1; cursor: pointer;
  opacity: .55;
  transition: opacity .15s ease, background .15s ease;
}
.icon svg { display: block; }
.icon:hover { background: color-mix(in srgb, var(--fg) 28%, transparent); opacity: 1; }
.swatch:hover .icon, .icon:focus-visible, .lock.on { opacity: 1; }
.icon:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
/* Locked = solid fill in the swatch's readable color: unmistakable on/off state. */
.lock.on { background: var(--fg); color: var(--c); }

.pick { position: relative; overflow: hidden; }
.pick-input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  margin: 0; padding: 0; border: none; background: none;
  opacity: 0; cursor: pointer;
}

.sw-info { display: flex; flex-direction: column; gap: 11px; position: relative; }

.hex {
  width: 100%;
  background: transparent; border: none;
  border-bottom: 1px solid transparent;
  font: 600 clamp(21px, 2.4vw, 28px)/1.1 var(--mono);
  letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 0; cursor: text;
}
.hex:focus { outline: none; border-bottom-color: currentColor; }
.hex:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; border-radius: 3px; }

.formats { display: flex; flex-wrap: wrap; gap: 6px; }
.fmt {
  display: inline-flex; align-items: center; gap: 7px;
  border: none; border-radius: 8px;
  padding: 6px 10px; /* 24px tall: WCAG 2.2 minimum target size */
  background: rgba(127, 127, 127, .2);
  background: color-mix(in srgb, var(--fg) 12%, transparent);
  color: var(--fg);
  font: 12px/1 var(--mono);
  cursor: pointer;
  transition: background .12s ease;
}
.fmt:hover { background: color-mix(in srgb, var(--fg) 22%, transparent); }
.fmt-label { font: 700 10px/1 var(--font); letter-spacing: .06em; opacity: .75; }
.fmt-val { font-variant-numeric: tabular-nums; }

.contrast { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; cursor: help; }
.sample {
  font: 700 13px/1 var(--font);
  letter-spacing: .02em;
  padding: 3px 7px; border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--fg) 32%, transparent);
}
.badges { display: inline-flex; gap: 5px; }
.badge {
  font: 700 10.5px/1 var(--font);
  letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid transparent;
}
.badge.pass { background: var(--fg); color: var(--c); }
.badge.fail { background: transparent; color: var(--fg); border-color: color-mix(in srgb, var(--fg) 45%, transparent); }
.ratio { font: 11.5px var(--mono); opacity: .8; }

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

.toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translate(-50%, 12px);
  background: #0a0a0c; color: #fff;
  border: 1px solid var(--line-strong);
  padding: 11px 20px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  opacity: 0; pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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

@media (max-width: 760px) {
  .bar { gap: 10px 12px; padding: 10px 14px; }
  .tools { gap: 8px; width: 100%; }
  .field { flex: 1 1 auto; }
  .select-wrap { flex: 1 1 auto; }
  select { width: 100%; }
  #regen { flex: 1 1 100%; justify-content: center; }
  .btn-primary kbd { display: none; }

  /* The formats wrap onto several lines at these widths, so a fixed swatch
     height clipped the hex value off the top and the lock overlapped the chips.
     Let each swatch take the height its content needs and scroll the page. */
  .palette { flex-direction: column; padding-bottom: 18px; }
  .swatch {
    flex: 0 0 auto;
    min-height: 0;
    gap: 14px;
    justify-content: flex-start;
  }
  .sw-actions { position: static; }
  .swatch:hover { transform: none; }
}

@media (max-width: 560px) {
  .tool-group { width: 100%; }
  .tool-group .btn { flex: 1 1 0; justify-content: center; padding: 11px 8px; }
  /* Icons carry the meaning here; each button keeps its aria-label. */
  .btn-text { display: none; }
}

/* Touch: hover never fires, so the swatch controls have to be visible already,
   and every target needs a finger-sized hit area. */
@media (hover: none) {
  .icon { opacity: 1; flex: none; width: 44px; height: 44px; }
  .btn, select, .stepper button { min-height: 44px; }
  .stepper button { padding: 12px 17px; }
  .fmt { min-height: 36px; padding: 9px 11px; }
}

/* A sticky toolbar is worth its space on a tall phone; on a short one it was
   eating 45% of the viewport, so let it scroll away instead. */
@media (max-width: 760px) and (max-height: 820px) {
  .bar { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- reading content below the tool ---------- */

.prose {
  max-width: 1140px;
  margin: 0 auto;
  padding: clamp(38px, 6vw, 76px) clamp(16px, 3vw, 30px) 64px;
}

/* One grid for every kind of block, so paragraphs, the harmony list and the FAQ
   all share the same column width and the same left and right edges. */
.cols {
  display: grid;
  /* min() so a track can collapse below 340px instead of overflowing a small screen. */
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 0 56px;
  align-items: start;
}
.cols > * { min-width: 0; }

.prose h2 {
  margin: 1.85em 0 .6em;
  font-size: clamp(21px, 2.6vw, 27px);
  font-weight: 700;
  letter-spacing: -.02em;
}
.prose h2:first-child { margin-top: 0; }
.prose h3 { margin: 1.5em 0 .35em; font-size: 16.5px; font-weight: 600; }
.prose p, .prose li { color: var(--muted); }
.prose p { margin: 0 0 1.05em; }
.prose li { margin-bottom: .85em; }
.prose li::marker { color: var(--line-strong); }
.prose strong { color: var(--text); font-weight: 600; }

.harmonies { margin: 0; padding-left: 1.15em; }
.qa h3 { margin-top: 0; }
.qa + .qa, .cols .qa { margin-bottom: 1.2em; }
.qa p { margin-bottom: 0; }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 24px clamp(16px, 3vw, 30px) 34px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.site-footer p { margin: 0; }
