:root {
  --paper: #f2efe6;
  --paper2: #e9e5d8;
  --ink: #191813;
  --ink2: #4f4b40;
  --rule: #cbc4b2;
  --accent: #b03a0d;
  --accent-ink: #ffffff;
  --pass: #1d6a37;
  --fail: #a32418;
  --focus: #191813;
  --halo: #f2efe6;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --gap: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121210;
    --paper2: #1c1c19;
    --ink: #ece8dc;
    --ink2: #aaa597;
    --rule: #3a3933;
    --accent: #ff7f4d;
    --accent-ink: #121210;
    --pass: #74d394;
    --fail: #ff8f80;
    --focus: #ece8dc;
    --halo: #121210;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 6px; z-index: 10; }
.skip:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 5px var(--halo); }

/* ---------- header ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 26px; height: 26px; flex: none; align-self: center; }
h1 { margin: 0; font: 600 22px/1.1 var(--serif); letter-spacing: -0.01em; }
.lede { margin: 0; color: var(--ink2); font: italic 16px/1.3 var(--serif); }

/* ---------- layout ---------- */
.lab {
  display: grid; gap: 22px 28px;
  padding: 16px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "plane" "panel" "notes" "preview" "export";
  max-width: 1440px; margin: 0 auto;
}
.plane-block { grid-area: plane; min-width: 0; }
.panel { grid-area: panel; min-width: 0; }
.notes { grid-area: notes; min-width: 0; }
.notes .help { margin-top: 0; }
.preview-block { grid-area: preview; min-width: 0; }
.export-block { grid-area: export; min-width: 0; }
@media (min-width: 900px) {
  .lab { grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "plane panel" "plane export" "notes export" "preview preview"; grid-template-rows: auto auto 1fr auto; padding: 20px 24px 24px; align-items: start; }
  .previews { grid-template-columns: 1fr 1fr; }
  .mini-ratio { display: none; }
}
@media (min-width: 1200px) {
  .lab { grid-template-columns: minmax(0, 1fr) 400px; gap: 22px 40px; padding: 22px 36px 28px; }
}

h2 { margin: 0; }
.lbl, .sec-head h2 {
  font: 600 11px/1.2 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink2);
}
.num { color: var(--accent); margin-right: 8px; font-weight: 700; }
.muted { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }

/* ---------- plane ---------- */
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.readout { margin: 0; font-size: 12px; color: var(--ink2); white-space: nowrap; }
.mini-ratio { margin: 0; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--ink); color: var(--paper); white-space: nowrap; }
.readout b { color: var(--ink); font-weight: 600; }
.plane-frame {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  grid-template-rows: auto auto auto;
  column-gap: 6px;
}
.axis-y { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; font-size: 10px; color: var(--ink2); margin: -6px 0; }
.plane {
  grid-column: 2; grid-row: 1;
  position: relative;
  aspect-ratio: 6 / 5;
  border-radius: 4px;
  background: var(--paper2);
  box-shadow: 0 0 0 1px var(--ink);
  touch-action: none;
  cursor: crosshair;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
@media (min-width: 900px) { .plane { aspect-ratio: auto; height: clamp(300px, calc(100vh - 290px), 600px); } }
.plane canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.axis-x { grid-column: 2; grid-row: 2; display: flex; justify-content: space-between; font-size: 10px; color: var(--ink2); margin: 4px -4px 0; }
.axis-name { margin: 0; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink2); }
.axis-name-x { grid-column: 2; grid-row: 3; text-align: center; margin-top: 2px; }
.axis-name-y { grid-column: 1; grid-row: 3; display: none; }

