/* The weather app that turns from day to night as the sun sets: Calder, a made-up weather app, alone in the middle of
   the page. Every part of the app is a zone with its own colours (--card, --fg, --mut, --line, --acc), so that the
   script can change them one zone at a time as the line of light coming down from the sky reaches it. The app's own
   ground is changed by a layer (.app__flood) that is revealed from the top with a soft edge. All the sizes are in em
   of a font size taken from the height of the app, so the whole app keeps its shape and fits a short, wide box. */
:root {
  /* day */
  --day-page: #e9edf2;      /* the page around the app */
  --day-app: #f6f7f9;       /* the ground of the app */
  --day-card: #ffffff;      /* the cards */
  --day-fg: #111722;        /* the words */
  --day-mut: #6b7483;       /* the small words */
  --day-line: rgba(17, 23, 34, 0.08); /* the thin lines and borders */
  --day-acc: #f0902f;       /* the accent: the warm light of the sun */
  --day-sky-ink: rgba(20, 32, 64, 0.55); /* the words under the horizon */
  /* night */
  --night-page: #04060b;
  --night-app: #0a0e18;
  --night-card: #111827;
  --night-fg: #e9edf6;
  --night-mut: #8a93a8;
  --night-line: rgba(233, 237, 246, 0.08);
  --night-acc: #a8bfff;     /* the accent at night: moonlight */
  --night-sky-ink: rgba(214, 224, 255, 0.6);
  /* the line of light that comes down */
  --dusk-light: 255, 150, 92;  /* at sunset, in r, g, b */
  --dawn-light: 255, 196, 176; /* at sunrise */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

body {
  --page: var(--day-page);
  min-height: 100svh;
  background: var(--page);
  color: var(--day-fg);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

p {
  margin: 0;
}

.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: min(16px, 2vh);
  overflow: hidden;
  /* a very soft light from above on the page */
  background: radial-gradient(120% 70% at 50% 0%, rgba(255, 255, 255, var(--page-glow, 0.55)), transparent 70%);
}

/* ------------------------------------------------------------------ the app */
.app {
  --h: min(700px, 94vh, 172vw);
  --app: var(--day-app);
  --sh: 0.16;
  position: relative;
  isolation: isolate;
  height: var(--h);
  width: calc(var(--h) * 0.55);
  font-size: calc(var(--h) / 42);
  padding: 1.25em 1.05em 0.85em;
  display: flex;
  flex-direction: column;
  gap: 0.72em;
  border-radius: 2.3em;
  background: var(--app);
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(17, 23, 34, calc(var(--sh) * 0.35)),
    0 2px 4px rgba(10, 14, 24, calc(var(--sh) * 0.4)),
    0 2.6em 4.4em -1.6em rgba(10, 14, 24, calc(var(--sh) * 1.6));
  opacity: 0;
}

/* the new ground of the app, revealed from the top with a soft edge as the light comes down */
.app__flood {
  --p: -20%;
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--flood, var(--night-app));
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(var(--p) - 14%), transparent var(--p));
  mask-image: linear-gradient(to bottom, #000 calc(var(--p) - 14%), transparent var(--p));
  pointer-events: none;
}

/* the line of light itself: a soft band and one hairline in the middle */
.app__band {
  --light: var(--dusk-light);
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 9em;
  margin-top: -4.5em;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(to bottom, rgba(var(--light), 0), rgba(var(--light), 0.16) 50%, rgba(var(--light), 0));
  will-change: transform;
}

.app__edge {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: linear-gradient(to right, rgba(var(--light), 0), rgba(var(--light), 0.85) 30%, rgba(255, 244, 230, 0.95) 50%, rgba(var(--light), 0.85) 70%, rgba(var(--light), 0));
}

.zone {
  --card: var(--day-card);
  --fg: var(--day-fg);
  --mut: var(--day-mut);
  --line: var(--day-line);
  --acc: var(--day-acc);
  --hi: 0;
  --sh: 0.1;
  position: relative;
  color: var(--fg);
  flex: none;
}

.card {
  background: var(--card);
  border-radius: 1.15em;
  box-shadow:
    inset 0 0 0 1px var(--line),
    inset 0 1px 0 rgba(255, 255, 255, var(--hi)),
    0 1px 2px rgba(10, 14, 24, calc(var(--sh) * 0.5)),
    0 0.9em 1.8em -1.1em rgba(10, 14, 24, var(--sh));
}

/* ------------------------------------------------------------------ the bar */
.bar {
  height: 2.6em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.2em;
}

.bar__place {
  display: grid;
  gap: 0.15em;
}

.bar__city {
  font-size: 1.12em;
  font-weight: 640;
  font-stretch: 108%;
  letter-spacing: -0.01em;
}

.bar__time {
  font-size: 0.76em;
  font-weight: 480;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}

.switch {
  position: relative;
  width: 3.1em;
  height: 1.75em;
  padding: 0;
  border: 0;
  border-radius: 1em;
  background: none;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.switch:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 3px;
}

.switch__track {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: color-mix(in srgb, var(--fg) 8%, transparent);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

.switch__knob {
  position: absolute;
  top: 0.2em;
  left: 0.2em;
  width: 1.35em;
  height: 1.35em;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16), 0 0.3em 0.6em -0.2em rgba(0, 0, 0, 0.25), inset 0 0 0 1px var(--line);
  display: grid;
  place-items: center;
}

.switch__knob svg {
  width: 1.05em;
  height: 1.05em;
  overflow: visible;
}

.switch__rays path {
  fill: none;
  stroke: var(--acc);
  stroke-width: 1.3;
  stroke-linecap: round;
}

.switch__rays {
  transform-origin: 8px 8px;
}

