/* ==========================================================================
   QRMagic — design tokens
   ========================================================================== */
:root {
  --bg: #faf4e6;
  --bg-soft: #f0e7d2;
  --surface: rgba(255, 255, 255, 0.66);
  --surface-strong: #fffdf7;
  --border: rgba(24, 38, 66, 0.10);
  --border-strong: rgba(24, 38, 66, 0.18);
  --text: #16233f;
  --text-dim: #455477;
  --text-faint: #586688;
  --on-accent: #ffffff;
  --accent: #2a6aa8;
  --accent-2: #1d4f85;
  --accent-3: #1f6b57;
  --danger: #a8382e;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --shadow: 0 22px 55px -32px rgba(30, 42, 66, 0.40);
  --ring: 0 0 0 3px rgba(42, 106, 168, 0.26);
  --maxw: 1160px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 78% -8%, rgba(42, 106, 168, 0.08), transparent 62%),
    radial-gradient(760px 480px at 8% 4%, rgba(186, 154, 92, 0.12), transparent 60%),
    var(--bg);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeSpeed;
  /* keep content clear of notches / rounded corners in landscape */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-tap-highlight-color: transparent;
}

/* Fixed backgrounds repaint badly (and can jank or band) on iOS Safari.
   Only pin the gradient on precise pointers with room to spare. */
@media (min-width: 981px) and (hover: hover) and (pointer: fine) {
  body { background-attachment: fixed; }
}

/* Touch: remove the legacy 300ms delay and stop text selection on UI chrome. */
button, select, input, summary, .btn, .brand, .site-nav a,
.color-field, .theme-chip, .mini-btn, .cp-swatch, .cp-close {
  touch-action: manipulation;
}
button, .btn, .brand, .site-nav a, summary { -webkit-user-select: none; user-select: none; }

/* Never let a wide child force the viewport to scroll sideways on phones. */
main, header, footer { max-width: 100%; }

img, svg, canvas { display: block; max-width: 100%; }

h1, h2, h3 {
  line-height: 1.15;
  letter-spacing: -0.022em;
  margin: 0 0 0.5rem;
  font-weight: 700;
}

p { margin: 0 0 1rem; }
a { color: var(--accent); }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: rgba(42, 106, 168, 0.08);
  border: 1px solid rgba(42, 106, 168, 0.16);
  color: #21547f;
}

.wrap {
  width: min(100% - 2.5rem, var(--maxw));
  margin-inline: auto;
}
.wrap-narrow { max-width: 780px; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 100;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:where(a, button, input, select, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  background: rgba(250, 244, 230, 0.84);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 66px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.08rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: var(--on-accent);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px -12px rgba(42, 106, 168, 0.55);
}

.brand-accent { color: var(--accent); }

.site-nav {
  display: flex;
  gap: 1.5rem;
  font-size: 0.92rem;
}
.site-nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.35rem 0;
  transition: color 0.16s ease;
}
@media (hover: hover) {
  .site-nav a:hover { color: var(--text); }
}

/* ==========================================================================
   Hero + generator
   ========================================================================== */
.hero { padding: clamp(2.4rem, 5vw, 4.4rem) 0 clamp(2rem, 4vw, 3rem); }

.hero-inner {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(2rem, 4vw, 3.5rem);
  align-items: start;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 1.1rem;
  padding: 0.4rem 0.85rem 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.eyebrow .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-3);
  box-shadow: 0 0 0 4px rgba(31, 107, 87, 0.16);
}

h1 {
  font-size: clamp(2.1rem, 4.6vw, 3.4rem);
  margin-bottom: 1rem;
}

