/* The cube calendar: a delivery day picker for a furniture maker, on a white page. The chosen date stands on a little
   desk at the top, set with two oak day cubes and a month drum on its stand, like a perpetual desk calendar; below,
   the weeks are one long strip of paper that rolls under a wooden tile. */
:root {
  --page: #ffffff;          /* the page */
  --card: #ffffff;          /* the picker */
  --ink: #1d1b17;           /* the days you can choose */
  --muted: #8b857b;         /* the names of the days */
  --off: #c4bdb2;           /* the days you can't choose */
  --line: rgba(29, 27, 23, 0.09);
  --oak: #dfc194;           /* the wood of the cubes, the drum and the tile */
  --walnut: #5e4029;        /* the stand of the drum */
  --engrave: #4a2e18;       /* the figures burnt into the wood */
  --button: #2e2117;        /* the booking button, dark walnut */
  --button-ink: #fbf8f2;
  --cube: 46px;             /* a day cube */
  --row: 42px;              /* a week */
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Gantari 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: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

/* ---------------------------------------------------------------- the picker */
.picker {
  position: relative;
  flex: none;
  width: min(360px, 100%);
  padding: 10px 18px 18px;
  border-radius: 26px;
  background: var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 2px 6px -2px rgba(60, 40, 15, 0.08), 0 40px 70px -42px rgba(60, 40, 15, 0.34);
}

.picker__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  height: 96px;
}

/* ---------------------------------------------------------------- the desk: two day cubes and the month drum */
.desk {
  position: relative;
  flex: none;
  height: 100%;
  perspective: 620px;
  perspective-origin: 50% 30%;
  transform-origin: 0 100%;
}

.desk__set {
  position: absolute;
  left: 0;
  bottom: 16px;
  transform-style: preserve-3d;
  transform-origin: 50% 100%;
}

.desk__set > *,
.cube > *,
.cube__rock > *,
.cube__body > *,
.drum > *,
.drum__body > *,
.post > * {
  position: absolute;
}

.drum {
  cursor: grab;
  touch-action: none;
}

.picker.is-dragging .drum {
  cursor: grabbing;
}

.cube,
.cube__rock,
.cube__body,
.drum,
.drum__body,
.post {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
}

.cube__rock,
.cube__body {
  width: 100%;
  height: 100%;
}

/* a face of oak: a little lighter towards the top, the grain running across, the edges worn round.
   The 3D faces are drawn --k times bigger and shrunk back, so every measure here grows with it */
.wood {
  --k: 1;
  background:
    linear-gradient(180deg, rgba(255, 249, 236, 0.3), rgba(255, 249, 236, 0) 45%, rgba(120, 78, 32, 0.06)),
    repeating-linear-gradient(var(--grain, 93deg), rgba(140, 94, 44, 0.1) 0 calc(1.1px * var(--k)), rgba(140, 94, 44, 0) calc(1.1px * var(--k)) calc(4.6px * var(--k)), rgba(140, 94, 44, 0.06) calc(4.6px * var(--k)) calc(5.5px * var(--k)), rgba(140, 94, 44, 0) calc(5.5px * var(--k)) calc(11px * var(--k))),
    var(--oak);
  box-shadow: inset 0 0 0 calc(1px * var(--k)) rgba(255, 244, 222, 0.38), inset 0 0 calc(7px * var(--k)) rgba(130, 86, 36, 0.32);
}

/* the two faces cut across the grain show its rings */
.wood--end {
  background:
    linear-gradient(180deg, rgba(255, 249, 236, 0.22), rgba(255, 249, 236, 0) 50%),
    repeating-radial-gradient(circle at 22% 118%, rgba(140, 94, 44, 0.15) 0 calc(1.1px * var(--k)), rgba(140, 94, 44, 0) calc(1.1px * var(--k)) calc(4.4px * var(--k))),
    var(--oak);
}

