@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --ink: #17181b;
  --muted: #696a70;
  --line: #dedee2;
  --paper: #f5f5f2;
  --white: #fff;
  --accent: #ff5c35;
  --radius: 18px;
  font-family: "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; overflow-x: hidden; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #377dff; outline-offset: 2px; }

.topbar {
  height: 60px; padding: 0 clamp(16px, 2.5vw, 38px); display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(245,245,242,.9);
  backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-size: 1.05rem; font-weight: 800; letter-spacing: -.04em; }
.brand-mark { display: flex; width: 24px; height: 24px; border: 2px solid var(--ink); border-radius: 50%; overflow: hidden; transform: rotate(-20deg); }
.brand-mark i { flex: 1; }
.brand-mark i:nth-child(1) { background: #ffca3a; }
.brand-mark i:nth-child(2) { background: #ff595e; }
.brand-mark i:nth-child(3) { background: #1982c4; }
.header-actions, .section-heading, .palette-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.button { border: 0; border-radius: 999px; padding: 9px 15px; font-weight: 700; transition: transform .18s ease, background .18s ease; }
.button:hover { transform: translateY(-1px); }
.button.ghost { background: transparent; border: 1px solid var(--line); }
.button.dark { background: var(--ink); color: white; }
.button-icon { margin-right: 5px; }
.export-wrap { position: relative; }
.export-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 170px; padding: 6px; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 50px rgba(20,20,20,.14); z-index: 30; }
.export-menu button { width: 100%; border: 0; background: none; text-align: left; padding: 10px 12px; border-radius: 8px; font-weight: 600; }
.export-menu button:hover { background: #f1f1ee; }

main { width: min(1600px, calc(100% - clamp(20px, 3vw, 48px))); margin: 0 auto; padding: 18px 0 48px; }
.intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 14px; }
.eyebrow { margin: 0 0 3px; text-transform: uppercase; letter-spacing: .14em; font-size: .65rem; font-weight: 800; color: var(--muted); }
h1 { margin: 0; max-width: none; font-size: clamp(1.55rem, 2.4vw, 2.5rem); line-height: 1; letter-spacing: -.055em; }
.shortcut { color: var(--muted); font-size: .85rem; white-space: nowrap; }
kbd { background: white; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 4px 7px; font: 500 .78rem "DM Mono", monospace; color: var(--ink); }

.toolbar { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(210px, 1fr) auto; gap: 8px; margin-bottom: 8px; }
.control-group { background: white; border: 1px solid var(--line); border-radius: 12px; min-height: 50px; padding: 7px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.control-group > span { font-size: .75rem; color: var(--muted); font-weight: 700; white-space: nowrap; }
select { border: 0; background: transparent; font-weight: 700; min-width: 125px; color: var(--ink); }
.segmented { display: flex; padding: 3px; background: #efefec; border-radius: 9px; }
.segmented button { border: 0; background: transparent; border-radius: 7px; padding: 5px 9px; font-size: .72rem; font-weight: 800; color: var(--muted); }
.segmented button.active { color: var(--ink); background: white; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.generate { min-width: 190px; border-radius: 12px; color: white; background: var(--accent); font-size: .9rem; }

.palette-shell { background: white; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 18px 60px rgba(18,18,18,.06); }
.palette { display: flex; height: clamp(330px, calc(100svh - 238px), 580px); overflow: hidden; }
.swatch { min-width: 0; flex: 1 1 0; position: relative; display: flex; flex-direction: column; justify-content: flex-end; padding: 14px 12px; transition: flex .22s ease, background .3s ease; isolation: isolate; }
.swatch:hover { flex-grow: 1.12; }
.swatch::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 54%, rgba(0,0,0,.18)); opacity: .48; z-index: -1; }
.swatch-top { position: absolute; inset: 10px 10px auto; display: flex; justify-content: space-between; gap: 6px; }
.icon-button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(255,255,255,.84); color: #151515; display: grid; place-items: center; box-shadow: 0 3px 14px rgba(0,0,0,.12); font-size: 1rem; }
.icon-button:hover { background: white; }
.swatch.locked .lock-button { background: #151515; color: white; }
.remove-button { opacity: 0; transition: opacity .18s ease; }
.swatch:hover .remove-button, .remove-button:focus-visible { opacity: 1; }
.swatch-number { margin: 0 0 auto; padding-top: 40px; color: rgba(0,0,0,.48); font: 500 .67rem "DM Mono", monospace; }
.color-input { width: 100%; border: 0; border-bottom: 1px solid currentColor; background: transparent; padding: 7px 0; color: inherit; font: 500 clamp(.78rem, 1vw, .92rem) "DM Mono", monospace; text-transform: uppercase; }
.color-input::selection { background: rgba(255,255,255,.3); }
.color-name { margin-top: 7px; font-size: .72rem; font-weight: 700; opacity: .72; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.native-picker { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.swatch-actions { display: flex; align-items: center; gap: 7px; }
.picker-button { width: 26px; height: 26px; border: 1px solid currentColor; border-radius: 50%; padding: 3px; background: transparent; color: inherit; }
.picker-button::after { content: ""; display: block; width: 100%; height: 100%; border-radius: 50%; background: currentColor; }
.palette-footer { min-height: 44px; padding: 7px 14px; border-top: 1px solid var(--line); }
.palette-footer p { margin: 0; color: var(--muted); font-size: .83rem; }
.add-color, .text-button { border: 0; background: transparent; font-weight: 800; color: var(--ink); }
.add-color[disabled] { opacity: .35; cursor: not-allowed; }

.adjustments { margin-top: 28px; }
.section-heading { margin-bottom: 12px; }
h2 { margin: 0; letter-spacing: -.04em; font-size: clamp(1.4rem, 2vw, 1.9rem); }
.text-button { color: var(--muted); text-decoration: underline; text-underline-offset: 4px; }
.slider-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.slider-card { background: white; border: 1px solid var(--line); border-radius: 13px; padding: 13px 14px; }
.slider-card > span { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.slider-card output { font: 500 .78rem "DM Mono", monospace; color: var(--muted); }
.slider-card small { display: block; color: var(--muted); margin-top: 7px; }
input[type="range"] { width: 100%; accent-color: var(--ink); }
input.temperature { accent-color: #ff6941; }

.variations-dialog { width: min(1180px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 0; border-radius: 22px; padding: 0; color: var(--ink); box-shadow: 0 32px 100px rgba(0,0,0,.3); overflow: hidden; }
.variations-dialog::backdrop { background: rgba(14,15,18,.65); backdrop-filter: blur(6px); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; padding: 26px 28px 18px; }
.dialog-header p:last-child { color: var(--muted); margin: 6px 0 0; }
.close-dialog { background: #efefec; box-shadow: none; flex: 0 0 auto; }
.variation-tabs { display: flex; gap: 4px; padding: 0 28px 16px; border-bottom: 1px solid var(--line); }
.variation-tabs button { border: 0; border-radius: 999px; background: transparent; padding: 8px 14px; font-weight: 700; color: var(--muted); }
.variation-tabs button.active { background: var(--ink); color: white; }
.variation-grid { display: grid; grid-template-columns: repeat(var(--columns, 6), minmax(110px, 1fr)); overflow: auto; max-height: 65vh; padding: 18px; gap: 8px; }
.variation-column { display: grid; grid-template-rows: repeat(11, 42px); border-radius: 12px; overflow: hidden; min-width: 110px; }
.variation-chip { border: 0; display: flex; justify-content: center; align-items: center; font: 500 .72rem "DM Mono", monospace; transition: transform .12s ease; }
.variation-chip:hover { transform: scale(.96); border-radius: 6px; z-index: 1; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--ink); color: white; padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; font-size: .85rem; font-weight: 700; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .generate { grid-column: 1 / -1; min-height: 46px; }
  .palette { height: clamp(320px, calc(100svh - 284px), 520px); }
  .slider-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .topbar { height: 56px; }
  .button.ghost { width: 38px; height: 38px; padding: 0; font-size: 0; }
  .button-icon { margin: 0; font-size: 1.2rem; }
  main { width: calc(100% - 16px); padding-top: 8px; }
  .intro { display: none; }
  .toolbar { grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
  .control-group { min-width: 0; min-height: 44px; padding: 5px 9px; }
  .control-group > span { display: none; }
  .control-group select, .segmented { width: 100%; }
  .control-group select { min-width: 0; }
  .segmented { justify-content: stretch; }
  .segmented button { flex: 1; }
  .generate { grid-column: 1 / -1; min-height: 44px; }
  .palette-shell { border-radius: 14px; }
  .palette { height: auto; min-height: 0; flex-direction: column; overflow: visible; }
  .swatch { width: 100%; min-width: 0; min-height: clamp(118px, 19svh, 148px); flex: 0 0 auto; padding: 12px 14px; }
  .swatch:hover { flex-grow: 0; }
  .swatch::after { background: linear-gradient(90deg, transparent 52%, rgba(0,0,0,.14)); }
  .swatch-number { padding-top: 30px; }
  .swatch-actions { max-width: min(62vw, 280px); }
  .remove-button { opacity: 1; }
  .palette-footer { position: sticky; bottom: 0; z-index: 4; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); }
  .slider-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .variation-grid { grid-template-columns: repeat(var(--columns, 6), 128px); }
}
@media (max-width: 430px) {
  .header-actions { gap: 6px; }
  .button.dark { padding-inline: 12px; }
  .toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .segmented button { padding-inline: 5px; }
  .swatch { min-height: 122px; }
  .color-name { margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition-duration: .01ms !important; } }

/* Compact, viewport-fitted workspace */
html { height: 100%; }
body { height: 100svh; overflow: hidden; }
main {
  height: calc(100svh - 60px);
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}
.toolbar { flex: 0 0 auto; }
.palette-shell {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.palette { min-height: 0; height: auto; flex: 1; }
.palette-footer { flex: 0 0 44px; }
.swatch-top { inset: 10px 10px auto auto; justify-content: flex-end; }
.inline-lock {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.82);
  color: #17181b;
  box-shadow: 0 2px 12px rgba(0,0,0,.14);
}
.inline-lock svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.swatch.locked .inline-lock { background: #17181b; color: white; }

.adjustments-panel {
  width: min(380px, calc(100vw - 20px));
  height: 100svh;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 20px 0 0 20px;
  color: var(--ink);
  box-shadow: -24px 0 80px rgba(0,0,0,.2);
}
.adjustments-panel::backdrop { background: rgba(14,15,18,.42); backdrop-filter: blur(3px); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 22px 20px 18px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 16px 20px; }
.adjustments-panel .slider-grid { grid-template-columns: 1fr; gap: 10px; }
.reset-panel { width: 100%; margin-top: 14px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 11px; background: transparent; font-weight: 800; }

@media (max-width: 860px) {
  .palette { height: auto; }
}

@media (max-width: 700px) {
  main { height: calc(100svh - 56px); padding: 8px 0; }
  .palette { min-height: 0; height: auto; flex: 1; flex-direction: column; overflow: hidden; }
  .swatch { width: 100%; min-width: 0; min-height: 0; flex: 1 1 0; padding: 6px 10px; }
  .swatch:hover { flex-grow: 1; }
  .swatch-number, .color-name { display: none; }
  .swatch-top { top: 5px; right: 5px; left: auto; }
  .swatch-actions { max-width: min(76vw, 340px); margin-top: auto; }
  .color-input { padding: 3px 0; }
  .icon-button, .inline-lock { width: 27px; height: 27px; }
  .picker-button { width: 21px; height: 21px; }
  .palette-footer { position: static; flex: 0 0 38px; min-height: 38px; padding-block: 4px; }
  .adjustments-panel { width: min(360px, 92vw); border-radius: 16px 0 0 16px; }
}

@media (max-width: 430px) {
  .swatch { min-height: 0; }
  .swatch-actions { max-width: calc(100% - 32px); }
}

/* Workspace controls */
[hidden] { display: none !important; }
.workspace { min-height: 0; flex: 1; display: flex; gap: 10px; }
.workspace .palette-shell { min-width: 0; }
.workspace .adjustments-panel {
  position: static; min-width: 0; width: 300px; height: auto; max-height: none; flex: 0 0 300px;
  margin: 0; overflow-y: auto; border: 1px solid var(--line); border-radius: 16px;
  background: white; box-shadow: 0 18px 60px rgba(18,18,18,.06);
}
.workspace .panel-header { padding: 14px; }
.workspace .panel-body { padding: 12px; }
.workspace .slider-card { padding: 11px; }
.workspace .slider-card, .workspace .panel-body, .workspace .slider-grid { min-width: 0; }
.workspace .slider-card input[type="range"] { display: block; width: 100%; max-width: 100%; min-width: 0; }
.workspace .slider-card > span { flex-wrap: wrap; gap: 3px; }
.workspace .slider-card small { font-size: .7rem; }
.button.dark { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.button.dark svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.add-color { padding: 7px 12px; border-radius: 9px; background: var(--ink); color: white; font-size: .82rem; }
.add-color:hover { background: #44464c; }
.swatch { cursor: grab; }
.swatch:active { cursor: grabbing; }
.swatch.dragging { opacity: .45; }
.swatch.drop-target { outline: 4px solid white; outline-offset: -4px; }
.swatch-top { position: absolute; inset: 9px 0 auto; justify-content: center; }
.remove-button { margin: auto; }
.swatch-number, .picker-button { display: none !important; }
.swatch-actions { min-width: 0; width: 100%; }
.color-input { min-width: 0; width: 100%; }
.inline-lock {
  position: absolute; left: 50%; bottom: 68px; transform: translateX(-50%);
  width: 36px; height: 36px; opacity: 0; transition: opacity .15s ease;
}
.swatch:hover .inline-lock, .inline-lock:focus-visible, .swatch.locked .inline-lock { opacity: 1; }
.native-picker { width: 1px; height: 1px; }
.variations-view { min-height: 0; flex: 1; display: flex; flex-direction: column; background: white; }
.variations-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; }
.variations-header button { border: 1px solid var(--line); border-radius: 8px; background: white; padding: 6px 10px; font-weight: 700; }
.variations-view .variation-tabs { flex: 0 0 auto; padding: 0 14px 8px; }
.variations-view .variation-grid { min-height: 0; max-height: none; flex: 1; padding: 8px; gap: 3px; grid-template-columns: repeat(var(--columns, 6), minmax(0, 1fr)); overflow: auto; }
.variations-view .variation-column { min-width: 0; grid-template-rows: repeat(11, minmax(28px, 1fr)); }

@media (max-width: 1100px) {
  .workspace.tuning .palette { flex-direction: column; }
  .workspace.tuning .swatch { min-height: 0; flex: 1 1 0; padding: 4px 12px; }
  .workspace.tuning .color-name { display: none; }
  .workspace.tuning .swatch-actions { max-width: 220px; }
  .workspace.tuning .inline-lock { bottom: 7px; left: auto; right: 9px; transform: none; }
  .workspace.tuning .swatch-top { inset: 5px 48px auto auto; }
}
@media (max-width: 700px) {
  .workspace .adjustments-panel { width: 44%; flex-basis: 44%; border-radius: 12px; }
  .workspace.tuning .palette { flex-direction: column; }
  .swatch-top { inset: 3px 0 auto; }
  .remove-button, .inline-lock { opacity: 1; }
  .swatch:hover .remove-button, .remove-button:focus-visible { opacity: 1; }
  .inline-lock { left: 50%; right: auto; bottom: 35px; transform: translateX(-50%); width: 28px; height: 28px; }
  .workspace.tuning .inline-lock { left: 50%; right: auto; bottom: 35px; transform: translateX(-50%); }
  .workspace.tuning .swatch-top { inset: 3px 0 auto; }
  .swatch-actions, .workspace.tuning .swatch-actions { max-width: calc(100% - 34px); }
  .workspace .panel-header { padding: 8px; }
  .workspace .panel-header h2 { font-size: 1rem; }
  .workspace .panel-body { padding: 7px; }
  .workspace .slider-card { padding: 7px; }
  .workspace .slider-card > span { margin-bottom: 5px; }
  .workspace .slider-card b { font-size: .78rem; }
  .workspace .slider-card output { font-size: .68rem; }
  .workspace .slider-card small { display: none; }
  .workspace .slider-grid { gap: 5px; }
  .workspace .palette-footer { gap: 3px; padding-inline: 5px; }
  .workspace .palette-footer p { font-size: .67rem; }
  .workspace .add-color { padding: 5px; font-size: .7rem; }
  .variations-view .variation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .variations-view .variation-column { grid-template-rows: repeat(11, 26px); }
}
@media (hover: none) {
  .inline-lock, .remove-button { opacity: 1; }
}

.mode-control { position: relative; }
.harmony-trigger {
  min-width: 150px; display: inline-flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 8px; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink); font-weight: 800; text-align: left;
}
.harmony-trigger:hover, .harmony-trigger[aria-expanded="true"] { background: #f2f2ef; }
.harmony-trigger svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.harmony-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  width: min(250px, 90vw); max-height: min(360px, 65svh); overflow-y: auto;
  padding: 6px; border: 1px solid var(--line); border-radius: 12px;
  background: white; box-shadow: 0 16px 48px rgba(20,20,20,.18);
}
.harmony-menu button {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 10px 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink); text-align: left; font-size: .86rem; font-weight: 700;
}
.harmony-menu button:hover, .harmony-menu button:focus-visible { background: #f2f2ef; }
.harmony-trigger:focus-visible, .harmony-menu button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.harmony-menu button[aria-selected="true"] { background: #fff1ec; color: #b23d21; }
.harmony-menu button[aria-selected="true"]::after { content: "✓"; }
.inline-lock { padding: 10px; }
.swatch-top { inset: 20px 0 auto; }
@media (max-width: 700px) {
  .harmony-trigger { min-width: 0; width: 100%; padding: 5px 3px; font-size: .85rem; }
  .harmony-menu { left: 0; right: auto; width: max(210px, 100%); }
  .inline-lock { padding: 8px; }
  .swatch-top, .workspace.tuning .swatch-top { inset: 12px 0 auto; }
}

/* Compact toolbar and swatch editing */
.toolbar-actions { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
.toolbar-actions .button { border-radius: 10px; white-space: nowrap; }
.theme-toggle { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme="dark"] .theme-toggle .sun-icon { display: block; }
[data-theme="dark"] .theme-toggle .moon-icon { display: none; }
.swatch-actions { gap: 3px; }
.format-cycle { flex: 0 0 25px; width: 25px; height: 25px; padding: 4px; border: 0; border-radius: 6px; background: rgba(255,255,255,.22); color: inherit; opacity: .82; }
.format-cycle:hover { background: rgba(255,255,255,.38); opacity: 1; }
.format-cycle svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.swatch-tools { position: absolute; left: 50%; bottom: 68px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; }
.swatch-tools .inline-lock, .workspace.tuning .swatch-tools .inline-lock { position: static; inset: auto; transform: none; }
.swatch-tools .edit-button { background: rgba(255,255,255,.82); color: #17181b; }
.swatch.locked .edit-button { opacity: 0; background: rgba(255,255,255,.82); color: #17181b; }
.swatch.locked:hover .edit-button, .swatch.locked .edit-button:focus-visible { opacity: 1; }
@media (hover: none) { .swatch.locked .edit-button { opacity: 1; } }

/* Dark theme */
[data-theme="dark"] { --ink: #f4f4f2; --muted: #b0b1b7; --line: #3a3c42; --paper: #151619; color-scheme: dark; }
[data-theme="dark"] .topbar { background: #1b1c20; }
[data-theme="dark"] .control-group,
[data-theme="dark"] .palette-shell,
[data-theme="dark"] .palette-footer,
[data-theme="dark"] .workspace .adjustments-panel,
[data-theme="dark"] .slider-card,
[data-theme="dark"] .variations-view,
[data-theme="dark"] .harmony-menu,
[data-theme="dark"] .export-menu { background: #222328; color: var(--ink); }
[data-theme="dark"] .harmony-trigger:hover,
[data-theme="dark"] .harmony-trigger[aria-expanded="true"],
[data-theme="dark"] .harmony-menu button:hover,
[data-theme="dark"] .harmony-menu button:focus-visible,
[data-theme="dark"] .export-menu button:hover { background: #35373e; }
[data-theme="dark"] .harmony-menu button[aria-selected="true"] { background: #403029; color: #ffad91; }
[data-theme="dark"] .harmony-menu button,
[data-theme="dark"] .export-menu button,
[data-theme="dark"] .variations-header button { color: var(--ink); }
[data-theme="dark"] .variations-header button { background: #292a30; }
[data-theme="dark"] .button.dark { background: #f4f4f2; color: #191a1e; }
[data-theme="dark"] .button.ghost { color: var(--ink); }
[data-theme="dark"] .add-color { background: #f4f4f2; color: #191a1e; }
[data-theme="dark"] .add-color:hover { background: #d9d9d6; }
[data-theme="dark"] .reset-panel { color: var(--ink); }

@media (max-width: 700px) {
  .toolbar-actions { gap: 4px; }
  .toolbar-actions .button.ghost { width: 38px; height: 38px; }
  .swatch-tools { bottom: 35px; gap: 6px; }
  .workspace.tuning .swatch-tools { bottom: 35px; }
  .swatch-tools .inline-lock { width: 28px; height: 28px; }
  .format-cycle { flex-basis: 23px; width: 23px; height: 23px; }
}

/* Swatch value editor */
main { width: 100%; padding-inline: 12px; }
.swatch { transition: background .3s ease; }
.swatch:hover { flex-grow: 1; }
.toolbar { grid-template-columns: minmax(180px, 1fr) auto auto; }
.toolbar-actions { justify-content: flex-end; }
.toolbar-actions .add-color { min-height: 39px; white-space: nowrap; }
.generate { transition: background .25s ease, color .25s ease; border: 1px solid rgba(0,0,0,.12); }
.swatch-actions { max-width: 100%; }
.value-field { display: flex; align-items: center; min-width: 0; width: 100%; border: 1px solid transparent; border-radius: 10px; padding: 3px 6px; cursor: text; }
.value-field:focus-within { border-color: #377dff; box-shadow: 0 0 0 2px #377dff; background: rgba(255,255,255,.12); }
.hex-prefix { font: 500 clamp(.78rem, 1vw, .92rem) "DM Mono", monospace; }
.color-input { border: 0; border-radius: 5px; padding: 5px 0; outline: 0 !important; outline-offset: 0 !important; text-transform: uppercase; cursor: text; }
.color-input:focus-visible { outline: 0 !important; }
.color-input::selection { background: rgba(255,255,255,.38); }
.swatch-format { position: relative; align-self: flex-start; margin: 6px 0 0 6px; min-width: 65px; border: 1px solid rgba(255,255,255,.38); border-radius: 8px; background: rgba(0,0,0,.13); }
.swatch-format select { appearance: none; min-width: 0; width: 100%; padding: 5px 22px 5px 8px; color: inherit; font-size: .72rem; font-weight: 700; cursor: pointer; }
.swatch-format select option { color: #17181b; background: #fff; }
.swatch-format svg { position: absolute; top: 50%; right: 6px; width: 12px; height: 12px; transform: translateY(-50%); fill: none; stroke: currentColor; stroke-width: 2; pointer-events: none; }
.swatch-tools, .workspace.tuning .swatch-tools { left: 50%; right: auto; bottom: 85px; width: 36px; height: 36px; transform: translateX(-50%); display: block; transition: transform .16s ease; }
.swatch-tools .inline-lock, .workspace.tuning .swatch-tools .inline-lock { position: absolute; top: 0; left: 0; width: 36px; height: 36px; }
.swatch-tools .edit-button, .swatch.locked .edit-button { left: 44px; opacity: 0; pointer-events: none; }
.workspace.tuning .swatch-tools .edit-button { left: 44px; }
.swatch:hover .swatch-tools, .swatch:focus-within .swatch-tools { transform: translateX(calc(-50% - 22px)); }
.swatch:hover .swatch-tools .edit-button, .swatch:focus-within .swatch-tools .edit-button { opacity: 1; pointer-events: auto; }
.swatch.locked .swatch-tools .lock-button { opacity: 1; }
.palette-footer { justify-content: flex-start; }
@media (max-width: 700px) {
  main { padding-inline: 6px; }
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .toolbar-actions { grid-column: 2; }
  .toolbar-actions .add-color { width: 38px; height: 38px; min-height: 0; overflow: hidden; font-size: 0; padding: 0; }
  .toolbar-actions .add-color span { font-size: 1.3rem; }
  .generate { grid-column: 1 / -1; }
  .swatch-format { margin-top: 2px; }
  .swatch-tools, .workspace.tuning .swatch-tools { left: auto; right: 12px; bottom: 10px; width: 72px; transform: none; }
  .swatch:hover .swatch-tools, .swatch:focus-within .swatch-tools { transform: none; }
  .swatch-actions, .workspace.tuning .swatch-actions { max-width: calc(100% - 82px); }
}
@media (hover: none) {
  .swatch-tools .edit-button, .swatch.locked .swatch-tools .edit-button { opacity: 1; pointer-events: auto; }
  .swatch-tools, .workspace.tuning .swatch-tools { transform: translateX(calc(-50% - 22px)); }
}
@media (max-width: 700px) and (hover: none) {
  .swatch-tools, .workspace.tuning .swatch-tools { transform: none; }
}

/* Centered swatch actions and dedicated color editor */
.swatch { align-items: center; cursor: default; }
.swatch:active { cursor: default; }
.swatch-code { position: relative; width: max-content; max-width: 100%; margin: 0 0 20px; padding: 5px 8px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: 800 clamp(1rem, 1.5vw, 1.7rem) "DM Mono", monospace; letter-spacing: -.04em; cursor: pointer; }
.swatch-code:hover, .swatch-code:focus-visible { background: rgba(255,255,255,.2); }
.swatch-code:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.swatch-rail { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); display: flex; flex-direction: column; align-items: center; gap: 5px; opacity: 0; pointer-events: none; transition: opacity .14s ease; }
.swatch:hover .swatch-rail, .swatch:focus-within .swatch-rail { opacity: 1; pointer-events: auto; }
.rail-button { width: 36px; height: 36px; padding: 8px; border: 0; border-radius: 10px; display: grid; place-items: center; background: transparent; color: inherit; font-size: 1.5rem; line-height: 1; cursor: pointer; }
.rail-button:hover, .rail-button:focus-visible { background: rgba(255,255,255,.24); outline: none; }
.rail-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.favorite-button.active svg { fill: currentColor; }
.swatch.locked .lock-button { background: rgba(0,0,0,.25); color: inherit; }
.swatch .remove-button { opacity: 1; }
.drag-handle { cursor: grab; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.color-editor { position: fixed; z-index: 80; width: min(326px, calc(100vw - 16px)); padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: #fff; color: #17181b; box-shadow: 0 20px 70px rgba(0,0,0,.3); }
.editor-head, .editor-footer { display: flex; align-items: center; justify-content: space-between; }
.editor-head { margin-bottom: 12px; }
.editor-head strong { font-size: .85rem; }
.editor-head button, .editor-footer button { width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; font-size: 1.25rem; }
.editor-head button:hover, .editor-footer button:hover { background: #f0f0f0; }
.color-plane { position: relative; height: 188px; border-radius: 12px; background: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), hsl(var(--hue, 0) 100% 50%); cursor: crosshair; touch-action: none; }
.plane-thumb { position: absolute; width: 16px; height: 16px; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.5),0 2px 5px rgba(0,0,0,.4); transform: translate(-50%,-50%); pointer-events: none; }
.editor-hue { display: block; width: 100%; height: 14px; margin: 16px 0; appearance: none; border-radius: 999px; background: linear-gradient(90deg,red,#ff0,#0f0,#0ff,#00f,#f0f,red); }
.editor-hue::-webkit-slider-thumb { appearance: none; width: 20px; height: 20px; border: 3px solid white; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px #888,0 1px 5px #777; }
.editor-value { display: flex; align-items: center; gap: 0; padding: 7px 9px; border: 1px solid #c9ccd2; border-radius: 10px; font: 600 1rem "DM Mono",monospace; }
.editor-value:focus-within { border-color: #377dff; box-shadow: 0 0 0 2px #377dff; }
.editor-value input { min-width: 0; flex: 1; border: 0; outline: 0 !important; background: transparent; color: #17181b; font: inherit; cursor: text; }
#editorPreview { width: 30px; height: 30px; flex: 0 0 30px; border: 1px solid rgba(0,0,0,.12); border-radius: 7px; }
.editor-footer { margin: 14px -14px -14px; padding: 10px 14px; border-top: 1px solid #e7e7e7; }
.editor-footer label { font-size: .72rem; color: #64676b; }
.editor-footer select { min-width: 72px; margin-left: 6px; padding: 5px 7px; border: 1px solid #dedee2; border-radius: 7px; background: #fff; color: #17181b; font-size: .82rem; }
.editor-footer svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[data-theme="dark"] .color-editor { background: #24252b; color: #f4f4f2; }
[data-theme="dark"] .editor-value input { color: #f4f4f2; }
[data-theme="dark"] .editor-footer select { background: #24252b; color: #f4f4f2; }
@media (max-width: 700px) {
  .swatch { flex-direction: row; justify-content: space-between; align-items: center; }
  .swatch-code { margin: 0; font-size: 1rem; }
  .swatch-rail { position: static; transform: none; flex-direction: row; gap: 0; opacity: 1; pointer-events: auto; }
  .rail-button { width: 27px; height: 30px; padding: 5px; }
  .rail-button svg { width: 17px; height: 17px; }
}
@media (max-width: 430px) {
  .rail-button { width: 25px; }
  .swatch-code { font-size: .85rem; padding-inline: 3px; }
}
