:root {
  color-scheme: light;
  --ink: #1c1917;
  --muted: #78716c;
  --paper: #f3efe8;
  --panel: #fffcf8;
  --line: #e5dfd6;
  --accent: #1d4ed8;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button, input { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  height: 100vh;
  overflow: hidden;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 0;
  padding: 28px 32px 40px;
  overflow: auto;
}

.preview-head { width: min(100%, 760px); }

h1 {
  margin: 0 0 4px;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#status {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.stage {
  position: relative;
  width: min(100%, 760px, calc(100vh - 170px));
  aspect-ratio: 598 / 600;
  background: white;
  box-shadow: 0 16px 40px rgba(68, 48, 28, 0.12);
  overflow: hidden;
}

.stage img,
.stage canvas,
#labels {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage img,
#labels { pointer-events: none; }

.drawer-label {
  position: absolute;
  width: max-content;
  max-width: 20%;
  transform: translate(-50%, -50%);
  text-align: center;
  line-height: 1.15;
  font-weight: 600;
  pointer-events: none;
  text-wrap: balance;
}

.drawer-label[data-drawer="center"] {
  white-space: nowrap;
  text-wrap: nowrap;
}

.ral-name {
  display: block;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.names-toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  font-size: 14px;
  cursor: pointer;
}

.names-toggle input { margin: 0; }

.drawer-label.on-light {
  color: #1c1917;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.95), 0 1px 0 rgba(255, 255, 255, 0.8);
}

.drawer-label.on-dark {
  color: white;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.8), 0 1px 1px rgba(0, 0, 0, 0.45);
}

.palette {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.palette-head {
  padding: 22px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.palette h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.drawer-list {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.drawer-pick {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 2px 10px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.drawer-pick::before {
  content: "";
  grid-row: 1 / span 2;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--pick, transparent);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.drawer-pick-name { font-size: 14px; font-weight: 600; }

.drawer-pick-detail {
  color: var(--muted);
  font-size: 12px;
}

.drawer-pick:hover { background: #f6f2eb; }

.drawer-pick.is-selected {
  background: #f3efe8;
  border-color: #1c1917;
}

.palette-tools {
  display: flex;
  gap: 8px;
}

#search {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

#search:focus, .swatch:focus-visible, .drawer-pick:focus-visible, #clear:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#clear {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

#clear:disabled { color: #a8a29e; cursor: default; }

.swatches {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px 28px;
}

.ral-group h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 10px 8px 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.swatch {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 4px 8px;
  scroll-margin-top: 38px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.swatch:hover { background: #f6f2eb; }

.swatch.is-current { box-shadow: inset 0 0 0 1.5px #1c1917; background: #f3efe8; }

.chip {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}

.swatch-text { display: flex; gap: 8px; align-items: baseline; min-width: 0; }

.swatch-code {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 13px;
}

.swatch-name {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  margin: 0;
  padding: 16px 18px 24px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .palette { border-left: 0; border-top: 1px solid var(--line); }
  .swatches { max-height: 70vh; }
  .stage { width: min(100%, calc(100vh - 220px)); }
}
