/* ===================
   Layout Containers
   =================== */
body {
  display: flex;
  min-width: 320px;
  min-height: 100vh;
}

#root {
  width: 100%;
  margin: 0;
  padding: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
}

/* ===================
   Year View — Main Structure
   =================== */

.year-view {
  width: 100%;
  height: 100%; /* Inherit full height from #root */
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1em;
  box-sizing: border-box;
  /* Base font size for calendar, using rem to reference root */
  font-size: 1rem;
}

.year-view h1,
.year-view h2,
.year-view h3 {
  line-height: inherit;
  font-weight: normal;
  line-height: 1em;
}

.view-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.view-header h1 {
  /* Scale relative to calendar container */
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-thin);
  text-align: center;
  padding-bottom: .8em;
}

/* Year navigation — invisible click targets */
.year-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20%;
  text-decoration: none;
  color: transparent;
  font-size: 0;
}

.year-nav.prev { left: 0; }
.year-nav.next { right: 0; }

/* Year title link */
.view-header h1 a {
  color: inherit;
  text-decoration: none;
}

/* Month link — entire month is click target */
.month-link {
  color: inherit;
  text-decoration: none;
  display: contents;
}

.month-link:hover .month-header h2 {
  color: var(--color-accent);
}

.year-grid {
  width: 100%;
  flex: 1; /* Allow grid to grow but not take full height */
  display: grid;
  gap: 3em;
  justify-content: center;
  grid-template-columns: repeat(1, minmax(200px, 1fr));
  grid-auto-rows: 1fr; /* Make all grid rows equal height */
  max-width: 1600px;
  box-sizing: border-box;
}

/* ===================
   Month Components
   =================== */
.month {
  /* Set as a new scaling context */
  font-size: 1em;
  display: grid;
  grid-template-rows: auto auto 1fr; /* Header, weekdays, month grid */
  width: 100%;
  height: 100%;
  gap: 0.5em;
}

.month-header {
  text-align: center;
}

.month-header h2 {
  /* Scale relative to month container */
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-light);
  color: var(--color-text);
  padding-bottom: .2em;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--color-text);
}
.weekdays .weekday {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.month-grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  height: 100%;
  min-height: 0; /* Allow shrinking */
}

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

/* ===================
   Day Components & Markers
   =================== */

.day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  font-size: clamp(var(--font-size-sm), 4vmin, 1em);
}

.month .day.other-month {
  color: var(--color-bg);
}

/* Day markers - base styles */
.day-marker {
  position: absolute;
  width: 1em;
  height: 1em;
  transform-origin: center;
}

/* Moon marker (SVG) */
.day-marker-moon {
  width: 1.3em;
  height: 1.3em;
  overflow: visible;
  flex-shrink: 0;
}

/* Solstice and equinox marker */
.day-marker-solstice,
.day-marker-equinox {
  width: 1em;
  height: 1em;
  top: 50%;
  left: 50%;
  transform: rotate(45deg);
  background: black;
}

/* ===================
   Print Styles
   =================== */
.print-container {
  width: 100%;
  height: 100%;
  position: relative;
  box-sizing: border-box;
  background: white;
  /* Set base font size for print container using rem */
  font-size: 1rem;
}

.year-view.print {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: inherit;
}

.year-view.print .year-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--print-columns, 3), minmax(0, 1fr));
  grid-template-rows: repeat(auto-fit, minmax(0, 1fr));
  gap: 1em;
  box-sizing: border-box;
}

.year-view.print .month {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.year-view.print .month-header {
  padding: 0;
}

.year-view.print .month-grid {
  flex: 1;
  display: grid;
  grid-template-rows: repeat(6, 1fr); /* Explicitly set 6 equal rows */
  height: 100%; /* Take full height */
}

.year-view.print .weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 0.8em;
}

.year-view.print .day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  box-sizing: border-box;
}

