:root {
  --bg: #0f0f10;
  --fg: #e8e8ea;
  --dim: #888;
  --line: #2a2a2c;
  --accent: #ff5577;
  --panel-bg: #161618;
  --panel-w: 280px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
}

body:has(#panel[hidden]) {
  grid-template-columns: 1fr;
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
button:hover { border-color: var(--fg); }
button:active { background: #1f1f22; }

/* ---------- stage ---------- */
#stage {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, #1a1a1c 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(-45deg, #1a1a1c 25%, transparent 25%) 0 10px/20px 20px,
    linear-gradient(45deg, transparent 75%, #1a1a1c 75%) 10px -10px/20px 20px,
    linear-gradient(-45deg, transparent 75%, #1a1a1c 75%) -10px 0/20px 20px,
    var(--bg);
}

#stage.empty {
  background: var(--bg);
}

/* ---------- empty state ---------- */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
}
#stage:not(.empty) #empty-state { display: none; }

#empty-state h1 {
  margin: 0;
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg);
}
#empty-state h1::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 6px;
  vertical-align: 4px;
}
#empty-state .hint {
  color: var(--dim);
  margin: 0;
  letter-spacing: 0.08em;
  font-size: 13px;
}
#empty-state .actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
#empty-state .formats,
#empty-state .kbd {
  color: var(--dim);
  font-size: 12px;
  margin: 4px 0 0;
}
#empty-state .kbd { margin-top: 16px; }

/* ---------- canvas ---------- */
#canvas-wrap {
  position: absolute;
  inset: 0;
}
#canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none; /* let pointer events handle pan/zoom */
}

/* ---------- loupe ---------- */
#loupe {
  position: fixed;
  width: 120px;
  height: 120px;
  pointer-events: none;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 2px #fff, 0 4px 20px rgba(0,0,0,0.6);
  z-index: 20;
  transform: translate(-50%, -50%) translate(0, -90px);
}
#loupe-canvas {
  display: block;
  image-rendering: pixelated;
}
#loupe-crosshair {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#loupe-crosshair::before,
#loupe-crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,0.85);
  mix-blend-mode: difference;
}
#loupe-crosshair::before {
  left: 50%; top: 0; bottom: 0;
  width: 1px;
  transform: translateX(-0.5px);
}
#loupe-crosshair::after {
  top: 50%; left: 0; right: 0;
  height: 1px;
  transform: translateY(-0.5px);
}

/* ---------- drop veil ---------- */
#drop-veil {
  position: fixed;
  inset: 0;
  background: rgba(255, 85, 119, 0.15);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 24px;
  letter-spacing: 0.1em;
  z-index: 100;
  pointer-events: none;
}

/* ---------- panel ---------- */
#panel {
  background: var(--panel-bg);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
  overflow-y: auto;
}

#current {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#swatch {
  width: 100%;
  aspect-ratio: 1.6;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #333;
  padding: 0;
  cursor: pointer;
}

#values {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.val {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.val:hover { border-color: var(--line); background: #1c1c1f; }
.val .lbl { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.val .v { color: var(--fg); }

#history {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  min-height: 24px;
}
#history button {
  aspect-ratio: 1;
  padding: 0;
  border-radius: 4px;
  border: 1px solid var(--line);
  cursor: pointer;
}

#copy-all {
  align-self: flex-start;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#controls {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}
#btn-reset {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--fg);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  pointer-events: none;
  z-index: 200;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #panel {
    border-left: none;
    border-top: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
    padding: 12px;
    --panel-w: auto;
  }
  #current { flex: 1; flex-direction: row; align-items: center; }
  #swatch { width: 56px; aspect-ratio: 1; flex-shrink: 0; }
  #values { flex: 1; }
  #history { display: none; }
  #copy-all { display: none; }
}