.grad {
  background: linear-gradient(100deg, var(--accent), var(--accent-2) 72%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  color: var(--text-dim);
  font-size: clamp(1rem, 1.4vw, 1.08rem);
  max-width: 46ch;
  margin-bottom: 1.8rem;
}
.lede strong { color: var(--text); }

.qr-form { margin-bottom: 1.4rem; }

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.input-row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.input-shell {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.input-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

#url-input {
  width: 100%;
  height: 54px;
  padding: 0 1rem 0 2.7rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
#url-input::placeholder { color: #63708b; }
@media (hover: hover) {
  #url-input:hover { border-color: rgba(24, 38, 66, 0.30); }
}
#url-input:focus {
  outline: none;
  border-color: rgba(42, 106, 168, 0.60);
  background: rgba(42, 106, 168, 0.04);
  box-shadow: var(--ring);
}
#url-input[aria-invalid="true"] {
  border-color: rgba(168, 56, 46, 0.65);
  box-shadow: 0 0 0 3px rgba(168, 56, 46, 0.15);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.97rem;
  font-weight: 650;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 0 1.15rem;
  height: 54px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.14s ease, box-shadow 0.16s ease, background 0.16s ease, opacity 0.16s ease;
  will-change: transform;
}
.btn:active { transform: translateY(1px) scale(0.995); }

.btn-primary {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), #2c6fad 58%, #1d4f85);
  box-shadow: 0 14px 34px -18px rgba(42, 106, 168, 0.50);
  white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { box-shadow: 0 18px 40px -16px rgba(42, 106, 168, 0.55); }
}

.btn-download {
  width: 100%;
  margin-top: 1.1rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.82);
  border-color: var(--border-strong);
  height: 52px;
}
@media (hover: hover) and (pointer: fine) {
  .btn-download:hover:not(:disabled) {
    background: rgba(42, 106, 168, 0.08);
    border-color: rgba(42, 106, 168, 0.36);
    color: #21547f;
  }
}
.btn-download:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.btn-meta {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.hint {
  font-size: 0.82rem;
  color: var(--text-faint);
  margin: 0.55rem 0 0;
}
.hint code { background: rgba(24,38,66,0.05); border-color: var(--border); color: var(--text-dim); }

.error {
  margin: 0.55rem 0 0;
  font-size: 0.86rem;
  color: var(--danger);
  font-weight: 500;
}

.trust-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.86rem;
  color: var(--text-dim);
}
.trust-row li { display: inline-flex; align-items: center; gap: 0.4rem; }
.trust-row svg { color: var(--accent-3); flex: none; }

/* ==========================================================================
   Preview card
   ========================================================================== */
.preview-card {
  position: sticky;
  top: 88px;
  padding: 1.15rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fffdf7, #fdf8ec);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.preview-head h2 {
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  color: var(--text-faint);
  background: rgba(24, 38, 66, 0.045);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.is-live {
  color: var(--on-accent);
  background: var(--accent-3);
  border-color: transparent;
}
.badge.is-error {
  color: var(--on-accent);
  background: var(--danger);
  border-color: transparent;
}

.preview-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(rgba(24,38,66,0.035) 0% 25%, transparent 0% 50%) 50% / 22px 22px,
    #f4ecd9;
  border: 1px dashed var(--border-strong);
  padding: 1rem;
  overflow: hidden;
}

#qr-canvas {
  /* Height must stay auto: a 100% height would stretch the square code
     whenever the stage is not itself square. */
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  max-width: 100%;
  border-radius: 8px;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  animation: pop 0.24s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: scale(0.965); }
  to { opacity: 1; transform: scale(1); }
}

.placeholder {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.9rem;
  line-height: 1.5;
}
.placeholder svg { margin: 0 auto 0.6rem; opacity: 0.55; }
.placeholder p { margin: 0; }
.placeholder span { font-size: 0.8rem; color: #63708b; }

.preview-target {
  margin: 0.85rem 0 0;
  font-size: 0.82rem;
  font-family: var(--mono);
  color: var(--text-dim);
  word-break: break-all;
  min-height: 1.3em;
}

.preview-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.8rem;
  align-items: end;
  margin-top: 0.95rem;
  padding-top: 0.95rem;
  border-top: 1px solid var(--border);
}

.control label,
.control-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
}

#size-select {
  height: 44px;
  padding: 0 0.7rem;
  font-family: inherit;
  /* 16px on touch keeps iOS Safari from zooming the page on focus */
  font-size: 1rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  width: 100%;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
#size-select:focus { outline: none; box-shadow: var(--ring); border-color: rgba(42,97,87,0.6); }
#size-select option { background: #ffffff; color: var(--text); }

/* --- Color fields (the picker triggers) --------------------------------- */
.control-colors { min-width: 0; }

