:root {
  font-family: Arial, Helvetica, sans-serif;
  color: #142033;
  background: #edf3f8;
  --navy: #123b88;
  --line: #d5dce4;
  --day-height: 24px;
  --sem-width: 24px;
  --date-width: 22px;
  --day-width: 19px;
  --notes-left: calc(var(--sem-width) + var(--date-width) + var(--day-width) + 4px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 8%, rgba(91, 184, 255, .2), transparent 30rem),
    linear-gradient(145deg, #f8fbfe, #e8eff6);
}

.calendar-shell {
  width: min(1540px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 100px;
}

.calendar-toolbar {
  position: static;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
  margin-bottom: 0;
  padding: 8px 10px;
  border: 1px solid rgba(22, 75, 196, .2);
  border-radius: 14px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 8px 22px rgba(29, 55, 94, .12);
  backdrop-filter: blur(12px);
}

.calendar-toolbar h1 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(18px, 3vw, 28px);
}

.calendar-actions {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.calendar-actions a {
  display: inline-flex;
  min-height: 72px;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border: 2px solid transparent;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, #174fae 0%, #2f75d2 100%);
  box-shadow: 0 7px 16px rgba(18, 59, 136, .25);
  font: inherit;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-weight: 800;
  text-decoration: none;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.calendar-actions a:hover,
.calendar-actions a:focus-visible {
  background: linear-gradient(135deg, #0f3f91 0%, #245fae 100%);
  box-shadow: 0 9px 20px rgba(18, 59, 136, .32);
  outline: none;
  transform: translateY(-1px);
}

.calendar-actions a:last-child {
  background: linear-gradient(135deg, #e57d14 0%, #f3a52b 100%);
  box-shadow: 0 7px 16px rgba(185, 99, 12, .25);
}

.calendar-actions a:last-child:hover,
.calendar-actions a:last-child:focus-visible {
  background: linear-gradient(135deg, #c8660b 0%, #de8b17 100%);
  box-shadow: 0 9px 20px rgba(185, 99, 12, .32);
}

.calendar-page {
  overflow: hidden;
  margin: 0 auto 18px;
  border: 1px solid #b9cbe5;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(29, 55, 94, .14);
  break-inside: avoid;
}

.semester-heading {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px;
  grid-template-rows: 64px 34px;
  align-items: center;
  min-height: 98px;
  border: 1px solid #b9cbe5;
  border-radius: 10px;
  overflow: hidden;
  color: #fff;
  background: #06245a;
}

.semester-heading h2 {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  margin: 0;
  padding: 0 8px;
  font-size: clamp(18px, 2vw, 30px);
  letter-spacing: .02em;
  line-height: 1.05;
  text-align: center;
}

.semester-heading p {
  grid-column: 1 / -1;
  grid-row: 2;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: #0c2d70;
  background: #eaf2fc;
  font-size: clamp(14px, 1.5vw, 20px);
  font-weight: 800;
}

.semester-icon {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 42px;
  line-height: 1;
}

.semester-icon svg {
  width: 44px;
  height: 44px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.7;
}

.book-icon { grid-column: 3; }

.months-grid {
  display: grid;
  gap: 7px;
  padding: 7px;
  background: #fff;
}

.months-grid-five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.months-grid-six { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.month-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #d4dbe4;
  border-radius: 6px;
  background: #fff;
}

.month-title {
  margin: 0;
  padding: 5px 4px;
  color: #fff;
  background: var(--month-color, #1757bb);
  font-size: clamp(13px, 1.25vw, 21px);
  font-weight: 900;
  text-align: center;
}

.month-head {
  display: grid;
  grid-template-columns: var(--sem-width) var(--date-width) var(--day-width) 1fr;
  min-height: 22px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  color: #1b2638;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.month-head .head-week { font-size: 8px; }

.month-body {
  position: relative;
  overflow: hidden;
  background: #fff;
}

.day-row {
  position: relative;
  display: grid;
  grid-template-columns: var(--sem-width) var(--date-width) var(--day-width) 1fr;
  min-height: var(--day-height);
  align-items: center;
  border-bottom: 1px solid #d5dce4;
  font-size: clamp(10px, .95vw, 16px);
  font-weight: 700;
}

.day-row:last-child { border-bottom: 0; }

.day-row::after {
  position: absolute;
  right: 4px;
  bottom: 4px;
  left: var(--notes-left);
  height: 1px;
  background: repeating-linear-gradient(
    to right,
    #cbd2d9 0 2px,
    transparent 2px 7px
  );
  content: '';
  pointer-events: none;
}

.day-row:last-child::after { display: none; }

.day-number,
.day-name { text-align: center; }

.day-row.weekend .day-number,
.day-row.weekend .day-name { color: #de2634; }

.day-note { min-width: 0; height: 100%; }

.week-label {
  position: absolute;
  left: 0;
  top: calc(var(--week-start) * var(--day-height));
  height: calc(var(--week-length) * var(--day-height));
  display: flex;
  width: var(--sem-width);
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line);
  color: var(--navy);
  font-size: clamp(9px, 1vw, 15px);
  font-weight: 900;
}

.week-label.week-blue {
  background: linear-gradient(135deg, #edf6ff, #dcecff);
  color: #1756a8;
}

.week-label.week-violet {
  background: linear-gradient(135deg, #f4efff, #e9ddff);
  color: #6a3ab8;
}

.week-label.week-break { color: transparent; }

.event-block {
  position: absolute;
  z-index: 2;
  top: calc(var(--event-start) * var(--day-height) + 2px);
  height: calc(var(--event-length) * var(--day-height) - 4px);
  left: var(--notes-left);
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, .78);
  border-radius: 6px;
  color: #163052;
  font-size: clamp(9px, .95vw, 14px);
  font-weight: 900;
  line-height: 1.12;
  text-align: center;
}

.event-block strong,
.event-block small { display: block; }
.event-block strong {
  max-width: 100%;
  font-size: 1em;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-align: center;
}
.event-intermediate strong {
  font-size: clamp(12px, 1.25vw, 18px);
  line-height: 1.02;
}
.event-block small { margin-top: 3px; font-size: .9em; font-weight: 800; }

.event-roomy {
  font-size: clamp(10px, 1.05vw, 15px);
  padding: 5px 7px;
}

.event-single {
  font-size: clamp(8px, .85vw, 12px);
  padding: 2px 4px;
}

.event-vacation { background: #cfe2f8; color: #124694; }
.event-exam { background: #e6dbf4; color: #4b287e; }
.event-holiday { background: #b3df8e; color: #164d28; }
.event-religious { background: #f7bd58; color: #694100; }

.calendar-legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(145px, 1fr));
  gap: 8px;
  align-items: center;
  padding: 1px 8px;
  border-top: 1px solid #d8e0e8;
  background: #fbfdff;
  font-size: 10px;
}

.calendar-legend span {
  display: grid;
  grid-template-columns: 16px 1fr;
  grid-template-rows: auto;
  column-gap: 5px;
  align-items: center;
}

.calendar-legend > span:last-of-type {
  grid-template-columns: 16px auto auto;
}

.calendar-legend span .legend-swatch { grid-row: 1; }
.calendar-legend strong { color: #164694; }
.calendar-legend small,
.calendar-legend em { display: none; }
.calendar-legend > span:last-of-type small {
  display: inline;
  margin-left: 4px;
  color: #d77a21;
  font-size: 7px;
  font-weight: 700;
  white-space: nowrap;
}

.legend-swatch {
  display: flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.legend-swatch svg {
  width: 12px;
  height: 12px;
}

.legend-swatch .icon-stroke {
  fill: none;
  stroke: #fff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.legend-note-icon {
  display: inline-flex;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  align-items: center;
  justify-content: center;
}

.legend-note-icon svg { width: 24px; height: 24px; }

.legend-swatch.vacation { background: #1b56ae; }
.legend-swatch.exam { background: #69369f; }
.legend-swatch.holiday { background: #179141; }
.legend-swatch.religious { background: #eb8a1d; }

@media (max-width: 720px) {
  body { overflow: auto; }

  .calendar-shell {
    width: 1120px;
    max-width: none;
    margin: 0;
    transform: scale(min(.62, calc(100vw / 1120px)));
    transform-origin: top left;
  }

  .calendar-page {
    width: 1120px;
    min-width: 1120px;
    min-height: 792px;
  }

  /* Render the phone view as a scaled A4 landscape sheet, like the PDF. */
  .semester-heading {
    grid-template-rows: 48px 26px;
    min-height: 74px;
  }
  .semester-icon svg { width: 34px; height: 34px; }
  .semester-heading h2 { font-size: 22px; }
  .semester-heading p { font-size: 13px; }
  .months-grid { gap: 3px; padding: 3px; }
  .month-title { padding: 3px; }
  .month-head { min-height: 22px; }
  :root { --day-height: 20.8px; }
  .day-row { font-size: 9px; }
  .event-block { font-size: 8px; padding: 2px 3px; }
  .event-roomy { font-size: 9px; padding: 2px 4px; }
  .event-single { font-size: 7px; padding: 1px 2px; }
  .event-intermediate strong { font-size: 10px; }
  .calendar-legend { padding: 1px 8px; gap: 8px; }
}

@media print {
  @page { size: A4 landscape; margin: 0; }
  body { background: #fff; }
  .calendar-shell { width: 100%; padding: 0; }
  .calendar-toolbar { display: none; }
  .calendar-page {
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    break-after: page;
  }
  .calendar-page:last-child { break-after: auto; }
  .semester-heading {
    grid-template-rows: 48px 26px;
    min-height: 74px;
  }
  .semester-icon svg { width: 34px; height: 34px; }
  .semester-heading h2 { font-size: 22px; }
  .semester-heading p { font-size: 13px; }
  .months-grid { gap: 3px; padding: 3px; }
  .month-title { padding: 3px; }
  .month-head { min-height: 22px; }
  :root { --day-height: 20.8px; }
  .day-row { font-size: 9px; }
  .event-block { font-size: 8px; padding: 2px 3px; }
  .event-roomy { font-size: 9px; padding: 2px 4px; }
  .event-single { font-size: 7px; padding: 1px 2px; }
  .event-intermediate strong { font-size: 10px; }
  .day-row::after {
    height: 0;
    background: none;
    border-bottom: 1px dotted #cbd2d9;
  }
  .calendar-legend { padding: 1px 8px; gap: 8px; }
}

@media (min-width: 721px) and (max-width: 900px) {
  .calendar-shell { width: calc(100% - 14px); padding-top: 10px; }
  .calendar-toolbar { align-items: stretch; flex-direction: column; top: 7px; }
  .calendar-actions { grid-template-columns: 1fr 1fr; }
  .calendar-actions a { width: 100%; }
}
