/**
 * ToolDuck — Colour tools
 * ===============================================================
 * The pieces the colour suite adds to the shared kit: a swatch that
 * can show transparency, the format rows, swatch grids and the preview
 * blocks the contrast checker draws text in.
 *
 * Deliberately small. Controls, buttons, status messages, badges,
 * cards and the two-column layout all come from tool.css and
 * devtools.css, because a colour tool that looks like a different
 * website is a worse colour tool. What is here is only what has no
 * equivalent already.
 *
 * No glass panels, no gradient chrome, no animation. The colour on
 * this page is the visitor's, and it should be the only thing
 * competing for attention.
 */

/* -----------------------------------------------------------------
   Local tokens
   -----------------------------------------------------------------
   The checkerboard is the one thing the site had no need for until
   now. It is a UI affordance — "this part of the swatch is not part
   of your colour" — so it is drawn in the theme's own greys and never
   in the visitor's colour.
   ----------------------------------------------------------------- */

.color {
  --checker: #d4d4d8;
  --checker-bg: #ffffff;
  --swatch-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

html[data-theme="dark"] .color {
  --checker: #3f3f46;
  --checker-bg: #18181b;
}

/* -----------------------------------------------------------------
   Preview swatch
   ----------------------------------------------------------------- */

.color-preview {
  position: relative;
  border-radius: var(--swatch-radius);
  border: 1px solid var(--border-strong);
  overflow: hidden;
  min-height: 96px;
}

/* The transparency grid, then the colour over it. Two elements rather
   than a background stack, so a screen reader and a screenshot both
   get the colour and the text that explains it. */
.color-preview__checker {
  position: absolute;
  inset: 0;
  background-color: var(--checker-bg);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.color-preview__fill {
  position: relative;
  height: 100%;
  min-height: 96px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: .75rem;
}

.color-preview--tall .color-preview__fill,
.color-preview--tall {
  min-height: 148px;
}

/* The value printed over the swatch picks its own contrast, which is
   the point of the tool rather than a decoration. */
.color-preview__label {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .02em;
  padding: .2rem .45rem;
  border-radius: 6px;
}

/* -----------------------------------------------------------------
   Input rows
   ----------------------------------------------------------------- */

.color-field {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
}

.color-field .field {
  flex: 1 1 auto;
  min-width: 0;
}

/* The native colour input, sized to match the text field beside it
   rather than to look like a form control from 1998. */
.color-native {
  flex: none;
  width: 56px;
  height: 44px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}

.color-native::-webkit-color-swatch-wrapper { padding: 0; }
.color-native::-webkit-color-swatch { border: none; border-radius: 7px; }
.color-native::-moz-color-swatch { border: none; border-radius: 7px; }

.color-field__small {
  flex: none;
  width: 104px;
}

/* A single short numeric field, kept from stretching across the pane. */
.color-count { max-width: 12rem; }

/* A monospace value the visitor reads and copies. */
.color-value {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: .86rem;
  word-break: break-all;
}

/* -----------------------------------------------------------------
   Format rows
   ----------------------------------------------------------------- */

.color-formats {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  overflow: hidden;
  background: var(--surface);
}

.color-format {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  border-top: 1px solid var(--border);
  min-height: 48px;
}

.color-format:first-child { border-top: 0; }

.color-format__label {
  flex: none;
  width: 3.9rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.color-format__value {
  flex: 1 1 auto;
  min-width: 0;
}

.color-format__copy {
  flex: none;
}

/* A row the page is about — the output a conversion page exists to
   show. Marked with a left edge rather than a colour, so it reads the
   same in both themes. */
.color-format--lead {
  background: color-mix(in srgb, var(--brand) 5%, transparent);
  box-shadow: inset 3px 0 0 var(--brand);
}

/* -----------------------------------------------------------------
   Swatch grids
   ----------------------------------------------------------------- */

.color-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: .5rem;
  /* The list is a grid of buttons; the browser's default markers and
     indent sit outside it and read as debris beside each swatch. */
  list-style: none;
  margin: 0;
  padding: 0;
}

.color-swatches li { list-style: none; }

.color-swatch {
  appearance: none;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  min-height: 64px;
}

.color-swatch:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.color-swatch__chip {
  height: 42px;
  width: 100%;
  position: relative;
}

.color-swatch__hex {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: .72rem;
  color: var(--ink-2);
  padding: .3rem .4rem;
  border-top: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-swatch[aria-pressed="true"] {
  border-color: var(--brand-border);
  box-shadow: inset 0 0 0 1px var(--brand);
}

/* Palette families: a strip per family, with the family named above. */
.color-family + .color-family { margin-top: 1rem; }

.color-family__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .4rem;
}

.color-family__name {
  font-size: .9rem;
  font-weight: 700;
}

.color-family__note {
  font-size: .78rem;
  color: var(--ink-3);
  margin: 0;
}

.color-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
}

.color-strip .color-swatch {
  border: 0;
  border-radius: 0;
  min-height: 76px;
}

/* -----------------------------------------------------------------
   Contrast checker
   ----------------------------------------------------------------- */

.color-ratio {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  flex-wrap: wrap;
}

.color-ratio__number {
  font-size: clamp(1.9rem, 1.4rem + 2vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.color-ratio__of {
  color: var(--ink-3);
  font-size: .95rem;
}

.color-checks {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  overflow: hidden;
  background: var(--surface);
}

.color-check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .55rem .8rem;
  border-top: 1px solid var(--border);
  min-height: 46px;
}

.color-check:first-child { border-top: 0; }

.color-check__label { font-size: .88rem; }

.color-check__threshold {
  color: var(--ink-3);
  font-size: .8rem;
  margin-left: .4rem;
}

/* The two text samples. This is the part that answers the visitor's
   real question — "can I read this?" — rather than only reporting a
   number. Nothing here is hidden or scaled: it is the size and weight
   the guideline names. */
.color-samples {
  display: grid;
  gap: .6rem;
}

.color-sample {
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 1rem;
  background: var(--color-sample-bg, #ffffff);
  color: var(--color-sample-fg, #111111);
}

.color-sample__tag {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  opacity: .75;
  margin-bottom: .35rem;
}

.color-sample__text {
  margin: 0;
}

.color-sample--normal .color-sample__text { font-size: 16px; line-height: 1.5; }
.color-sample--large  .color-sample__text { font-size: 24px; font-weight: 700; line-height: 1.35; }

/* -----------------------------------------------------------------
   Gradient generator
   ----------------------------------------------------------------- */

.color-gradient {
  border: 1px solid var(--border-strong);
  border-radius: var(--swatch-radius);
  height: 168px;
}

.color-stops {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.color-stop {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.color-stop .field { flex: 1 1 auto; min-width: 0; }

.color-stop__remove {
  flex: none;
}

/* -----------------------------------------------------------------
   Responsive
   -----------------------------------------------------------------
   Everything above is fluid already; these are the two places where a
   row cannot simply wrap without losing its meaning.
   ----------------------------------------------------------------- */

@media (max-width: 560px) {
  .color-field { flex-wrap: wrap; }
  .color-field__small { width: 100%; }
  .color-format { flex-wrap: wrap; gap: .35rem .6rem; }
  .color-format__label { width: 100%; }
  .color-format__value { flex: 1 1 100%; }
  .color-format__copy { flex: none; }
  .color-strip { grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: repeat(3, 1fr); }
  .color-swatch__hex { font-size: .68rem; }
  .color-preview__label { font-size: .76rem; }
}
