:root {
  --ink: #111;
  --muted: #9a9a9a;
  --line: #ececec;
  --mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* No fixed height here: on phones a 100% tall body is taller than the visible
   area while the browser toolbars are showing, which left blank scrollable
   space under the page. The app sets its own height. */
html, body { margin: 0; }

body {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.app {
  --m: clamp(16px, 2.4vw, 32px);
  /* The text and panel share one centred row and line up along their top
     edges, so the title stays put when the code below it grows. */
  display: grid;
  grid-template-columns: minmax(0, auto) auto;
  align-items: start;
  align-content: center;
  justify-content: center;
  gap: clamp(32px, 6vw, 120px);
  height: 100vh;
  height: 100dvh;
  padding: var(--m) clamp(20px, 4vw, 64px);
  background: var(--gradient);
}

/* Left: the gradient, title and code */

.preview {
  --fg: #fff;
  --inv: #111;
  display: flex;
  flex-direction: column;
  gap: 28px;
  color: var(--fg);
  flex: 0 1 auto;
  min-width: 0;
  transition: color .2s;
}

.preview.on-light { --fg: #111; --inv: #fff; }

.lead { display: flex; flex-direction: column; align-items: flex-start; }

h1 {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 900;
  font-size: clamp(40px, 6vw, 104px);
  line-height: .92;
  letter-spacing: -.01em;
}

#css {
  margin-top: clamp(18px, 2.2vw, 32px);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  max-width: 46ch;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all;
}

.actions {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-top: 18px;
}

.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: 13px;
  border-bottom: 1px solid transparent;
}

.link:hover, .link:focus-visible, .link[aria-expanded="true"] { border-bottom-color: currentColor; }

.png { position: relative; }

.menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 5;
  min-width: 210px;
  padding: 6px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 12px;
}

.menu button {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  text-align: left;
}

.menu button span:last-child { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.menu button:hover, .menu button:focus-visible { background: #f4f4f4; outline: none; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  font-size: 13px;
}

.switch i {
  position: relative;
  width: 28px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-radius: 99px;
  transition: background .15s;
}

.switch i::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  transition: transform .15s, background .15s;
}

/* Same outline and knob in both states: on slides the knob and tints the track. */
.switch[aria-checked="true"] i { background: color-mix(in srgb, currentColor 28%, transparent); }
.switch[aria-checked="true"] i::after { transform: translateX(12px); }

/* Right: color blocks */

/* On desktop the controls float over the gradient in one panel. */
.editor {
  display: flex;
  flex-direction: column;
  flex: none;
  width: min(46vw, clamp(400px, 30vw, 560px));
  max-height: calc(100vh - 2 * var(--m));
  min-height: 0;
  background: #fff;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .1);
}

.blocks {
  display: flex;
  height: clamp(160px, 28vh, 300px);
  flex: none;
}

.blocks-inner {
  flex: 1;
  position: relative;
  display: flex;
  min-width: 0;
}

.block {
  flex: none;
  width: var(--size);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 2px;
  padding: 12px;
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

.block.on-light { color: var(--ink); }
.block:focus-visible { outline: 2px solid currentColor; outline-offset: -5px; }

.grip {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--at);
  width: 22px;
  margin-left: -11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  touch-action: none;
  z-index: 1;
}

.grip::after {
  content: '';
  width: 5px;
  height: 36px;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .16);
  opacity: 0;
  transition: opacity .15s, transform .12s;
}

/* Handles appear when the pointer is anywhere over the color blocks, and
   always on touch screens. */
.blocks-inner:hover .grip::after,
.grip.dragging::after,
.grip:focus-visible::after { opacity: 1; }
@media (hover: none) { .grip::after { opacity: 1; } }

.grip:hover::after, .grip.dragging::after { transform: scale(1.25); }
.grip:focus-visible { outline: none; }
.grip:focus-visible::after { box-shadow: 0 0 0 2px var(--ink); }

.rm {
  position: absolute;
  top: 8px;
  left: calc(var(--end) - 40px);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  opacity: 0;
  transition: opacity .12s, transform .12s;
  z-index: 2;
}

.rm.on-light { color: var(--ink); }
.rm.show { opacity: .85; }
.rm:hover, .rm:focus-visible { opacity: 1; transform: scale(1.2); }
@media (hover: none) { .rm { opacity: .85; } }

.add {
  flex: 0 0 48px;
  font-size: 26px;
  font-weight: 300;
  transition: background .15s;
}

