:root {
  --paper: #f3ecdf;
  --sheet: #fffaf3;
  --ink: #1d1914;
  --muted: #6b6156;
  --line: #e3d7c6;
  --accent: #e07a2f;
  --accent-ink: #8a3d0c;
  --wash: #f4c99a;
  --wash-deep: #efbc84;
  --rise: #8f3f0e;
  --set: #243652;
  --dst: #d7e6f6;
  --dst-deep: #c5daf0;
  --dst-ring: #2a6294;
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 280px at 0% 0%, #ffe6c4 0%, transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.7rem 1.4rem;
  padding: 0.85rem max(1.1rem, env(safe-area-inset-right)) 0.75rem max(1.1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}

.brand { margin-right: auto; min-width: 16rem; }

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: inherit;
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.wordmark:hover { color: var(--accent-ink); }

.mark { width: 1.55rem; height: 1.55rem; display: block; }

.tld { color: var(--muted); font-weight: 500; font-size: 0.72em; }

.tagline { margin: 0.28rem 0 0; color: var(--muted); font-size: 0.95rem; }

.controls { display: flex; flex-wrap: wrap; gap: 0.75rem 0.9rem; align-items: flex-end; }

.field { display: flex; flex-direction: column; gap: 0.22rem; }

.field > span { font-size: 0.82rem; font-weight: 600; color: var(--muted); }

select {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  height: 2.65rem;
  min-width: 13.5rem;
  padding: 0 0.7rem;
  border: 1px solid #d3c6b2;
  border-radius: 10px;
  background: var(--sheet);
}

.year-stepper {
  display: flex;
  align-items: center;
  height: 2.65rem;
  padding: 0 0.15rem;
  border: 1px solid #d3c6b2;
  border-radius: 10px;
  background: var(--sheet);
}

.year-stepper strong {
  min-width: 3.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.year-stepper button {
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.year-stepper button:hover { background: var(--wash); }

button:disabled { opacity: 0.35; cursor: default; }

.today-line {
  flex-basis: 100%;
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
}

.today-line strong { font-weight: 650; }

.legend-row {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.9rem;
}

.legend { margin: 0; color: var(--muted); font-size: 0.92rem; }

.swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.2rem;
  border-radius: 2px;
  background: var(--wash);
  vertical-align: -1px;
  box-shadow: inset 0 0 0 1px rgba(138, 61, 12, 0.28);
}

.swatch.solid { background: var(--accent); }

.swatch.dst {
  background: var(--dst);
  box-shadow: inset 0 0 0 2px var(--dst-ring);
}

#jump-today {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--sheet);
  border: 1px solid #d3c6b2;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}

#jump-today:hover { background: var(--wash); }

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

main { flex: 1; min-height: 0; display: flex; }

.table-scroll {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  /* Paint containment keeps the table's overflow inside this scroller.
     Without it the page grows a second vertical scrollbar. */
  contain: paint;
  background: var(--sheet);
  padding-bottom: env(safe-area-inset-bottom);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: max(100%, max-content);
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

th, td {
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.28rem 0.4rem 0.34rem;
  text-align: center;
  vertical-align: middle;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-top: 0.55rem;
  padding-bottom: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
}

th.corner, th.day {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 3.15rem;
  width: 3.15rem;
  padding-right: 0.65rem;
  text-align: right;
  font-weight: 650;
  color: var(--muted);
  box-shadow: 8px 0 8px -8px rgba(40, 28, 16, 0.35);
}

th.corner { z-index: 3; top: 0; }

td { min-width: 4.7rem; }

.t { display: block; line-height: 1.28; white-space: nowrap; }
.rise { color: var(--rise); }
.set { color: var(--set); }

thead th.col-today,
td.col-today,
tr.row-today > th,
tr.row-today > td {
  background: var(--wash);
}

thead th.col-today,
tr.row-today > th.day {
  color: var(--accent-ink);
}

tr.row-today > td.today {
  background: var(--accent);
}

tr.row-today > td.today .rise,
tr.row-today > td.today .set {
  color: var(--ink);
  font-weight: 700;
}

td.dst {
  background: var(--dst);
  box-shadow: inset 0 0 0 2px var(--dst-ring);
}

tr.row-today > td.dst,
td.col-today.dst {
  background: var(--wash);
}

tr.row-today > td.today.dst {
  background: var(--accent);
  box-shadow: inset 0 0 0 2px #1d1914;
}

.dst-label {
  display: block;
  margin-top: 0.08rem;
  color: var(--dst-ring);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.1;
  text-transform: lowercase;
}

tr.row-today > td.today .dst-label { color: var(--ink); }

tbody td:not(.empty):not(.today):not(.dst):hover { background: #f7efe4; }

tbody tr:not(.row-today) > td.dst:not(.col-today):hover { background: var(--dst-deep); }

tbody tr.row-today td:not(.today):hover,
tbody td.col-today:not(.today):hover { background: var(--wash-deep); }

@media (max-width: 720px) {
  .top { padding-top: 0.7rem; }
  .brand { min-width: 0; }
  .wordmark { font-size: 1.45rem; }
  .controls { width: 100%; }
  .field.place { flex: 1; min-width: 10rem; }
  select { width: 100%; min-width: 0; }
  .today-line { font-size: 0.98rem; }
  td { min-width: 4.35rem; font-size: 0.86rem; }
}

@media print {
  body { display: block; height: auto; background: white; }
  .table-scroll { overflow: visible; contain: none; }
  .year-stepper button, #jump-today { display: none; }
  th, td, thead th.col-today, td.col-today, tr.row-today > th, tr.row-today > td, tr.row-today > td.today, td.dst {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
