/* Before and after of the restoration with the glass handle: the case study card of a made-up conservation studio
   on a warm dark page. The frame holds two plates of the same size: the painting as it left the studio (under) and
   the same photo as it came in (over, clipped up to the handle), treated here in CSS and SVG. The loupe holds a copy
   of both plates, scaled up. */
:root {
  --page: #12100e;          /* the page */
  --card: #1b1916;          /* the card */
  --edge: rgba(255, 244, 228, 0.08); /* the card's edge at rest */
  --ink: #f2ece2;           /* the words */
  --muted: #9b9286;         /* the small words */
  --accent: #e9c48a;        /* the light on the line and the numbers */
  --varnish: #b7862f;       /* the colour of the old varnish */
  --crack: rgba(34, 22, 10, 0.62); /* the cracks in the paint */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background:
    radial-gradient(120% 80% at 50% 0%, #1f1b17 0%, transparent 60%),
    var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(8px, 2.4vh, 24px) 10px;
  overflow: hidden;
}

/* ------------------------------------------------------------------ the card */
.case {
  --fw: min(calc(94vw - 20px), 540px);
  position: relative;
  width: calc(var(--fw) + 2 * var(--pad));
  --pad: clamp(8px, 1.6vh, 14px);
  padding: var(--pad);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 244, 228, 0.035), transparent 40%),
    var(--card);
  box-shadow:
    inset 0 0 0 1px var(--edge),
    inset 0 1px 0 rgba(255, 244, 228, 0.07),
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 18px 40px -18px rgba(0, 0, 0, 0.8),
    0 50px 90px -40px rgba(0, 0, 0, 0.7);
  opacity: 0;
}

/* the fine grain of the card */
.case::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.case__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 4px clamp(6px, 1.4vh, 12px);
}

.case__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.case__mark {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.case__studio {
  font-size: 13.5px;
  font-weight: 600;
  font-variation-settings: 'wdth' 108;
  letter-spacing: 0.01em;
}

.case__studio i {
  font-family: 'Newsreader Variable', Georgia, serif;
  font-weight: 400;
  color: var(--accent);
}

.case__chip {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 244, 228, 0.1);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ the frame */
.frame {
  position: relative;
  width: var(--fw);
  height: min(calc(var(--fw) * 1.08), calc(100vh - 136px), 600px);
  min-height: 180px;
  border-radius: 14px;
  overflow: hidden;
  background: #0b0a09;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 10px 26px -14px rgba(0, 0, 0, 0.9);
  cursor: ew-resize;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.frame::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 244, 228, 0.07), inset 0 0 60px rgba(0, 0, 0, 0.35);
  z-index: 3;
}

.plate {
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
}

.plate__img {
  position: absolute;
  inset: 0;
  background: url('dipinto.webp') 50% 34% / cover no-repeat;
}

.plate--after .plate__img {
  filter: saturate(1.06) contrast(1.04);
}

/* a soft fresh varnish sheen, only on the cleaned side */
.plate__sheen {
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 250, 240, 0.07) 46%, transparent 60%);
  mix-blend-mode: screen;
}

/* the painting as it came in: yellowed, flat and dark */
.plate--before .plate__img {
  filter: sepia(0.55) saturate(0.6) brightness(0.74) contrast(0.86);
}