/* Hover only where there is a real pointer; on touch it sticks after a tap. */
@media (hover: hover) { .add:hover { background: #f6f6f6; } }

/* Controls and presets */

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 24px 24px 40px;
  min-height: 0;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
}

.types { display: flex; gap: 18px; }

.types button {
  padding: 4px 0;
  color: var(--muted);
  border-bottom: 1.5px solid transparent;
  transition: color .15s;
}

.types button:hover { color: var(--ink); }
.types button[aria-checked="true"] { color: var(--ink); border-bottom-color: var(--ink); }

.opts { display: flex; align-items: center; gap: 20px; }
.opt { display: flex; align-items: center; gap: 10px; }

.readout, .num { font-family: var(--mono); font-size: 12px; }
.num { display: inline-flex; align-items: baseline; }

.num input {
  width: 3ch;
  text-align: right;
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 1px 0;
  font-family: var(--mono);
  font-size: 12px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.num input::-webkit-inner-spin-button,
.num input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num input:hover, .num input:focus { border-bottom-color: var(--ink); outline: none; }

.dial {
  position: relative;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
}

.dial i {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 1.5px;
  height: 42%;
  margin-left: -.75px;
  background: var(--ink);
  transform-origin: 50% 100%;
  pointer-events: none;
}

.pad {
  position: relative;
  width: 60px;
  height: 60px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}

.dot {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--ink);
  pointer-events: none;
}

.presets-wrap { flex: none; padding: 0 24px 24px; }

.presets-label {
  padding-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.presets { display: flex; flex-wrap: wrap; gap: 10px; }

/* The faint ring keeps near-white presets visible on the white panel. */
.presets button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
  transition: transform .12s;
}

.presets button:hover { transform: scale(1.12); }
.presets button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Credit line: centred along the bottom of the gradient on desktop. */

.app { position: relative; }

.credit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20px;
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: #fff;
  opacity: .8;
  transition: color .2s;
}

.credit.on-light { color: var(--ink); }

/* Color picker */

.picker {
  position: absolute;
  z-index: 10;
  width: 216px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--ink);
  border-radius: 14px;
}

.sv {
  position: relative;
  height: 132px;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}

.sv span {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
  pointer-events: none;
}

.hue {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  margin: 0;
  border-radius: 99px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  cursor: pointer;
}

.hue::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--ink);
}

.hue::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--ink);
}

.hue::-moz-range-track { background: transparent; }

.picker-hex {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #ddd;
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
}

.picker-hex:focus { border-color: var(--ink); outline: none; }

/* Mobile: stack the two columns, colors become long strips */

@media (max-width: 760px) {
  .app {
    display: flex;
    flex-direction: column;
    /* Exactly one screen tall, so the color strips can shrink to keep the
       presets on screen. If everything still can't fit at the strips'
       minimum height, the rest overflows and the page scrolls.
       svh, not dvh: dvh changes as a phone's browser toolbar slides away
       during scrolling, which makes the layout jump. */
    height: 100vh;
    height: 100svh;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
    background: none;
  }

  /* The gradient takes whatever height is left above the controls. */
  .preview { flex: 1 0 auto; background: var(--gradient); }

  /* The panel and the block row dissolve on mobile, so the strips, add
     button, controls and presets are laid out directly in the page column. */
  .editor, .blocks { display: contents; }

  .preview { gap: 22px; padding: 22px 20px; }

  h1 { font-size: clamp(40px, 13vw, 72px); }

  #css { font-size: 13px; margin-top: 16px; }

  /* Strips are 64px each when there is room and shrink to 36px each to keep
     everything on one screen. */
  .blocks-inner {
    flex: 0 1 calc(var(--n, 3) * 64px);
    min-height: calc(var(--n, 3) * 36px);
    flex-direction: column;
  }

  .block {
    width: auto;
    height: var(--size);
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0 52px 0 20px;
    font-size: 13px;
  }

  .rm {
    top: calc(var(--mid) - 14px);
    left: auto;
    right: 12px;
    opacity: .85;
  }

  .grip {
    top: var(--at);
    bottom: auto;
    left: 50%;
    width: 84px;
    height: 28px;
    margin: -14px 0 0 -42px;
    cursor: row-resize;
  }

  .grip::after { width: 36px; height: 5px; opacity: 1; }

  /* Spacing below is kept tight so five colors fit on a typical phone. */
  .add { flex: none; height: 44px; border-bottom: 1px solid var(--line); }

  .panel { flex: none; padding: 16px 20px; gap: 24px; }

  .controls { min-height: 48px; }

  .pad { width: 48px; height: 48px; }

  .presets-wrap { flex: none; padding: 0 20px 20px; }

  .presets { gap: 12px; }

  .presets button { width: 36px; height: 36px; }

  /* On mobile the credit sits in the white area under the presets. */
  .credit,
  .credit.on-light {
    position: static;
    flex: none;
    padding: 0 20px 16px;
    text-align: left;
    color: var(--muted);
    opacity: 1;
  }
}