.year-view.print .day-marker {
  position: absolute;
}

.year-view.print .day-marker-moon {
  width: 1em;
  height: 1em;
}

.year-view.print .day-marker-solstice,
.year-view.print .day-marker-equinox {
  width: 0.9em;
  height: 0.9em;
  top: 50%;
  left: 50%;
  transform: rotate(45deg);
}

/* ===================
   Size-specific Styles
   =================== */

/* Paper dimensions and orientations */
#root.size-a6 {
  width: 105mm;
  height: 148mm;
}

#root.size-a6.orientation-landscape {
  width: 148mm;
  height: 105mm;
}

#root.size-a5 {
  width: 148mm;
  height: 210mm;
}

#root.size-a5.orientation-landscape {
  width: 210mm;
  height: 148mm;
}

#root.size-a4 {
  width: 210mm;
  height: 297mm;
}

#root.size-a4.orientation-landscape {
  width: 297mm;
  height: 210mm;
}

#root.size-letter, #root.size-letter.orientation-portrait {
  width: 215.9mm;
  height: 279.4mm;
}

#root.size-letter.orientation-landscape {
  width: 279.4mm;
  height: 215.9mm;
}
#root.size-legal.orientation-landscape {
  width: 355.6mm;
  height: 215.9mm;
}
#root.size-legal, #root.size-legal.orientation-portrait {
  width: 215.9mm;
  height: 355.6mm;
}

#root.size-tabloid, #root.size-tabloid.orientation-portrait {
  width: 279.4mm;
  height: 431.8mm;
}

#root.size-tabloid.orientation-landscape {
  width: 431.8mm;
  height: 279.4mm;
}

#root.size-half-letter, #root.size-half-letter.orientation-portrait {
  width: 139.7mm;
  height: 215.9mm;
}

#root.size-half-letter.orientation-landscape {
  width: 215.9mm;
  height: 139.7mm;
}

#root.size-5x7, #root.size-5x7.orientation-portrait {
  width: 127mm;
  height: 177.8mm;
}
#root.size-5x7.orientation-landscape {
  width: 177.8mm;
  height: 127mm;
}

#root.size-4x6, #root.size-4x6.orientation-portrait {
  width: 101.6mm;
  height: 152.4mm;
}
#root.size-4x6.orientation-landscape {
  width: 152.4mm;
  height: 101.6mm;
}

/* A6 styles */
.size-a6 .year-view.print {
  font-size: 0.5rem;
  padding: 1.5em;
}

.size-a6 .year-view.print .year-grid {
  gap: 1em 2em;
}

.size-a6 .year-view.print .view-header {
  margin-bottom: 1em;
}

.size-a6 .year-view.print .view-header h1 {
  font-size: 2.5em;
}

/* A5 styles */
.size-a5 .year-view.print {
  font-size: 0.6rem;
  padding: 3em;
}

.size-a5 .year-view.print .year-grid {
  gap: 1.5em 3em;
}

.size-a5.orientation-landscape .year-view.print .year-grid {
  gap: 2em 2.6em;
}

/* A4/Letter styles */
.size-a4 .year-view.print,
.size-letter .year-view.print {
  font-size: 0.8rem;
  padding: 4em;
}

.size-a4 .year-view.print .year-grid,
.size-letter .year-view.print .year-grid {
  gap: 2em 4em;
}

.size-a4.orientation-landscape .year-view.print .year-grid,
.size-letter.orientation-landscape .year-view.print .year-grid {
  gap: 3em 3.5em;
}

/* Additional print-specific styles */
.year-view.print .view-header h1 {
  padding-bottom: 1em;
}

.year-view.print .month-header {
  padding: 0;
}

/* legal ========= */