.plate__varnish {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(70% 60% at 40% 45%, color-mix(in srgb, var(--varnish) 40%, transparent), transparent 70%),
    linear-gradient(180deg, color-mix(in srgb, var(--varnish) 55%, transparent), color-mix(in srgb, #5a3a12 60%, transparent));
  mix-blend-mode: multiply;
}

.plate__wear {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ------------------------------------------------------------------ the chips that ride with the handle */
.tag {
  position: absolute;
  left: 0;
  top: clamp(8px, 1.6vh, 14px);
  z-index: 6;
  pointer-events: none;
}

.tag__in {
  display: block;
  padding: 5px 10px 5px;
  font-size: 11.5px;
  font-weight: 560;
  font-variation-settings: 'wdth' 104;
  letter-spacing: 0.02em;
  color: #fffaf2;
  border-radius: 999px;
  background: rgba(20, 16, 12, 0.34);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
  backdrop-filter: blur(10px) saturate(1.3);
  box-shadow: inset 0 0 0 1px rgba(255, 250, 240, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 4px 14px -6px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.tag--after .tag__in {
  background: rgba(255, 250, 240, 0.16);
}

/* ------------------------------------------------------------------ the handle */
.split {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 100%;
  z-index: 5;
}

.split__line {
  position: absolute;
  left: -1px;
  top: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(180deg, rgba(255, 250, 240, 0.35), rgba(255, 250, 240, 0.7) 50%, rgba(255, 250, 240, 0.35));
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.25), 0 0 calc(var(--lit, 0) * 14px) rgba(233, 196, 138, calc(var(--lit, 0) * 0.8));
}

/* the light that runs along the line: a bright band at the pointer's height (--ly), stronger as the line moves */
.split__glint {
  position: absolute;
  left: -1px;
  top: 0;
  width: 4px;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(180deg, transparent calc(var(--ly, 50%) - 90px), var(--accent) calc(var(--ly, 50%) - 20px), #ffffff var(--ly, 50%), var(--accent) calc(var(--ly, 50%) + 20px), transparent calc(var(--ly, 50%) + 90px));
  opacity: calc(0.15 + var(--lit, 0) * 0.85);
  filter: blur(0.4px);
}

.knob {
  position: absolute;
  left: 0;
  top: 0;
  width: 34px;
  height: 64px;
  margin: -32px 0 0 -17px;
  border-radius: 999px;
  outline: none;
  cursor: grab;
}

.knob__glass {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.08) 46%, rgba(255, 255, 255, 0.14)),
    rgba(30, 24, 18, 0.18);
  -webkit-backdrop-filter: blur(9px) saturate(1.5) brightness(1.15);
  backdrop-filter: blur(9px) saturate(1.5) brightness(1.15);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    inset 0 1px 1px rgba(255, 255, 255, 0.6),
    inset 0 -6px 10px -6px rgba(233, 196, 138, 0.55),
    0 8px 18px -6px rgba(0, 0, 0, 0.6),
    0 2px 4px rgba(0, 0, 0, 0.3);
  will-change: transform;
}

/* a tall soft highlight on the left of the glass */
.knob__glass::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 7px;
  width: 6px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), transparent);
  opacity: 0.7;
}

.knob__icon {
  width: 14px;
  height: 22px;
  fill: none;
  stroke: #fffaf2;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
}

.knob:focus-visible .knob__glass {
  box-shadow:
    0 0 0 3px rgba(233, 196, 138, 0.55),
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    0 8px 18px -6px rgba(0, 0, 0, 0.6);
}

.is-dragging .knob {
  cursor: grabbing;
}

/* ------------------------------------------------------------------ the loupe */
.loupe {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--d, 104px);
  height: var(--d, 104px);
  margin: calc(var(--d, 104px) / -2) 0 0 calc(var(--d, 104px) / -2);
  border-radius: 50%;
  pointer-events: none;
  will-change: transform;
}

.loupe__view {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #0b0a09;
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, 0.85), 0 3px 8px rgba(0, 0, 0, 0.4);
}

.loupe__view .plate {
  transform-origin: 0 0;
}

/* the glass of the loupe: a thick rim with a highlight on top and the line of the split shown again inside */
.loupe__rim {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.55),
    inset 0 0 0 4px rgba(255, 250, 240, 0.12),
    inset 0 10px 18px -10px rgba(255, 255, 255, 0.55),
    inset 0 -14px 22px -14px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(0, 0, 0, 0.35);
  background: radial-gradient(60% 40% at 34% 18%, rgba(255, 255, 255, 0.22), transparent 70%);
}

.loupe__rim::after {
  content: '';
  position: absolute;
  left: calc(50% - 0.75px);
  top: 4px;
  bottom: 4px;
  width: 1.5px;
  background: linear-gradient(180deg, transparent, rgba(255, 250, 240, 0.85) 20%, rgba(255, 250, 240, 0.85) 80%, transparent);
}

/* ------------------------------------------------------------------ the foot of the card */
.case__foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(8px, 1.6vh, 14px) 4px 2px;
}

.case__title {
  min-width: 0;
}

.case__name {
  margin: 0;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-style: italic;
  font-size: clamp(16px, min(4.6vw, 3.2vh), 21px);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.case__meta {
  margin: 4px 0 0;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
}

.case__read {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
}

.case__pct {
  font-size: clamp(18px, min(5vw, 3.6vh), 24px);
  font-weight: 620;
  font-variation-settings: 'wdth' 92;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--accent);
  display: inline-block;
  min-width: 2.2ch;
  text-align: right;
}

.case__unit {
  font-size: 11.5px;
  color: var(--muted);
}

@media (max-width: 420px) {
  .case__meta {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@media (max-height: 480px) {
  .case__meta {
    display: none;
  }
}
