/* style.css */
/* WCAG Colour Finder — mockup-aligned styles (05-05 rebuild) */

/* Visually hidden but screen-reader readable */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

:root {
  --ink: #111111;
  --ink-mute: #555555;
  --paper: #ffffff;
  --border-w: 2px;
}
* { box-sizing: border-box; }
html, body {
  margin:0; padding:0; background: var(--ink); color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-feature-settings: 'ss01','cv11';
  min-height: 100vh;
}
body { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; display: flex; flex-direction: column; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-ligatures: none; }

/* ——— Top bar (the top of the T) ——— */
.topbar-wrap {
  --topbar-bg: #6BD4AC;
  --topbar-fg: #111111;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  transition: background 0.2s;
  border-bottom: var(--border-w) solid var(--topbar-fg);
}
.topbar {
  padding: 32px 32px 32px;
  max-width: none;
  width: 100%;
  margin: 0;
  position: relative;
}
.title-row {
  position: static;
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1;
  max-width: none;
  gap: 14px;
  margin-bottom: 40px;
}
h1 {
  font-size: 40px; font-weight: 700; margin: 0;
  letter-spacing: -0.02em;
  line-height: 1;
}
.subtitle {
  font-size: 20px; font-weight: 400; margin: 0;
  line-height: 1.4;
  text-align: left;
  max-width: 720px;
}
.credit {
  position: absolute;
  top: 44px; right: 32px;
  font-size: 16px;
  color: var(--topbar-fg);
  line-height: 1;
}
.credit a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
}
.credit a:hover { opacity: 0.75; }
.credit .link-btn {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
  cursor: pointer;
}
.credit .link-btn:hover { opacity: 0.75; }
.credit .link-btn:focus-visible { outline: 2px solid var(--topbar-fg); outline-offset: 2px; }
.controls {
  display: block;
}
.row-one {
  display: flex; gap: 12px; align-items: stretch;
  margin-bottom: 32px;
  max-width: 720px;
  margin-top: 0;
}
.row-two { width: 100%; }
.controls > .card { width: 100%; max-width: none; justify-self: stretch; }
.card {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--topbar-fg);
}
.card-label {
  font-size: 16px; letter-spacing: 0;
  color: var(--topbar-fg); margin-bottom: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
  text-transform: none;
}
.card-label .hint { font-weight: 400; color: var(--topbar-fg); opacity: 0.7; font-size: 16px; }

.base-row { display: flex; align-items: stretch; gap: 10px; }
.hex-input {
  flex: 1;
  display: flex; align-items: center; gap: 10px;
  background: var(--paper);
  border: var(--border-w) solid var(--topbar-fg);
  border-radius: 6px;
  padding: 0 16px;
  height: 72px;
}
.hex-input .swatch {
  width: 36px; height: 36px; border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
  flex-shrink: 0; cursor: pointer; position: relative; overflow: hidden;
}
.hex-input .swatch input[type="color"] {
  position: absolute; inset: -4px; width: 200%; height: 200%; border: 0; opacity: 0; cursor: pointer;
}
.hex-input .hash { color: var(--ink); font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 500; }
.hex-input input[type="text"] {
  flex: 1;
  background: transparent; border: 0; outline: 0;
  color: var(--ink);
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px; font-weight: 500;
  text-transform: uppercase;
  min-width: 0;
}
/* AA / AAA segmented toggle next to Find */
.target-toggle {
  display: inline-flex;
  align-items: stretch;
  height: 72px;
  border: var(--border-w) solid var(--topbar-fg);
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper);
}
.target-opt {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  padding: 0 20px;
  cursor: pointer;
  min-width: 64px;
}
.target-opt + .target-opt {
  border-left: var(--border-w) solid var(--topbar-fg);
}
.target-opt.is-active {
  background: #111111;
  color: #FFFFFF;
}

.toggle-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.toggle {
  position: relative;
  width: 40px; height: 22px;
  background: var(--paper);
  border: var(--border-w) solid var(--topbar-fg);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--topbar-fg);
  transition: transform 0.15s, background 0.15s;
}
.toggle.on { background: var(--topbar-fg); }
.toggle.on::after { transform: translateX(18px); background: var(--topbar-bg); }
.toggle-label { font-size: 16px; color: var(--topbar-fg); }
.toggle-label strong { color: var(--topbar-fg); font-weight: 600; }

