:root {
  --paper: #f6efdf;
  --ink: #2b2118;
  --muted: #7a6a55;
  --rule: #d8c9a8;
  --cell: #fffaf0;
  --dark-days: #e7dcc4;
  --lunatos: #e3b11f;
  --lunatos-edge: #9c7608;
  --porporos: #b8322a;
  --porporos-edge: #7a1c16;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

/* Always show the vertical scrollbar, so the page width doesn't change when the
   moons are toggled and the page gets shorter than the window. */
html { overflow-y: scroll; }

body {
  margin: 0;
  padding: 16px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  max-width: 1100px;
  margin: 0 auto 16px;
}

h1 {
  margin: 0;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  font-size: 2rem;
}

.era { margin: 0; font-size: 1.25rem; }
.era small { color: var(--muted); font-size: 0.75em; font-variant: small-caps; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.controls label { white-space: nowrap; }
.controls input[type="number"] { width: 6em; font: inherit; padding: 4px 6px; }
.controls button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--muted);
  border-radius: 4px;
  background: var(--cell);
  color: var(--ink);
  cursor: pointer;
}
.controls button:hover { background: var(--dark-days); }

.toggle { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.no-moons .moons { display: none; }
/* Hidden but still taking its space, so the header doesn't shift when toggling. */
.no-moons .legend { visibility: hidden; }
.no-moons .day { min-height: 0; }

.legend { display: flex; gap: 16px; list-style: none; margin: 0; padding: 0; order: 3; }

/* Wide screens: title left, legend centered, controls right. */
@media (min-width: 1000px) {
  header { display: grid; grid-template-columns: 1fr auto 1fr; }
  .legend { order: 0; }
  .controls { justify-self: end; }
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .moon { width: 16px; height: 16px; }

#calendar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px 24px;
  max-width: 1100px;
  margin: 0 auto;
}

.month h2, .propantrion h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: normal;
}
.month .idx { color: var(--muted); }
.season { color: var(--muted); font-size: 0.85em; }

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

.wd {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--rule);
}

.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 3px 1px 2px;
  background: var(--cell);
  border-radius: 3px;
  font-size: 0.85rem;
}
.day.empty { background: transparent; }

.moons { display: flex; gap: 2px; }
.moon { width: 12px; height: 12px; display: block; }

.moon-lunatos .moon-dark { fill: var(--lunatos); fill-opacity: 0.12; stroke: var(--lunatos-edge); stroke-width: 1; }
.moon-lunatos .moon-lit { fill: var(--lunatos); }
.moon-porporos .moon-dark { fill: var(--porporos); fill-opacity: 0.12; stroke: var(--porporos-edge); stroke-width: 1; }
.moon-porporos .moon-lit { fill: var(--porporos); }

.propantrion {
  grid-column: 1 / -1;
  padding: 8px 12px 10px;
  background: var(--dark-days);
  border-radius: 6px;
}
.prop-days {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.day.prop { flex-direction: row; justify-content: center; gap: 8px; min-height: 0; padding: 4px; }

@media (max-width: 960px) {
  #calendar { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  #calendar { grid-template-columns: 1fr; }
  .prop-days { grid-template-columns: 1fr; }
  .day.prop { justify-content: space-between; }
}

@media print {
  @page { size: A4 portrait; margin: 8mm; }
  body { padding: 0; background: #fff; font-size: 9pt; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  header { margin: 0 0 2mm; max-width: none; }
  .controls { display: none; }
  h1 { font-size: 15pt; }
  .era { font-size: 11pt; }
  #calendar { grid-template-columns: repeat(3, 1fr); gap: 2.5mm 6mm; max-width: none; }
  .month { break-inside: avoid; }
  .month h2, .propantrion h2 { font-size: 10pt; margin-bottom: 0.5mm; }
  .wd { font-size: 7pt; padding-bottom: 0.3mm; }
  .grid { gap: 0.6mm; }
  .day { min-height: 7.4mm; padding: 0.3mm 0; font-size: 8pt; border: 0.2mm solid var(--rule); }
  .day.empty { border: none; }
  .moon { width: 2.6mm; height: 2.6mm; }
  .legend .moon { width: 3.5mm; height: 3.5mm; }
  .propantrion { padding: 1.5mm 3mm; }
  .day.prop { padding: 0.8mm; }
}