.switch__core {
  fill: var(--acc);
}

/* ------------------------------------------------------------------ the sky */
.sky {
  --sky-ink: var(--day-sky-ink);
  height: 10.4em;
  border-radius: 1.3em;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), 0 0.8em 1.6em -1.2em rgba(10, 14, 24, 0.35);
}

.sky__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sky__arc {
  fill: none;
  stroke: var(--sky-ink);
  stroke-width: 0.5;
  stroke-dasharray: 1.2 2.4;
  opacity: 0.55;
}

.sky__horizon,
.sky__tick {
  stroke: var(--sky-ink);
  stroke-width: 0.5;
}

.sky__label {
  fill: var(--sky-ink);
  font-size: 6.4px;
  font-weight: 520;
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.sky__sun {
  fill: #fff7e4;
}

.sky__sun-rim {
  fill: none;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 0.5;
}

.sky__moon {
  fill: #edf1ff;
}

/* ------------------------------------------------------------------ now */
.now {
  height: 3.8em;
  display: flex;
  align-items: center;
  gap: 0.9em;
  padding: 0 0.25em;
}

.now__temp {
  display: flex;
  align-items: flex-start;
  font-size: 3.5em;
  line-height: 1;
  font-weight: 300;
  font-stretch: 112%;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.now__deg {
  font-size: 0.55em;
  font-weight: 400;
  margin-top: 0.08em;
  color: var(--acc);
}

.now__words {
  display: grid;
  gap: 0.28em;
}

.now__cond {
  font-size: 0.95em;
  font-weight: 600;
}

.now__range {
  font-size: 0.76em;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}

/* two words in the same place: one goes up and out, the other comes in */
.swap {
  position: relative;
  display: inline-grid;
  overflow: hidden;
  vertical-align: bottom;
  padding: 0.06em 0;
}

.swap > span {
  grid-area: 1 / 1;
  white-space: nowrap;
}

.swap__b {
  opacity: 0;
}

/* ------------------------------------------------------------------ the hours */
.hours {
  height: 5.3em;
  padding: 0.55em 0.4em;
}

.hours__row {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.hour {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  align-items: center;
  border-radius: 0.8em;
}

.hour.is-now::before {
  content: '';
  position: absolute;
  inset: 0 0.12em;
  border-radius: 0.8em;
  background: color-mix(in srgb, var(--acc) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--acc) 26%, transparent);
}

.hour > * {
  position: relative;
}

.hour__when,
.hour__deg {
  display: grid;
}

.hour__when > span,
.hour__deg > span,
.hour__icon > svg {
  grid-area: 1 / 1;
}

.hour__when {
  font-size: 0.68em;
  color: var(--mut);
  font-weight: 520;
  font-variant-numeric: tabular-nums;
}

.hour.is-now .hour__when {
  color: var(--fg);
}

.hour__deg {
  font-size: 0.86em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hour__icon {
  display: grid;
  width: 1.45em;
  height: 1.45em;
}

.hour__icon svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-origin: 50% 50%;
}

.hour__icon .lit {
  fill: var(--acc);
  stroke: none;
}

.hour__icon .cloud {
  fill: var(--card);
}

.hour [data-b] {
  opacity: 0;
}

/* ------------------------------------------------------------------ the chart */
.chart {
  flex: 1 1 auto;
  min-height: 5em;
  padding: 0.75em 0.85em 0.55em;
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}

.chart__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.chart__title {
  font-size: 0.82em;
  font-weight: 620;
}

.chart__read {
  font-size: 0.72em;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}

.chart__plot {
  position: relative;
  flex: 1 1 auto;
  min-height: 2.4em;
  cursor: crosshair;
  touch-action: pan-y;
}

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

.chart__grid {
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart__line {
  fill: none;
  stroke: var(--acc);
  stroke-width: 1.6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.chart__area {
  fill: url(#g-area);
}

.chart__stop-a {
  stop-color: var(--acc);
  stop-opacity: 0.28;
}

.chart__stop-b {
  stop-color: var(--acc);
  stop-opacity: 0;
}

.chart__drop {
  stroke: var(--acc);
  stroke-width: 1;
  stroke-dasharray: 2 2;
  vector-effect: non-scaling-stroke;
  opacity: 0.6;
}

.chart__dot {
  position: absolute;
  left: 0;
  top: 0;
  width: 0.62em;
  height: 0.62em;
  margin: -0.31em 0 0 -0.31em;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 0 0 0.16em var(--acc), 0 0.2em 0.5em rgba(0, 0, 0, 0.2);
  will-change: transform;
}

.chart__axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.6em;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ the two stats */
.stats {
  height: 3.5em;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6em;
}

.stat {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.5em;
  align-content: center;
  padding: 0 0.8em;
}

.stat__icon {
  grid-row: 1 / 3;
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: var(--acc);
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  align-self: center;
}

.stat__name {
  font-size: 0.66em;
  color: var(--mut);
}

.stat__value {
  font-size: 0.9em;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ the tabs */
.tabs {
  height: 2.9em;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  border-top: 1px solid var(--line);
  margin: 0 -1.05em -0.85em;
  padding: 0 1.05em 0.3em;
}

.tab {
  display: grid;
  justify-items: center;
  gap: 0.2em;
  color: var(--mut);
  text-decoration: none;
  font-size: 0.62em;
  font-weight: 540;
}

.tab svg {
  width: 1.9em;
  height: 1.9em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-on {
  color: var(--fg);
}

.tab.is-on svg {
  stroke: var(--acc);
}

@media (hover: hover) {
  .switch:hover .switch__track {
    background: color-mix(in srgb, var(--fg) 12%, transparent);
  }

  .tab:hover {
    color: var(--fg);
  }
}
