*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  overscroll-behavior-y: none;
  background: #0a0a0a;
  color: #e5e5e5;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
    Noto Sans, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji';
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */

:root {
  --step-h: 30px;
  --step-gap: 6px;
  --swatch-h: calc(75dvh / 17);
}

.app {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.palette-area {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.palette-with-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--step-gap);
}

.palette-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

/* ── Step controls ── */

.step-controls {
  display: flex;
  gap: 4px;
  height: var(--step-h);
}

.step-btn {
  flex: 1;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  color: #e5e5e5;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.step-btn:hover  { background: #1f2937; }
.step-btn:active { background: #374151; }

/* ── Palette labels ── */

#palette-labels {
  display: grid;
  grid-template-columns: 6ch 3ch 3ch 3ch;
  column-gap: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: #6b7280;
}

#palette-labels span {
  height: var(--swatch-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
}

/* ── Palette (swatch column) ── */

#palette {
  width: 15vw;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid #374151;
}

.swatch {
  width: 100%;
  height: var(--swatch-h);
  flex-shrink: 0;
  position: relative;
  transition: filter 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.swatch-middle {
  cursor: pointer;
}

.swatch-middle:active {
  filter: brightness(1.15);
}

.swatch-kebab {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.swatch-kebab svg {
  width: 20px;
  height: 4px;
}

/* ── HSB slider controls ──
   margin-top offsets past the top step-controls row so that
   justify-content: center aligns sliders with the palette's centerline. */

#palette-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  /* height set dynamically in JS to match palette column height */
  margin-top: calc(var(--step-h) + var(--step-gap));
  padding-left: 8px;
}

.slider-group {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: flex-end;
}

.vslider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.vslider-track {
  width: 28px;
  height: 150px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.vslider-track input[type="range"] {
  position: absolute;
  width: 150px;
  height: 28px;
  margin: 0;
  padding: 0;
  transform: rotate(-90deg);
  cursor: pointer;
  accent-color: #6366f1;
}

.reset-btn {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  color: #9ca3af;
  font-size: 16px;
  padding: 5px;
  cursor: pointer;
  align-self: stretch;
  -webkit-tap-highlight-color: transparent;
}

.reset-btn:hover  { background: #1f2937; color: #e5e5e5; }
.reset-btn:active { background: #374151; }

.vslider label {
  font-size: 10px;
  color: #6b7280;
  letter-spacing: 0.05em;
}

/* ── Export button ── */

#export-btn {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  border: 1px solid #374151;
  border-radius: 20px;
  color: #e5e5e5;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 24px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  z-index: 10;
}

#export-btn:hover  { background: #1f2937; }
#export-btn:active { background: #374151; }

/* ── Modal ── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.modal-card {
  position: relative;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: calc(100vw - 48px);
  max-width: 320px;
}

#color-preview {
  width: 100%;
  height: 64px;
  border-radius: 10px;
  background: #888;
}

/* ── Color inputs ── */

.color-inputs {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hex-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0a0a0a;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 0 12px;
}

.hex-row:focus-within {
  box-shadow: 0 0 0 2px #6366f1;
}

.input-prefix {
  font-size: 14px;
  color: #6b7280;
}

.hex-row input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e5e5e5;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.08em;
  padding: 10px 0;
}

.rgb-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.rgb-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.rgb-field label {
  font-size: 11px;
  color: #6b7280;
  letter-spacing: 0.05em;
}

.rgb-field input {
  width: 100%;
  background: #0a0a0a;
  border: 1px solid #1f2937;
  border-radius: 10px;
  outline: none;
  color: #e5e5e5;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 4px;
  text-align: center;
}

.rgb-field input:focus {
  box-shadow: 0 0 0 2px #6366f1;
}
