/* Keep the requested lunar and historical calendar diagrams compact without
   changing the larger visual scale used by the other calendar systems. */
html body.page-calendars :is(
  #phaseOrderGenericLunarCalendar,
  #phaseOrderLunarYearCalendar,
  #phaseOrderThirteenCalendar
) .natural-calendar-circle {
  --natural-circle-size: 460px;
}

html body.page-calendars :is(
  #genericLunarCircularSliderShell,
  #thirteenCircularSliderShell
) {
  min-height: 510px;
}

html body.page-calendars #lunarYearCircularSliderShell {
  min-height: 540px;
  padding-block: 44px;
}

html body.page-calendars #phaseOrderTurtleShellCalendar .thirteen-turtle-calendar {
  width: min(100%, 420px);
}

html body.page-calendars #phaseOrderTurtleShellCalendar .thirteen-turtle-calendar svg {
  width: min(100%, 400px);
}

html body.page-calendars :is(
  #phaseOrderAtticCalendar,
  #phaseOrderRomanRepublicanCalendar
) .classical-calendar-wheel {
  width: min(100%, 460px);
}

/* Place the boundary dates inside the month band, immediately outside each
   wheel's inner circle, instead of beyond the outer edge of the wheel. */
html body.page-calendars #phaseOrderGenericLunarCalendar .generic-lunar-boundary-date {
  transform: translate(-50%, -50%) rotate(var(--generic-lunar-date-angle))
    translateY(calc(-1 * var(--natural-circle-size) * .28))
    rotate(calc(-1 * var(--generic-lunar-date-angle)));
}

html body.page-calendars #phaseOrderLunarYearCalendar .lunar-year-boundary-date {
  transform: translate(-50%, -50%) rotate(var(--lunar-year-date-angle))
    translateY(calc(-1 * var(--natural-circle-size) * .28))
    rotate(calc(-1 * var(--lunar-year-date-angle)));
}

html body.page-calendars #phaseOrderThirteenCalendar .thirteen-boundary-date > i {
  transform: translate(-50%, -50%) rotate(var(--thirteen-date-angle))
    translateY(calc(-1 * var(--natural-circle-size) * .255));
}

html body.page-calendars #phaseOrderThirteenCalendar .thirteen-boundary-date > b {
  transform: translate(-50%, -50%) rotate(var(--thirteen-date-angle))
    translateY(calc(-1 * var(--natural-circle-size) * .28))
    rotate(calc(-1 * var(--thirteen-date-angle)));
}

@media (max-width: 720px) {
  /* Keep browser scroll anchoring and smooth-scroll interpolation from nudging
     these fixed canvases while touch gestures move horizontally. */
  html body.page-calendars .diagram-scroll-viewport {
    scroll-behavior: auto;
    overflow-anchor: none;
  }

  html body.page-calendars :is(
    #phaseOrderGenericLunarCalendar,
    #phaseOrderLunarYearCalendar,
    #phaseOrderThirteenCalendar
  ) .natural-calendar-circle {
    --natural-circle-size: 390px;
  }

  html body.page-calendars :is(
    #genericLunarCircularSliderShell,
    #thirteenCircularSliderShell
  ) {
    min-height: 430px;
    padding-block: 20px;
  }

  html body.page-calendars #lunarYearCircularSliderShell {
    min-height: 490px;
    padding: 50px;
  }

  html body.page-calendars :is(
    #phaseOrderAtticCalendar,
    #phaseOrderRomanRepublicanCalendar
  ) .classical-calendar-wheel {
    width: min(100%, 390px);
  }
}

/* Keep the seasonal and zodiac wheels compact on phones, independent of the
   shared mobile canvas size used by the larger circular calendars. */
@media (max-width: 600px) {
  html body.page-calendars #phaseOrderSeason .diagram-scroll-viewport > .hemisphere-season-wheel {
    box-sizing: border-box;
    width: min(90vw, 360px);
    min-width: min(90vw, 360px);
    max-width: min(90vw, 360px);
    min-height: 0;
    margin-inline: auto;
    aspect-ratio: 1;
  }

  html body.page-calendars #phaseOrderSeason .hemisphere-season-wheel > svg {
    width: 100%;
    height: 100%;
  }

  html body.page-calendars #zodiacCard .diagram-scroll-viewport > .zodiac-circle-panel {
    box-sizing: border-box;
    display: grid;
    place-items: center;
    width: 420px;
    min-width: 420px;
    max-width: 420px;
    min-height: 430px;
    margin-inline: auto;
    padding: 0;
    overflow: visible;
  }

  html body.page-calendars #zodiacCard .zodiac-wheel {
    --zodiac-wheel-size: 340px;
    --zodiac-sign-radius: calc(var(--zodiac-wheel-size) * .38);
    --zodiac-date-radius: calc(var(--zodiac-wheel-size) * .25);
    --zodiac-season-radius: calc(var(--zodiac-wheel-size) * .39 + 15px);
    width: var(--zodiac-wheel-size);
    height: var(--zodiac-wheel-size);
    margin: 0;
    left: auto;
  }
}

@media (max-width: 560px) {
  html body.page-calendars #lunarYearCircularSliderShell.diagram-scroll-canvas {
    width: 490px;
    min-width: 490px;
    max-width: 490px;
    min-height: 490px;
    padding: 50px;
  }

  html body.page-calendars #phaseOrderSeason .diagram-scroll-canvas.hemisphere-season-wheel {
    width: 360px;
    min-width: 360px;
    max-width: 360px;
  }
}

/* On phones, let calendar diagrams use nearly the full available screen width.
   max() preserves any wheel that is already larger than 90vw. */
@media (max-width: 720px) {
  html body.page-calendars :is(
    .natural-calendar-circle,
    #zodiacCard .zodiac-wheel,
    #phaseOrderAtticCalendar .classical-calendar-wheel,
    #phaseOrderRomanRepublicanCalendar .classical-calendar-wheel,
    #egyptianCalendarCard .egyptian-calendar-wheel,
    #ethiopianCalendarCard .ethiopian-wheel-stage,
    #mesopotamianCalendarCard .mesopotamian-wheel-stage,
    .hemisphere-season-wheel,
    .meso-dual-ring
  ) {
    width: max(90vw, var(--natural-circle-size, var(--zodiac-wheel-size, 0px)));
    height: max(90vw, var(--natural-circle-size, var(--zodiac-wheel-size, 0px)));
    max-width: none;
  }

  html body.page-calendars :is(
    #egyptianCalendarCard .egyptian-calendar-wheel,
    .meso-dual-ring
  ) {
    min-width: max(90vw, 500px);
    height: max(90vw, 500px);
  }

  html body.page-calendars #egyptianCalendarCard .egyptian-calendar-wheel {
    width: max(90vw, 500px);
    height: max(90vw, 500px);
    max-height: none;
    flex-basis: max(90vw, 500px);
  }
}
