:root {
  --bar-h: 50px;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #ffffff;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background: var(--bg);
}

/* ---- toolbar ---- */
.toolbar {
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
  font-size: 13px;
}
.brand {
  font-weight: 700;
  letter-spacing: 0;
  font-size: 15px;
  white-space: nowrap;
  color: var(--ink);
  text-decoration: none;
}
.brand span { color: var(--muted); margin: 0 1px; }
.controls { display: flex; gap: 5px; align-items: center; flex-wrap: nowrap; white-space: nowrap; }
.badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}
.badge:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; }
/* When the badge is present it takes the auto-margin; keep the hint snug. */
.badge + .hint { margin-left: 12px; }
/* Drop the verbose hint on narrower widths so the toolbar stays on one line. */
@media (max-width: 1280px) {
  .hint { display: none; }
}

button, select, input, textarea {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 5px;
  padding: 7px 11px;
  cursor: pointer;
}
/* toolbar controls are tighter than form fields in the drawers */
.controls button, .controls select { padding: 5px 8px; border-radius: 4px; }
button:hover { background: #f7f7f8; }
button:active { transform: translateY(1px); }
select { cursor: pointer; }
textarea, input { cursor: text; width: 100%; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#generate { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
#generate:hover { opacity: 0.9; background: var(--ink); }
button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
button.active:hover { background: var(--ink); opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: default; }

/* ---- shared (read-only) view ---- */
.shared-title { display: flex; align-items: center; gap: 12px; margin-left: auto; min-width: 0; }
.shared-title.hidden { display: none; }
.shared-title .shared-name { font-weight: 700; }
.shared-title a { color: var(--muted); font-size: 13px; text-decoration: none; white-space: nowrap; }
.shared-title a:hover { color: var(--ink); }
/* name + the fun LLM description stacked; description is muted and clipped */
.shared-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.shared-blurb {
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  max-width: 56ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shared-blurb.hidden { display: none; }
/* In shared mode, hide the editor controls — only the title + strip remain. */
body.shared .controls,
body.shared .badge,
body.shared .hint,
body.shared #userChip { display: none; }
/* let the header grow to fit the stacked name + description */
body.shared .toolbar { height: auto; min-height: var(--bar-h); padding-top: 6px; padding-bottom: 6px; }
body.shared .swatch.readonly { cursor: default; }

/* ---- swatch strip ---- */
.strip {
  height: calc(100vh - var(--bar-h));
  display: flex;
}

/* On narrow screens a single row turns the swatches into unusable slivers.
   Switch to a gapless 2-column grid that scrolls instead. */
@media (max-width: 640px) {
  /* the toolbar wraps onto as many rows as it needs instead of scrolling
     sideways — every control stays reachable without horizontal scrolling */
  .toolbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px 6px; }
  .controls { flex-wrap: wrap; }
  .badge { margin-left: 0; }
  /* (mobile drawer = full-screen sheet; rules live after the .drawer base
     below so they win the cascade — see the dedicated media query there) */

  .strip {
    height: auto;
    min-height: calc(100vh - var(--bar-h));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }
  .strip .swatch {
    min-height: 32vh;
    padding: 0 8px 14px;
    justify-content: center;
    cursor: default;
    /* allow vertical flicks to scroll the grid; the touch editor engages only
       after a press-and-hold, then preventDefault()s to take over the drag */
    touch-action: pan-y;
  }
  /* a lone trailing swatch spans the full width instead of leaving a gap */
  .strip .swatch:last-child:nth-child(odd) { grid-column: 1 / -1; }
  /* resting state stays clean: just the icons + hex + name. No hover, so the
     action icons are always shown; the dense readout and HSB panel are hidden. */
  .strip .swatch .actions { opacity: 1; }
  .strip .swatch .icon.move { display: inline-block; }
  .strip .swatch .formats { display: none; }
  .strip .swatch .adjust { display: none; }
  /* engaged feedback: an inner ring in the swatch's adaptive ink */
  .strip .swatch.adjusting { box-shadow: inset 0 0 0 3px currentColor; }
  /* brightness strip appears only while a swatch is being edited */
  .strip .swatch.editing .bright {
    display: block;
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 8px;
    width: auto;
    height: 16px;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit; /* so accent-color follows the swatch's adaptive ink */
    accent-color: currentColor;
    opacity: 0.95;
  }
}
.swatch {
  flex: 1 1 0;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 7vh;
  transition: transform 0.16s ease;
  user-select: none;
  cursor: grab;
  touch-action: none; /* allow pointer-drag on touch devices */
}
.swatch .actions {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding-top: 12px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.swatch:hover .actions { opacity: 1; }
.swatch .icon {
  background: transparent;
  border: none;
  color: inherit; /* follow the swatch's adaptive ink instead of the global --ink */
  line-height: 0;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
}
.swatch .icon svg { width: 17px; height: 17px; display: block; }
.swatch .icon:hover { background: rgba(0,0,0,0.08); }
.swatch.locked .lock { opacity: 1; }
.swatch .lock { opacity: 0.55; }

.swatch .hexval {
  font-weight: 700;
  font-size: clamp(15px, 1.6vw, 22px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: transparent;
  border: none;
  color: inherit; /* follow the swatch's adaptive ink instead of the global --ink */
  text-align: center;
  width: 8ch;
  cursor: text;
  padding: 2px 0;
}
.swatch .cname {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 4px;
  min-height: 1em;
  text-align: center;
  max-width: 90%;
}
/* Instant nearest-color guess, before/without the LLM idiom. */
.swatch .cname-local { opacity: 0.55; font-style: italic; }
.swatch .formats {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.12s ease;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.swatch:hover .formats { opacity: 0.8; }
.swatch.dragging {
  transition: none; /* follow the cursor with no lag */
  z-index: 30;
  cursor: grabbing;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

/* The bottom brightness strip and the reorder handle are mobile-only controls
   (shown in the media query below); the desktop swatch uses the hover HSB panel
   and whole-swatch drag instead. */
.swatch .bright { display: none; }
.swatch .move { display: none; }
.swatch.reordering { opacity: 0.5; }
.swatch.drop-target { box-shadow: inset 0 0 0 4px currentColor; }

/* long-hover HSB adjust panel — sits in the swatch's empty middle */
.swatch .adjust {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: min(82%, 200px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
.swatch .adjust.show {
  opacity: 0.92;
  pointer-events: auto;
}
.swatch .adjust label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
}
.swatch .adjust input[type="range"] {
  flex: 1;
  margin: 0;
  cursor: pointer;
  accent-color: currentColor; /* thumb follows the swatch's adaptive ink */
}

/* ---- drawers ---- */
.drawer {
  position: fixed;
  top: var(--bar-h);
  right: 0;
  width: min(420px, 100vw);
  height: calc(100vh - var(--bar-h));
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0,0,0,0.06);
  z-index: 10;
  display: flex;
  flex-direction: column;
}
.drawer.hidden { display: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 15px; }
.close { border: none; font-size: 20px; padding: 2px 8px; }
.drawer-body { padding: 16px; overflow-y: auto; }

/* On phones the drawer becomes a full-screen sheet that slides up — an opaque,
   self-contained surface instead of a desktop side panel peeking over the app.
   Placed after the .drawer base so these win the cascade on mobile. */
@media (max-width: 640px) {
  .drawer {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh; /* dvh tracks the iOS dynamic toolbar; vh fallback below */
    border-left: none;
    box-shadow: none;
    z-index: 40; /* above toolbar (5) + toast (20), below login overlay (50) */
  }
  .drawer-head { padding: 16px; }
  .drawer-head h2 { font-size: 18px; }
  /* a comfortable 44px tap target for dismiss */
  .close { font-size: 26px; line-height: 1; padding: 10px 12px; margin: -8px -6px -8px 0; }
  .drawer-body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  /* lock the page behind the sheet so it can't scroll through */
  body.drawer-open { overflow: hidden; }
}

.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { flex: 1; }

.palettes-list { display: flex; flex-direction: column; gap: 12px; }
.pcard { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pcard .swatches { display: flex; height: 44px; }
.pcard .swatches div { flex: 1; }
.pcard .meta { padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.pcard .meta .title { font-size: 13px; font-weight: 600; }
.pcard .meta .sub { font-size: 11px; color: var(--muted); }
.pcard .meta .spacer { margin-left: auto; }
.pcard .meta button { padding: 4px 8px; font-size: 12px; }

.ai-block { margin-bottom: 18px; }
.ai-block label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.ai-block textarea { margin-bottom: 8px; }
.ai-output { font-size: 13px; color: var(--ink); }
.ai-output .row { display: flex; height: 40px; border-radius: 8px; overflow: hidden; margin: 8px 0; }
.ai-output .row div { flex: 1; }
.ai-output .reason { color: var(--muted); margin-top: 6px; }
.ai-output .err { color: #b91c1c; }
.ai-output .applybar { display: flex; gap: 8px; margin-top: 8px; }
.spinner { color: var(--muted); font-size: 13px; }

/* ---- palette audit ---- */
.audit-report {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.audit-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.audit-summary h3,
.audit-section h3,
.audit-issues h3,
.audit-pro h3 {
  margin: 0;
  font-size: 13px;
}
.audit-summary strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.audit-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.audit-rating-strong { border-color: #86efac; background: #f0fdf4; }
.audit-rating-usable { border-color: #bfdbfe; background: #eff6ff; }
.audit-rating-limited { border-color: #fde68a; background: #fffbeb; }
.audit-rating-decorative { border-color: #fecaca; background: #fef2f2; }
.audit-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.audit-stats div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.audit-stats strong {
  display: block;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.audit-stats span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}
.audit-section,
.audit-issues {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.audit-issues ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.audit-issues p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.audit-roles {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.audit-role {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}
.audit-role > span:first-child {
  color: var(--muted);
  font-weight: 700;
}
.audit-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.audit-empty {
  color: var(--muted);
  font-size: 12px;
}
.audit-pairs {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.audit-pair {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
}
.audit-pair-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-weight: 900;
}
.audit-pair strong,
.audit-pair span {
  display: block;
  font-size: 12px;
}
.audit-pair span {
  margin-top: 2px;
  color: var(--muted);
}
.audit-matrix {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 11px;
}
.audit-matrix th,
.audit-matrix td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.audit-matrix th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.audit-matrix .audit-chip {
  min-width: 72px;
  min-height: 24px;
  font-size: 10px;
}
.audit-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.audit-label-aaa,
.audit-label-aa { color: #166534; background: #dcfce7; }
.audit-label-aa-large { color: #92400e; background: #fef3c7; }
.audit-label-fail { color: #991b1b; background: #fee2e2; }
.audit-pro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 14px;
  border: 1px dashed #c8ccd3;
  border-radius: 8px;
  background: #fafafa;
}
.audit-pro p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.audit-pro a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

/* ---- user chip ---- */
.userchip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.userchip.hidden { display: none; }
.userchip img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
}
.userchip .name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userchip button { padding: 5px 9px; font-size: 12px; white-space: nowrap; border-radius: 4px; }
.userchip .name { white-space: nowrap; }

/* ---- login overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.login-brand { font-weight: 700; font-size: 22px; letter-spacing: 0; }
.login-brand span { color: var(--muted); }
.login-sub { color: var(--muted); font-size: 14px; margin: 8px 0 20px; }
.login-buttons { display: flex; flex-direction: column; gap: 10px; }
.login-buttons a {
  display: block;
  text-decoration: none;
  text-align: center;
  font-weight: 600;
  padding: 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--ink);
}
.login-buttons a:hover { background: #f7f7f8; }
.login-buttons a.github { background: var(--ink); color: #fff; border-color: var(--ink); }
.login-skip {
  margin-top: 16px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
}

/* ---- image color picker ---- */
.image-card {
  background: #fff;
  border-radius: 16px;
  width: min(520px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
}
.image-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.image-head h2 { margin: 0; font-size: 15px; }
.image-body { padding: 18px; }
.image-dropzone {
  display: flex;
  min-height: 112px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px;
  border: 1px dashed #c8ccd3;
  border-radius: 10px;
  background: #fafafa;
  text-align: center;
  cursor: pointer;
}
.image-dropzone:hover,
.image-dropzone.dragover {
  border-color: var(--ink);
  background: #f4f4f5;
}
.image-drop-main {
  font-weight: 700;
  font-size: 14px;
}
.image-drop-sub {
  color: var(--muted);
  font-size: 12px;
}
.image-drop-mobile,
.image-mobile-actions { display: none; }
.image-source-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.image-source-button:hover { background: #f7f7f8; }
.image-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.image-tools label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.image-tools input {
  width: 76px;
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
}
.image-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  min-height: 160px;
  max-height: 42vh;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f3f4f6;
  overflow: hidden;
}
.image-preview.hidden { display: none; }
.image-preview img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 42vh;
  object-fit: contain;
}
.image-palette-row {
  display: flex;
  height: 58px;
  margin-top: 14px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.image-palette-row:empty { display: none; }
.image-palette-row div {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 7px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.image-status {
  min-height: 18px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}
.image-status.err { color: #b91c1c; }
.image-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}
.image-actions button {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  font-weight: 600;
}
.image-actions button:hover { background: var(--ink); opacity: 0.9; }

@media (max-width: 640px) {
  .image-card {
    width: min(100vw - 16px, 420px);
    max-height: calc(100dvh - 24px);
    border-radius: 12px;
  }
  .image-head { padding: 14px 16px; }
  .image-head h2 { font-size: 16px; }
  .image-body { padding: 16px; }
  .image-dropzone {
    min-height: 92px;
    padding: 14px;
  }
  .image-drop-main,
  .image-drop-sub { display: none; }
  .image-drop-mobile {
    display: block;
    font-size: 14px;
    font-weight: 700;
  }
  .image-mobile-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
  }
  .image-tools {
    justify-content: space-between;
    margin-top: 12px;
  }
  .image-tools input {
    width: 84px;
    min-height: 40px;
  }
  .image-preview {
    min-height: 132px;
    max-height: 32dvh;
    margin-top: 12px;
  }
  .image-preview img { max-height: 32dvh; }
  .image-palette-row {
    height: 50px;
    margin-top: 12px;
  }
  .image-palette-row div {
    padding: 6px 2px;
    font-size: 9px;
  }
  .image-actions { margin-top: 12px; }
  .image-actions button {
    min-height: 44px;
    min-width: 132px;
  }
}

/* ---- export / share modal ---- */
.export-card {
  background: #fff;
  border-radius: 16px;
  width: min(420px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
}
.export-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.export-head h2 { margin: 0; font-size: 15px; }
.export-preview {
  padding: 18px;
  display: flex;
  justify-content: center;
  background: repeating-conic-gradient(#f3f4f6 0% 25%, #fff 0% 50%) 50% / 22px 22px;
  border-bottom: 1px solid var(--line);
}
#exportCanvas {
  max-width: 100%;
  max-height: 46vh;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.export-controls { padding: 16px 18px 18px; }
.seg {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}
.seg button {
  flex: 1;
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  font-weight: 600;
  padding: 8px;
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--ink); color: #fff; }
.seg button.active:hover { background: var(--ink); opacity: 0.9; }
.export-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.export-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  width: 52px;
  flex: none;
}
.export-row button { padding: 7px 12px; font-size: 13px; flex: 1; }
.export-row button.motion { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.export-row button.motion:hover { opacity: 0.9; background: var(--ink); }
.export-progress {
  font-size: 12px;
  color: var(--muted);
  width: 116px;
  text-align: right;
  flex: 0 0 116px;
  font-variant-numeric: tabular-nums;
}

/* ---- production token export modal ---- */
.token-card {
  background: #fff;
  border-radius: 16px;
  width: min(760px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.token-body {
  padding: 16px 18px 18px;
}
.token-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.token-title {
  font-size: 15px;
  font-weight: 700;
}
.token-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.token-swatches {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.token-swatches span {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.14);
}
.token-section {
  margin-top: 16px;
}
.token-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}
.token-role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.token-role-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}
.token-role-row span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.token-role-row select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  background: #fff;
}
.token-format-seg {
  margin-bottom: 10px;
}
.token-code {
  margin: 0;
  min-height: 260px;
  max-height: 40vh;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111827;
  color: #e5e7eb;
  font-size: 12px;
  line-height: 1.55;
}
.token-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}
.token-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.token-actions button {
  min-width: 108px;
  padding: 8px 12px;
}
.token-actions .motion {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  font-weight: 600;
}

@media (max-width: 640px) {
  .token-summary {
    align-items: flex-start;
    flex-direction: column;
  }
  .token-role-grid {
    grid-template-columns: 1fr;
  }
  .token-role-row {
    grid-template-columns: 82px minmax(0, 1fr);
  }
  .token-code {
    min-height: 220px;
    max-height: 34vh;
  }
}

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 20;
}
.toast.hidden { display: none; }

/* ---- home page ---- */
.home-page {
  --home-ink: #151515;
  --home-muted: #666b73;
  --home-line: #d9dde3;
  --home-soft: #f6f7f9;
  --home-surface: #ffffff;
  --home-accent: #f2673a;
  --home-blue: #6f4938;
  --home-primary: #6f4938;
  min-height: 100%;
  color: var(--home-ink);
  background:
    linear-gradient(180deg, rgba(246, 247, 249, 0.9) 0%, rgba(255, 255, 255, 0) 42%),
    #ffffff;
}

.home-page a { color: inherit; }

.home-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  min-height: 64px;
  padding: 0 clamp(18px, 4vw, 52px);
  border-bottom: 1px solid rgba(21, 21, 21, 0.08);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.home-brand,
.home-footer > span {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.home-brand span,
.home-footer span span { color: var(--home-muted); }

.home-nav nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3vw, 30px);
}

.home-nav nav a,
.home-nav-cta,
.home-footer a {
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.home-nav nav a { color: var(--home-muted); }
.home-nav nav a:hover,
.home-footer a:hover { color: var(--home-ink); }

.home-nav-cta {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--home-ink);
  border-radius: 6px;
  color: #fff;
  background: var(--home-ink);
}

.hero-section,
.ksp-section,
.comparison-section,
.pricing-section {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
}

.hero-section {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(520px, 1.1fr);
  gap: clamp(34px, 5vw, 76px);
  align-items: center;
  min-height: clamp(680px, calc(100svh - 140px), 780px);
  padding: clamp(42px, 6vw, 74px) 0 clamp(36px, 5vw, 58px);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 24px;
}

.hero-copy h1 {
  margin: 0;
  max-width: 10.5ch;
  font-size: clamp(54px, 8vw, 102px);
  line-height: 0.94;
  letter-spacing: 0;
}

.hero-copy h1 span { color: var(--home-primary); }

.hero-copy p {
  margin: 0;
  max-width: 58ch;
  color: var(--home-muted);
  font-size: clamp(17px, 1.8vw, 21px);
  line-height: 1.55;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  border: 1px solid var(--home-line);
}

.home-page .button-primary {
  background: var(--home-primary);
  border-color: var(--home-primary);
  color: #fff;
}

.home-page .button-primary:hover { background: #064ec1; border-color: #064ec1; }

.home-page .home-nav-cta { color: #fff; }

.home-nav-cta:hover { background: #2a2a2a; }

.button-secondary {
  background: #fff;
  color: var(--home-ink);
}

.button-secondary:hover { background: var(--home-soft); }

.studio-preview {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(21, 21, 21, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 22px 60px rgba(21, 21, 21, 0.12);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.preview-toolbar span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--home-line);
  border-radius: 6px;
  background: #fff;
  color: var(--home-muted);
  font-size: 12px;
  font-weight: 800;
}

.preview-swatches {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  min-height: 360px;
  overflow: hidden;
  border-radius: 7px;
}

.preview-swatches div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  padding: 18px 12px;
  color: var(--ink);
  background: var(--swatch);
}

.preview-swatches strong,
.preview-swatches span {
  display: block;
  color: var(--ink);
  overflow-wrap: normal;
}

.preview-swatches strong {
  font-size: 14px;
  line-height: 1.15;
}

.preview-swatches span {
  font-size: 12px;
  font-weight: 800;
  opacity: 0.82;
}

.preview-panels {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 12px;
}

.image-picker-panel,
.token-panel {
  min-height: 116px;
  border: 1px solid var(--home-line);
  border-radius: 8px;
  background: #fff;
}

.image-picker-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--home-muted);
  font-size: 12px;
  font-weight: 800;
}

.image-chip-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.image-chip-grid span {
  display: block;
  aspect-ratio: 1;
  border-radius: 6px;
}

.token-panel {
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 14px;
}

.token-panel code {
  display: block;
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--home-soft);
  color: #2b3037;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  overflow-x: auto;
}

.ksp-section,
.comparison-section,
.pricing-section {
  padding: clamp(54px, 7vw, 88px) 0;
  border-top: 1px solid rgba(21, 21, 21, 0.08);
}

.section-intro {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(300px, 0.65fr);
  gap: clamp(20px, 5vw, 72px);
  align-items: end;
  margin-bottom: 30px;
}

.section-intro h2 {
  margin: 0;
  font-size: clamp(34px, 5vw, 62px);
  line-height: 1;
  letter-spacing: 0;
}

.section-intro p {
  margin: 0;
  color: var(--home-muted);
  font-size: 16px;
  line-height: 1.6;
}

.ksp-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.ksp-grid article {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 226px;
  padding: 20px;
  border: 1px solid var(--home-line);
  border-radius: 8px;
  background: #fff;
}

.ksp-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: var(--home-soft);
  color: var(--home-ink);
  font-size: 12px;
  font-weight: 900;
}

.ksp-grid article:nth-child(2) .ksp-marker { background: #f3ece7; color: var(--home-blue); }
.ksp-grid article:nth-child(3) .ksp-marker { background: #e9f7f1; color: #27725c; }
.ksp-grid article:nth-child(4) .ksp-marker { background: #fff0e9; color: var(--home-accent); }

.ksp-grid h3,
.pricing-card h3,
.newsletter-panel h3 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
}

.ksp-grid p,
.pricing-card li,
.newsletter-panel p {
  margin: 0;
  color: var(--home-muted);
  font-size: 14px;
  line-height: 1.55;
}

.comparison-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--home-line);
  border-radius: 8px;
  background: #fff;
}

.comparison-table {
  width: 100%;
  min-width: 740px;
  border-collapse: collapse;
  text-align: left;
}

.comparison-table th,
.comparison-table td {
  padding: 18px 20px;
  border-bottom: 1px solid var(--home-line);
  vertical-align: top;
  font-size: 14px;
  line-height: 1.45;
}

.comparison-table thead th {
  color: var(--home-muted);
  font-size: 12px;
  text-transform: uppercase;
}

.comparison-table tbody th {
  width: 28%;
  font-size: 15px;
}

.comparison-table td { color: var(--home-muted); }
.comparison-table td:last-child { color: var(--home-ink); font-weight: 700; }
.comparison-table tr:last-child th,
.comparison-table tr:last-child td { border-bottom: none; }

.pricing-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr) minmax(320px, 0.9fr);
  gap: 14px;
  align-items: stretch;
}

.pricing-card,
.newsletter-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--home-line);
  border-radius: 8px;
  background: #fff;
}

.pricing-card-pro {
  border-color: rgba(21, 21, 21, 0.42);
  box-shadow: inset 0 0 0 1px rgba(21, 21, 21, 0.18);
}

.price {
  margin: 8px 0 0;
  font-size: 44px;
  line-height: 1;
  font-weight: 900;
}

.price span {
  color: var(--home-muted);
  font-size: 16px;
  font-weight: 800;
}

.pricing-card ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pricing-card li {
  position: relative;
  padding-left: 18px;
}

.pricing-card li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.66em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--home-accent);
}

.pricing-card .button { margin-top: auto; width: 100%; }

.newsletter-panel {
  background:
    linear-gradient(135deg, rgba(242, 103, 58, 0.12), rgba(83, 103, 255, 0.12)),
    #fff;
}

.newsletter-form {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.newsletter-form label {
  font-size: 12px;
  font-weight: 900;
  color: var(--home-muted);
}

.newsletter-form > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.newsletter-form input {
  min-height: 44px;
  border-radius: 6px;
  background: #fff;
}

.newsletter-form button {
  min-height: 44px;
  border-color: var(--home-ink);
  border-radius: 6px;
  background: var(--home-ink);
  color: #fff;
  font-weight: 800;
}

.form-status {
  min-height: 20px;
  margin: 0;
  color: var(--home-muted);
  font-size: 13px;
}

.form-status.error { color: #a23b25; }
.form-status.success { color: #1d6b55; }

.home-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 34px 0 46px;
  border-top: 1px solid rgba(21, 21, 21, 0.08);
  color: var(--home-muted);
}

.home-footer > span { margin-right: auto; color: var(--home-ink); }

@media (max-width: 980px) {
  .home-nav {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px 18px;
  }

  .home-nav nav {
    grid-column: 1 / -1;
    order: 3;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .hero-section {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 50px;
  }

  .hero-copy h1 { max-width: 11.5ch; }
  .studio-preview { max-width: 760px; }
  .section-intro,
  .pricing-grid { grid-template-columns: 1fr; }
  .ksp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .home-nav-cta { min-height: 36px; padding: 0 12px; }
  .hero-section,
  .ksp-section,
  .comparison-section,
  .pricing-section,
  .home-footer { width: min(100% - 28px, 1180px); }
  .hero-copy h1 {
    max-width: 12ch;
    font-size: 50px;
  }
  .preview-swatches {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 520px;
  }
  .preview-panels,
  .ksp-grid,
  .newsletter-form > div { grid-template-columns: 1fr; }
  .comparison-table th,
  .comparison-table td { padding: 15px 16px; }
}

@media (max-width: 520px) {
  .comparison-table { min-width: 0; }
  .comparison-table th,
  .comparison-table td {
    padding: 12px 7px;
    font-size: 11px;
    line-height: 1.35;
  }
  .comparison-table thead th { font-size: 9px; }
  .comparison-table tbody th {
    width: 33%;
    font-size: 11px;
  }
}