.cross { position: absolute; pointer-events: none; background: rgba(0,0,0,.55); box-shadow: 0 0 0 1px rgba(255,255,255,.45); }
.cross-x { left: 0; right: 0; height: 1px; top: 0; }
.cross-y { top: 0; bottom: 0; width: 1px; left: 0; }
.handle {
  position: absolute; left: 0; top: 0;
  width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1.5px #000, inset 0 0 0 1.5px #000, 0 3px 10px rgba(0,0,0,.35);
  cursor: grab;
  touch-action: none;
}
.handle:focus-visible { outline: none; box-shadow: 0 0 0 1.5px #000, 0 0 0 5px #fff, 0 0 0 7px #000, inset 0 0 0 1.5px #000; }
.plane.dragging, .plane.dragging .handle { cursor: grabbing; }
.handle::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; } /* 48px touch area */

.help { margin: 10px 0 0; color: var(--ink2); font-size: 13px; max-width: 70ch; }
.chroma { display: flex; align-items: center; gap: 12px; margin-top: 10px; min-height: 44px; }
.chroma .lbl { flex: none; }
.chroma output { flex: none; width: 5ch; text-align: right; font-size: 14px; }
input[type="range"] { flex: 1; min-width: 0; height: 44px; margin: 0; background: transparent; accent-color: var(--accent); cursor: pointer; }

.legend { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--ink2); }
.legend li { display: flex; align-items: center; gap: 7px; }
.key { width: 18px; height: 14px; border-radius: 2px; box-shadow: 0 0 0 1px var(--rule); flex: none; background: var(--paper2); }
.key-line { box-shadow: none; background: linear-gradient(var(--ink), var(--ink)) center / 100% 2px no-repeat; }
.key-sparse { background-image: radial-gradient(circle, var(--ink) 0.8px, transparent 1.2px); background-size: 6px 6px; }
.key-dense { background-image: radial-gradient(circle, var(--ink) 0.9px, transparent 1.3px); background-size: 3.5px 3.5px; }
.key-hatch { background-image: repeating-linear-gradient(135deg, var(--ink) 0 1px, transparent 1px 5px); }
.share-stat { margin: 10px 0 0; font-size: 12.5px; color: var(--ink); }

/* ---------- panel ---------- */
.pair { display: grid; grid-template-columns: minmax(0,1fr) 44px minmax(0,1fr); gap: 10px; align-items: end; }
.field .lbl { margin-bottom: 6px; }
.field-row { display: flex; gap: 6px; }
input[type="color"] {
  flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 6px; background: none; cursor: pointer;
  box-shadow: 0 0 0 1px var(--ink);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }
.hex {
  min-width: 0; width: 100%; height: 44px; padding: 0 10px;
  font-size: 15px; letter-spacing: 0.02em;
  color: var(--ink); background: var(--paper); border: 1px solid var(--ink2); border-radius: 6px;
}
.hex[aria-invalid="true"] { border-color: var(--fail); box-shadow: inset 0 0 0 1px var(--fail); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: var(--paper); color: var(--ink); border: 1px solid var(--ink2); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--paper2); }
.gamut-note { margin: 8px 0 0; font-size: 12.5px; color: var(--ink2); min-height: 2.8em; }
.gamut-note.out { color: var(--ink); }