.size-legal .print {
  font-size: .8rem;
  padding: 4em;
}
.size-legal.orientation-landscape .print .view-header h1 {
  padding-bottom: .8em;
}
.size-legal.orientation-portrait .print .view-header h1 {
  font-size: 4em;
  font-weight: var(--font-weight-thin);
  padding-bottom: 1em;
}
.size-legal .print .year-grid {
  gap: 3em 4em;
}
.size-legal .print .month:not(.mini) .month-header h2 {
  padding-bottom: .5em;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-light);
}

/* tabloid ========= */

.size-tabloid .print {
  font-size: 1rem;
  padding: 6em;
}
.size-tabloid.orientation-landscape .print .view-header h1 {
  padding-bottom: .8em;
}
.size-tabloid.orientation-portrait .print .view-header h1 {
  font-size: 4em;
  font-weight: var(--font-weight-thin);
}
.size-tabloid .print .year-grid {
  gap: 3em 4em;
}
.size-tabloid .print .month:not(.mini) .month-header h2 {
  padding-bottom: .5em;
}

/* half-letter ========= */

.size-half-letter .print {
  font-size: 0.55rem;
  padding: 2em;
}
.size-half-letter .print .year-grid {
  gap: 1em 2em;
}
.size-half-letter .print .view-header {
  margin-bottom: 1em;
}
.size-half-letter .print .view-header h1 {
  font-size: 2.5em;
}


/* ===================
   Responsive Styles (Non-print only)
   =================== */

@media screen and (min-width: 600px) {
  .year-view:not(.print) {
    padding: 1.5em;
  }

  .year-view:not(.print) .year-grid {
    gap: 2rem;
    grid-template-columns: repeat(2, minmax(200px, 1fr));
  }
}

@media screen and (min-width: 900px) {
  .year-view:not(.print) .year-grid {
    gap: 2.5em;
    grid-template-columns: repeat(3, minmax(200px, 1fr));
  }
}

@media screen and (min-width: 1200px) {
  .year-view:not(.print) {
    padding: 2em;
  }

  .year-view:not(.print) .year-grid {
    gap: 2em;
    grid-template-columns: repeat(4, minmax(200px, 1fr));
  }
}

/* ===================
   Today Highlight (screen only)
   =================== */

.year-view:not(.print) .day.today .date,
.month-view:not(.print) .day.today .day-number {
  font-weight: bold;
  color: var(--color-accent);
}

.date-leading-zero {
  visibility: hidden;
}

/* ===================
   Month View
   =================== */

.month-view {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1em;
  box-sizing: border-box;
  font-size: 1rem;
}

/* h1 reset handled by .view-title */

.month-view .view-header {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 5fr 1fr;
  align-items: center;
  padding: 0 0 0.5em 0;
}

/* Month navigation — invisible click targets (hidden on desktop, visible on mobile when mini calendars are hidden) */
.month-nav {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  text-decoration: none;
  color: transparent;
  font-size: 0;
  z-index: 1;
}

.month-nav.prev { left: 0; }
.month-nav.next { right: 0; }

/* Align mini calendars with the first and last day columns */
.view-nav .month.mini {
  width: 100%;
}

.view-title {
  text-align: center;
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-thin);
  margin: 0;
  padding: 0 0 0.5em 0;
  line-height: 1;
}

.view-title a {
  color: inherit;
  text-decoration: none;
}

.view-nav {
  display: flex;
  align-items: flex-start;
}

.view-nav:last-child {
  justify-content: flex-end;
}

/* Mini calendars: clickable links to prev/next month */
.month.mini {
  text-decoration: none;
  color: inherit;
  display: block;
}

/* Mini calendar — explicit sizes, no container-level scaling */
.month.mini .month-header h2 {
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  line-height: 1;
  padding-bottom: 0.4em;
}

.month.mini .weekdays .weekday {
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  line-height: 1.7;
}

.month.mini .day {
  padding: 0;
  font-size: var(--font-size-sm);
  line-height: 1.7;
}

.month.mini .day-marker-moon {
  width: 0.8em;
  height: 0.8em;
}