.cube__face,
.drum__face,
.drum__cap {
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* a figure burnt into the wood */
.cube__digit {
  font-size: calc(var(--cube) * 0.68 * var(--k));
  font-weight: 760;
  line-height: 1;
  color: var(--engrave);
  text-shadow: 0 calc(1px * var(--k)) 0 rgba(255, 245, 225, 0.5), 0 calc(-0.5px * var(--k)) 0 rgba(90, 55, 20, 0.35);
  font-variant-numeric: lining-nums;
}

/* the darkness of a face turned away from the light, set by the script */
.shade {
  position: absolute;
  inset: 0;
  background: #2a1a0b;
  opacity: 0;
  pointer-events: none;
}

.drum__label {
  display: flex;
  align-items: baseline;
  gap: calc(5px * var(--k));
}

.drum__month {
  font-size: calc(var(--cube) * 0.44 * var(--k));
  font-weight: 760;
  letter-spacing: 0.07em;
  color: var(--engrave);
  text-shadow: 0 calc(1px * var(--k)) 0 rgba(255, 245, 225, 0.5), 0 calc(-0.5px * var(--k)) 0 rgba(90, 55, 20, 0.35);
}

.drum__year {
  font-size: calc(var(--cube) * 0.2 * var(--k));
  font-weight: 700;
  letter-spacing: 0.04em;
  color: color-mix(in srgb, var(--engrave) 72%, transparent);
  font-variant-numeric: tabular-nums;
}

/* the stand of the drum: a walnut base and two posts */
.post__face {
  left: 0;
  top: 0;
  background: linear-gradient(90deg, rgba(255, 230, 200, 0.12), rgba(255, 230, 200, 0) 60%), var(--walnut);
  box-shadow: inset 0 1px 0 rgba(255, 228, 196, 0.22);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.post__face--top {
  background: color-mix(in srgb, var(--walnut) 78%, #ffffff);
  box-shadow: none;
}

.post__face--side {
  background: color-mix(in srgb, var(--walnut) 76%, #000000);
  box-shadow: none;
}

/* shadows on the desk */
.floor {
  left: 0;
  top: 0;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(74, 48, 20, 0.42), rgba(74, 48, 20, 0.18) 58%, rgba(74, 48, 20, 0) 100%);
  pointer-events: none;
}

/* ---------------------------------------------------------------- the arrows */
.picker__arrows {
  display: flex;
  gap: 4px;
  padding-bottom: 20px;
}

.arrow {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(29, 27, 23, 0.1);
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.6, 0.5, 1);
}

/* a finger gets a target a little bigger than the circle */
.arrow::after {
  content: '';
  position: absolute;
  inset: -4px -3px;
}

.arrow svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) and (pointer: fine) {
  .arrow:not([aria-disabled='true']):hover {
    background: color-mix(in srgb, var(--oak) 14%, #ffffff);
    box-shadow: inset 0 0 0 1px rgba(29, 27, 23, 0.2);
  }
}

/* under the pointer the chevron leans the way the weeks will go */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .arrow[data-prev]:not([aria-disabled='true']):hover svg {
    transform: translateY(-1.5px);
  }

  .arrow[data-next]:not([aria-disabled='true']):hover svg {
    transform: translateY(1.5px);
  }
}

.arrow svg {
  transition: transform 0.3s cubic-bezier(0.34, 1.6, 0.5, 1);
}

.arrow:not([aria-disabled='true']):active {
  transform: scale(0.92);
}

.arrow[aria-disabled='true'] {
  opacity: 0.3;
  cursor: default;
}

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

/* ---------------------------------------------------------------- the weeks */
.cal__week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: center;
  height: 26px;
  font-size: 11.5px;
  font-weight: 640;
  letter-spacing: 0.03em;
  text-align: center;
  color: var(--muted);
}

.cal__week .is-closed {
  color: var(--off);
}

/* the window on the strip of weeks: six of them show; the edges fade instead of cutting the numbers sharp */
.cal__window {
  position: relative;
  height: calc(var(--row) * 6);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-mask-image: linear-gradient(transparent, #000 5px, #000 calc(100% - 5px), transparent);
  mask-image: linear-gradient(transparent, #000 5px, #000 calc(100% - 5px), transparent);
}

.picker.is-dragging .cal__window {
  cursor: grabbing;
}

.cal__strip,
.tile__copy {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  will-change: transform;
}

.cal__row,
.copy__row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  height: var(--row);
}

.day,
.copy__day {
  display: grid;
  place-items: center;
  height: var(--row);
}

.day {
  outline: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.picker.is-dragging .day {
  cursor: grabbing;
}

/* the number sits in a box as big as the tile */
.day__n,
.copy__n {
  display: grid;
  place-items: center;
  width: min(calc(100% - 6px), 44px);
  height: calc(var(--row) - 6px);
  border-radius: 11px;
  font-size: 15px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
}

.day__n {
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.day.is-off {
  cursor: default;
}

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

/* a day already fully booked is hatched */
.day.is-full .day__n {
  background-image: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--ink) 8%, transparent) 0 1.5px, transparent 1.5px 5.5px);
}

