:root {
  --fondo: #f2f2f2;
  --card: #ffffff;
  --inchiostro: #111113;
  --grigio: #6f6f77;
  --grigio-chiaro: #a1a1aa;
  --bordo: rgba(17, 17, 19, 0.09);
  --campo: #f4f4f5;
  --spunta: #1f9d55;
  --scelto: #5b5bd6;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --gap: clamp(8px, 2.2vh, 14px);
}

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

html, body { height: 100%; }

body {
  background: var(--fondo);
  color: var(--inchiostro);
  font-family: "Mona Sans Variable", "Mona Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 14px;
}

.panel {
  width: min(352px, 100%);
  background: var(--card);
  border: 1px solid var(--bordo);
  border-radius: 20px;
  padding: clamp(12px, 3.6vmin, 18px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  box-shadow: 0 1px 2px rgba(17, 17, 19, 0.04), 0 18px 48px -18px rgba(17, 17, 19, 0.16);
}

.panel__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.panel__title { font-size: 15px; font-weight: 640; letter-spacing: -0.01em; }
.panel__sub { margin-top: 2px; font-size: 12px; color: var(--grigio); }
.panel__sub span { color: var(--grigio-chiaro); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--bordo);
  background: var(--campo);
  font-size: 11.5px; font-weight: 640;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge__roll { display: inline-grid; overflow: hidden; height: 1.25em; line-height: 1.25em; }
.badge__roll > span { grid-area: 1 / 1; }
.badge__ratio { color: var(--grigio); font-weight: 520; }

.sv {
  position: relative;
  height: clamp(84px, 24vh, 168px);
  border-radius: 12px;
  background: hsl(240 60% 50%);
  cursor: crosshair;
  touch-action: none;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(17, 17, 19, 0.06);
}
.sv__white, .sv__black { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.sv__white { background: linear-gradient(90deg, #fff, rgba(255, 255, 255, 0)); }
.sv__black { background: linear-gradient(0deg, #000, rgba(0, 0, 0, 0)); }

.hue {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f00 0%, #ff0 16.66%, #0f0 33.33%, #0ff 50%, #00f 66.66%, #f0f 83.33%, #f00 100%);
  box-shadow: inset 0 0 0 1px rgba(17, 17, 19, 0.06);
  cursor: pointer;
  touch-action: none;
  outline: none;
}

.thumb {
  position: absolute; left: 0; top: 0;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
}
.thumb--hue { top: 50%; }
.thumb__ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2.5px solid #fff;
  background: var(--scelto);
  box-shadow: 0 0 0 1px rgba(17, 17, 19, 0.18), 0 3px 8px -2px rgba(17, 17, 19, 0.35);
}
.sv:focus-visible .thumb__ring, .hue:focus-visible .thumb__ring { box-shadow: 0 0 0 1px rgba(17, 17, 19, 0.18), 0 0 0 4px rgba(91, 91, 214, 0.35); }

.swatches { display: flex; gap: 8px; }
.swatch {
  position: relative;
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 0; padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(17, 17, 19, 0.1);
}
.swatch__ring {
  position: absolute; inset: -4px;
  border-radius: 11px;
  border: 1.5px solid var(--inchiostro);
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}
.swatch:focus-visible { outline: 2px solid var(--scelto); outline-offset: 3px; }

.hexrow { display: flex; gap: 8px; }
.hex {
  flex: 1;
  display: flex; align-items: center; gap: 2px;
  height: 36px; padding: 0 12px;
  border-radius: 10px;
  background: var(--campo);
  border: 1px solid var(--bordo);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 560;
  letter-spacing: 0.02em;
}
.hex__hash { color: var(--grigio-chiaro); }
.hex__digits { display: inline-flex; }
.dig { position: relative; display: inline-block; width: 1ch; height: 1.3em; line-height: 1.3em; overflow: hidden; text-align: center; }
.dig > span { position: absolute; left: 0; right: 0; top: 0; }

.copy {
  flex: none;
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 12px;
  border-radius: 10px;
  background: var(--inchiostro); color: #fff;
  border: 1px solid var(--inchiostro);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 14px -6px rgba(17, 17, 19, 0.5);
}
.copy:focus-visible { outline: 2px solid var(--scelto); outline-offset: 2px; }
.copy svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.copy__check { stroke: #6ee7a0; stroke-width: 2.3; }
.copy__roll { display: inline-grid; overflow: hidden; height: 1.3em; line-height: 1.3em; }
.copy__label { grid-area: 1 / 1; }

.preview {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding-top: var(--gap);
  border-top: 1px solid var(--bordo);
}
.preview__title { font-size: clamp(15px, 4.4vmin, 18px); font-weight: 680; letter-spacing: -0.02em; color: var(--scelto); white-space: nowrap; }
.preview__btn {
  flex: none;
  display: inline-flex; align-items: center;
  height: 32px; padding: 0 14px;
  border-radius: 999px;
  background: var(--scelto); color: var(--testo-pulsante, #fff);
  font-size: 12.5px; font-weight: 620;
  box-shadow: 0 6px 14px -8px var(--scelto);
}

.ghost {
  position: absolute; left: 0; top: 0;
  width: 22px; height: 22px;
  fill: var(--inchiostro); stroke: #fff; stroke-width: 1.4; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

@media (hover: hover) {
  .swatch { transition: translate 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease; }
  .swatch:hover { translate: 0 -2px; box-shadow: inset 0 0 0 1px rgba(17, 17, 19, 0.1), 0 6px 12px -6px rgba(17, 17, 19, 0.35); }
  .copy:hover { background: #2a2a2e; }
}
@media (prefers-reduced-motion: reduce) { .swatch { transition: none; } }
