:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f8f7f3;
  --surface-3: #f2efe8;
  --ink: #171a21;
  --muted: #6a6e78;
  --line: #dedbd3;
  --accent: #d96c4c;
  --accent-dark: #a8452d;
  --accent-soft: #f6ddd5;
  --green: #2d7a5e;
  --green-soft: rgba(45, 122, 94, .12);
  --shadow: 0 18px 50px rgba(30, 27, 22, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  font-family: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(217, 108, 76, .10), transparent 25rem),
    radial-gradient(circle at 100% 30%, rgba(45, 122, 94, .08), transparent 28rem),
    var(--bg);
}
button, input, select, textarea { font: inherit; }
button, label, input, select, summary, textarea { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding: 12px clamp(16px, 4vw, 54px);
  background: rgba(244, 241, 234, .88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(80, 72, 61, .10);
}
.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: #fff;
  font-size: 25px;
  background: var(--ink);
  transform: rotate(-4deg);
}
.brand strong {
  display: block;
  font-size: 18px;
  letter-spacing: -.02em;
}
.brand small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.top-actions { display: flex; align-items: center; gap: 10px; }
.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.65);
  color: #434852;
  font-size: 12px;
  font-weight: 700;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.privacy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(45, 122, 94, .12);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 22px;
  width: min(1540px, calc(100% - 36px));
  margin: 26px auto 40px;
  align-items: start;
}
.workspace-card, .controls {
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(98, 89, 76, .13);
  box-shadow: var(--shadow);
}
.workspace-card {
  min-height: 680px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.controls {
  position: sticky;
  top: 95px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  max-height: calc(100vh - 116px);
}

.empty-state {
  display: flex;
  min-height: 680px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 42px 24px;
  text-align: center;
  border: 2px dashed rgba(80, 72, 61, .17);
  border-radius: calc(var(--radius-lg) - 5px);
  margin: 12px;
}
.empty-state.dragging { border-color: var(--accent); background: var(--accent-soft); }
.empty-icon {
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  margin-bottom: 22px;
  border-radius: 26px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 48px;
  transform: rotate(-5deg);
}
.empty-state h1 {
  max-width: 700px;
  margin: 0;
  font-size: clamp(32px, 4vw, 56px);
  line-height: 1.03;
  letter-spacing: -.045em;
}
.empty-state > p:not(.microcopy):not(.privacy-note) {
  max-width: 620px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.microcopy, .muted, .disclaimer, footer, .warning-text, .pool-summary-text, .privacy-note {
  font-family: "Segoe UI", system-ui, sans-serif;
}
.microcopy {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}
.privacy-note {
  max-width: 620px;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--line);
  color: #42474f;
  font-size: 12px;
  line-height: 1.5;
}
.centered { text-align: center; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 800;
  font-family: "Segoe UI", system-ui, sans-serif;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button-primary {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 9px 20px rgba(23, 26, 33, .18);
}
.button-primary:hover { background: #2b303a; }
.button-ghost {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}
.button-small {
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12px;
}
.button-full { width: 100%; }
.file-button { cursor: pointer; }

.editor { min-height: 680px; }
.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.8);
}
.image-meta { min-width: 0; }
.image-meta strong, .image-meta span { display: block; }
.image-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 44vw;
  font-size: 13px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.image-meta span {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.toolbar-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.canvas-stage {
  position: relative;
  display: grid;
  min-height: 618px;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(45deg, #e7e4dc 25%, transparent 25%),
    linear-gradient(-45deg, #e7e4dc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7e4dc 75%),
    linear-gradient(-45deg, transparent 75%, #e7e4dc 75%), #f0ede6;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  overflow: hidden;
}
.canvas-stage.dragging::after {
  content: "Drop the image here";
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 18px;
  color: var(--accent-dark);
  background: rgba(246, 221, 213, .88);
  font-weight: 900;
  font-size: 20px;
  z-index: 5;
  font-family: "Segoe UI", system-ui, sans-serif;
}
#viewCanvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 190px);
  min-height: 220px;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 18px 60px rgba(20, 19, 17, .25);
  cursor: crosshair;
  touch-action: manipulation;
}
.canvas-hint {
  position: absolute;
  bottom: 31px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 999px;
  color: #fff;
  background: rgba(18, 20, 26, .78);
  backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
  white-space: nowrap;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.pick-marker {
  position: absolute;
  width: 25px;
  height: 25px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #111, 0 5px 16px rgba(0,0,0,.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.mobile-actions {
  display: none;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--line);
}
.mobile-actions .button { width: 100%; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 7px;
  background: #eeece6;
  border-bottom: 1px solid var(--line);
}
.tab {
  border: 0;
  border-radius: 10px;
  padding: 10px 5px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.tab.active { color: var(--ink); background: #fff; box-shadow: 0 3px 10px rgba(30,27,22,.08); }
.panel {
  display: none;
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 170px);
}
.panel.active { display: block; }
.panel-heading, .section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.panel-heading { margin-bottom: 18px; }
.panel-heading-stack {
  align-items: flex-start;
  flex-direction: column;
}
.panel h2, .panel h3 {
  margin: 0;
  letter-spacing: -.03em;
}
.panel h2 { font-size: 25px; }
.panel h3 { font-size: 18px; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 9px;
  font-weight: 900;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.selected-swatch {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: #fff;
  border: 5px solid #fff;
  box-shadow: 0 0 0 1px var(--line), 0 8px 18px rgba(0,0,0,.08);
}

.color-values {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-bottom: 18px;
}
.value-card {
  min-width: 0;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  cursor: pointer;
}
.value-card span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .1em;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.value-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.field { display: grid; gap: 8px; margin: 16px 0; }
.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.field output { color: var(--muted); font-weight: 700; }
.field small {
  color: var(--muted);
  line-height: 1.45;
  font-size: 10px;
}
.field input[type="number"],
.field input[type="text"],
.field input[type="search"],
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}
.field input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.checkbox-field { align-items: center; }
.checkbox-field input { width: 22px; height: 22px; accent-color: var(--accent); }
.checkbox-field.horizontal {
  grid-template-columns: 1fr auto;
  align-items: center;
}
.checkbox-field.horizontal span { justify-content: flex-start; }
.field-grid { display: grid; gap: 10px; }
.two-columns { grid-template-columns: 1fr 1fr; }

.loupe-row {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 14px;
  align-items: center;
}
#loupeCanvas {
  width: 116px;
  height: 116px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: #f0ede6;
  image-rendering: pixelated;
}
.muted {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  margin: 0;
}
.section-divider {
  height: 1px;
  margin: 22px 0;
  background: var(--line);
}
.text-button {
  border: 0;
  padding: 4px 0;
  color: var(--accent-dark);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.recipes { display: grid; gap: 9px; margin-top: 13px; }
.recipe-empty {
  padding: 17px;
  border: 1px dashed var(--line);
  border-radius: 13px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
  line-height: 1.5;
}
.recipe-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.recipe-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.recipe-rank {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 900;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.recipe-match {
  color: var(--muted);
  font-size: 10px;
}
.recipe-swatches {
  display: flex;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #eee;
}
.recipe-swatches span { display: block; height: 100%; }
.recipe-parts { display: grid; gap: 5px; margin-top: 10px; }
.recipe-part {
  display: grid;
  grid-template-columns: 13px 1fr auto;
  gap: 7px;
  align-items: center;
  font-size: 11px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.recipe-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.recipe-part strong { font-size: 10px; }
.disclaimer {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.5;
}
.pool-summary-text {
  margin: 0;
  color: #3f444d;
  font-size: 12px;
}
.warning-text {
  margin: 8px 0 0;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.pool-summary-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(248,247,243,.92));
}
.pool-summary-card strong {
  display: block;
  font-size: 18px;
  margin-bottom: 6px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.pool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.template-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.template-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.template-card.is-active {
  border-color: rgba(45, 122, 94, .42);
  box-shadow: inset 0 0 0 1px rgba(45, 122, 94, .12);
}
.template-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.template-card h4 {
  margin: 0;
  font-size: 15px;
}
.template-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.template-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.template-actions {
  display: flex;
  justify-content: flex-end;
}
.paint-grid {
  display: grid;
  gap: 10px;
}
.library-groups {
  display: grid;
  gap: 16px;
}
.brand-group {
  display: grid;
  gap: 10px;
}
.brand-group header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.brand-group h4 {
  margin: 0;
  font-size: 16px;
}
.brand-group p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.paint-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.paint-card.is-custom {
  border-color: rgba(45, 122, 94, .35);
  box-shadow: inset 0 0 0 1px rgba(45, 122, 94, .08);
}
.paint-card .swatch {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.paint-meta {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.paint-meta strong,
.paint-meta span,
.paint-meta code {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.paint-meta strong { font-size: 13px; }
.paint-meta span,
.paint-meta code {
  color: var(--muted);
  font-size: 11px;
}
.paint-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: #4b5059;
  font-size: 10px;
  font-weight: 800;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.badge-custom {
  background: var(--green-soft);
  color: var(--green);
}
.badge-warning {
  background: rgba(217, 108, 76, .14);
  color: var(--accent-dark);
}
.paint-warning {
  color: var(--accent-dark);
  font-size: 10px;
  line-height: 1.45;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.empty-pool,
.empty-library {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  font-family: "Segoe UI", system-ui, sans-serif;
}

.custom-form {
  display: grid;
  gap: 6px;
}

.grid-summary {
  margin-top: 20px;
  padding: 15px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
}
.grid-summary strong,
.grid-summary span {
  display: block;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.grid-summary strong { font-size: 16px; }
.grid-summary span {
  margin-top: 4px;
  color: rgba(255,255,255,.68);
  font-size: 10px;
}

footer {
  padding: 0 20px 34px;
  color: var(--muted);
  text-align: center;
  font-size: 10px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  font-family: "Segoe UI", system-ui, sans-serif;
  transition: .2s;
  box-shadow: 0 10px 30px rgba(0,0,0,.22);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 980px);
    margin-top: 12px;
  }
  .controls {
    position: static;
    max-height: none;
  }
  .panel { max-height: none; }
  .workspace-card, .editor, .empty-state { min-height: auto; }
  .empty-state { min-height: 70vh; }
  .canvas-stage { min-height: 52vh; }
  #viewCanvas { max-height: 70vh; }
  .mobile-actions { display: block; }
}

@media (max-width: 760px) {
  .tabs { grid-template-columns: repeat(2, 1fr); }
  .two-columns { grid-template-columns: 1fr; }
  .paint-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }
  .paint-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 64px;
    padding: 9px 12px;
  }
  .brand small { display: none; }
  .brand-mark { width: 38px; height: 38px; }
  .privacy-pill { padding: 7px 9px; font-size: 10px; }
  .privacy-pill .privacy-dot { width: 7px; height: 7px; }
  .app-shell {
    width: calc(100% - 12px);
    gap: 10px;
    margin-bottom: 18px;
  }
  .workspace-card, .controls { border-radius: 17px; }
  .empty-state {
    margin: 7px;
    padding: 34px 17px;
  }
  .empty-state h1 { font-size: 34px; }
  .empty-state > p:not(.microcopy):not(.privacy-note) { font-size: 14px; }
  .canvas-stage {
    padding: 7px;
    min-height: 49vh;
  }
  #viewCanvas {
    max-height: 63vh;
    min-height: 180px;
  }
  .canvas-hint { bottom: 17px; }
  .panel { padding: 17px; }
  .image-meta strong { max-width: 42vw; }
  .toolbar-actions .button { padding-inline: 9px; }
  .pool-actions { flex-direction: column; }
  .pool-actions .button,
  .pool-actions .file-button { width: 100%; }
}

@media print {
  .topbar,
  .controls,
  .canvas-toolbar,
  .canvas-hint,
  .mobile-actions,
  footer { display: none !important; }
  body,
  .app-shell,
  .workspace-card,
  .editor,
  .canvas-stage {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 0;
    background: #fff;
    border: 0;
    box-shadow: none;
  }
  #viewCanvas {
    max-width: 100%;
    max-height: 100vh;
    box-shadow: none;
  }
}
