/* The glass air quality widget: a frosted glass card on a near black page, with two soft lights behind it that take the
   colour of the air. The card is one element that turns on a spring (the script swaps front and back at 90 degrees);
   its 1px edge and a soft spotlight follow the pointer; a sheen crosses the glass while it turns. */
:root {
  --page: #08090b;            /* the page */
  --ink: #f2f4f3;             /* the words */
  --muted: #8d9592;           /* the small words */
  --good: #5be3b0;            /* the colour of good air */
  --moderate: #f6c35b;        /* the colour of moderate air */
  --sensitive: #ff8f5e;       /* the colour of air bad for sensitive groups */
  --unhealthy: #ff5d73;       /* the colour of unhealthy air */
  --lvl: #5be3b0;             /* the colour of the air right now (the script moves it) */
  --glass: rgba(255, 255, 255, 0.075); /* the tint of the glass */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: 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 {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, 0.035), transparent 60%),
    var(--page);
}

/* the lights behind the glass */
.orb {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
}

.orb--a {
  width: min(96vw, 66vh, 360px);
  height: min(96vw, 66vh, 360px);
  margin: calc(min(96vw, 66vh, 360px) / -2) 0 0 calc(min(96vw, 66vh, 360px) / -2);
  background: radial-gradient(circle, color-mix(in srgb, var(--lvl) 55%, transparent), color-mix(in srgb, var(--lvl) 14%, transparent) 42%, transparent 70%);
}

.orb--b {
  width: min(60vw, 44vh, 220px);
  height: min(60vw, 44vh, 220px);
  margin: calc(min(60vw, 44vh, 220px) / -2) 0 0 calc(min(60vw, 44vh, 220px) / -2);
  background: radial-gradient(circle, rgba(120, 150, 255, 0.5), rgba(120, 150, 255, 0.12) 42%, transparent 70%);
}

.widget {
  position: relative;
  width: min(86vw, 300px);
}

.widget__shadow {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -14px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  filter: blur(16px);
  pointer-events: none;
  opacity: 0;
}

/* the glass */
.card {
  --mx: 30%;
  --my: -10%;
  position: relative;
  border-radius: 26px;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.025) 48%, rgba(255, 255, 255, 0.05)),
    var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -1px 0 rgba(255, 255, 255, 0.03),
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 12px 24px -10px rgba(0, 0, 0, 0.55),
    0 40px 70px -30px rgba(0, 0, 0, 0.8);
  opacity: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* the 1px edge: always faint, bright where the light is */
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background:
    radial-gradient(150px circle at var(--mx) var(--my), rgba(255, 255, 255, 0.85), color-mix(in srgb, var(--lvl) 40%, transparent) 38%, transparent 70%),
    linear-gradient(170deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05) 45%, rgba(255, 255, 255, 0.1));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
  z-index: 3;
}

.card__grain,
.card__spot,
.card__sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.card__grain {
  opacity: 0.09;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='140' height='140' filter='url(%23n)'/></svg>");
}

/* the light that follows the pointer on the glass */
.card__spot {
  background: radial-gradient(260px circle at var(--mx) var(--my), rgba(255, 255, 255, 0.075), transparent 65%);
}

/* the band of light that crosses the glass while it turns */
.card__sheen {
  --sh: -60%;
  opacity: 0;
  background: linear-gradient(105deg, transparent calc(var(--sh) + 20%), rgba(255, 255, 255, 0.16) calc(var(--sh) + 40%), rgba(255, 255, 255, 0.03) calc(var(--sh) + 52%), transparent calc(var(--sh) + 64%));
  z-index: 2;
}

.face {
  position: relative;
  z-index: 1;
  padding: clamp(14px, 4.2vh, 20px) clamp(16px, 5vw, 20px) clamp(14px, 3.8vh, 18px);
  display: flex;
  flex-direction: column;
}

.face--back {
  position: absolute;
  inset: 0;
  visibility: hidden;
}

.is-back .face--front {
  visibility: hidden;
}