.month.mini .day-marker-solstice,
.month.mini .day-marker-equinox {
  width: 0.5em;
  height: 0.5em;
}

/* Main month grid */
.month-expanded {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.month-expanded > .weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 1em;
}

.month-expanded > .weekdays .weekday {
  padding: 0.4em 0.5em;
  text-align: left;
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text);
  min-width: 0;
  overflow: hidden;
}

.dayname-short {
  display: none;
}

.dayname-full {
  display: inline;
}

.month-days {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

/* Borders: top + right on day cells; weekday bottom + right as header separator */
.month-view.borders .month-expanded > .weekdays .weekday {
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

.month-view.borders .month-expanded > .weekdays .weekday:last-child {
  border-right: none;
}

.month-view.borders .month-days .day {
  border-top: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

/* First row of days: no top border (weekday bottom is the separator) */
.month-view.borders .month-days .day:nth-child(-n+7) {
  border-top: none;
}

/* Last column: no right border */
.month-view.borders .month-days .day:nth-child(7n) {
  border-right: none;
}

/* Rows with current-month days: dark top borders */
.month-view.borders .month-days .day.current-row {
  border-top-color: var(--color-border);
}

/* Rows that are all other-month: light top borders */
.month-view.borders .month-days .day:not(.current-row) {
  border-top-color: var(--color-border-light);
}

/* Right borders: current-month = dark, other-month = light */
.month-view.borders .month-days .day.other-month {
  border-right-color: var(--color-border-light);
}

/* Dark border between other-month and current-month cells */
.month-view.borders .month-days .day.other-month:has(+ .day:not(.other-month)) {
  border-right-color: var(--color-border);
}

/* Day cells in month-view expanded grid */
.month-days .day {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0.3em 0.4em;
  min-height: 4em;
  min-width: 0;
  box-sizing: border-box;
  font-size: 1em;
  overflow: visible;
}

.month-days .day.other-month {
  color: var(--color-muted);
}

.month-days .day.other-month .day-marker-moon {
  opacity: 0.25;
}

.month-days .day.other-month .day-marker-solstice,
.month-days .day.other-month .day-marker-equinox {
  opacity: 0.25;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.2em;
}

.day-number {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-book);
}

/* Multiple markers side by side */
.day-markers {
  display: inline-flex;
  gap: 0.4em;
  align-items: center;
}

/* Moon/solar icons in month view — right-aligned */
.day-header .day-marker-moon {
  width: 1em;
  height: 1em;
}

.day-header .day-marker-solstice,
.day-header .day-marker-equinox {
  width: 0.7em;
  height: 0.7em;
  transform: rotate(45deg);
  background: black;
}

/* Events — left aligned, wrapping with hanging indent */
.day-events {
  list-style: none;
  margin: 0;
  padding: 0;
}

.event {
  font-size: var(--font-size-sm);
  line-height: 1.3;
  color: var(--color-text);
  text-align: left;
  margin-bottom: 0.3em;
  text-wrap: balance;
  overflow-wrap: break-word;
  padding-left: 1.15em;
  text-indent: -1.15em;
  overflow: visible;
}

.event-icon {
  width: 0.9em;
  height: 0.9em;
  display: inline-block;
  vertical-align: baseline;
  position: relative;
  top: 0.1em;
  margin-right: 0.25em;
}

/* Month view print */
.month-view.print .month-expanded {
  min-height: 0;
}

.month-view.print .month-days {
  min-height: 0;
}

.month-view.print .month-days .day {
  min-height: 0;
}

.month-view.print .day.today .day-number {
  font-weight: var(--font-weight-book);
  color: inherit;
}

/* Month view responsive */
@media screen and (max-width: 600px) {
  .month-view:not(.print) .month.mini {
    display: none;
  }

  .month-view:not(.print) .view-title {
    font-size: 2em;
  }

  .month-view:not(.print) {
    padding: 0.5em;
  }

  .month-view:not(.print) .month-expanded > .weekdays {
    grid-template-columns: repeat(7, 1fr);
  }

  .month-view:not(.print) .dayname-full {
    display: none;
  }

  .month-view:not(.print) .dayname-short {
    display: inline;
  }

  .month-view:not(.print) .month-expanded > .weekdays .weekday {
    font-size: 0.75em;
    padding: 0.3em 0.2em;
    letter-spacing: 0;
  }

  .month-view:not(.print) .month-days {
    grid-template-columns: repeat(7, 1fr);
  }

  .month-days .day {
    min-height: 3em;
    padding: 0.2em;
  }

  .month-view:not(.print) .month-nav {
    display: block;
  }

  .month-view:not(.print) .event {
    font-size: 0;
    line-height: 0;
    margin-bottom: 0.15em;
    gap: 0;
  }

  .month-view:not(.print) .event::before {
    content: "";
    display: inline-block;
    width: 0.35em;
    height: 0.35em;
    border-radius: 50%;
    background: var(--color-muted);
    flex-shrink: 0;
  }

  .month-view:not(.print) .event .event-icon {
    display: none;
  }
}

@media screen and (min-width: 900px) {
  .month-view:not(.print) {
    padding: 1.5em 2em;
  }

  .month-days .day {
    min-height: 5em;
  }
}

/* ===================
   Config View
   =================== */

body:has(.config) {
  background: var(--color-config-bg);
}

.config {
  display: flex;
  width: 100%;
  height: 100vh;
  background: var(--color-config-bg);
  color: var(--color-config-text);
}

.config-sidebar {
  width: var(--config-sidebar-width);
  padding: 1em;
  overflow-y: auto;
  flex-shrink: 0;
}

.config-nav {
  margin-bottom: 1.5em;
}

.config-section {
  margin-bottom: 1em;
}

.config-year {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  margin-bottom: 0.3em;
}

.config-year a {
  color: inherit;
  text-decoration: none;
}

.config-months {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em;
}

.config-month {
  font-size: var(--font-size-sm);
  color: inherit;
  text-decoration: none;
  padding: 0.15em 0.4em;
  border-radius: 0.8em;
}

.config-month:hover {
  background: var(--color-config-active);
}

.config-month.active {
  background: var(--color-config-active);
  font-weight: var(--font-weight-medium);
}

.config-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  margin-bottom: 0.3em;
}

.config-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em;
}

