:root {
  color-scheme: light;
  --navy-950: #07192a;
  --navy-900: #102a43;
  --navy-800: #183b56;
  --navy-700: #33566f;
  --blue-600: #1769aa;
  --blue-500: #2687c8;
  --cyan-400: #37bfd5;
  --ink: #13283b;
  --muted: #60788e;
  --line: #d9e4ec;
  --line-strong: #b9cbd8;
  --surface: #ffffff;
  --surface-soft: #f4f8fb;
  --surface-blue: #eaf4fa;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(16, 42, 67, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--surface-soft); }

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(55, 191, 213, 0.07), transparent 36rem),
    var(--surface-soft);
}

body::before {
  content: "";
  position: fixed;
  z-index: 0;
  inset: 76px 0 0;
  pointer-events: none;
  background: url("./surtec-logo.png") center 16vh / min(72vmin, 820px) auto no-repeat;
  opacity: 0.026;
  filter: grayscale(20%);
}

button, input, select { font: inherit; }
button, label.file-button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .file-button:focus-within {
  outline: 3px solid rgba(38, 135, 200, 0.32);
  outline-offset: 2px;
}

.app-header {
  position: relative;
  z-index: 2;
  min-height: 76px;
  padding: 14px clamp(18px, 3vw, 44px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: white;
  background: var(--navy-950);
  border-bottom: 1px solid rgba(255,255,255,0.13);
}

.header-branding { display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.surtec-logo { width: 54px; height: 54px; flex: 0 0 auto; display: block; border: 1px solid rgba(255,255,255,.22); border-radius: 9px; object-fit: cover; box-shadow: 0 5px 16px rgba(0,0,0,.18); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.02rem; letter-spacing: 0.01em; }
.brand small { margin-top: 2px; color: #aac2d4; font-size: 0.78rem; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 11px;
  background: rgba(255,255,255,0.06);
}
.brand-mark span { border-radius: 999px; }
.brand-mark span:nth-child(1) { background: #46cf7c; }
.brand-mark span:nth-child(2) { background: #ffc443; }
.brand-mark span:nth-child(3) { background: #e74f7d; }

.catalog-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 52vw;
  color: #dce9f2;
  font-size: 0.86rem;
  text-align: right;
}
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #f2bd32; box-shadow: 0 0 0 4px rgba(242,189,50,0.13); }
.catalog-status.ready .status-dot { background: #46cf7c; box-shadow: 0 0 0 4px rgba(70,207,124,0.13); }
.catalog-status.error .status-dot { background: #ff786e; box-shadow: 0 0 0 4px rgba(255,120,110,0.13); }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 2.5vw, 36px);
  display: grid;
  grid-template-columns: minmax(300px, 370px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(18px, 2.2vw, 32px);
}

.app-footer { position: relative; z-index: 1; padding: 4px 24px 28px; color: var(--muted); font-size: 0.76rem; font-weight: 700; text-align: center; letter-spacing: .02em; }

.control-panel, .best-result, .chart-card, .ranking-card, .chart3d-card, .method-note {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 20px;
  border-radius: 18px;
  overflow: hidden;
}

.panel-heading { padding: 26px 26px 18px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--blue-600); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; max-width: 14ch; font-size: clamp(1.55rem, 2vw, 2rem); line-height: 1.08; letter-spacing: -0.03em; color: var(--navy-900); }
.panel-heading > p:last-child { margin: 12px 0 0; color: var(--muted); font-size: 0.93rem; line-height: 1.5; }

#match-form { padding: 22px 26px 24px; }
.lab-inputs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.lab-field {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--blue-500);
  border-radius: 11px;
  background: #fbfdff;
}
.field-l { border-top-color: #7390a6; }
.field-a { border-top-color: #d94e67; }
.field-b { border-top-color: #e7ac2d; }
.lab-field > span, .select-field > span { color: var(--navy-800); font-weight: 800; font-size: 0.9rem; }
.lab-field input {
  width: 100%;
  padding: 5px 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--navy-950);
  font-size: 1.18rem;
  font-weight: 750;
}
.lab-field small { min-height: 2.1em; color: var(--muted); font-size: 0.7rem; line-height: 1.2; }
.select-field { display: grid; gap: 8px; margin-top: 18px; }
.select-field select {
  width: 100%;
  min-height: 46px;
  padding: 0 40px 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: white;
}
.form-error { margin: 12px 0 0; color: var(--danger); font-size: 0.86rem; }

.primary-button, .secondary-button, .copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button {
  width: 100%;
  margin-top: 18px;
  padding: 0 16px;
  border: 1px solid #0e578e;
  color: white;
  background: linear-gradient(135deg, #1769aa, #0d507f);
  box-shadow: 0 8px 18px rgba(23,105,170,0.18);
}
.primary-button:hover { filter: brightness(1.06); }
.primary-button svg, .secondary-button svg, .copy-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.data-section { padding: 20px 26px 24px; border-top: 1px solid var(--line); background: #f9fbfd; }
.data-section h2 { margin: 0; font-size: 0.96rem; color: var(--navy-900); }
.data-section p { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.data-actions { display: grid; gap: 6px; margin-top: 14px; }
.secondary-button { min-height: 42px; padding: 0 13px; border: 1px solid var(--line-strong); color: var(--navy-800); background: white; font-size: 0.84rem; }
.secondary-button:hover { border-color: var(--blue-500); color: var(--blue-600); }
.file-button input { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.text-button { justify-self: center; padding: 7px; border: 0; color: var(--blue-600); background: transparent; font-size: 0.82rem; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.privacy-note { padding-left: 20px; position: relative; }
.privacy-note::before { content: ""; position: absolute; left: 2px; top: 4px; width: 9px; height: 11px; border: 1.5px solid #5d7a8e; border-radius: 2px; }
.privacy-note::after { content: ""; position: absolute; left: 4px; top: 0; width: 5px; height: 7px; border: 1.5px solid #5d7a8e; border-bottom: 0; border-radius: 5px 5px 0 0; }

.results-workspace { min-width: 0; }
.workspace-topline { min-height: 56px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.workspace-topline h2 { margin: 0; color: var(--navy-900); font-size: clamp(1.35rem, 2vw, 1.8rem); letter-spacing: -0.02em; }
.workspace-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.copy-button { min-height: 40px; padding: 0 13px; border: 1px solid var(--line-strong); color: var(--navy-800); background: white; font-size: 0.82rem; }
.copy-button:disabled { opacity: 0.45; cursor: not-allowed; }
.print-status { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 360px; padding: 11px 14px; border: 1px solid #b8d7e9; border-radius: 10px; color: var(--navy-800); background: white; box-shadow: 0 12px 30px rgba(16,42,67,.18); font-size: 0.78rem; font-weight: 700; line-height: 1.4; }

.best-result {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  grid-template-areas: "comparison identity delta" "details details details";
  align-items: center;
  gap: 16px 18px;
  padding: 22px;
  overflow: hidden;
  border-radius: 17px;
}
.best-result::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--best-color, var(--blue-500)); }
.best-comparison { grid-area: comparison; display: grid; grid-template-columns: repeat(2, 52px); gap: 8px; }
.best-comparison > span, .rank-swatches > span, .blend-colour-comparison > span { display: grid; justify-items: center; gap: 4px; min-width: 0; }
.comparison-swatch { display: block; width: 52px; height: 52px; border: 1px solid rgba(0,0,0,0.18); border-radius: 12px; background: #d9e4ec; box-shadow: inset 0 0 0 3px rgba(255,255,255,0.32); }
.best-comparison small, .rank-swatches small, .blend-colour-comparison small { color: var(--muted); font-size: 0.6rem; font-weight: 750; line-height: 1.1; text-align: center; }
.best-identity { grid-area: identity; min-width: 0; }
.rank-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.best-title-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.best-title-line h3 { margin: 0; color: var(--navy-950); font-size: clamp(1.25rem, 2vw, 1.7rem); letter-spacing: -0.025em; }
.code-pill { padding: 5px 9px; border-radius: 999px; color: var(--navy-800); background: var(--surface-blue); font-size: 0.78rem; font-weight: 850; }
.best-identity p { margin: 5px 0 0; color: var(--muted); font-size: 0.88rem; }
.delta-block { grid-area: delta; min-width: 94px; padding-left: 18px; border-left: 1px solid var(--line); text-align: right; }
.delta-block span, .delta-block small { display: block; color: var(--muted); }
.delta-block span { font-size: 0.76rem; font-weight: 750; }
.delta-block strong { display: block; margin: 2px 0; color: var(--navy-950); font-size: 2.15rem; line-height: 1; font-variant-numeric: tabular-nums; }
.delta-block small { font-size: 0.73rem; }
.best-details { grid-area: details; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); padding-top: 15px; }
.best-details > div { min-width: 0; padding: 0 14px; border-right: 1px solid var(--line); }
.best-details > div:first-child { padding-left: 0; }
.best-details > div:last-child { padding-right: 0; border-right: 0; }
.best-details span, .best-details strong { display: block; }
.best-details span { margin-bottom: 5px; color: var(--muted); font-size: 0.71rem; }
.best-details strong { color: var(--navy-800); font-size: 0.84rem; line-height: 1.35; font-variant-numeric: tabular-nums; }

.analysis-grid { margin-top: 18px; display: grid; grid-template-columns: minmax(430px, 1.32fr) minmax(300px, 0.88fr); gap: 18px; align-items: start; }
.chart-card, .ranking-card, .chart3d-card { min-width: 0; border-radius: 17px; overflow: hidden; }
.card-heading { min-height: 76px; padding: 17px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.card-heading h3 { margin: 0; color: var(--navy-900); font-size: 1rem; }
.card-heading p { margin: 5px 0 0; max-width: 55ch; color: var(--muted); font-size: 0.76rem; line-height: 1.4; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 13px; color: var(--muted); font-size: 0.69rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-line { width: 20px; height: 3px; background: var(--blue-600); }
.legend-arrow { color: var(--blue-600); font-size: 1rem; font-style: normal; font-weight: 900; line-height: 1; }
.legend-sample { width: 9px; height: 9px; border: 2px solid var(--navy-950); border-radius: 50%; background: white; }
.legend-match { width: 9px; height: 9px; transform: rotate(45deg); border: 2px solid var(--blue-600); background: white; }
.zoom-control { display: grid; gap: 3px; color: var(--muted); font-size: 0.62rem; font-weight: 750; white-space: nowrap; }
.zoom-control select { min-width: 112px; padding: 6px 24px 6px 8px; border: 1px solid #b7cad7; border-radius: 8px; color: var(--navy-800); background: #f7fbfd; font: inherit; font-size: 0.7rem; font-weight: 800; cursor: pointer; }
.chart-card .card-heading { flex-wrap: wrap; }
.canvas-wrap { aspect-ratio: 1 / 1; padding: 12px; background: #f7fafc; }
#ab-chart { display: block; width: 100%; height: 100%; border-radius: 9px; }
.chart3d-card { margin-top: 18px; background: white; box-shadow: var(--shadow); }
.canvas3d-wrap { width: min(100%, 900px); aspect-ratio: 1 / 1; min-height: 420px; margin: 0 auto; padding: 10px; background: #f7fafc; }
.chart3d-tools { display: grid; justify-items: end; gap: 9px; }
.reset-view-button { padding: 6px 10px; border: 1px solid #b7cad7; border-radius: 8px; color: var(--navy-800); background: #f7fbfd; font-size: 0.68rem; font-weight: 800; cursor: pointer; }
.reset-view-button:hover { border-color: var(--blue-500); color: var(--blue-600); }
#lab-chart-3d { display: block; width: 100%; height: 100%; border-radius: 9px; cursor: grab; touch-action: none; user-select: none; }
#lab-chart-3d.is-dragging { cursor: grabbing; }
#lab-chart-3d:focus-visible { outline: 3px solid rgba(38, 135, 200, 0.32); outline-offset: -3px; }

.ranking-heading { min-height: 76px; }
.ranking-list { margin: 0; padding: 0; list-style: none; }
.ranking-item {
  --item-color: #5a7d92;
  --target-color: #d9e4ec;
  display: grid;
  grid-template-columns: 30px 68px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 126px;
  padding: 12px 17px;
  border-bottom: 1px solid var(--line);
}
.ranking-item:last-child { border-bottom: 0; }
.ranking-item:first-child { background: #f6fbfe; }
.rank-number { color: #8297a7; font-size: 0.78rem; font-weight: 850; }
.rank-swatches { display: grid; grid-template-columns: repeat(2, 30px); gap: 6px; }
.rank-target-swatch, .rank-swatch { display: block; width: 30px; height: 30px; border: 1px solid rgba(0,0,0,0.15); border-radius: 7px; }
.rank-target-swatch { background: var(--target-color); }
.rank-swatch { background: var(--item-color); }
.rank-swatches small { font-size: 0.52rem; }
.rank-info { min-width: 0; }
.rank-info strong, .rank-info span { display: block; }
.rank-info strong { color: var(--navy-900); font-size: 0.86rem; }
.rank-info span { margin-top: 4px; color: var(--muted); font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-info .rank-offset {
  color: var(--navy-700);
  font-size: 0.68rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.rank-info .rank-dose { color: #12623d; font-size: 0.69rem; font-weight: 850; font-variant-numeric: tabular-nums; white-space: normal; overflow: visible; }
.rank-info .rank-analysis { color: var(--navy-800); font-size: 0.68rem; font-style: italic; font-weight: 700; line-height: 1.3; white-space: normal; overflow: visible; text-overflow: clip; }
.rank-score { text-align: right; }
.rank-score strong, .rank-score span { display: block; }
.rank-score strong { color: var(--navy-950); font-size: 1.08rem; font-variant-numeric: tabular-nums; }
.rank-score span { margin-top: 2px; color: var(--muted); font-size: 0.65rem; }

.blend-section {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: white;
  box-shadow: var(--shadow);
}
.blend-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.blend-heading h3 { margin: 2px 0 4px; color: var(--navy-950); font-size: 1.16rem; }
.blend-heading > div > p:last-child { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.blend-controls { display: flex; align-items: flex-start; gap: 10px; }
.estimate-pill { flex: 0 0 auto; padding: 6px 9px; border: 1px solid #b8d7e9; border-radius: 999px; color: var(--blue-700); background: #edf8fd; font-size: 0.68rem; font-weight: 850; letter-spacing: 0.04em; text-transform: uppercase; }
.blend-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.blend-proposal { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: #f8fbfd; }
.blend-proposal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.blend-count { color: var(--navy-800); font-size: 0.78rem; font-weight: 850; letter-spacing: 0.05em; text-transform: uppercase; }
.blend-delta { text-align: right; }
.blend-delta span, .blend-delta strong { display: block; }
.blend-delta span { color: var(--muted); font-size: 0.64rem; }
.blend-delta strong { margin-top: 2px; color: var(--navy-950); font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.blend-colour-comparison { display: flex; justify-content: center; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.blend-target-preview, .blend-result-preview { display: block; width: 44px; height: 44px; border: 1px solid rgba(0,0,0,.16); border-radius: 10px; background: #d9e4ec; box-shadow: inset 0 0 0 3px rgba(255,255,255,.28); }
.blend-colour-comparison > span { width: 82px; }
.blend-components { display: grid; gap: 8px; margin: 13px 0; padding: 0; list-style: none; }
.blend-components li { display: grid; grid-template-columns: 68px 28px minmax(0, 1fr); align-items: center; gap: 9px; }
.blend-dose { color: var(--navy-950); font-size: 0.78rem; font-weight: 850; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.blend-swatch { width: 28px; height: 28px; border: 1px solid rgba(0,0,0,.14); border-radius: 7px; background: var(--blend-color); }
.blend-name { min-width: 0; }
.blend-name strong, .blend-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blend-name strong { color: var(--navy-900); font-size: 0.8rem; }
.blend-name small { margin-top: 2px; color: var(--muted); font-size: 0.66rem; }
.blend-summary { display: grid; gap: 5px; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.7rem; line-height: 1.45; }
.blend-summary strong { color: var(--navy-800); font-variant-numeric: tabular-nums; }
.blend-improvement { font-weight: 750; }
.blend-improvement.is-positive { color: #17774a; }
.blend-warning { margin-top: 14px; padding: 11px 13px; border-left: 3px solid #d59a18; border-radius: 7px; color: #67551e; background: #fff9e8; font-size: 0.74rem; line-height: 1.5; }
.blend-warning strong { color: #4f4219; }

.method-note { margin-top: 18px; border-radius: 14px; box-shadow: none; }
.method-note summary { padding: 15px 18px; color: var(--navy-800); font-size: 0.84rem; font-weight: 800; cursor: pointer; }
.method-note > div { padding: 0 18px 16px; border-top: 1px solid var(--line); }
.method-note p { margin: 13px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.55; }

noscript { display: block; margin: 20px; padding: 15px; color: var(--danger); background: white; border: 1px solid #f1b9b4; }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 320px minmax(0, 1fr); }
  .analysis-grid { grid-template-columns: 1fr; }
  .ranking-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ranking-item { border-right: 1px solid var(--line); }
}

@media (max-width: 820px) {
  .app-header { min-height: 68px; }
  .catalog-status { max-width: 45vw; font-size: 0.75rem; }
  .app-shell { display: block; padding: 16px; }
  .control-panel { position: static; }
  .results-workspace { margin-top: 24px; }
  .ranking-list { grid-template-columns: 1fr; }
  .ranking-item { border-right: 0; }
  .blend-grid { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .app-header { align-items: flex-start; }
  .brand small { display: none; }
  .brand-mark { width: 38px; height: 38px; }
  .catalog-status { max-width: 44vw; padding-top: 7px; }
  .catalog-status span:last-child { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .header-branding { gap: 9px; }
  .surtec-logo { width: 42px; height: 42px; border-radius: 7px; }
  .panel-heading, #match-form, .data-section { padding-left: 18px; padding-right: 18px; }
  .lab-inputs { grid-template-columns: 1fr; }
  .lab-field { grid-template-columns: 40px 1fr auto; align-items: center; border-top-width: 1px; border-left: 3px solid var(--blue-500); }
  .field-l { border-left-color: #7390a6; }
  .field-a { border-left-color: #d94e67; }
  .field-b { border-left-color: #e7ac2d; }
  .lab-field small { min-height: 0; text-align: right; }
  .workspace-topline { align-items: flex-end; }
  .copy-button span { display: none; }
  .best-result { grid-template-columns: auto 1fr; grid-template-areas: "comparison identity" "delta delta" "details details"; }
  .delta-block { display: grid; grid-template-columns: auto auto 1fr; align-items: baseline; gap: 8px; padding: 12px 0 0; border-left: 0; border-top: 1px solid var(--line); text-align: left; }
  .delta-block strong { font-size: 1.75rem; }
  .best-details { grid-template-columns: 1fr; }
  .best-details > div { padding: 9px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .best-details > div:last-child { border-bottom: 0; }
  .card-heading { display: block; }
  .chart-legend { margin-top: 10px; justify-content: flex-start; }
  .chart3d-tools { margin-top: 10px; justify-items: start; }
  .blend-heading { display: block; }
  .blend-controls { margin-top: 12px; justify-content: space-between; }
}

/* v21: neutral comparison frames, readable results and accessible controls. */
:root { --muted: #526a7e; --shadow: 0 6px 24px rgba(16,42,67,.045); }
html { min-width: 0; }
.app-shell { width: min(1660px, 100%); grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); }
.app-header { background: #043e61; }
.lab-field { padding: 12px 8px; }
.lab-field input { font-size: 1.05rem; font-variant-numeric: tabular-nums; appearance: textfield; -moz-appearance: textfield; }
.lab-field input::-webkit-inner-spin-button, .lab-field input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.surtec-logo { border-radius: 3px; box-shadow: none; width: 64px; height: 64px; }
.app-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 24px; }
.skip-link { position: absolute; top: -100px; z-index: 99; padding: 14px; color: #043e61; background: white; }
.skip-link:focus { top: 8px; left: 8px; }
:focus-visible, #lab-chart-3d:focus-visible, .file-button:focus-within { outline: 3px solid #1769aa; outline-offset: 3px; }
.sample-summary { margin: 0 0 14px; color: #33566f; font-size: .83rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.preview-note, .chart-footnote, .blend-status { color: var(--muted); font-size: .76rem; line-height: 1.55; }
.preview-note { margin: 10px 3px 0; }
.chart-footnote { padding: 0 20px 12px; }
.catalog-note { padding-top: 8px; }
.best-result { grid-template-columns: auto minmax(0, 1fr) auto; }
.best-details { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 0; }
.best-details > div { padding: 0 16px; }
.best-details > div:nth-child(odd) { padding-left: 0; }
.best-details > div:nth-child(even) { border-right: 0; }
#best-dose-note { display: block; margin-top: 5px; color: var(--muted); line-height: 1.5; font-size: .73rem; }
.best-comparison, .rank-swatches, .blend-colour-comparison {
  position: relative; border: 1px solid #a8b5bd; border-radius: 10px;
  background: #f3f3f3; padding: 12px 12px 30px; gap: 8px;
}
.best-comparison::after, .rank-swatches::after, .blend-colour-comparison::after {
  content: "SurTec · comparison"; position: absolute; bottom: 8px; left: 0; right: 0;
  color: #52616d; font: 600 9px system-ui; text-align: center; letter-spacing: .02em;
}
.comparison-swatch, .blend-target-preview, .blend-result-preview, .rank-target-swatch, .rank-swatch { border-radius: 4px; box-shadow: none; }
.best-comparison small, .rank-swatches small, .blend-colour-comparison small { color: #354e5c; font-size: .65rem; }
.analysis-grid { grid-template-columns: minmax(0, 1fr); }
.chart-card .canvas-wrap { max-width: 920px; margin: auto; }
.ranking-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ranking-item { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: 20px auto; grid-template-areas: "number info score" "swatches info score"; gap: 6px 14px; align-items: start; padding: 20px; border-right: 1px solid var(--line); }
.rank-number { grid-area: number; font-size: .85rem; color: #526a7e; }
.rank-info { grid-area: info; }
.rank-score { grid-area: score; }
.rank-swatches { grid-area: swatches; grid-template-columns: repeat(2, 36px); padding: 9px 9px 29px; }
.rank-target-swatch, .rank-swatch { width: 36px; height: 36px; }
.rank-info strong { font-size: .94rem; }
.rank-info span, .rank-info .rank-offset, .rank-info .rank-analysis, .rank-info .rank-dose { white-space: normal; overflow: visible; text-overflow: clip; font-size: .77rem; line-height: 1.5; }
.rank-info .rank-dose-note { font-size: .7rem; }
.rank-score strong { font-size: 1.25rem; }
.ranking-item:last-child { border-bottom: 1px solid var(--line); }
.ranking-item:first-child { background: #f2f8fb; }
.canvas3d-wrap { min-height: 0; }
.canvas-wrap, .canvas3d-wrap { background: #f7fafc; }
.blend-colour-comparison { margin: 16px auto; width: max-content; max-width: 100%; }
.blend-target-preview, .blend-result-preview { width: 64px; height: 64px; }
.blend-name strong, .blend-name small { white-space: normal; overflow: visible; line-height: 1.45; }
.blend-name small { font-size: .7rem; }
.blend-summary { font-size: .8rem; }
.blend-warning { font-size: .82rem; }
.blend-proposal { background: white; }
.view-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.view-buttons button { border: 1px solid var(--line-strong); border-radius: 7px; color: var(--navy-800); background: white; cursor: pointer; font-size: 1.1rem; }
button, .zoom-control select, .secondary-button { min-height: 44px; }
.view-buttons button, .copy-button { min-width: 44px; min-height: 44px; }
.is-stale .best-result, .is-stale .analysis-grid, .is-stale .blend-grid { opacity: .42; }
.is-stale .sample-summary { color: #9b3219; }
#print-pages { display: none; }
@media (min-width: 1201px) {
  .analysis-grid { grid-template-columns: minmax(0, 1.12fr) minmax(350px, 1fr); }
  .ranking-list { display: block; }
  .chart-card { position: sticky; top: 20px; }
}

.conservative-heading { display: grid; grid-template-columns: 1fr minmax(230px, .8fr); gap: 18px; align-items: end; }
.conservative-heading h4 { margin: 14px 0 6px; color: #043e61; font-size: 1.05rem; }
.conservative-heading p, .free-blend-search > p, .guided-disclaimer { color: var(--muted); font-size: .8rem; line-height: 1.55; }
.conservative-grid .blend-proposal { border-top: 3px solid #1769aa; }
.free-blend-search { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.free-blend-search summary { cursor: pointer; padding: 10px 0; color: var(--navy-800); font-size: .88rem; font-weight: 750; }
.guided-disclaimer { padding: 12px 15px; background: #fff9e8; border-radius: 8px; }
.correction-summary { font-weight: 650; color: #33566f; }
@media (max-width: 640px) { .conservative-heading { grid-template-columns: 1fr; } }
@media (max-width: 1200px) {
  .app-shell { grid-template-columns: minmax(250px, 290px) minmax(0, 1fr); padding: 22px; gap: 22px; }
  .ranking-list { display: block; }
  .blend-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app-shell { display: block; padding: 18px; }
  .control-panel { position: static; }
  .results-workspace { margin-top: 24px; }
  .panel-heading h1 { max-width: none; }
  .ranking-list { display: grid; }
}
@media (max-width: 640px) {
  .ranking-list { display: block; }
  .workspace-topline { align-items: flex-start; gap: 10px; }
  .workspace-actions { gap: 5px; }
  .copy-button { padding: 0 10px; }
  .best-result { padding: 16px; gap: 16px; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "comparison identity" "delta delta" "details details"; }
  .delta-block { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .best-title-line h3 { font-size: 1.15rem; }
  .best-details { grid-template-columns: 1fr; gap: 10px; }
  .best-details > div { padding: 0 0 10px; border-right: 0; }
  .card-heading { flex-wrap: wrap; }
  .chart3d-tools { justify-items: start; }
  .ranking-item { padding: 16px; gap: 8px; }
  .rank-swatches { grid-template-columns: repeat(2, 30px); }
  .rank-target-swatch, .rank-swatch { width: 30px; height: 30px; }
  .rank-info .rank-dose-note { font-size: .67rem; }
  .brand-mark { display: none; }
}
@media (max-width: 360px) {
  .app-shell { padding: 10px; }
  .rank-swatches { grid-column: 1 / -1; grid-row: auto; width: max-content; }
  .ranking-item { grid-template-areas: "number info score"; }
}

@page { size: A4 portrait; margin: 0; }

@media print {
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  body { min-width: 0; background: white; }
  body::before { opacity: .018; }
  .app-header { min-height: 50px; padding: 8px 0; }
  .app-shell { width: 100%; max-width: none; padding: 10px 0 0; grid-template-columns: 235px minmax(0, 1fr); gap: 12px; }
  .app-footer { padding: 8px 0 0; font-size: .68rem; }
  .control-panel, .best-result, .chart-card, .ranking-card, .chart3d-card, .blend-section { box-shadow: none; break-inside: avoid; }
  .control-panel { position: static; }
  .panel-heading { padding: 16px; }
  .panel-heading p:last-child, .data-section, .select-field, .primary-button, .form-error, .workspace-actions, .print-status, .zoom-control, .reset-view-button, .method-note { display: none !important; }
  #match-form { padding: 12px 16px 16px; }
  .lab-inputs { grid-template-columns: 1fr; }
  .analysis-grid { margin-top: 12px; grid-template-columns: minmax(390px, 1.2fr) minmax(270px, .8fr); gap: 12px; }
  .best-result { padding: 15px 18px; }
  .card-heading { padding: 12px 14px; }
  .ranking-item { min-height: 92px; padding: 8px 12px; }
  .chart3d-card { margin-top: 12px; }
  .blend-section { margin-top: 12px; padding: 15px; }
  .blend-proposal { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media print {
  html, body { min-width: 0; margin: 0; padding: 0; background: white; }
  body::before, body > :not(#print-pages) { display: none !important; }
  #print-pages { display: block; }
  .report-page { display: block; width: 210mm; height: 296.9mm; margin: 0; break-after: page; }
  .report-page:last-child { break-after: auto; }
}