.color-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.color-field:hover { border-color: rgba(24, 38, 66, 0.32); }
.color-field:focus-visible { outline: none; box-shadow: var(--ring); border-color: rgba(42, 106, 168, 0.6); }
.color-field[aria-expanded="true"] {
  border-color: rgba(42, 106, 168, 0.6);
  background: rgba(42, 106, 168, 0.07);
}

.color-chip {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid rgba(24, 38, 66, 0.22);
  /* checkerboard shows through when a color is very light or transparent-ish */
  background-image:
    linear-gradient(var(--chip), var(--chip)),
    repeating-conic-gradient(#bbb 0% 25%, #fff 0% 50%);
  background-size: 100% 100%, 8px 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.color-field-body { min-width: 0; display: grid; }
.color-field-name {
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  line-height: 1.3;
}
.color-field-hex {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

/* --- Theme chips -------------------------------------------------------- */
.theme-row {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.theme-chip {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid rgba(24, 38, 66, 0.22);
  /* diagonal split: foreground over background */
  background: linear-gradient(135deg, var(--t-fg) 0 50%, var(--t-bg) 50% 100%);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.theme-chip:hover { transform: scale(1.1); }
.theme-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-chip[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* --- Actions + contrast meter ------------------------------------------- */
.color-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.55rem;
  flex-wrap: wrap;
}

.mini-btn {
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  background: rgba(255, 253, 247, 0.8);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.34rem 0.6rem;
  min-height: 30px;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); background: rgba(24, 38, 66, 0.06); }
.mini-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.contrast-meter {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 0.24rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-faint);
  white-space: nowrap;
}
.contrast-meter.is-good { color: var(--on-accent); background: var(--accent-3); border-color: transparent; }
.contrast-meter.is-warn { color: #3a2600; background: #efc061; border-color: transparent; }
.contrast-meter.is-bad  { color: var(--on-accent); background: var(--danger); border-color: transparent; }

/* ==========================================================================
   Color picker dialog
   ========================================================================== */
.cp-dialog {
  width: min(340px, calc(100vw - 2rem));
  padding: 0;
  color: var(--text);
  background: #fffdf7;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 80px -30px rgba(52, 47, 39, 0.45);
  /* reset UA dialog centring: JS positions this next to the trigger */
  margin: auto;
  position: fixed;
  inset: 0;
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.cp-dialog::backdrop {
  background: rgba(30, 42, 66, 0.34);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.cp-dialog[open] { animation: cp-in 0.16s ease-out; }
@keyframes cp-in {
  from { opacity: 0; transform: translateY(6px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.cp-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem 0.7rem;
}
.cp-head h2 { font-size: 1rem; margin: 0 0 0.15rem; }
.cp-sub { margin: 0; font-size: 0.78rem; color: var(--text-faint); }

.cp-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--text-dim);
  background: rgba(24, 38, 66, 0.05);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}
.cp-close:hover { color: var(--text); background: rgba(24, 38, 66, 0.09); }
.cp-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cp-body { padding: 0 1.1rem 0.4rem; }

/* Saturation / brightness pad */
.cp-pad {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 0.62;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none; /* let pointermove drive the pad instead of scrolling */
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, hsl(var(--cp-hue, 220) 100% 50%));
  border: 1px solid rgba(24, 38, 66, 0.14);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.cp-pad:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cp-pad-thumb {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  left: 50%;
  top: 50%;
}

/* Hue slider — styled consistently across engines */
.cp-hue-wrap { margin: 0.85rem 0 0; }
.cp-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.cp-hue {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
.cp-hue::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  border: 1px solid rgba(24, 38, 66, 0.16);
}
.cp-hue::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #5b6780;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}
.cp-hue::-moz-range-track {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  border: 1px solid rgba(24, 38, 66, 0.16);
}
.cp-hue::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #5b6780;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}
.cp-hue:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Readout row */
.cp-readout {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
}
.cp-preview {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(24, 38, 66, 0.18);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.cp-hex-wrap { flex: 1 1 auto; min-width: 0; }
.cp-hex-wrap label {
  display: block;
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.2rem;
}
.cp-hex {
  width: 100%;
  height: 40px;
  padding: 0 0.6rem;
  font-family: var(--mono);
  /* 16px prevents iOS Safari from zooming on focus */
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--text);
  background: #fffdf7;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  text-transform: uppercase;
}
.cp-hex:focus { outline: none; border-color: rgba(42, 106, 168, 0.6); box-shadow: var(--ring); }
.cp-hex[aria-invalid="true"] { border-color: rgba(168, 56, 46, 0.7); }

.cp-error {
  margin: 0.45rem 0 0;
  font-size: 0.76rem;
  color: var(--danger);
}

/* Presets */
.cp-presets {
  border: 0;
  padding: 0;
  margin: 0.9rem 0 0;
  min-width: 0;
}
.cp-presets legend {
  padding: 0;
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.45rem;
}
.cp-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 0.35rem;
}
.cp-swatch {
  aspect-ratio: 1 / 1;
  width: 100%;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(24, 38, 66, 0.16);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.10);
  transition: transform 0.12s ease;
}
.cp-swatch:hover { transform: scale(1.08); }
.cp-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cp-swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px #fffdf7, 0 0 0 4px var(--accent);
}

.cp-hint {
  margin: 0.85rem 0 0;
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text-faint);
}
.cp-hint.is-warn { color: #8a5504; }

.cp-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem 1.05rem;
  margin-top: 0.6rem;
  border-top: 1px solid var(--border);
  padding-bottom: calc(1.05rem + env(safe-area-inset-bottom));
}
.cp-apply { height: 42px; padding: 0 1.1rem; font-size: 0.9rem; }

.stage-msg {
  margin: 0.6rem 0 0;
  font-size: 0.82rem;
  color: var(--accent-3);
  min-height: 1.2em;
}
.stage-msg.is-error { color: var(--danger); }

/* ==========================================================================
   Sections
   ========================================================================== */
.section { padding: clamp(2.8rem, 6vw, 4.6rem) 0; }
.section-alt {
  background: linear-gradient(180deg, transparent, rgba(255, 253, 247, 0.62) 18%, rgba(255, 253, 247, 0.62) 82%, transparent);
  border-top: 1px solid rgba(24, 38, 66, 0.07);
  border-bottom: 1px solid rgba(24, 38, 66, 0.07);
}

.section-head { max-width: 620px; margin-bottom: clamp(1.6rem, 3vw, 2.4rem); }
.section-head h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
.section-head p { color: var(--text-dim); margin: 0; }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  counter-reset: step;
}

.step {
  position: relative;
  padding: 1.4rem 1.3rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.step h3 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.step p { margin: 0; font-size: 0.92rem; color: var(--text-dim); }

.step-num {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  margin-bottom: 0.8rem;
  font-size: 0.85rem;
  font-weight: 750;
  color: var(--on-accent);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.card {
  padding: 1.4rem 1.3rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fffdf7, #fdf9ef);
  border: 1px solid var(--border);
  transition: transform 0.18s ease, border-color 0.18s ease;
}
/* Only lift cards on devices that can actually hover — touch leaves :hover stuck. */
@media (hover: hover) and (pointer: fine) {
  .card:hover { transform: translateY(-2px); border-color: rgba(42, 106, 168, 0.30); }
}
.card-icon { font-size: 1.35rem; display: block; margin-bottom: 0.55rem; }
.card h3 { font-size: 1rem; margin-bottom: 0.35rem; }
.card p { margin: 0; font-size: 0.9rem; color: var(--text-dim); }

/* FAQ */
.faq { display: grid; gap: 0.6rem; }
.faq details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0.15rem 1rem;
}
.faq summary {
  cursor: pointer;
  padding: 0.9rem 0;
  font-weight: 620;
  font-size: 0.97rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  flex: none;
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--accent);
  line-height: 1;
  transition: transform 0.18s ease;
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { margin: 0 0 1rem; font-size: 0.92rem; color: var(--text-dim); max-width: 62ch; }

/* CTA band */
.cta-band { padding: clamp(2.4rem, 5vw, 4rem) 0; }
.cta-inner {
  text-align: center;
  padding: clamp(2rem, 4vw, 3rem) 1.5rem;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(600px 240px at 50% 0%, rgba(42, 106, 168, 0.10), transparent 70%),
    linear-gradient(180deg, #fffdf7, #fbf6e8);
  border: 1px solid var(--border-strong);
}
.cta-inner h2 { font-size: clamp(1.45rem, 3vw, 1.9rem); }
.cta-inner p { color: var(--text-dim); margin-bottom: 1.4rem; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0 2.6rem;
  background: rgba(240, 231, 210, 0.60);
}
.footer-inner {
  display: grid;
  gap: 0.4rem;
  text-align: center;
  justify-items: center;
  font-size: 0.86rem;
  color: var(--text-faint);
  padding-bottom: env(safe-area-inset-bottom);
}
.footer-brand { margin: 0; font-weight: 700; color: var(--text); }
.footer-brand span { color: var(--accent); }
.footer-note { margin: 0; max-width: 46ch; }
.footer-copy { margin: 0; }

/* ==========================================================================
   Responsive — phones, tablets, landscape and touch refinements
   ========================================================================== */

/* Anchor links must clear the sticky header, or headings land underneath it. */
html { scroll-padding-top: 84px; }
section[id] { scroll-margin-top: 84px; }

/* --- Small laptops / large tablets (landscape iPad) ---------------------- */
@media (max-width: 1100px) {
  .hero-inner { gap: 2rem; }
}

/* --- Tablets: iPad portrait, Android tablets, small laptops -------------- */
@media (max-width: 980px) {
  .hero-inner { grid-template-columns: 1fr; }
  .eyebrow { margin-bottom: 0.9rem; }
  .lede { max-width: 60ch; }

  /* Preview moves under the form and stops being sticky. */
  .preview-card {
    position: static;
    order: 2;
    width: 100%;
    max-width: 520px;
    margin-inline: auto;
  }
  /* Keep the square from becoming taller than the screen on small tablets.
     Width is capped on the card instead of the stage, so the preview stays
     a true 1:1 square rather than a squashed rectangle. */
  .preview-stage { margin-inline: auto; }

  .steps, .grid { grid-template-columns: repeat(2, 1fr); }
  .section-head { max-width: 100%; }
}

/* --- Phones ------------------------------------------------------------- */
@media (max-width: 720px) {
  .site-nav { display: none; }
  .hero { padding-top: 1.8rem; }
  .hero-inner { gap: 1.6rem; }

  /* Stack the field and the button so neither needs to shrink. */
  .input-row { flex-direction: column; gap: 0.55rem; }
  .btn-primary { width: 100%; height: 52px; }
  #url-input { height: 52px; }

  .steps, .grid { grid-template-columns: 1fr; }
  .preview-controls { grid-template-columns: 1fr; }
  .preview-controls .control-colors { justify-self: stretch; }
  .preview-stage { padding: 0.85rem; }
  .trust-row { font-size: 0.82rem; gap: 0.4rem 1rem; }
  .cta-inner { padding: 1.8rem 1.1rem; }
  .faq details { padding: 0.15rem 0.85rem; }
  .faq summary { font-size: 0.94rem; }
}

/* --- Small phones (iPhone SE, 360px Androids) --------------------------- */
@media (max-width: 400px) {
  .wrap { width: min(100% - 1.75rem, var(--maxw)); }
  .preview-card { padding: 0.85rem; }
  .preview-controls { gap: 0.7rem; }
  h1 { font-size: 1.95rem; }
  .step, .card { padding: 1.15rem 1.05rem; }
}

/* --- Landscape phones: vertical space is the scarce resource ------------ */
/* Width-guarded so a short desktop window keeps its normal two-column layout. */
@media (max-height: 560px) and (orientation: landscape) and (max-width: 1024px) {
  .hero { padding-block: 1.4rem; }
  .site-header { position: static; }
  /* Constrain width (never height) so the preview stays a true square. */
  .preview-card { max-width: 340px; }
  .section { padding-block: 2rem; }
}

/* --- Touch devices: bigger targets, no sticky hover states -------------- */
@media (hover: none), (pointer: coarse) {
  /* 44px is the recommended minimum comfortable target size. */
  .site-nav a { padding-block: 0.7rem; }
  .faq summary { padding-block: 1rem; }
  .color-field { min-height: 44px; }
  .theme-chip { width: 30px; height: 30px; }
  .cp-swatch { min-height: 32px; }
  .btn { min-height: 46px; }

  /* iOS taps can leave a stuck hover/focus ring on the last tapped element. */
  .card:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