.config-option {
  border: none;
  border-radius: 1em;
  padding: 0.3em 0.8em;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  color: inherit;
  text-align: left;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
}

/* Format and orientation SVG icons */
.format-icon,
.orientation-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

.config-option.active .format-icon,
.config-option.active .orientation-icon {
  opacity: 1;
}

/* Format and feeds options: one per line */
.config-options-format,
.config-options-feeds {
  flex-direction: column;
}

.config-option:hover {
  background: var(--color-config-active);
}

.config-option.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.config-option.active {
  background: var(--color-config-active);
}

.config-button {
  display: block;
  width: 100%;
  border: none;
  border-radius: 0.5em;
  padding: 0.5em 0.8em;
  background: var(--color-config-active);
  cursor: pointer;
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  color: inherit;
  margin-bottom: 0.3em;
  text-align: center;
}

.config-button:hover {
  opacity: 0.8;
}

.config-export {
  margin-top: 1.5em;
}

.config-export .config-button:first-of-type {
  margin-top: 0.8em;
}

.config-content {
  flex: 1;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.config-status {
  font-size: var(--font-size-sm);
  color: var(--color-config-muted);
  margin: 0;
  padding: 0.8em 1em;
  align-self: flex-start;
  flex-shrink: 0;
}

/* Calendar preview inside config — sandboxed color scheme */
.config-content #root,
.config-content .page {
  background: var(--color-bg);
  color: var(--color-text);
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--color-shadow);
}

