/* =====================================================================
   Color Match — page styles
   Self-contained on top of style.css. Reuses the site's tokens
   (--ink, --line, --line-2, --muted) and its Apple-style ease curve.
   ===================================================================== */

:root {
  --cm-accent: #3b82f6;
  --cm-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --cm-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Hero ---------- */
.tool-hero h1 {
  background: linear-gradient(180deg, #18181b 0%, #3f3f46 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Card shell + ambient glow ---------- */
.cm-card-wrap {
  position: relative;
  isolation: isolate;
  animation: cmRise 0.8s var(--cm-ease) both;
}
.cm-card-wrap::before {
  content: "";
  position: absolute;
  inset: -60px -30px;
  z-index: -1;
  background: radial-gradient(
    55% 55% at 20% 0%,
    color-mix(in srgb, var(--cm-accent) 20%, transparent),
    transparent 70%
  );
  filter: blur(50px);
  opacity: 0.55;
  transition: background 0.5s var(--cm-ease);
  pointer-events: none;
}

.tool-card.cm-card {
  border-radius: 24px;
  background: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 1px 1px rgba(9, 9, 11, 0.04),
    0 10px 24px -14px rgba(9, 9, 11, 0.14),
    0 32px 64px -32px color-mix(in srgb, var(--cm-accent) 22%, transparent);
}

/* ---------- Input row ---------- */
.cm-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
  border-radius: 16px;
  background: #fafafa;
  box-shadow: inset 0 0 0 1px var(--line-2);
  transition: box-shadow 0.25s var(--cm-ease), background 0.25s var(--cm-ease);
}
.cm-input-row:focus-within {
  background: #fff;
  box-shadow:
    inset 0 0 0 1.5px var(--ink),
    0 0 0 5px color-mix(in srgb, var(--cm-accent) 14%, transparent);
}

#cm-picker {
  width: 42px !important;
  height: 42px !important;
  flex: none;
  border: none;
  padding: 0;
  border-radius: 12px !important;
  cursor: pointer;
  box-shadow:
    0 0 0 1px var(--line-2),
    0 3px 8px -3px rgba(9, 9, 11, 0.25),
    inset 0 1px 1px rgba(255, 255, 255, 0.5) !important;
  transition: transform 0.2s var(--cm-ease-spring);
}
#cm-picker:hover {
  transform: scale(1.06) rotate(-2deg);
}
#cm-picker::-webkit-color-swatch-wrapper {
  padding: 3px;
}
#cm-picker::-webkit-color-swatch {
  border: none;
  border-radius: 9px;
}

#cm-input {
  flex: 1;
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 10px 6px;
  font: inherit;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  color: var(--ink);
  outline: none;
}
#cm-input.is-invalid {
  color: #ef4444;
}
#cm-error {
  margin-top: 6px;
  padding-left: 4px;
  font-size: 12px;
  color: #ef4444;
  min-height: 1em;
}

/* ---------- Hero preview ---------- */
.cm-hero-preview {
  position: relative;
  margin-top: 20px;
  height: 140px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(9, 9, 11, 0.06),
    inset 0 1px 12px rgba(255, 255, 255, 0.25),
    0 20px 40px -24px rgba(9, 9, 11, 0.35);
  transition: background 0.4s var(--cm-ease);
}
.cm-hero-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.06) 30%, rgba(255, 255, 255, 0) 55%);
  mix-blend-mode: overlay;
  pointer-events: none;
}
.cm-hero-chip {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(16, 16, 18, 0.4);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  color: #fff;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.cm-hero-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
}

/* ---------- Toolbar ---------- */
.cm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.cm-toolbar-hint {
  font-size: 12.5px;
  color: var(--muted);
}
.cm-export-btn {
  flex: none;
}

/* ---------- Sections ---------- */
.cm-section {
  margin-top: 40px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.cm-section-title {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.cm-section-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Contrast cards ---------- */
.cm-contrast-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .cm-contrast-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.cm-contrast-card {
  position: relative;
  border-radius: 16px;
  padding: 20px;
  box-shadow: inset 0 0 0 1px rgba(9, 9, 11, 0.06);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.25s var(--cm-ease), box-shadow 0.25s var(--cm-ease);
}
.cm-contrast-card:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 1px rgba(9, 9, 11, 0.08),
    0 14px 28px -18px rgba(9, 9, 11, 0.35);
}
.cm-contrast-sample {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  background: rgba(127, 127, 127, 0.12);
}
.cm-contrast-meta {
  flex: 1;
  min-width: 0;
}
.cm-contrast-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cm-contrast-name {
  font-size: 13.5px;
  font-weight: 600;
}
.cm-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  padding: 2px 7px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px currentColor;
}
.cm-contrast-ratio-row {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cm-contrast-ratio {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  opacity: 0.85;
}
.cm-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
}
.cm-badge--pass {
  background: rgba(16, 185, 129, 0.16);
  color: #059669;
}
.cm-badge--warn {
  background: rgba(245, 158, 11, 0.18);
  color: #b45309;
}
.cm-badge--fail {
  background: rgba(239, 68, 68, 0.16);
  color: #dc2626;
}
.cm-contrast-card .cm-copy {
  position: absolute;
  top: 12px;
  right: 12px;
}