.alts {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.alt {
  background: var(--paper);
  border: var(--border-w) solid var(--topbar-fg);
  border-radius: 6px;
  padding: 14px 14px 12px;
  cursor: pointer;
  transition: transform 0.08s;
  display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
}
.alt .chips {
  display: flex; gap: 4px; height: 44px;
  border-radius: 4px; overflow: hidden;
}
.alt .hex { font-size: 16px; text-align: center; color: var(--ink); font-weight: 500; white-space: nowrap; font-family: 'JetBrains Mono', monospace; }
.alt .chip { flex: 1; }
.alt .chip.light { background: var(--alt-light, #fff); }
.alt .chip.dark { background: var(--alt-dark, #000); }
.alt.single .chip { background: var(--alt-colour); }
.alt .hex { font-size: 16px; text-align: center; color: var(--ink); font-weight: 500; white-space: nowrap; font-family: 'JetBrains Mono', monospace; }
.alt.placeholder { cursor: default; background: transparent; border-style: dashed; opacity: 0.55; }
.alt.placeholder .chips { background: transparent; }
.alt.placeholder .chip { background: transparent; }
.alt.placeholder .hex { color: var(--topbar-fg); }

.alts-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 14px 0;
  text-align: left;
  color: var(--topbar-fg);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 16px;
  font-weight: 500;
  opacity: 0.75;
}
.alts-empty__cta {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.alts-empty__cta:hover { text-decoration-thickness: 2px; }
.alts-empty__cta:focus-visible {
  outline: 2px solid var(--topbar-fg, #111111);
  outline-offset: 2px;
}

/* ——— Preview panels — the stem of the T, flex-grow to fill ——— */
.previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
}
.preview {
  padding: 32px 32px 32px;
  position: relative;
  display: flex; flex-direction: column;
  min-width: 0;
}
.preview.is-light .preview-inner { margin-right: auto; margin-left: 0; max-width: 640px; }
.preview.is-dark .preview-inner  { margin-left: 0; margin-right: auto; max-width: 640px; }
.preview-inner { padding-top: 180px; }
.preview.is-dark { border-left: var(--border-w) solid var(--ink); }
.preview-inner { width: 100%; color: var(--specimen, currentColor); }

.bg-tag {
  position: absolute;
  top: 88px;
  display: flex; align-items: center; gap: 10px;
  background: transparent;
  border: var(--border-w) solid var(--specimen, currentColor);
  border-radius: 6px;
  padding: 8px 12px;
  height: 44px;
}
.preview.is-light .bg-tag { right: 32px; }
.preview.is-dark  .bg-tag { right: 32px; }

.fg-tag {
  position: absolute;
  top: 88px; left: 32px;
  display: flex; align-items: center; gap: 10px;
  border: var(--border-w) solid var(--specimen, currentColor);
  border-radius: 6px;
  padding: 8px 0 8px 12px;
  height: 44px;
  color: var(--specimen, currentColor);
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px; font-weight: 500;
}
.fg-tag .fg-swatch {
  width: 20px; height: 20px; border-radius: 3px;
  background: var(--specimen, currentColor);
  border: var(--border-w) solid var(--specimen, currentColor);
  flex-shrink: 0;
}

/* Section label above each tag */
.tag-label {
  position: absolute;
  top: 64px;
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--specimen, currentColor);
  line-height: 1;
}
/* A11Y-03 fix: tag-labels are UI chrome — must pass 4.5:1 on panel background */
.preview.is-light .tag-label { color: #555555; }
.preview.is-dark .tag-label { color: #d1d5db; }
/* A11Y-03 fix: fg-tag/bg-tag hex text must pass on panel bg regardless of user colour */
.preview.is-light .fg-tag { color: var(--ink); }
.preview.is-light .bg-tag .hash-sm,
.preview.is-light .bg-tag input[type="text"] { color: var(--ink); }
.preview.is-light .copy-btn { color: var(--ink); border-left-color: var(--specimen, currentColor); }
.preview .tag-label.is-fg { left: 32px; }
.preview .tag-label.is-bg { right: 32px; }

/* Copy button lives at the end of fg-tag and bg-tag */
.copy-btn {
  appearance: none;
  background: transparent;
  border: 0;
  border-left: var(--border-w) solid var(--specimen, currentColor);
  align-self: stretch;
  margin-left: 4px;
  padding: 0 12px;
  cursor: pointer;
  color: var(--specimen, currentColor);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: 'Inter', sans-serif;
  font-size: 16px; font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity 0.15s;
}
.copy-btn:hover { opacity: 0.65; }
.copy-btn svg { width: 16px; height: 16px; display: block; }
.copy-btn .check-icon { display: none; }
.copy-btn.copied .copy-icon { display: none; }
.copy-btn.copied .check-icon { display: block; }
.bg-tag .label {
  display: none;
}
.bg-tag .swatch-sm {
  width: 20px; height: 20px; border-radius: 3px;
  border: var(--border-w) solid var(--specimen, currentColor);
  cursor: pointer; position: relative; overflow: hidden; flex-shrink: 0;
}
.bg-tag .swatch-sm input[type="color"] { position: absolute; inset: -4px; width: 200%; height: 200%; border: 0; opacity: 0; cursor: pointer; }
.bg-tag .hash-sm { color: var(--specimen, currentColor); font-size: 16px; font-weight: 500; }
.bg-tag input[type="text"] {
  background: transparent; border: 0; outline: 0;
  color: var(--specimen, currentColor);
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px; font-weight: 500;
  text-transform: uppercase;
  width: 78px;
}

/* Top of panel: ratio + pills side by side */
.ratio-row {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  margin: 0 0 40px;
  flex-wrap: nowrap;
}
@media (max-width: 991px) {
  .ratio-row { flex-wrap: wrap; }
}
.ratio {
  font-family: 'JetBrains Mono', monospace;
  font-size: 64px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.85;
  margin: 0;
  flex-shrink: 0;
}
.pills {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 10px 18px;
  margin: 0;
  justify-content: start;
}
@media (max-width: 1400px) {
  .pills { grid-template-columns: repeat(2, auto); }
}
.pill-wrap { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: 5px;
  font-size: 17px; font-weight: 700; letter-spacing: 0;
  text-transform: none;
  border: var(--border-w) solid var(--specimen, currentColor);
}
.pill.pass { background: var(--specimen, currentColor); color: var(--bg-for-specimen, transparent); }
.pill.fail { background: transparent; color: var(--specimen, currentColor); opacity: 0.45; }
.pill .glyph { font-size: 16px; line-height: 1; }
.pill-label { font-size: 16px; color: var(--specimen, currentColor); opacity: 0.8; font-weight: 500; padding-left: 2px; }
/* A11Y-03 fix: pill-labels and fail pills must pass 4.5:1 regardless of user colour */
.preview.is-light .pill-label { color: #555555; opacity: 1; }
.preview.is-light .pill.fail { color: #555555; opacity: 1; border-color: #d1d5db; }
.preview.is-dark .pill-label { color: #d1d5db; opacity: 1; }
.preview.is-dark .pill.fail { color: #d1d5db; opacity: 1; border-color: #4b5563; }

/* Specimen */
.heading {
  font-size: 64px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.02;
  margin: 0 0 22px;
}
.para {
  font-size: 16px;
  line-height: 1.6;
  font-weight: 400;
  margin: 0 0 26px;
  max-width: 52ch;
}
.digits {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin: 0;
}

/* Mobile tabs (hidden on desktop) */
.preview-tabs {
  display: none;
  background: transparent;
}
.preview-tabs-inner {
  display: flex;
}
.tab-btn {
  flex: 1;
  appearance: none;
  border: 0;
  border-bottom: var(--border-w) solid var(--ink);
  background: #FFFFFF;
  color: var(--light-fg, var(--ink));
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 18px;
  padding: 18px 0;
  cursor: pointer;
}
.tab-btn[data-tab="dark"] {
  background: var(--ink);
  color: var(--dark-fg, #FFFFFF);
}
.tab-btn.is-active {
  border-bottom: var(--border-w) solid transparent;
}

@media (max-width: 767px) {
  .topbar { padding: 32px 24px; display: flex; flex-direction: column; }
  .credit { position: static; margin: 8px 0; order: 2; }
  .title-row { margin: 0; gap: 0; display: contents; }
  .controls { display: contents; }
  .row-two { display: contents; }
  h1 { order: 1; margin: 0; }
  .subtitle { order: 3; margin: 8px 0 0; }
  .row-one { order: 4; margin-top: 24px; margin-bottom: 0; }
  .alts { order: 5; margin-top: 12px; }
  h1 { font-size: 32px; }
  .subtitle { font-size: 16px; }
  .row-one {
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
  }
  .hex-input { flex: 1 1 100%; height: 64px; }
  .target-toggle { flex: 0 0 auto; height: 56px; }
  .target-opt { padding: 0 16px; min-width: 56px; font-size: 16px; }
  .alts {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .alts-empty { padding: 10px 0; }
  .alt { flex-direction: row; align-items: center; padding: 10px 14px; gap: 14px; }
  .alt .chips { flex: 0 0 72px; height: 40px; }
  .alt .hex { flex: 1; text-align: left; }

  /* Tabs replace side-by-side previews */
  .preview-tabs { display: block; }
  .previews { display: block; }
  /* fg / bg tags laid out as 2-col grid: fg left, bg right */
  .preview {
    display: none;
    padding: 24px 24px 32px;
    border-left: 0 !important;
    position: relative;
  }
  .preview.is-visible { display: grid; }
  .preview.is-visible {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "fg-label bg-label"
      "fg-tag   bg-tag"
      "body     body";
    column-gap: 16px;
    row-gap: 8px;
  }
  .preview-inner { grid-area: body; padding-top: 32px; max-width: none !important; margin: 0 !important; }
  .tag-label { position: static; display: block; margin: 0; }
  .tag-label.is-fg { grid-area: fg-label; justify-self: start; }
  .tag-label.is-bg { grid-area: bg-label; justify-self: end; }
  .fg-tag {
    grid-area: fg-tag;
    position: static;
    display: inline-flex;
    justify-self: start;
    width: fit-content;
    max-width: 100%;
    margin: 0;
  }
  .bg-tag {
    grid-area: bg-tag;
    position: static;
    display: inline-flex;
    justify-self: end;
    width: fit-content;
    max-width: 100%;
    margin: 0;
    right: auto !important;
  }

  .ratio-row { flex-wrap: wrap; }
  .pills {
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
  }
  .heading { font-size: 40px; }
  .ratio { font-size: 48px; }
  .para { font-size: 18px; }
}

/* RESP-01 + RESP-02 — narrow-viewport fixes (Phase 9) */
@media (max-width: 480px) {
  /* RESP-01: pills relax from 4-col to 2-col so full label text fits */
  .pills {
    grid-template-columns: repeat(2, 1fr);
  }
  .pill-wrap { min-width: 0; }            /* allow grid cell to shrink and contain wrapping label */
  .pill {
    flex-wrap: wrap;                       /* allow glyph + Pass/Fail to wrap if cell is very narrow */
    padding: 6px 12px;                     /* trim padding so 2-col fits the 320px floor */
  }
  .pill-label {
    overflow-wrap: anywhere;               /* defensive: break long words if they ever appear */
  }

  /* RESP-02: hex input scales fluidly down to the 320px floor */
  .row-one { min-width: 0; }
  .hex-input {
    min-width: 0;
    padding: 0 12px;                       /* trim from 16px so 320px viewport fits */
  }
  .hex-input input[type="text"],
  .hex-input .hash {
    font-size: clamp(16px, 4.5vw, 22px);   /* iOS-safe floor (≥16px avoids Safari focus zoom — D-05) */
  }
}

/* --- Unified focus — A11Y-03 --- */
.topbar-wrap :focus-visible,
.topbar-wrap .hex-input:focus-within {
  outline: 2px solid var(--topbar-fg, #111111);
  outline-offset: 2px;
}
.preview :focus-visible {
  outline: 2px solid var(--specimen, currentColor);
  outline-offset: 2px;
}
.preview-tabs .tab-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}
.input--error { outline: 2px solid #dc2626 !important; }

/* --- Alts selection + focus (A11Y-03) --- */
.alt.is-selected {
  outline: 2px solid var(--topbar-fg, #111111);
  outline-offset: 2px;
}
button.alt {
  font: inherit;
  text-align: left;
  color: inherit;
}
button.alt:focus-visible {
  outline: 2px solid var(--topbar-fg, #111111);
  outline-offset: 2px;
}

/* --- Feedback modal --- */
.fb-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
@media (max-width: 767px) {
  .fb-modal { padding: 24px; }
}
.fb-modal[hidden] { display: none; }
.fb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.fb-panel {
  position: relative;
  background: #fff;
  color: #111;
  border: 2px solid #111;
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.fb-panel h2 { margin: 0 0 8px; font-size: 20px; font-weight: 700; }
.fb-hint { margin: 0 0 12px; font-size: 14px; color: #555; }
.fb-panel textarea {
  width: 100%;
  font: 16px 'Inter', system-ui, sans-serif;
  padding: 10px;
  border: 2px solid #111;
  border-radius: 4px;
  resize: vertical;
}
.fb-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.fb-actions button {
  font: 600 14px 'Inter', system-ui, sans-serif;
  padding: 8px 16px;
  border-radius: 4px;
  border: 2px solid #111;
  cursor: pointer;
}
.fb-cancel { background: #fff; color: #111; }
.fb-submit { background: #111; color: #fff; }
.fb-submit:disabled { opacity: 0.6; cursor: default; }
.fb-status { margin: 10px 0 0; font-size: 14px; min-height: 1.2em; }
.fb-status a { color: #111; }

.fb-context {
  margin-top: 12px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px 10px;
  background: #fafafa;
}
.fb-context > summary {
  cursor: pointer;
  font-weight: 500;
  color: #555;
  user-select: none;
}
.fb-context[open] > summary { margin-bottom: 8px; }
.fb-context-list {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  max-height: 200px;
  overflow: auto;
}
.fb-context-list dt {
  color: #555;
  font-weight: 500;
}
.fb-context-list dd {
  margin: 0;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  word-break: break-all;
  color: #111;
}