/* today: a thin frame */
.day.is-today .day__n {
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ink) 55%, transparent);
  color: var(--ink);
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .picker:not(.is-dragging) .day:not(.is-off):hover .day__n {
    background-color: color-mix(in srgb, var(--oak) 24%, transparent);
  }
}

.day:focus-visible .day__n {
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink);
}

/* ---------------------------------------------------------------- the tile on the chosen day */
.tile {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  pointer-events: none;
  will-change: transform;
}

.tile__shadow {
  position: absolute;
  inset: 6px 5px -3px;
  border-radius: 11px;
  background: rgba(74, 46, 18, 0.5);
  filter: blur(5px);
}

.tile__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 11px;
  background:
    linear-gradient(180deg, rgba(255, 249, 236, 0.4), rgba(255, 249, 236, 0) 55%, rgba(120, 78, 32, 0.08)),
    repeating-linear-gradient(94deg, rgba(140, 94, 44, 0.1) 0 1.1px, rgba(140, 94, 44, 0) 1.1px 4.6px, rgba(140, 94, 44, 0.06) 4.6px 5.5px, rgba(140, 94, 44, 0) 5.5px 11px),
    var(--oak);
  box-shadow: inset 0 1px 0 rgba(255, 248, 232, 0.7), inset 0 -1.5px 0 rgba(130, 86, 36, 0.28), inset 0 0 6px rgba(130, 86, 36, 0.2), 0 1px 1.5px rgba(74, 46, 18, 0.32);
}

/* under the tile the days are burnt into the wood */
.copy__n {
  font-weight: 760;
  color: var(--engrave);
  text-shadow: 0 1px 0 rgba(255, 246, 228, 0.6);
}

.copy__day.is-off .copy__n {
  color: color-mix(in srgb, var(--engrave) 42%, transparent);
}

/* ---------------------------------------------------------------- booking */
.picker__foot {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  margin-top: 14px;
}

.picker__done {
  display: none;
  flex: 1 1 0;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  margin: 0;
  font-size: 14.5px;
  font-weight: 620;
  white-space: nowrap;
}

.picker__done svg {
  flex: none;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.picker.is-done .picker__done {
  display: flex;
}

.book {
  position: relative;
  flex: 1 1 auto;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
  padding: 0 20px;
  overflow: hidden;
  border: 0;
  border-radius: 16px;
  background: var(--button);
  color: var(--button-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.16s ease-out, background-color 0.3s ease, color 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
  .book:hover {
    background: color-mix(in srgb, var(--button) 86%, #ffffff);
  }

  .picker.is-done .book:hover {
    background: color-mix(in srgb, var(--oak) 30%, #ffffff);
  }
}

.book:active {
  transform: scale(0.97);
}

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

.book__label,
.book__date {
  display: block;
}

.book__date {
  font-weight: 520;
  color: color-mix(in srgb, var(--button-ink) 64%, transparent);
  font-variant-numeric: tabular-nums;
}

.book__spin {
  position: absolute;
  right: 20px;
  top: 50%;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  opacity: 0;
}

.picker.is-busy .book {
  cursor: progress;
}

.picker.is-done .book {
  flex: 0 0 auto;
  justify-content: center;
  padding: 0 22px;
  background: color-mix(in srgb, var(--oak) 20%, #ffffff);
  color: var(--ink);
}

.picker.is-done .book__date {
  display: none;
}

.book[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* while the delivery is booked the weeks rest */
.cal {
  transition: opacity 0.35s ease;
}

.picker.is-done .cal {
  opacity: 0.42;
}

/* with less motion the buttons don't move: only their colours change */
@media (prefers-reduced-motion: reduce) {
  .arrow,
  .arrow svg,
  .book {
    transition-property: background-color, box-shadow, color, opacity;
  }

  .arrow:not([aria-disabled='true']):active,
  .book:active {
    transform: none;
  }
}
