@media (min-width: 741px) {
  .calendar { padding-block: 27px 29px; }
  .box .cell .number { font-size: clamp(1rem, 1.75vw, 1.55rem); }
}

.box {
  --cols: 6;
  --cell-h: clamp(51px, 7.7svh, 86px);
  --lid-space: clamp(10px, 2.4svh, 24px);
  --box-depth: clamp(29px, 5.5svh, 51px);
  --box-angle: 26deg;
  --side-width: calc(var(--box-depth) * tan(var(--box-angle)));
  --rim: var(--bronze);
  --rim-light: color-mix(in srgb, var(--bronze) 62%, var(--linen));
  --rim-dark: color-mix(in srgb, var(--bronze) 56%, var(--midnight));
  --case-dark: #351d1d;
  --well: var(--midnight);
  --lid: color-mix(in srgb, var(--bronze) 75%, var(--linen));
  --print: #392019;
  --velvet: var(--burgundy);
  --velvet-light: #903b4a;
  --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.81' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath d='M0 0h120v120H0z' filter='url(%23p)' opacity='.27'/%3E%3C/svg%3E");
  position: relative;
  width: calc(100% - 38px);
  max-width: 1260px;
  margin: 0 auto;
  padding: var(--lid-space) 0 calc(var(--box-depth) + 1px);
  perspective: none;
}

.box-object {
  position: relative;
  transform: rotate(-1deg) skewX(1deg);
}

.box-object::before {
  content: "";
  position: absolute;
  inset: 9% 4% calc(-1 * var(--box-depth) + 9px);
  background: #2a130d;
  border-radius: 14px;
  transform: translate(5px, 12px);
  filter: blur(25px);
  opacity: .38;
  pointer-events: none;
}

.box-tray {
  position: relative;
  padding: clamp(10px, 1.4vw, 17px);
  background: var(--paper-grain), linear-gradient(152deg, var(--rim-light), var(--rim) 42%, var(--rim-dark));
  border-radius: 7px 7px 3px 3px;
  box-shadow: inset 0 2px 1px #ffe2bb85, inset -2px -1px 2px #49232060;
}

