/* Base reset */
:root{color-scheme:light;box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
html{scroll-padding-top:env(safe-area-inset-top,0px)}
body{margin:0;padding:0;font:14px -apple-system,BlinkMacSystemFont,sans-serif;background:#fff;color:#000}
img{max-width:100%}
[hidden]:not([hidden=until-found i]){display:none!important}

/* Layout: a single working column — controls, a row of "spools" (the palette), then the shopping list, the full shade chart and saved palettes. */
:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --ink: #1a1c22;
  --muted: #4b5060;
  --line: #d6d9e0;
  --accent: #3b438d;          /* Metrosene 0013 Venetian Blue */
  --accent-ink: #ffffff;
  --chip: #e3e6ec;
  --display: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c; --surface: #1e2128; --ink: #eceef3; --muted: #aab0bd;
    --line: #333844; --accent: #9aa4f0; --accent-ink: #12142a; --chip: #2a2e37;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c; --surface: #1e2128; --ink: #eceef3; --muted: #aab0bd;
  --line: #333844; --accent: #9aa4f0; --accent-ink: #12142a; --chip: #2a2e37;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 17px; line-height: 1.55;
}
.wrap {
  max-width: 1080px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 56px;
  display: grid; gap: 28px;
}
header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
h1 { font-family: var(--display); font-weight: 700; font-size: clamp(28px, 4.4vw, 42px); line-height: 1.05; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h1 { display: flex; align-items: center; gap: 0.3em; }
h1 .logo { width: 1.15em; height: 1.15em; flex: none; border-radius: 0.25em; }
.lede { margin: 6px 0 0; color: var(--muted); max-width: 60ch; }
h2 { font-family: var(--display); font-weight: 700; font-size: 22px; margin: 0; }
.label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }

/* Controls */
.group { display: grid; gap: 6px; }
.seg { display: inline-flex; background: var(--chip); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button {
  font: inherit; font-size: 16px; font-weight: 500; border: 0; background: transparent; color: var(--ink);
  min-height: 44px; padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.seg button:hover { color: var(--accent); }
.primary {
  font: inherit; font-weight: 600; font-size: 17px; border: 0; cursor: pointer; min-height: 48px;
  background: var(--accent); color: var(--accent-ink); padding: 11px 20px; border-radius: 10px;
  display: inline-flex; align-items: center; gap: 10px;
}
.primary kbd { font-family: var(--mono); font-size: 11px; opacity: .75; border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; }
.ghost {
  font: inherit; font-size: 16px; font-weight: 500; cursor: pointer; color: var(--ink);
  background: transparent; border: 1px solid var(--muted); min-height: 44px; padding: 8px 14px; border-radius: 8px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Spools */
.spools { display: flex; gap: 12px; min-height: 380px; }
.spool {
  flex: 1 1 0; min-width: 0; position: relative; border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  background-color: var(--c);
  color: var(--t);
  box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 8px 24px -14px rgba(0,0,0,.35);
  transition: background-color .35s ease;
}
.spool > * { position: relative; }
.spool .top { display: flex; justify-content: flex-end; gap: 6px; padding: 10px; }
.icon-btn {
  height: 44px; padding: 0 12px; border-radius: 10px; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 15px; font-weight: 600; color: var(--t);
  background: var(--b);
}
.icon-btn:hover { box-shadow: inset 0 0 0 2px var(--t); }
.icon-btn[aria-pressed="true"] { background: #ffffff; color: #15171c; box-shadow: inset 0 0 0 2px #15171c; }
.icon-btn svg { width: 18px; height: 18px; flex: none; }
.spool .top { flex-wrap: wrap; }
@media (hover: none) { .primary kbd { display: none; } }
.tag {
  margin: 10px; padding: 12px 12px 11px; border-radius: 10px;
  background: var(--surface); color: var(--ink);
  display: grid; gap: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.tag .no { min-height: 44px; display: flex; align-items: baseline; padding-top: 6px; font-family: var(--mono); font-size: 26px; font-weight: 500; letter-spacing: .02em; line-height: 1.1; font-variant-numeric: tabular-nums; cursor: copy; background: none; border: 0; padding: 0; color: inherit; text-align: left; }
.tag .no small { font-size: 13px; color: var(--muted); letter-spacing: .06em; margin-right: 4px; }
.tag .nm { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.tag .old { font-size: 15px; color: var(--muted); }
.tag .old b { font-family: var(--mono); font-weight: 500; }
.tag .hx { font-family: var(--mono); font-size: 13px; color: var(--muted); }

@media (max-width: 680px) {
  .spools { flex-direction: column; min-height: 0; }
  .spool { flex: none; flex-direction: row; align-items: stretch; min-height: 96px; }
  .spool .top { order: 2; flex-direction: column; justify-content: center; }
  .spool .tag { order: 1; flex: 1; min-width: 0; align-content: center; max-width: 230px; }
}

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 18px 20px; display: grid; gap: 14px; align-content: start; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.list { font-family: var(--mono); font-size: 16px; margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.list li { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.note { font-size: 15px; color: var(--muted); margin: 0; max-width: 70ch; }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .cols { grid-template-columns: 1fr; } }

/* Chart */
.search { font: inherit; font-size: 17px; min-height: 44px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: min(300px, 100%); }
.chart { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 5px; }
.chart button {
  position: relative; aspect-ratio: 1; max-width: 100%; border: 0; border-radius: 6px; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
  transition: transform .12s ease;
}
.chart button:hover, .chart button:focus-visible { transform: scale(1.25); position: relative; z-index: 1; }
.chart button.in { outline: 2px solid var(--ink); outline-offset: 1px; }
.chart button.sel { outline: 3px solid var(--accent); outline-offset: 2px; transform: scale(1.15); position: relative; z-index: 1; }
.pick { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; min-height: 48px; }
.pick .sw { width: 40px; height: 40px; border-radius: 8px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.pick .txt { min-width: 0; font-size: 16px; }
.pick .txt b { font-family: var(--mono); font-weight: 500; }
.hover-info { font-size: 16px; color: var(--muted); min-height: 1.5em; }

.saved { display: grid; gap: 8px; }
.saved-row { display: flex; align-items: center; gap: 10px; }
.saved-row .strip { flex: 1; display: flex; height: 44px; border-radius: 8px; overflow: hidden; border: 0; padding: 0; cursor: pointer; min-width: 0; }
.saved-row .strip span { flex: 1; }
.saved-row .nums { font-family: var(--mono); font-size: 14px; color: var(--muted); }
.empty { color: var(--muted); font-size: 16px; margin: 0; }

[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(10,12,16,.55);
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet { background: var(--surface); color: var(--ink); border-radius: 16px; padding: 18px; display: grid; gap: 14px; width: min(480px, 100%); max-height: 100%; overflow: auto; }
.sheet img { display: block; width: 100%; height: auto; max-height: 62vh; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; }
a.ghost { text-decoration: none; display: inline-flex; align-items: center; }
.chart button.own::after { content: ""; position: absolute; right: 4px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px #1a1c22; }
.own-tag { font-size: 14px; font-weight: 600; color: var(--muted); }
.have { font: inherit; font-family: var(--body); font-size: 15px; font-weight: 600; margin-left: auto; flex: none; min-height: 44px; padding: 4px 12px; border-radius: 999px; cursor: pointer; border: 1px solid var(--muted); background: transparent; color: var(--ink); }
.have[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.list li { flex-wrap: wrap; }
.matches { display: grid; gap: 14px; }
.mrow { display: grid; gap: 8px; }
.mrow h3 { margin: 0; font-size: 16px; }
.mitem { display: flex; align-items: center; gap: 12px; }
.mitem .sw { width: 40px; height: 40px; border-radius: 8px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.mitem .txt { min-width: 0; font-size: 16px; }
.mitem .txt b { font-family: var(--mono); font-weight: 500; }
.mitem .q { display: block; font-size: 13px; color: var(--muted); }
.strip { display: flex; height: 44px; border-radius: 8px; overflow: hidden; }
.strip span { flex: 1; }
.value-note { font-size: 16px; color: var(--ink); max-width: none; margin-top: -12px; }
.settings { display: grid; gap: 12px; max-width: 720px; }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 16px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; text-align: left; }
.rows > .row:first-child, .rows > .row[hidden] + .row:not([hidden]):nth-child(2) { border-top: 0; }
button.row { cursor: pointer; }
button.row:hover { background: var(--chip); }
.rl { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; display: grid; gap: 2px; }
.rl small { font-size: 15px; font-weight: 400; color: var(--muted); }
.rv { font-size: 17px; color: var(--muted); text-align: right; min-width: 0; }
.chev { font-size: 24px; color: var(--muted); line-height: 1; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--muted); background: transparent; color: var(--ink); font: inherit; font-size: 24px; cursor: pointer; }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper output { min-width: 36px; text-align: center; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.switch { flex: none; width: 52px; height: 32px; border-radius: 999px; background: var(--chip); box-shadow: inset 0 0 0 1px var(--muted); position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.row[aria-checked="true"] .switch { background: var(--accent); box-shadow: none; }
.row[aria-checked="true"] .switch::after { transform: translateX(20px); }
.row:disabled { cursor: default; }
.row:disabled .rl { opacity: .6; }
.more summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; font-weight: 600; font-size: 17px; color: var(--accent); padding: 4px 2px; }
.more .rows { margin-top: 4px; }
.gen-row { max-width: 720px; }
.gen-row .primary { width: 100%; justify-content: center; }
.options { display: grid; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 4px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.opt:first-child { border-top: 0; }
.opt .rl small { font-size: 15px; }
.opt .tick { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; }
.opt[aria-checked="true"] .tick { border-color: var(--accent); background: var(--accent); }
.opt[aria-checked="true"] .tick::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-ink); }
@media (max-width: 680px) {
  .actions { display: grid !important; grid-template-columns: 1fr 1fr; width: 100%; }
  .actions .ghost { width: 100%; justify-content: center; }
  .pick { display: grid; grid-template-columns: auto 1fr; }
  .pick .primary, .pick .ghost { grid-column: 1 / -1; width: 100%; justify-content: center; }
}
@media (max-width: 680px) { .sheet-modal { place-items: end center; padding-bottom: env(safe-area-inset-bottom, 0px); } .sheet-modal .sheet { border-radius: 18px 18px 0 0; width: 100%; } }
.hh { display: flex; align-items: center; gap: 10px; }
.help { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--muted); background: transparent; color: var(--ink); font: inherit; font-size: 20px; font-weight: 700; cursor: pointer; }
.help[aria-expanded="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.help-text { background: var(--chip); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; font-size: 16px; }
.help-text p { margin: 0; }
.dot-key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px #1a1c22; vertical-align: middle; margin: 0 2px; }
.foot { border-top: 1px solid var(--line); padding-top: 16px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 17px; font-weight: 500;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
:root[data-text="large"] .wrap { zoom: 1.2; }
/* Phones: show the palette and Generate first, settings after */
@media (max-width: 680px) {
  .wrap > header { order: 0; }
  #spools, .value-note { order: 1; }
  .gen-row { order: 2; }
  .settings { order: 3; }
  .wrap > .cols, .wrap > .panel { order: 4; }
  .wrap > .foot { order: 5; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