.is-back .face--back {
  visibility: visible;
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.head__words {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.head__kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.head__kicker svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}

.head__place {
  font-size: 15px;
  font-weight: 600;
  font-variation-settings: 'wdth' 106;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip {
  flex: none;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}

/* the gauge */
.gauge {
  position: relative;
  width: min(100%, 52vh);
  margin: clamp(6px, 2vh, 12px) auto 0;
}

.gauge__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.gauge__seg {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
  opacity: 0.2;
}

.gauge__fill,
.gauge__glow {
  fill: none;
  stroke: var(--lvl);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 0 1;
}

.gauge__glow {
  stroke-width: 9;
  opacity: 0.55;
  filter: url(#soft);
}

.gauge__tick {
  stroke: #ffffff;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.gauge__end {
  font: 500 10px 'Mona Sans Variable', system-ui, sans-serif;
  fill: var(--muted);
}

.gauge__read {
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  display: grid;
  justify-items: center;
  gap: 4px;
}

.num {
  display: inline-flex;
  font-size: clamp(42px, 12vh, 58px);
  line-height: 1;
  font-weight: 620;
  font-variation-settings: 'wdth' 92;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.num__digit {
  position: relative;
  display: inline-block;
  height: 1em;
  width: 0.6em;
  overflow: hidden;
  -webkit-mask: linear-gradient(transparent, #000 18%, #000 82%, transparent);
  mask: linear-gradient(transparent, #000 18%, #000 82%, transparent);
}

.num__reel {
  display: block;
}

.num__reel span {
  display: block;
  height: 1em;
  text-align: center;
}

.level,
.insight,
.foot__time {
  display: block;
  overflow: hidden;
}

.roll {
  display: inline-block;
}

.level {
  font-size: 12.5px;
  font-weight: 600;
  font-variation-settings: 'wdth' 110;
  letter-spacing: 0.02em;
  color: var(--lvl);
}

.insight {
  margin: clamp(2px, 1vh, 6px) 0 0;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(242, 244, 243, 0.78);
  min-height: 1.35em;
}

.foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: clamp(10px, 3vh, 16px);
  padding-top: clamp(10px, 2.6vh, 13px);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.foot__time {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: none;
}

button:focus-visible .btn-face {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), 0 0 0 2px var(--page), 0 0 0 3.5px color-mix(in srgb, var(--lvl) 80%, transparent);
}

.btn-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

.btn-face svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .btn-face {
  width: 32px;
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.pill-btn .btn-face {
  padding: 0 10px 0 13px;
  font-size: 12.5px;
  font-weight: 560;
  font-variation-settings: 'wdth' 104;
}

.pill-btn--back .btn-face {
  padding: 0 13px 0 9px;
}

.pill-btn svg {
  width: 14px;
  height: 14px;
}

@media (hover: hover) {
  button:hover .btn-face {
    background: rgba(255, 255, 255, 0.11);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  }
}

/* the back */
.rows {
  list-style: none;
  margin: clamp(8px, 2.4vh, 18px) 0 0;
  padding: 0;
  display: grid;
  gap: clamp(7px, 2.4vh, 15px);
  align-content: start;
}

.row {
  display: grid;
  grid-template-columns: 46px 1fr 30px;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}

.row__name {
  font-weight: 560;
  color: rgba(242, 244, 243, 0.86);
}

.row__name sub {
  font-size: 0.72em;
  vertical-align: -0.2em;
}

.row__bar {
  position: relative;
  height: 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.row__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--lvl) 45%, transparent), var(--lvl));
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.row__val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 560;
}

/* the next twelve hours: small columns, each in the colour of its hour */
.hours {
  display: grid;
  gap: 6px;
  margin-top: clamp(8px, 2.2vh, 16px);
}

.hours__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}

.hours__peak {
  color: rgba(242, 244, 243, 0.7);
  font-variant-numeric: tabular-nums;
}

.hours__bars {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: end;
  gap: 6px;
  height: clamp(20px, 5.6vh, 38px);
  padding: 0 1px;
}

.hours__bar {
  display: block;
  height: 100%;
  width: 100%;
  max-width: 9px;
  justify-self: center;
  border-radius: 4px 4px 1.5px 1.5px;
  transform-origin: 50% 100%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.hours__axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: rgba(141, 149, 146, 0.8);
}

.foot--back {
  margin-top: auto;
}

.best {
  flex: 1;
  display: grid;
  gap: 2px;
  min-width: 0;
}

.best__label {
  font-size: 11px;
  color: var(--muted);
}

.best__time {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--lvl);
}

/* the autopilot's pointer */
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.ghost path {
  fill: #ffffff;
  stroke: #08090b;
  stroke-width: 1.4;
  stroke-linejoin: round;
}