/* ---------- Mode cards ---------- */
.cm-mode-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .cm-mode-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.cm-mode-card {
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 0 0 1px var(--line-2);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.25s var(--cm-ease);
}
.cm-mode-card:hover {
  transform: translateY(-2px);
}
.cm-mode-swatch {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 6px 16px -6px rgba(0, 0, 0, 0.35);
}
.cm-mode-meta {
  flex: 1;
  min-width: 0;
}
.cm-mode-label {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.9;
}
.cm-mode-hex-row {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cm-mode-hex {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  opacity: 0.85;
}
.cm-mode-note {
  margin-top: 6px;
  font-size: 11.5px;
  opacity: 0.6;
  line-height: 1.5;
}

/* ---------- Ramp ---------- */
.cm-ramp {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line-2);
}
@media (min-width: 640px) {
  .cm-ramp {
    grid-template-columns: repeat(10, 1fr);
    gap: 0;
  }
}
.cm-ramp-swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 2px;
  height: 96px;
  padding: 10px;
  transition: flex 0.3s var(--cm-ease), filter 0.15s var(--cm-ease);
}
@media (min-width: 640px) {
  .cm-ramp-swatch:hover {
    flex: 1.6;
  }
}
.cm-ramp-swatch:hover {
  filter: brightness(1.03);
}
.cm-ramp-step {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.85;
}
.cm-ramp-hex {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 9.5px;
  opacity: 0;
  transform: translateY(3px);
  transition: 0.2s var(--cm-ease);
  white-space: nowrap;
}
.cm-ramp-swatch:hover .cm-ramp-hex,
.cm-ramp-swatch:focus-visible .cm-ramp-hex {
  opacity: 0.75;
  transform: translateY(0);
}
.cm-ramp-swatch.is-copied::after {
  content: "Copied";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.85);
  color: #fff;
  animation: cmFade 0.9s var(--cm-ease) forwards;
}

/* ---------- Harmony ---------- */
.cm-harmony-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 640px) {
  .cm-harmony-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
.cm-harmony-swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  height: 92px;
  padding: 12px;
  border-radius: 14px;
  box-shadow:
    0 0 0 1px rgba(9, 9, 11, 0.08),
    0 1px 2px rgba(9, 9, 11, 0.04);
  transition: transform 0.25s var(--cm-ease), box-shadow 0.25s var(--cm-ease);
}
.cm-harmony-swatch:hover {
  transform: translateY(-3px);
  box-shadow:
    0 0 0 1px rgba(9, 9, 11, 0.1),
    0 16px 28px -16px rgba(9, 9, 11, 0.35);
}
.cm-harmony-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.cm-harmony-hex {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.cm-harmony-swatch.is-copied::after {
  content: "Copied";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.85);
  color: #fff;
  animation: cmFade 0.9s var(--cm-ease) forwards;
}

/* ---------- Copy buttons (contrast + mode cards) ---------- */
.cm-copy {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(127, 127, 127, 0.12);
  color: currentColor;
  transition: background 0.2s var(--cm-ease), color 0.2s var(--cm-ease), transform 0.15s var(--cm-ease-spring);
}
.cm-copy svg {
  width: 13px;
  height: 13px;
  transition: opacity 0.15s var(--cm-ease), transform 0.2s var(--cm-ease-spring);
}
.cm-copy:hover {
  background: rgba(127, 127, 127, 0.22);
  transform: scale(1.06);
}
.cm-copy:active {
  transform: scale(0.92);
}
.cm-copy.is-copied {
  background: #10b981;
  color: #fff;
}
.cm-copy.is-copied svg {
  opacity: 0;
  transform: scale(0.5);
}
.cm-copy.is-copied::after {
  content: "";
  position: absolute;
  width: 11px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: translateY(-1px) rotate(-45deg) scale(0);
  animation: cmCheckIn 0.35s var(--cm-ease-spring) 0.05s forwards;
}
.cm-mode-hex-row .cm-copy,
.cm-contrast-ratio-row ~ .cm-copy {
  position: relative;
}

/* ---------- Keyframes ---------- */
@keyframes cmRise {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes cmCheckIn {
  to {
    transform: translateY(-1px) rotate(-45deg) scale(1);
  }
}
@keyframes cmFade {
  0% { opacity: 0; }
  15% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .cm-card-wrap,
  .cm-contrast-card,
  .cm-mode-card,
  .cm-harmony-swatch,
  .cm-ramp-swatch,
  .cm-copy,
  #cm-picker {
    animation: none !important;
    transition: none !important;
  }
}