:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #241c17;
  --muted: #6b625a;
  --line: #e4ddd2;
  --wood: #2e231c;
  --wood-ink: #f6eee2;
  --accent: #c2410c;
  --accent-soft: #fdeee4;
  --good: #15803d;
  --ok: #4d7c0f;
  --meh: #b45309;
  --bad: #b91c1c;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

a { color: var(--accent); }

/* ---------- Top bar: a dark workbench edge ---------- */

.topbar {
  background: linear-gradient(180deg, #3a2c23, var(--wood));
  color: var(--wood-ink);
  border-bottom: 3px solid #1d1611;
}

.topbar-row {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: 0.01em; }

.logo {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: conic-gradient(#c2410c 0 25%, #1d4ed8 0 50%, #15803d 0 75%, #eab308 0);
  box-shadow: inset 0 0 0 3px var(--wood), 0 0 0 1px #5a473a;
}

.topbar-right { display: flex; align-items: center; gap: 16px; }

.back, .sheet-link { color: #d9cbb8; text-decoration: none; font-size: 14px; }
.back:hover, .sheet-link:hover { color: #fff; text-decoration: underline; }
.sheet-link { font-weight: 600; color: #fdba74; }

.pill {
  display: inline-block;
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 20px;
}

/* ---------- Layout ---------- */

.wrap { max-width: 1120px; margin: 0 auto; padding: 8px 16px 40px; }

.intro { color: var(--muted); margin: 14px 0 12px; }
.intro strong { color: var(--ink); }

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tabs button {
  flex: none;
  border: 0;
  background: none;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 12px 0;
}

.switch, .check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #cfc6b9;
  transition: background 0.15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; background: var(--card); overflow: hidden; }
.seg button {
  border: 0;
  background: none;
  padding: 7px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg.small button { padding: 5px 10px; font-size: 13px; }
.seg.disabled { opacity: 0.45; pointer-events: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: #cbbfae; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #a63a0d; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.linkish { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }

.hint { margin: 0; color: var(--muted); font-size: 13px; }
.private::before { content: "\1F512  "; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

/* ---------- Color picker ---------- */

.picker { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
#colorInput {
  width: 96px;
  height: 96px;
  border: 0;
  padding: 0;
  border-radius: 16px;
  background: none;
  cursor: pointer;
}
#colorInput::-webkit-color-swatch-wrapper { padding: 0; }
#colorInput::-webkit-color-swatch { border: 1px solid rgba(0, 0, 0, 0.15); border-radius: 16px; }
#colorInput::-moz-color-swatch { border: 1px solid rgba(0, 0, 0, 0.15); border-radius: 16px; }
.picker-fields { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.picker-fields label, .scheme-head label { font-size: 13px; font-weight: 700; color: var(--muted); }

input[type="text"], input[type="search"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
input[type="text"]:focus, input[type="search"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#hexInput { width: 120px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
#hexInput.bad { border-color: var(--bad); }

/* ---------- Paint grid ---------- */

.search-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
#search { flex: 1 1 240px; }

.paint-grid { max-height: 420px; overflow-y: auto; padding-right: 4px; }
.range-group + .range-group { margin-top: 14px; }
.range-group h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  min-width: 0;
}
.chip:hover { border-color: #cbbfae; }
.chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip small { display: block; color: var(--muted); font-size: 11px; }
.empty-note { color: var(--muted); font-size: 14px; margin: 4px 0; }

/* A drop of paint: a little highlight so it reads as wet paint, not a flat box */
.dot {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.22), inset 0 3px 4px rgba(255, 255, 255, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.12);
}

/* ---------- Photo ---------- */

.dropzone {
  border: 2px dashed #cbbfae;
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-title { margin: 0 0 4px; font-weight: 700; font-size: 17px; }
.dz-sub { margin: 0; color: var(--muted); }
.photo-stage { display: flex; flex-direction: column; gap: 10px; }
.photo-wrap { position: relative; align-self: center; max-width: 100%; }
#photoCanvas { display: block; max-width: 100%; max-height: 520px; border-radius: 8px; cursor: crosshair; touch-action: manipulation; }
.photo-mark {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #000;
  pointer-events: none;
}
.photo-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
#panel-photo .private { margin-top: 10px; }

/* ---------- Results ---------- */

.results { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }

.target {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.big-swatch {
  width: 140px;
  height: 140px;
  border-radius: 18px;
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.2), inset 0 8px 14px rgba(255, 255, 255, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.target h2.kicker { margin-bottom: 2px; }
.target h3 { margin: 0; font-size: 24px; line-height: 1.2; }
.meta { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #efe9df; color: #5b4f44; }
.note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.grad-row { margin-top: 10px; max-width: 320px; }
.grad { height: 14px; border-radius: 7px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12); }
.grad-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.target-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.matches { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.range-col { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.range-col h2 { margin-bottom: 10px; }
.match {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.match + .match { margin-top: 8px; }
.match:hover { border-color: #cbbfae; }
.match-top {
  border: 0;
  padding: 0;
  background: none;
  width: 100%;
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.match-top { display: flex; align-items: center; gap: 10px; }
.match .dot { width: 44px; height: 44px; }
.match-name { flex: 1; min-width: 0; font-weight: 600; line-height: 1.25; }
.match-name small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.de { flex: none; text-align: right; font-size: 12px; line-height: 1.2; }
.de b { display: block; font-size: 16px; }
.de.good b, .de.good { color: var(--good); }
.de.ok b, .de.ok { color: var(--ok); }
.de.meh b, .de.meh { color: var(--meh); }
.de.bad b, .de.bad { color: var(--bad); }

.triad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.triad-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.triad-cell .bar { width: 100%; height: 22px; border-radius: 5px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1); }
.triad-cell span { width: 100%; font-size: 11px; color: var(--muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.triad-cell.self span { color: var(--ink); font-weight: 600; }
.triad-cell.none .bar { background: repeating-linear-gradient(45deg, #eee, #eee 4px, #f8f8f8 4px, #f8f8f8 8px); }
.target .triad { max-width: 420px; margin-top: 12px; }

/* ---------- Scheme ---------- */

.scheme-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-width: 420px; }
.scheme-parts { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.part { display: grid; grid-template-columns: 30px minmax(0, 0.8fr) minmax(0, 1.4fr) auto; gap: 8px; align-items: center; }
.part .dot { width: 30px; height: 30px; }
.part input { width: 100%; }
.part input.bad { border-color: var(--bad); }
.scheme-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

/* ---------- Card ---------- */

.card-area {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-preview { flex: none; }
#cardCanvas {
  display: block;
  width: 252px;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(40, 25, 10, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.card-side { flex: 1 1 240px; display: flex; flex-direction: column; gap: 10px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; max-width: 260px; }

/* ---------- Print sheet ---------- */

.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.sheet-cards { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
.sheet-cards li { position: relative; }
.sheet-cards img { display: block; width: 110px; border-radius: 6px; box-shadow: 0 0 0 1px var(--line); }
.sheet-cards .remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* ---------- Footer / toast ---------- */

.foot { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.foot p { margin: 0 0 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--wood);
  color: var(--wood-ink);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .long { display: none; }
  .target { grid-template-columns: 1fr; }
  .big-swatch { width: 100%; height: 110px; }
  .part { grid-template-columns: 30px minmax(0, 1fr) auto; }
  .part .part-paint { grid-column: 1 / -1; grid-row: 2; }
  .part .remove-part { grid-column: 3; grid-row: 1; }
  #cardCanvas { width: 200px; }
}