/* ===================
   Scrollable Config Preview
   =================== */

.config-scroll {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.scroll-month {
  flex-shrink: 0;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  padding: 1.5em 0;
}

.scroll-month:first-child {
  padding-top: 0.5em;
}

/* Bottom spacer — padding-bottom is unreliable in scroll containers */
.scroll-month:last-child {
  padding-bottom: 3em;
}

/* .page mirrors #root sizing for config scroll view (avoids duplicate IDs) */
.page {
  margin: 0;
  padding: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  transform-origin: top left;
}

/* Paper size dimensions for .page (mirrors #root.size-* selectors) */
.page.size-a6 { width: 105mm; height: 148mm; }
.page.size-a6.orientation-landscape { width: 148mm; height: 105mm; }
.page.size-a5 { width: 148mm; height: 210mm; }
.page.size-a5.orientation-landscape { width: 210mm; height: 148mm; }
.page.size-a4 { width: 210mm; height: 297mm; }
.page.size-a4.orientation-landscape { width: 297mm; height: 210mm; }
.page.size-letter, .page.size-letter.orientation-portrait { width: 215.9mm; height: 279.4mm; }
.page.size-letter.orientation-landscape { width: 279.4mm; height: 215.9mm; }
.page.size-legal, .page.size-legal.orientation-portrait { width: 215.9mm; height: 355.6mm; }
.page.size-legal.orientation-landscape { width: 355.6mm; height: 215.9mm; }
.page.size-tabloid, .page.size-tabloid.orientation-portrait { width: 279.4mm; height: 431.8mm; }
.page.size-tabloid.orientation-landscape { width: 431.8mm; height: 279.4mm; }
.page.size-half-letter, .page.size-half-letter.orientation-portrait { width: 139.7mm; height: 215.9mm; }
.page.size-half-letter.orientation-landscape { width: 215.9mm; height: 139.7mm; }
.page.size-5x7, .page.size-5x7.orientation-portrait { width: 127mm; height: 177.8mm; }
.page.size-5x7.orientation-landscape { width: 177.8mm; height: 127mm; }
.page.size-4x6, .page.size-4x6.orientation-portrait { width: 101.6mm; height: 152.4mm; }
.page.size-4x6.orientation-landscape { width: 152.4mm; height: 101.6mm; }

/* Print font sizes for .page (mirrors .size-* .print selectors) */
.size-a6 .month-view.print,
.page.size-a6 .month-view.print { font-size: 0.5rem; }
.size-a5 .month-view.print,
.page.size-a5 .month-view.print { font-size: 0.6rem; }
.size-a4 .month-view.print,
.size-letter .month-view.print,
.page.size-a4 .month-view.print,
.page.size-letter .month-view.print { font-size: 0.8rem; }
.size-legal .month-view.print,
.page.size-legal .month-view.print { font-size: 0.8rem; }
.size-tabloid .month-view.print,
.page.size-tabloid .month-view.print { font-size: 1rem; }
.size-half-letter .month-view.print,
.page.size-half-letter .month-view.print { font-size: 0.55rem; }
.size-5x7 .month-view.print,
.page.size-5x7 .month-view.print { font-size: 0.55rem; }
.size-4x6 .month-view.print,
.page.size-4x6 .month-view.print { font-size: 0.5rem; }

/* ===================
   Spread Layout (Photo + Calendar)
   =================== */

/* Wrapper around spread-image + page — single shadow for the pair */
.spread-pair {
  box-shadow: 0 2px 8px var(--color-shadow);
  overflow: hidden;
}

.spread-gutter {
  background: var(--color-bg);
  width: 100%;
}

.spread-pair > .page,
.spread-pair > .page.month-facing {
  box-shadow: none;
  /* White outline covers the anti-aliased edge from transform: scale() */
  outline: 2px solid var(--color-bg);
  outline-offset: -1px;
}

.spread-image {
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-bg) 90%, var(--color-config-bg) 10%);
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: top left;
}

