:root {
  --bg: #f7f7f5;
  --text: #1f1d1a;
  --muted: #5f5a52;
  --accent: #2f46c8;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --text: #e9ecf2;
    --muted: #9aa3b5;
    --accent: #8fa2ff;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
}

.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.compare {
  --pos: 50%;
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 12px;
  background: #cfd3d6;
  user-select: none;
}

.img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* The "after" photo sits on top and is clipped from the right, so only the left part shows. */
.img--after {
  clip-path: inset(0 calc(100% - var(--pos)) 0 0);
}

.label {
  position: absolute;
  top: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  pointer-events: none;
}

.label--after {
  left: 0.75rem;
}

.label--before {
  right: 0.75rem;
}

/* The divider and the round grip follow --pos. They are drawn by us, not by the input. */
.handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 3px;
  background: #fff;
  transform: translateX(-50%);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.3);
  pointer-events: none;
}

.grip {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: #fff;
  color: #1f1d1a;
  font-size: 1.2rem;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.35);
  transform: translate(-50%, -50%);
}

/* The real control: a range input stretched over the whole picture, invisible but fully working. */
.range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: ew-resize;
  touch-action: pan-y; /* the page can still scroll up and down on touch screens */
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.range::-webkit-slider-runnable-track {
  height: 100%;
  background: transparent;
}

/* A 1px thumb, so the value matches the pointer position exactly from edge to edge. */
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1px;
  height: 100%;
  background: transparent;
  border: 0;
}

.range::-moz-range-track {
  height: 100%;
  background: transparent;
}

.range::-moz-range-thumb {
  width: 1px;
  height: 100%;
  background: transparent;
  border: 0;
}

/* The input is invisible, so the focus ring goes on the grip. */
.compare:has(.range:focus-visible) .grip {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
