:root {
  --bg: #0f1116;
  --panel: #171a22;
  --border: #272c38;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 20px 72px;
}

.page-head { text-align: center; margin-bottom: 36px; }

.page-head h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sub { margin: 0; color: var(--muted); font-size: 16px; }

/* ---------- Picker ---------- */
.picker {
  display: flex;
  gap: 22px;
  align-items: flex-start;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.picker-controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 240px;
}

.sv-pad {
  position: relative;
  width: 240px;
  height: 170px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: crosshair;
  overflow: hidden;
  touch-action: none;
}

.sv-white, .sv-black {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.sv-white { background: linear-gradient(to right, #fff, rgba(255, 255, 255, 0)); }
.sv-black { background: linear-gradient(to top, #000, rgba(0, 0, 0, 0)); }

.sv-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sv-pad:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.hue-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: linear-gradient(to right,
    #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
}
.hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #333;
  cursor: pointer;
}
.hue-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #333;
  cursor: pointer;
}
.hue-slider:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.base-readout {
  display: flex;
  gap: 16px;
  align-items: center;
  flex: 1 1 280px;
}

.base-chip {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.base-fields { display: flex; flex-direction: column; gap: 10px; flex: 1 1 auto; }

.field { display: flex; align-items: center; gap: 10px; }

.field label, .field-label {
  flex: 0 0 56px;
  width: 56px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.field input {
  flex: 1 1 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 14px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field input.invalid { border-color: #ef4444; }

/* Read-only derived values (CMYK, Pantone) — styled to align with inputs but
   plainly non-editable. */
.field-value {
  flex: 1 1 auto;
  padding: 8px 10px;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 14px;
}

/* ---------- Palette ---------- */
.palette-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
  margin: 40px 0 16px;
}

.palette {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 540px) {
  .palette { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.swatch {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.swatch:hover { transform: translateY(-3px); }

.swatch-copy {
  display: block;
  width: 100%;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
}
.swatch-copy:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }

.swatch-color { height: 96px; width: 100%; }

.swatch-meta {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 10px 50px 10px 12px;
}

.swatch-promote {
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(15, 17, 22, 0.82);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, transform 0.12s ease;
}
.swatch-promote:hover { background: var(--accent); transform: translateY(-1px); }
.swatch-promote:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.swatch-role { font-size: 12px; color: var(--muted); margin-bottom: 2px; }

.swatch-hex {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
}

.swatch-sub {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 18px; min-height: 1em; }
.hint.copied { color: #34d399; }

/* ---------- Tints & Shades ---------- */
.ts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
}

.ts-swatch {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.ts-swatch:hover { transform: translateY(-3px); }

.ts-copy {
  display: block;
  width: 100%;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  background: none;
}
.ts-copy:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }

.ts-color { height: 68px; width: 100%; display: block; }

.ts-meta {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  padding: 5px 4px;
  text-align: center;
}

.ts-hex {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
}

.ts-swatch.is-base .ts-hex { color: var(--text); }
.ts-swatch.is-base .ts-meta { border-color: var(--accent); }

@media (max-width: 540px) {
  .ts-color { height: 52px; }
  .ts-hex { font-size: 9px; }
}

/* ---------- Palette header (title + export trigger) ---------- */
.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 40px 0 16px;
}
.palette-header .palette-title { margin: 0; }

.export-trigger {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.export-trigger:hover { color: var(--text); border-color: var(--accent); }
.export-trigger:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

@media (max-width: 640px) {
  .export-trigger { display: none; }
}

/* ---------- Export drawer ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.export-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 340px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.export-drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.drawer-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.drawer-close:hover { background: var(--bg); color: var(--text); }
.drawer-close:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.drawer-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.drawer-body .field { flex-direction: column; align-items: flex-start; gap: 6px; }
.drawer-body .field label { width: auto; }
.drawer-body .field input { width: 100%; font-family: inherit; font-size: 15px; }

.export-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.12s ease;
}
.export-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.export-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.export-help {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.6;
}
.export-help summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}
.export-help ol { margin: 12px 0 8px; padding-left: 20px; }
.export-help li { margin-bottom: 6px; }
.export-help code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.footnote {
  margin: 28px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}
.footnote a { color: var(--text); text-decoration: underline; }
.footnote a:hover { color: var(--accent); }

.page-foot {
  margin-top: 44px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}
.page-foot a {
  color: var(--muted);
  text-decoration: none;
}
.page-foot a:hover { color: var(--text); text-decoration: underline; }