.box-side {
  position: absolute;
  top: 0;
  bottom: calc(-1 * var(--box-depth));
  left: calc(100% - 1px);
  width: calc(var(--side-width) + 1px);
  clip-path: polygon(0 0, 100% var(--box-depth), 100% 100%, 0 calc(100% - var(--box-depth)));
  background:
    linear-gradient(90deg, #ffdca74a, transparent 25%, #23110e60),
    var(--paper-grain),
    linear-gradient(170deg, var(--rim-dark), var(--case-dark));
  pointer-events: none;
}

.box .cells {
  gap: clamp(4px, .65vw, 10px);
  padding: clamp(4px, .65vw, 10px);
  border-radius: 3px;
  background: var(--well);
  box-shadow: inset 0 3px 8px #1a090684, 0 1px 0 #ffe7be63;
}

.box-front {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: var(--box-depth);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #f2c894;
  border-radius: 0 0 0 5px;
  background: var(--paper-grain), linear-gradient(175deg, var(--rim) 8%, var(--rim-dark) 95%);
  box-shadow: inset 0 1px 0 #f5c79767, inset 0 -3px 5px #32110e40;
  transform-origin: top;
  transform: skewX(var(--box-angle));
  pointer-events: none;
}

.box-front::before {
  content: "";
  position: absolute;
  inset: 5px 8px;
  border: 1px solid currentColor;
  opacity: .38;
  border-radius: 2px;
}

.box-front svg { width: 26px; height: 26px; stroke-width: 1; }
.box-front svg:nth-child(2) { width: 11px; height: 11px; }
.box-front svg:last-child { transform: scaleX(-1); }
.box-lid {
  position: absolute;
  z-index: 6;
  inset: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  border-radius: 8px 8px 4px 4px;
  background: var(--paper-grain), linear-gradient(135deg, var(--rim-light), var(--lid) 66%, var(--rim));
  box-shadow: inset 0 2px 1px #fff1c67a, 0 7px 0 var(--rim-dark), 0 11px 0 var(--case-dark), 0 17px 23px #2d100d54;
}

.lid-paper {
  position: absolute;
  inset: clamp(8px, 1.3vw, 18px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 2vw, 26px);
  border: 1px solid var(--print);
  outline: 1px solid color-mix(in srgb, var(--print) 38%, transparent);
  outline-offset: -5px;
  border-radius: 4px;
  color: var(--print);
}

.lid-paper svg {
  width: clamp(20px, 6vw, 96px);
  height: auto;
  stroke-width: .85;
}

.lid-paper svg:last-child { transform: scaleX(-1); }
.lid-paper svg:nth-child(2) { width: clamp(19px, 4.6vw, 66px); }
.lid-band {
  position: absolute;
  inset: 0 auto 0 12%;
  width: clamp(7px, 2.1vw, 31px);
  background: var(--paper-grain), linear-gradient(90deg, var(--velvet), var(--velvet-light) 47%, var(--velvet));
  box-shadow: 2px 0 6px #2a111948;
}

.box .cell {
  --tile: var(--linen);
  --tile-ink: #522821;
  border-radius: 3px;
  background: #32211a;
  box-shadow: 1px 3px 2px #100807b0;
}

.box .cell:nth-of-type(8n + 2) { --tile: var(--burgundy); --tile-ink: #fff4de; }
.box .cell:nth-of-type(8n + 3) { --tile: var(--olive); --tile-ink: #ffe5af; }
.box .cell:nth-of-type(8n + 4) { --tile: var(--midnight); --tile-ink: #fff4d9; }
.box .cell:nth-of-type(8n + 5) { --tile: color-mix(in srgb, var(--linen) 82%, var(--bronze)); }
.box .cell:nth-of-type(8n + 6) { --tile: color-mix(in srgb, var(--bronze) 84%, var(--midnight)); --tile-ink: #fffaf0; }
.box .cell:nth-of-type(8n + 8) { --tile: #af7b72; --tile-ink: #321b1f; }

.box .cell-face {
  --pattern: linear-gradient(140deg, #fff4 0%, transparent 48%, #2c170f30 100%);
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 0;
  color: var(--tile-ink);
  border: 1px solid #351d1660;
  border-bottom-color: #351d16a0;
  background-image: var(--paper-grain), var(--pattern);
  box-shadow: inset 0 1px 0 #fff1cb7a, inset 0 -3px 0 #28110d32, inset -2px 0 0 #2c101926;
  transform-origin: center center;
  transition: transform calc(.55s * var(--motion-factor)) cubic-bezier(.2,.75,.22,1), opacity calc(.4s * var(--motion-factor));
}

.box .cell-face::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 50%;
  width: clamp(9px, 1.2vw, 18px);
  height: clamp(4px, .58vw, 8px);
  border-radius: 0 0 100px 100px;
  background: #33221c;
  box-shadow: inset 0 2px 2px #100b08, 0 1px 0 #ffedce7b;
  transform: translateX(-50%);
}

.box .cell:is(:nth-of-type(7n + 4), :nth-of-type(13n)) {
  --tile: var(--linen);
  --tile-ink: var(--burgundy);
}

.box .cell-striped .cell-face {
  --pattern: repeating-linear-gradient(136deg, transparent 0 10px, #a1515259 10px 15px);
}

.box .cell-striped:nth-of-type(13n) .cell-face {
  --pattern: repeating-linear-gradient(136deg, transparent 0 10px, color-mix(in srgb, var(--olive) 32%, transparent) 10px 15px);
}

.box .cell .number {
  position: absolute;
  top: 7px;
  left: 8px;
  font-size: clamp(1rem, 1.8vw, 1.65rem);
}

.box .cell .motif {
  width: clamp(19px, 3.2vw, 36px);
  height: clamp(19px, 3.2vw, 36px);
  margin-top: 5px;
  stroke-width: 1.1;
  opacity: .85;
}

.box .cell .state { top: 7px; right: 7px; width: 12px; height: 12px; }
.box .cell.is-today { outline-color: #f7be75; }
.box .cell.is-future .state { opacity: 1; }
.box .cell-striped .state { display: none; }
.box .cell.is-opening .cell-face { transform: translate3d(4px, -29%, 82px) rotate(-8deg) scale(1.07); opacity: 0; }

.box .cell-finale {
  grid-column: 1 / -1;
  --tile: var(--burgundy);
  --tile-ink: #f9dca9;
}

.box .cell-finale .cell-face {
  --pattern: radial-gradient(ellipse at 50% 22%, #fff1c51a, transparent 70%),
    linear-gradient(160deg, #fff1c515, #250c1640);
}

.box .cell-finale .cell-face::before { content: none; }

.finale-engraving {
  position: absolute;
  inset: 3px 0;
  width: min(91%, 480px);
  height: calc(100% - 6px);
  margin-inline: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 0 #2b0b17b0);
  pointer-events: none;
}

.box .cell-finale .number {
  position: relative;
  inset: auto;
  font-size: clamp(1.5rem, 3vw, 2.45rem);
  text-shadow: 0 1px 0 #2b0b17;
}

.box.unfold .box-lid {
  animation: unseal calc(1.43s * var(--motion-factor)) cubic-bezier(.44,.1,.24,1) both;
}

@keyframes unseal {
  0%, 12% { visibility: visible; opacity: 1; transform: translateX(0); }
  23% { transform: translateX(4%); }
  78% { opacity: 1; }
  99% { visibility: visible; }
  100% { visibility: hidden; opacity: 0; transform: translateX(109%); }
}

@media (min-width: 741px) and (max-height: 800px) {
  .calendar { padding-block: 18px 15px; }
  .calendar h2 { font-size: clamp(2.4rem, 4vw, 3.55rem); }
  .calendar-head { margin-bottom: 12px; }
  .calendar-caption { margin-top: 8px; }
  .box {
    --lid-space: 15px;
    --box-depth: clamp(26px, 4.5svh, 36px);
    --cell-h: clamp(44px, 7.4svh, 60px);
  }
  .box-tray { padding: clamp(10px, 1.05vw, 14px); }
}

@media (max-width: 740px) {
  .box {
    --cell-h: clamp(43px, 6.4svh, 56px);
    --lid-space: 8px;
    --box-depth: 28px;
    width: calc(100% - 18px);
  }
  .box-object { transform: rotate(-.6deg); }
  .box-tray { padding: 7px; }
  .box .cells { gap: 3px; padding: 3px; }
  .box .cell .number { top: 5px; left: 4px; font-size: .92rem; }
  .box .cell .motif { align-self: end; margin: 0 0 5px; width: 16px; height: 16px; }
  .box .cell-finale { min-height: 56px; }
  .box .cell-finale .number { font-size: 1.52rem; }
  .box .cell .state { top: 6px; right: 3px; width: 8px; height: 8px; }
  .box-front svg { width: 18px; height: 18px; }
  .lid-paper { inset: 7px; outline-offset: -3px; }
}

@media (prefers-reduced-motion: reduce) {
  .box.unfold .box-lid { animation: none; }
}