.ratio-block { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--rule); }
.ratio {
  margin: 2px 0 0; font: 400 76px/1 var(--serif);
  font-variant-numeric: lining-nums tabular-nums; letter-spacing: -0.03em;
}
.ratio .colon { color: var(--ink2); font-size: 0.55em; letter-spacing: 0; margin-left: 4px; }
.verdict { margin: 6px 0 10px; font: italic 17px/1.3 var(--serif); min-height: 1.3em; }
.checks { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.checks th { text-align: left; font: 600 10.5px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink2); padding: 0 0 6px; border-bottom: 1px solid var(--rule); }
.checks td { padding: 7px 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
.checks td:first-child { padding-right: 8px; }
.checks .need { font-family: var(--mono); font-size: 11.5px; color: var(--ink2); margin-left: 6px; }
.res { font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.res::before { content: ""; width: 9px; height: 9px; border-radius: 2px; flex: none; }
.res.pass { color: var(--pass); }
.res.pass::before { background: var(--pass); }
.res.fail { color: var(--fail); }
.res.fail::before { box-shadow: inset 0 0 0 1.5px var(--fail); }
.res.na { color: var(--ink2); font-weight: 400; }
.res.na::before { display: none; }
.honest { margin: 10px 0 0; font-size: 12.5px; color: var(--ink2); }

.nudge { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); }
.nudge-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--ink2); border-radius: 999px; padding: 2px; }
.seg button {
  min-height: 40px; min-width: 52px; padding: 0 10px; border: 0; border-radius: 999px; background: none; color: var(--ink);
  font: 500 13px var(--mono); cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.nudge-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn {
  min-height: 44px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  font: 600 14px/1.2 var(--sans);
  background: var(--paper); color: var(--ink); border: 1px solid var(--ink);
}
.btn:hover:not(:disabled) { background: var(--paper2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); background: var(--accent); }
.btn:disabled, .btn.primary:disabled { cursor: default; color: var(--ink2); background: var(--paper); border-color: var(--rule); filter: none; }
.nudge-out { margin: 10px 0 0; font-size: 13px; min-height: 2.6em; color: var(--ink); }
.nudge-out .mono { font-size: 12.5px; white-space: nowrap; }
.link-btn { background: none; border: 0; padding: 0 4px; min-height: 44px; color: var(--accent); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- preview ---------- */
.preview-block .lbl, .export-block .lbl { margin-bottom: 8px; }
.previews { display: grid; gap: 12px; }
.pv-tag { margin: 0 0 14px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.preview {
  --t: #000; --b: #fff;
  background: var(--b); color: var(--t);
  min-width: 0;
  border-radius: 6px; padding: 22px 22px 24px;
  box-shadow: 0 0 0 1px var(--rule);
}
.pv-meta { margin: 0 0 6px; font: 500 12px/1.2 var(--mono); letter-spacing: 0.06em; }
.pv-head { margin: 0; font: 600 clamp(24px, 3.2vw, 32px)/1.15 var(--serif); letter-spacing: -0.01em; }
.pv-body { margin: 10px 0 18px; font-size: 16px; line-height: 1.55; max-width: 58ch; }
.pv-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pv-btn { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px; background: var(--t); color: var(--b); font-weight: 600; font-size: 14px; }
.pv-input { display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 6px; border: 1.5px solid var(--t); font-size: 14px; min-width: 150px; }
.pv-chip { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: 999px; border: 1.5px solid var(--t); font: 600 12px var(--mono); letter-spacing: 0.04em; }

/* ---------- export ---------- */
.css {
  margin: 0; padding: 14px; border-radius: 6px; background: var(--paper2); color: var(--ink);
  font-size: 12.5px; line-height: 1.6; overflow-x: auto; white-space: pre;
  box-shadow: inset 0 0 0 1px var(--rule);
}
.export-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.export-btns .btn { flex: 1 1 auto; }
.export-out { margin: 8px 0 0; font-size: 13px; min-height: 1.5em; color: var(--ink2); }

.foot { padding: 14px 16px 22px; text-align: center; font-size: 12.5px; color: var(--ink2); border-top: 1px solid var(--rule); }
.foot a { color: var(--ink); text-underline-offset: 3px; display: inline-block; padding: 12px 2px; margin: -12px 0; }

@media (max-width: 420px) {
  .hex { padding: 0 6px; font-size: 14px; letter-spacing: 0; }
  .pair { gap: 6px; }
  .field-row { gap: 4px; }
  .ratio { font-size: 64px; }
  .legend { font-size: 12px; }
  .readout { font-size: 11px; }
  .sec-head h2 { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
.preview.flip { background: var(--t); color: var(--b); }
.preview.flip .pv-btn { background: var(--b); color: var(--t); }
.preview.flip .pv-input, .preview.flip .pv-chip { border-color: var(--b); }
