/* The memory foam picker: the firmness of a mattress chosen on a long cushion of night blue velvet, on a white page.
   The cushion, its piping, the press and the trail it leaves are drawn by the script in WebGL with the colours below;
   the four names are the real labels of the radio buttons, printed in ivory over the velvet. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #171a2c;           /* the title over the cushion */
  --muted: #6d7086;         /* the line that says who the firmness is for */
  --velvet: #22306a;        /* the velvet, in the light */
  --velvet-deep: #0b1131;   /* the velvet, in its own shade */
  --sheen: #a9bcf4;         /* the glow of the pile where the cover turns away from the light */
  --crushed: #3a4d97;       /* the pile crushed by the press, a little paler */
  --thread: #f4efe3;        /* the names printed on the velvet */
  --shadow: #10163a;        /* the cushion's shadow on the page */
  --focus: #f4efe3;         /* the ring of the keyboard's focus, on the velvet */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap */
html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Fraunces Variable', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
}

/* the letters follow the foam: the script turns the SOFT axis of the typeface from 100 (soft) to 0 (firm) */
.firm {
  width: min(440px, 100%);
  font-variation-settings: 'SOFT' var(--soft, 60), 'WONK' 0;
}

/* ---------------------------------------------------------------- the title and who it is for */
.firm__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin: 0 8px 13px;
}

.firm__title {
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.firm__hint {
  font-size: 15px;
  line-height: 24px;
  font-weight: 420;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the cushion */
/* four equal columns, each a whole label, a little in from the round ends: the canvas under them reaches past the
   cushion for its shadow */
.firm__bed {
  position: relative;
  height: 56px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  padding: 0 8px;
  border-radius: 999px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.firm__canvas {
  position: absolute;
  left: -14px;
  top: -8px;
  width: calc(100% + 28px);
  height: calc(100% + 32px);
  pointer-events: none;
}

.firm__opt {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  cursor: pointer;
}

/* the radio itself is hidden but stays in the page: it takes the focus, the arrow keys and the clicks */
.firm__radio {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  opacity: 0;
}

/* the script lowers each name into the foam with the cover under it, and lights the one under the press */
.firm__name {
  display: block;
  padding: 0 4px;
  color: var(--thread);
  opacity: 0.56;
  font-size: 16px;
  line-height: 22px;
  font-weight: 470;
  letter-spacing: 0.005em;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(5, 8, 30, 0.35);
}

/* the ring of the keyboard's focus, round the whole option, inside the cushion */
.firm__opt::before {
  content: '';
  position: absolute;
  inset: 7px 5px;
  border-radius: 999px;
  box-shadow: 0 0 0 2px var(--focus);
  opacity: 0;
  pointer-events: none;
}

.firm__opt:has(.firm__radio:focus-visible)::before {
  opacity: 0.9;
}

/* ---------------------------------------------------------------- without WebGL */
/* the cushion is a velvet pill drawn by the CSS, and the press a soft hollow moved by the script */
.firm__dent {
  display: none;
}

.firm.is-flat .firm__bed {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 40%, rgba(0, 0, 0, 0.22)),
    var(--velvet);
  box-shadow:
    inset 0 0 0 2px var(--velvet-deep),
    inset 0 2px 1px rgba(255, 255, 255, 0.2),
    0 6px 14px -4px rgba(16, 22, 58, 0.45);
}

.firm.is-flat .firm__dent {
  display: block;
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  border-radius: 999px;
  background: radial-gradient(closest-side, var(--crushed), rgba(58, 77, 151, 0));
  box-shadow: inset 4px 5px 8px -2px rgba(5, 8, 30, 0.55), inset -3px -3px 6px -2px rgba(169, 188, 244, 0.35);
  pointer-events: none;
}

@media (max-width: 420px) {
  .firm__name {
    font-size: 15px;
    padding: 0 2px;
  }

  .firm__hint {
    font-size: 14px;
  }
}