.spread-image:not(.empty) {
  background: var(--color-bg);
}

.spread-image.empty {
  cursor: pointer;
}

.spread-image img {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.spread-image.scaling-fit img {
  object-fit: contain;
  width: 100%;
  height: 100%;
}

.spread-image.scaling-crop img {
  object-fit: cover;
  width: 100%;
  height: 100%;
}

/* Month + Month facing page */
.month-facing {
  background: var(--color-bg);
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: top left;
}

.month-facing .page-facing {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  text-align: center;
}

.month-facing.empty {
  background: color-mix(in srgb, var(--color-bg) 90%, var(--color-config-bg) 10%);
}

.spread-add-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  color: var(--color-muted);
  padding: 1em;
}

.spread-add-btn:hover {
  color: var(--color-text);
}

/* Per-image fit/crop toggle — overlaid icon, not printed */
.spread-image {
  position: relative;
}

.spread-scaling-toggle {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 48px;
  height: 48px;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: var(--color-overlay);
  color: white;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}

.spread-scaling-toggle svg {
  display: block;
  width: 100%;
  height: 100%;
}

.spread-image:hover .spread-scaling-toggle {
  opacity: 1;
}

.spread-scaling-toggle:hover {
  background: var(--color-overlay-hover);
}

/* ===================
   Thinner borders for small print sizes
   =================== */

.page.size-a6 .month-view.borders .month-expanded > .weekdays .weekday,
.page.size-a6 .month-view.borders .month-days .day,
.page.size-a5 .month-view.borders .month-expanded > .weekdays .weekday,
.page.size-a5 .month-view.borders .month-days .day,
.page.size-half-letter .month-view.borders .month-expanded > .weekdays .weekday,
.page.size-half-letter .month-view.borders .month-days .day,
.page.size-5x7 .month-view.borders .month-expanded > .weekdays .weekday,
.page.size-5x7 .month-view.borders .month-days .day,
.page.size-4x6 .month-view.borders .month-expanded > .weekdays .weekday,
.page.size-4x6 .month-view.borders .month-days .day,
#root.size-a6 .month-view.borders .month-expanded > .weekdays .weekday,
#root.size-a6 .month-view.borders .month-days .day,
#root.size-a5 .month-view.borders .month-expanded > .weekdays .weekday,
#root.size-a5 .month-view.borders .month-days .day,
#root.size-half-letter .month-view.borders .month-expanded > .weekdays .weekday,
#root.size-half-letter .month-view.borders .month-days .day,
#root.size-5x7 .month-view.borders .month-expanded > .weekdays .weekday,
#root.size-5x7 .month-view.borders .month-days .day,
#root.size-4x6 .month-view.borders .month-expanded > .weekdays .weekday,
#root.size-4x6 .month-view.borders .month-days .day {
  border-width: 0.5px;
}

/* ===================
   Print media — white background, hide config UI
   =================== */

@media print {
  body:has(.config) {
    background: white;
  }

  .config-sidebar {
    display: none;
  }

  .config {
    background: white;
  }

  .config-content {
    overflow: visible;
  }

  .config-content .page {
    box-shadow: none;
  }

  .spread-pair {
    box-shadow: none;
  }

  .spread-scaling-toggle {
    display: none;
  }
}

/* ===================
   Mini calendar width for small sizes
   =================== */

/* Narrow content: wider mini cal columns when content area < 480px */
.page.narrow-content .month-view .view-header {
  grid-template-columns: 1.5fr 4fr 1.5fr;
}

.page.narrow-content .view-nav .month.mini {
  min-width: 0;
  letter-spacing: -0.02em;
}

/* ===================
   Testing Styles
   =================== */

.testing {
  border-width: .1em;
  border-style: dashed;
  border-color: #999;
}
