/* The zooming calendar: the year in twelve small months on a white page. Choosing a month the view zooms into it
   until it is the big month; the way back zooms out to the year. Today is orange, the chosen day black. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #141414;           /* text, and the chosen day */
  --muted: #9a9a9f;
  --line: rgba(20, 20, 20, 0.08);
  --today: #ff5a1f;         /* today */
  --soft: #f3f3f4;
  --weekend: #a1a1a6;       /* Saturdays and Sundays */
  --num: 0.36;              /* how big a number is in its cell: the same in the small and the big months, so that
                               zooming the small numbers grow exactly into the big ones */
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Geist 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: 32px 16px;
}

.zoomcal {
  width: min(920px, 100%);
}

/* ---------------------------------------------------------------- the head */
/* the title in the middle, the way back on its left, the arrows on its right */
.zoomcal__head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 26px;
}

.zoomcal__title {
  grid-column: 2;
  margin: 0;
  font-size: clamp(26px, 5vw, 40px);
  font-weight: 640;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.zoomcal__back {
  grid-column: 1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 40px;
  padding: 0 14px 0 6px;
  border: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.zoomcal__back[hidden] {
  display: none;
}

.zoomcal__back svg,
.zoomcal__arrow svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.zoomcal__arrows {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 4px;
}

.zoomcal__arrow {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
  .zoomcal__arrow:hover,
  .zoomcal__back:hover {
    background: #e9e9eb;
  }
}

.zoomcal__arrow:focus-visible,
.zoomcal__back:focus-visible,
.mini:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- the two views, one over the other */
/* the views are clipped, with some room inside for the hover backgrounds and the focus rings: zooming in, the year
   grows far past them */
.zoomcal__views {
  position: relative;
  overflow: hidden;
  padding: 16px;
  margin: -16px;
}

/* while the year moves (the zoom, a new year) its edges fade instead of being cut */
.zoomcal__views.is-moving {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent), linear-gradient(transparent, #000 16px, #000 calc(100% - 16px), transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent), linear-gradient(transparent, #000 16px, #000 calc(100% - 16px), transparent);
  mask-composite: intersect;
}

.year {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 30px 34px;
  transform-origin: 0 0;
}

.month {
  position: absolute;
  inset: 16px;
  display: grid;
  place-items: center;
  align-content: start;
}

.month[hidden] {
  display: none;
}

/* a small month: a button that opens it */
.mini {
  display: grid;
  justify-self: stretch;
  gap: 8px;
  padding: 10px;
  margin: -10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
  .mini:hover {
    background: var(--soft);
  }
}

.mini__name {
  font-size: 13px;
  font-weight: 650;
}

.mini.is-now .mini__name {
  color: var(--today);
}

.mini__days,
.big__days,
.big__week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

/* the numbers are sized on the width of their month (a seventh of it is a cell) */
.mini__days,
.big__days {
  container-type: inline-size;
}

.mini__days span {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  font-size: calc(100cqi / 7 * var(--num));
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: #4a4a4f;
  isolation: isolate;
}

.mini__days .is-weekend {
  color: var(--weekend);
}

/* the discs are as big as the ones of the big month, so that they too grow into each other */
.mini__days .is-today::before,
.mini__days .is-picked::before {
  content: '';
  position: absolute;
  inset: 8%;
  z-index: -1;
  border-radius: 50%;
  background: var(--ink);
}

.mini__days .is-picked {
  color: #fff;
}

.mini__days .is-today {
  color: #fff;
  font-weight: 650;
}

.mini__days .is-today::before {
  background: var(--today);
}

/* the big month */
.big {
  width: min(470px, 100%);
}

.big__week {
  margin-bottom: 6px;
}

.big__week span {
  padding: 6px 0;
  font-size: 12px;
  font-weight: 620;
  text-align: center;
  color: var(--muted);
}

.big__days {
  transform-origin: 0 0;
}

.big__days > span {
  aspect-ratio: 1;
}

.day {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: calc(100cqi / 7 * var(--num));
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* the disc behind a day: orange for today, black for the chosen one */
.day__disc {
  position: absolute;
  inset: 8%;
  z-index: -1;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0;
  transform: scale(0.6);
}

.day.is-weekend {
  color: var(--weekend);
}

.day.is-today {
  color: var(--today);
  font-weight: 650;
}

.day.is-picked {
  color: #fff;
}

.day.is-picked .day__disc {
  opacity: 1;
  transform: none;
}

.day.is-today.is-picked .day__disc {
  background: var(--today);
}

@media (hover: hover) and (pointer: fine) {
  .day:not(.is-picked):hover .day__disc {
    opacity: 1;
    transform: none;
    background: var(--soft);
  }
}

.day .day__disc {
  transition: opacity 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.6, 0.5, 1), background-color 0.2s ease;
}

.day:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
  .day .day__disc {
    transform: none;
    transition: opacity 0.2s ease, background-color 0.2s ease;
  }
}

@media (max-width: 720px) {
  :root {
    --num: 0.42;
  }

  .year {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px 14px;
  }

  .mini {
    gap: 5px;
    padding: 6px;
    margin: -6px;
  }

  .mini__name {
    font-size: 12px;
  }
}

/* the year that leaves when the year changes: a copy over the new one, for as long as it slides away */
.year--ghost {
  position: absolute;
  inset: 16px;
  pointer-events: none;
}

/* on a phone the views take sideways swipes (the page still scrolls up and down) */
.zoomcal__views {
  touch-action: pan-y;
}
