:root {
  --bg: #f4f1ea;
  --surface: #fffaf1;
  --surface-2: #eee5d7;
  --text: #171717;
  --muted: #665f56;
  --line: rgba(23, 23, 23, .14);
  --accent: #c7832f;
  --accent-dark: #7a471d;
  --shadow: 0 24px 80px rgba(34, 25, 15, .15);
  --radius-lg: 30px;
  --radius-md: 22px;
  --tap: 48px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff4d8 0, transparent 38rem), var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow-x: hidden;
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(199, 131, 47, .55); outline-offset: 3px; }
.wrap { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 241, 234, .94);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.header-grid { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.brand { min-width: 0; display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #171717;
  color: #fff;
  font-weight: 800;
  letter-spacing: -.04em;
}
.brand span:last-child { min-width: 0; }
.brand strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { display: block; color: var(--muted); font-size: .85rem; }
.top-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top-nav a { min-height: 42px; display: inline-flex; align-items: center; text-decoration: none; color: var(--muted); padding: 9px 12px; border-radius: 999px; white-space: nowrap; }
.top-nav a:hover { background: var(--surface-2); color: var(--text); }
.top-nav a[aria-current="page"] { background: var(--text); color: #fff; }

.hero { padding: 82px 0 42px; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 32px; align-items: center; }
.eyebrow { margin: 0 0 10px; color: var(--accent-dark); text-transform: uppercase; letter-spacing: .11em; font-size: .78rem; font-weight: 800; }
h1, h2, h3 { line-height: 1.08; letter-spacing: -.04em; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(2.35rem, 7vw, 5.4rem); max-width: 850px; }
h2 { font-size: clamp(1.65rem, 4vw, 3rem); }
h3 { font-size: clamp(1.28rem, 3vw, 2rem); }
.lead { max-width: 720px; color: var(--muted); font-size: clamp(1.03rem, 2.2vw, 1.28rem); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.button {
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  padding: 13px 20px;
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  touch-action: manipulation;
}
.button:hover { transform: translateY(-1px); }
.button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.hero-card, .panel {
  background: rgba(255, 250, 241, .88);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.hero-card { padding: 28px; }
.hero-card strong { font-size: 1.3rem; }
.hero-card p { color: var(--muted); margin-bottom: 0; }
.panel { padding: clamp(20px, 4vw, 34px); margin-block: 28px; }
.section-head { margin-bottom: 20px; }
.section-head p:not(.eyebrow) { color: var(--muted); max-width: 720px; }

.upload-box { display: grid; gap: 16px; }
.dropzone {
  min-height: 220px;
  border: 2px dashed rgba(23, 23, 23, .26);
  border-radius: 24px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: rgba(255,255,255,.45);
  cursor: pointer;
  touch-action: manipulation;
}
.dropzone:hover { border-color: rgba(122, 71, 29, .5); background: rgba(255,255,255,.62); }
.dropzone input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; pointer-events: none; }
.dropzone strong { font-size: 1.18rem; }
.dropzone small { color: var(--muted); display: block; max-width: 44rem; }
.drop-icon { width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; margin-bottom: 12px; background: var(--text); color: #fff; font-size: 2rem; line-height: 1; }
.status { min-height: 1.4em; color: var(--muted); margin: 0; overflow-wrap: anywhere; }
.status.error { color: #a01616; font-weight: 700; }

.result { display: grid; grid-template-columns: minmax(0, .95fr) minmax(280px, 1.05fr); gap: 22px; margin-top: 28px; }
.hidden { display: none !important; }
.preview-card, .result-card { border-radius: 24px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.preview-card img { width: 100%; height: 100%; min-height: 320px; object-fit: contain; background: #222; }
.result-card { padding: 24px; }
.swatch-row { display: flex; gap: 14px; margin: 20px 0; }
.swatch { width: 86px; height: 86px; border-radius: 24px; border: 1px solid rgba(0,0,0,.18); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.facts { display: grid; gap: 10px; margin: 0; }
.facts div { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 800; text-align: right; overflow-wrap: anywhere; }
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.palette-item { width: 38px; height: 38px; border-radius: 12px; border: 1px solid rgba(0,0,0,.18); }

.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.small-panel { margin: 0; box-shadow: none; }
.small-panel p { color: var(--muted); }
.history-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.history-card { display: grid; gap: 6px; padding: 16px; border-radius: 18px; background: rgba(255,255,255,.48); border: 1px solid var(--line); }
.history-card small { color: var(--muted); overflow-wrap: anywhere; }
.mini-swatch { width: 34px; height: 34px; border-radius: 12px; border: 1px solid rgba(0,0,0,.18); }
.site-footer { padding: 36px 0 calc(36px + env(safe-area-inset-bottom)); color: var(--muted); }
.footer-links a,
.site-footer a { color: var(--text); font-weight: 700; text-decoration-thickness: .08em; text-underline-offset: .18em; }
.legal-page { padding: 56px 0 20px; }
.legal-panel { max-width: 920px; }
.legal-panel h1 { margin-bottom: 28px; }
.legal-panel h2 { font-size: clamp(1.25rem, 2.4vw, 1.8rem); margin-top: 30px; margin-bottom: 10px; letter-spacing: -.03em; }
.legal-panel p { color: var(--muted); overflow-wrap: anywhere; }
.legal-panel strong { color: var(--text); }
.setup-error {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 18px;
  background: #fff0f0;
  color: #7f1414;
  border: 1px solid rgba(127, 20, 20, .25);
}

@media (max-width: 900px) {
  .hero-grid, .result, .info-grid { grid-template-columns: 1fr; }
  .hero { padding: 54px 0 30px; }
  .hero-card { max-width: 720px; }
}

@media (max-width: 760px) {
  :root { --radius-lg: 22px; --radius-md: 18px; }
  .wrap { width: min(100% - 24px, 1120px); }
  .site-header { position: sticky; }
  .header-grid { min-height: auto; align-items: stretch; flex-direction: column; gap: 10px; padding: 10px 0 9px; }
  .brand { width: 100%; gap: 10px; }
  .brand-mark { width: 42px; height: 42px; border-radius: 14px; }
  .brand strong { font-size: .98rem; }
  .brand small { font-size: .78rem; }
  .top-nav {
    width: calc(100% + 24px);
    margin-left: -12px;
    padding: 0 12px 3px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .top-nav::-webkit-scrollbar { display: none; }
  .top-nav a { min-height: 40px; padding: 8px 12px; background: rgba(255,255,255,.55); font-size: .94rem; }
  .hero { padding: 34px 0 18px; }
  h1 { font-size: clamp(2.05rem, 12vw, 3.15rem); letter-spacing: -.055em; }
  h2 { font-size: clamp(1.55rem, 8vw, 2.1rem); }
  .lead { font-size: 1.02rem; }
  .hero-actions { display: grid; grid-template-columns: 1fr; margin-top: 22px; }
  .button { width: 100%; min-height: 50px; padding: 14px 18px; }
  .hero-card, .panel { border-radius: var(--radius-lg); box-shadow: 0 16px 44px rgba(34, 25, 15, .12); }
  .hero-card { padding: 20px; }
  .panel { padding: 18px; margin-block: 18px; }
  .dropzone { min-height: 180px; padding: 20px 16px; border-radius: 20px; }
  .drop-icon { width: 48px; height: 48px; border-radius: 16px; font-size: 1.8rem; }
  .dropzone strong { font-size: 1.03rem; }
  .dropzone small { font-size: .91rem; }
  .result { gap: 14px; margin-top: 20px; }
  .preview-card, .result-card { border-radius: 20px; }
  .preview-card img { min-height: 230px; max-height: 52vh; }
  .result-card { padding: 18px; }
  .swatch-row { gap: 10px; margin: 16px 0; }
  .swatch { flex: 1 1 0; min-width: 0; height: 74px; border-radius: 18px; }
  .facts div { align-items: flex-start; flex-direction: column; gap: 2px; }
  .facts dd { text-align: left; }
  .palette-item { width: 34px; height: 34px; border-radius: 11px; }
  .history-grid { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 40px 1fr; align-items: center; }
  .history-card small { grid-column: 2; }
  .legal-page { padding: 22px 0 8px; }
  .legal-panel h1 { margin-bottom: 20px; }
  .legal-panel h2 { margin-top: 24px; }
}

@media (max-width: 420px) {
  .wrap { width: min(100% - 18px, 1120px); }
  .panel { padding: 16px; }
  .top-nav { width: calc(100% + 18px); margin-left: -9px; padding-left: 9px; padding-right: 9px; }
  .hero-card { padding: 18px; }
  .result-card { padding: 16px; }
  .preview-card img { min-height: 210px; }
  .site-footer { font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

.result-hint {
  color: var(--muted);
  margin: -4px 0 16px;
}

.matches-block {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.ral-matches {
  display: grid;
  gap: 9px;
}

.ral-match {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.54);
}

.ral-match.best {
  background: rgba(255,255,255,.82);
  box-shadow: 0 10px 24px rgba(34, 25, 15, .08);
}

.ral-match-swatch {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.28);
}

.ral-match-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.ral-match-text strong,
.ral-match-text small {
  overflow-wrap: anywhere;
}

.ral-match-text small {
  color: var(--muted);
}

@media (max-width: 420px) {
  .ral-match { grid-template-columns: 40px 1fr; gap: 10px; padding: 9px; }
  .ral-match-swatch { width: 40px; height: 40px; border-radius: 12px; }
}

.selection-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.selection-toolbar {
  display: grid;
  gap: 2px;
  padding: 4px 4px 0;
}

.selection-toolbar small {
  color: var(--muted);
}

.canvas-shell {
  width: 100%;
  overflow: hidden;
  border-radius: 18px;
  background: #222;
  border: 1px solid rgba(0,0,0,.18);
  touch-action: none;
}

#photoCanvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: move;
  touch-action: none;
  user-select: none;
}

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button.compact {
  min-height: 42px;
  padding: 10px 14px;
  width: auto;
  font-size: .95rem;
}

@media (max-width: 760px) {
  .selection-card { padding: 10px; }
  .selection-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .button.compact { width: 100%; min-height: 46px; padding: 11px 12px; }
}

@media (max-width: 420px) {
  .selection-actions { grid-template-columns: 1fr; }
}

.brand-photo {
  padding: 0;
  overflow: hidden;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid rgba(199, 131, 47, .95);
  box-shadow: 0 8px 22px rgba(34, 25, 15, .14);
}

.brand-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.hero-logo-card {
  display: grid;
  justify-items: start;
  gap: 14px;
}

.hero-logo {
  width: min(220px, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid rgba(199, 131, 47, .95);
  box-shadow: 0 18px 50px rgba(34, 25, 15, .18);
  background: var(--surface);
  object-fit: cover;
}

@media (max-width: 760px) {
  .brand-photo {
    width: 46px;
    height: 46px;
    border-radius: 50%;
  }
  .hero-logo-card {
    justify-items: center;
    text-align: center;
  }
  .hero-logo {
    width: min(190px, 58vw);
  }
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.compare-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255,255,255,.52);
  border: 1px solid var(--line);
}

.compare-card h3 {
  font-size: clamp(1.2rem, 2.5vw, 1.7rem);
}

.compare-card p {
  margin: 0;
  color: var(--muted);
}

.compare-upload {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
  text-align: center;
}

.compare-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.compare-canvas-shell {
  overflow: hidden;
  border-radius: 18px;
  background: #242424;
  min-height: 220px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0,0,0,.18);
}

.compare-canvas-shell canvas {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}

.compare-readout {
  min-height: 64px;
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.62);
  color: var(--muted);
}

.compare-readout strong {
  color: var(--text);
}

.compare-color-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.compare-swatch {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 11px;
  border: 1px solid rgba(0,0,0,.18);
}

.compare-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-top: 18px;
}

.compare-actions .status {
  flex: 1 1 260px;
}

.compare-result {
  margin-top: 18px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255,255,255,.66);
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.compare-result h3 {
  font-size: clamp(1.28rem, 3vw, 2rem);
}

.compare-result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.compare-result-card {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.58);
}

.compare-result-card small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

@media (max-width: 900px) {
  .compare-grid,
  .compare-result-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .compare-card { padding: 14px; border-radius: 20px; }
  .compare-canvas-shell { min-height: 190px; }
  .compare-actions { display: grid; grid-template-columns: 1fr; }
  .compare-result { padding: 14px; }
}
