:root {
  --ink: #f4f6f8;
  --ink-2: #c9cfd6;
  --line: rgba(255, 255, 255, 0.14);
  --panel: rgba(16, 18, 22, 0.86);
  --focus: #9fdcff;
  --font: "Inter", "SF Pro Text", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.22, .61, .36, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: #111316;
  color: var(--ink);
  font: 400 0.875rem/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.surface { position: fixed; inset: 0; width: 100%; height: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- gradient control: one small swatch, a panel on demand ---------- */
.grad {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex; flex-direction: column; align-items: flex-end; gap: .625rem;
}

.grad__toggle {
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--panel);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: grid; place-items: center;
  cursor: pointer;
  opacity: .55;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.grad__toggle:hover, .grad__toggle:focus-visible, .grad__toggle[aria-expanded="true"] { opacity: 1; }
.grad__toggle:active { transform: scale(.95); }
.grad__toggle span {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--g2), var(--g1) 55%, var(--g0));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}

.grad__panel {
  width: min(18.5rem, calc(100vw - 2rem));
  padding: 1rem;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
  display: grid; gap: .875rem;
}
.grad__panel[hidden] { display: none; }

.grad__head { display: flex; justify-content: space-between; align-items: baseline; }
.grad__title { margin: 0; font-size: .875rem; font-weight: 600; }

.grad__preview {
  height: 28px; border-radius: 8px;
  background: linear-gradient(90deg, var(--g0), var(--g1) 50%, var(--g2));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.seg { display: grid; gap: .375rem; }
.seg__label { color: var(--ink-2); font-size: .75rem; }
.seg__row {
  display: flex; padding: 3px; gap: 3px;
  border: 1px solid var(--line); border-radius: 10px;
  background: rgba(0, 0, 0, .25);
}
.seg__btn {
  flex: 1; min-height: 32px; padding: 0 .5rem;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--ink-2);
  font: 500 .8125rem/1 var(--font); cursor: pointer;
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.seg__btn:hover { color: var(--ink); background: rgba(255, 255, 255, .06); }
.seg__btn[aria-pressed="true"] { background: rgba(255, 255, 255, .16); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18); }
#grad-label { margin-bottom: -.375rem; }

.grad__label { display: block; margin: 0 0 .375rem; color: var(--ink-2); font-size: .75rem; }

.presets { display: flex; flex-wrap: wrap; gap: .375rem; margin: 0; padding: 0; border: 0; }
.preset {
  width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: linear-gradient(135deg, var(--p2), var(--p1) 55%, var(--p0));
  cursor: pointer;
}
.preset[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }

.stops { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stop { display: grid; gap: .3rem; color: var(--ink-2); font-size: .75rem; }
.stop input[type="color"] {
  width: 100%; height: 36px; padding: 2px;
  border: 1px solid var(--line); border-radius: 8px;
  background: transparent; cursor: pointer;
}
.stop input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.stop input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
.stop input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }
.stop output { font-variant-numeric: tabular-nums; color: var(--ink); font-size: .75rem; }

.slider { display: grid; gap: .3rem; color: var(--ink-2); font-size: .75rem; }
.slider__row { display: flex; justify-content: space-between; }
.slider output { color: var(--ink); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; margin: 0; accent-color: #d2d7dd; min-height: 24px; }

.grad__actions { display: flex; gap: .5rem; }
.btn {
  flex: 1; min-height: 36px; padding: 0 .75rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255, 255, 255, .06); color: var(--ink);
  font: 500 .8125rem/1 var(--font); cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, .12); }

@media (prefers-reduced-motion: reduce) { .grad__toggle, .seg__btn { transition: none; } }

/* short screens: the panel scrolls instead of running off the top */
.grad__panel { max-height: calc(100dvh - 5.5rem); overflow-y: auto; overscroll-behavior: contain; }

/* QA stills: hide the control */
.qa-still .grad { display: none; }
