:root {
  --ink: #1d1d1f;
  --paper: #fff;
  --accent: #0066ff;
  --topbar-h: 52px;
  --shadow: 0 4px 20px rgba(0,0,0,.18);
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--paper);
  border-bottom: 1px solid #e6e6e9;
  position: relative;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.3px; }
.logo { width: 26px; height: 26px; }
.actions { display: flex; align-items: center; gap: 8px; }

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid #d8d8dc;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f3f3f5; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #333; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #0052cc; }

/* ---------- dropdown menu ---------- */
.dropdown { position: relative; }
.menu {
  position: absolute;
  right: 0; top: calc(100% + 6px);
  min-width: 200px;
  background: var(--paper);
  border: 1px solid #e0e0e4;
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 50;
}
.menu button {
  display: block; width: 100%;
  font: inherit; font-size: 13px;
  text-align: left;
  padding: 8px 10px;
  border: 0; border-radius: 6px;
  background: none; cursor: pointer;
}
.menu button:hover { background: #f3f3f5; }
.menu hr { border: 0; border-top: 1px solid #eee; margin: 5px 4px; }

/* ---------- palette columns ---------- */
.palette {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  position: relative;
}
.column {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  transition: background-color .15s;
}
.hex {
  margin-top: 12vh;
  font: inherit;
  font-size: clamp(13px, 1.6vw, 22px);
  font-weight: 600;
  letter-spacing: .06em;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}
.hex:hover { text-decoration: underline; }

.tools {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tool {
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 22px;
}
.tool svg { width: 20px; height: 20px; }
.column .tool { color: inherit; opacity: .85; }
.column .tool:hover { background: rgba(0,0,0,.12); opacity: 1; }
.column.light .tool:hover { background: rgba(255,255,255,.25); }

/* lock icon swap */
.ic-locked { display: none; }
.column.locked .ic-locked { display: block; }
.column.locked .ic-unlocked { display: none; }
.column.locked .act-lock { opacity: 1; background: rgba(0,0,0,.15); }
.column.light.locked .act-lock { background: rgba(255,255,255,.3); }

/* ---------- +/− edge controls ---------- */
.edge {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--pos);
  width: 40px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 6;
}
.edge-first { transform: none; }
.edge-last { transform: translateX(-100%); }
.edge-btn {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #333;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s, transform .12s;
}
.edge:hover .edge-btn,
.edge:focus-within .edge-btn { opacity: 1; pointer-events: auto; }
.edge-btn:hover { transform: scale(1.15); }
.edge-minus { color: #d33; }

/* ---------- hint ---------- */
.hint {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: #555;
  background: rgba(255,255,255,.9);
  border: 1px solid #e4e4e8;
  padding: 8px 16px;
  border-radius: 99px;
  pointer-events: none;
  z-index: 20;
}
kbd {
  font-family: inherit;
  background: #eee;
  border: 1px solid #ccc;
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 12px;
}

/* ---------- overlays & panels ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: grid;
  place-items: center;
  z-index: 100;
}
.panel {
  background: var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  width: min(420px, 92vw);
  max-height: 85vh;
  overflow: auto;
}
.panel h3 { margin-bottom: 14px; }
.panel-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

.edit-row { display: flex; gap: 10px; margin-bottom: 14px; }
#edit-picker {
  width: 52px; height: 40px;
  border: 1px solid #ddd; border-radius: 8px;
  padding: 2px; background: none; cursor: pointer;
}
#edit-hex {
  flex: 1;
  font: inherit; font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 6px 10px;
  border: 1px solid #d8d8dc; border-radius: 8px;
  text-transform: uppercase;
}
.panel label {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px;
  margin: 10px 0;
}
.panel label input[type="range"] { flex: 1; }

/* shades */
.shades-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.shade {
  aspect-ratio: 1;
  border: 0; border-radius: 8px;
  cursor: pointer;
  display: grid; place-items: end start;
  padding: 4px;
}
.shade span {
  font-size: 9px;
  font-family: ui-monospace, Menlo, monospace;
  background: rgba(255,255,255,.85);
  border-radius: 4px;
  padding: 1px 3px;
  opacity: 0;
}
.shade:hover span { opacity: 1; }
.muted { color: #777; font-size: 12px; margin-top: 10px; }
#shades-for { font-family: ui-monospace, Menlo, monospace; color: #888; font-size: 14px; }

/* ---------- image extract ---------- */
.dropzone {
  border: 2px dashed #cfcfd4;
  border-radius: 12px;
  padding: 26px 14px;
  text-align: center;
  color: #888;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 14px;
}
.dropzone:hover, .dropzone.over {
  border-color: var(--accent);
  color: var(--accent);
  background: #f5f9ff;
}
#image-preview {
  display: block;
  max-width: 100%;
  max-height: 200px;
  margin: 0 auto 12px;
  border-radius: 10px;
}
.extract-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
}
.extract-row select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid #d8d8dc;
  border-radius: 8px;
}

/* ---------- library drawer ---------- */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 90vw);
  background: var(--paper);
  border-left: 1px solid #e4e4e8;
  box-shadow: -6px 0 24px rgba(0,0,0,.12);
  z-index: 90;
  padding: 16px;
  overflow-y: auto;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.saved {
  border: 1px solid #e6e6ea;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}
.saved-strip { display: flex; height: 34px; border-radius: 7px; overflow: hidden; cursor: pointer; margin-bottom: 8px; }
.saved-strip div { flex: 1; }
.saved-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.saved-name {
  font: inherit; font-size: 13px; font-weight: 600;
  border: 0; border-bottom: 1px dashed transparent;
  background: none; min-width: 0; flex: 1;
}
.saved-name:hover, .saved-name:focus { border-bottom-color: #aaa; outline: none; }
.saved-del { border: 0; background: none; cursor: pointer; color: #999; font-size: 16px; }
.saved-del:hover { color: #d33; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 64px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 99px;
  z-index: 200;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.85); opacity: 0; } }

.hidden { display: none !important; }

/* narrow screens: stack columns vertically */
@media (max-width: 640px) {
  .palette { flex-direction: column; }
  .column { flex-direction: row; justify-content: space-between; padding: 0 14px; }
  .hex { margin: 0; }
  .tools { position: static; transform: none; flex-direction: row; }
  .tool { width: 34px; height: 34px; }
  .act-left svg { transform: rotate(90deg); }
  .act-right svg { transform: rotate(90deg); }
  .edge {
    left: 0; right: 0;
    top: var(--pos);
    bottom: auto;
    width: auto; height: 36px;
    transform: translateY(-50%);
    flex-direction: row;
  }
  .edge-first { transform: none; }
  .edge-last { transform: translateY(-100%); }
  .hint { display: none; }
}
