:root {
  --page-scale: 1;
  --bg: #fbf3e4;
  --surface: #fffaf3;
  --ink: #2a2118;
  --muted: #6d6256;
  --line: #eadfce;
  --accent: #e07a2f;
  --accent-hover: #c45e18;
  --on-accent: #fffaf3;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171716;
    --surface: #222220;
    --ink: #f2f0ec;
    --muted: #ada8a0;
    --line: #353430;
    --accent: #f0a35e;
    --accent-hover: #f6c08a;
    --on-accent: #171716;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ececec;
  color: #000;
  font-family: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
}

.controls {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px 22px;
  padding: 12px 20px;
  background: var(--bg);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
  font-weight: 400;
}

.range-fields,
.option-fields {
  display: flex;
  align-items: center;
  gap: 14px 22px;
}

.range-fields {
  flex-wrap: nowrap;
  grid-column: 1;
  grid-row: 1;
}

.option-fields {
  flex-wrap: wrap;
  grid-column: 2;
  grid-row: 1;
}

.option-fields > .field {
  flex: none;
}

.holidays span {
  white-space: nowrap;
}

#download {
  grid-column: 3;
  grid-row: 1;
}

@media (max-width: 1120px) {
  .controls {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #download {
    grid-column: 2;
  }

  .option-fields {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

.segment {
  display: flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.segment-option {
  padding: 0.32rem 0.75rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segment-option[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.holidays {
  cursor: pointer;
  user-select: none;
}

.holidays input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

.field-label {
  color: var(--muted);
  font-size: 0.95rem;
}

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

select,
button {
  font: inherit;
  font-size: 0.95rem;
}

select,
.month-trigger {
  padding: 0.45rem 0.7rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.month-field {
  position: relative;
}

.month-trigger[aria-expanded="true"] {
  border-color: var(--accent);
}

.month-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 2;
  width: 17.5rem;
  padding: 0.7rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(42, 33, 24, 0.12);
}

.month-panel[hidden] {
  display: none;
}

.year-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.year-label {
  font-weight: 500;
}

.year-step,
.month-choice {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.year-step {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.month-choice {
  padding: 0.45rem 0.2rem;
  border-radius: 10px;
  font-size: 0.85rem;
}

.year-step:hover,
.month-choice:hover {
  background: var(--bg);
}

.month-choice[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.month-choice[aria-pressed="true"]:hover {
  background: var(--accent-hover);
}

.year-step:disabled {
  opacity: 0.35;
  cursor: default;
}

#download {
  padding: 0.55rem 1.15rem;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  font-weight: 500;
  cursor: pointer;
}

#download:hover {
  background: var(--accent-hover);
}

#download:disabled {
  opacity: 0.4;
  cursor: default;
}

.message {
  width: fit-content;
  margin: 16px 20px 0;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 28px 16px 48px;
}

.sheet {
  position: relative;
  width: min(11in, 100%);
  aspect-ratio: 11 / 8.5;
}

.orient-portrait .sheet {
  width: min(8.5in, 100%);
  aspect-ratio: 8.5 / 11;
}

.page {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: 11in;
  height: 8.5in;
  padding: 0.5in;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
  transform: scale(var(--page-scale));
  transform-origin: top left;
}

.orient-portrait .page {
  width: 8.5in;
  height: 11in;
}

.title {
  margin: 0 0 0.4rem;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.year {
  margin-left: 0.3em;
}

.font-montserrat .page {
  font-family: "Montserrat", "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
}

.font-montserrat .title {
  margin-bottom: 0.55rem;
  text-transform: uppercase;
  font-size: 2.35rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  line-height: 1;
}

.font-montserrat .dow {
  padding: 0.4rem 0.1rem 0.45rem;
  text-transform: uppercase;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.1em;
}

.font-montserrat .num {
  font-weight: 500;
}

.font-allison .page {
  padding-top: 0.28in;
}

.font-allison .title {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1.6rem;
  margin-bottom: 0.45rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
}

.font-allison .month {
  font-family: "Allison", cursive;
  font-size: 4.75rem;
  line-height: 0.85;
}

.font-allison .year {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.16em;
}

.font-allison .grid {
  border-color: #c4c4c4;
}

.font-allison .dow,
.font-allison .day {
  border-right-color: #c4c4c4;
  border-bottom-color: #c4c4c4;
}

.font-allison .dow {
  padding: 0.42rem 0.08rem;
  color: #545454;
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.font-allison .num {
  padding: 0.38rem 0.42rem;
  color: #545454;
  font-size: 0.85rem;
  font-weight: 400;
}

.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: auto repeat(var(--weeks, 5), 1fr);
  border: 1px solid #000;
}

.dow,
.day {
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
}

.grid > :nth-child(7n) {
  border-right: 0;
}

.grid > :nth-last-child(-n + 7) {
  border-bottom: 0;
}

.dow {
  padding: 0.35rem 0.15rem;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
}

.num {
  display: block;
  padding: 0.28rem 0.4rem;
  font-size: 0.95rem;
  line-height: 1;
}

.holiday {
  display: block;
  padding: 0.16rem 0.4rem 0;
  font-size: 0.58rem;
  font-weight: 600;
  line-height: 1.15;
}

.font-montserrat .holiday {
  font-size: 0.5rem;
  font-weight: 500;
}

.font-allison .holiday {
  padding: 0.12rem 0.42rem 0;
  color: #555;
  font-size: 0.62rem;
  font-weight: 500;
}

@page landscape {
  size: letter landscape;
  margin: 0.5in;
}

@page portrait {
  size: letter portrait;
  margin: 0.5in;
}

@page allison {
  size: letter landscape;
  margin: 0.28in 0.5in 0.5in;
}

@page allison-portrait {
  size: letter portrait;
  margin: 0.28in 0.5in 0.5in;
}

@media print {
  body {
    background: #fff;
  }

  .controls,
  .message {
    display: none;
  }

  .preview {
    display: block;
    padding: 0;
    gap: 0;
  }

  .sheet,
  .orient-portrait .sheet {
    position: static;
    width: auto;
    height: auto;
    aspect-ratio: auto;
  }

  .page {
    position: static;
    width: 100%;
    height: 7.5in;
    margin: 0;
    padding: 0;
    box-shadow: none;
    transform: none;
    break-after: page;
    page-break-after: always;
    page: landscape;
  }

  .orient-portrait .page {
    width: 100%;
    height: 10in;
    page: portrait;
  }

  .sheet:last-child .page {
    break-after: auto;
    page-break-after: auto;
  }

  .font-allison .page {
    page: allison;
    height: 7.72in;
    padding-top: 0;
  }

  .font-allison.orient-portrait .page {
    page: allison-portrait;
    height: 10.22in;
  }
}
