:root {
  color-scheme: light;
  --bg: #e6e1d6;
  --card: #fbf9f4;
  --ink: #1c1915;
  --muted: #7a7468;
  --sat: #1d4e96;
  --sun: #a33b32;
  --line: rgba(28, 25, 21, 0.1);
  --line-strong: rgba(28, 25, 21, 0.28);
  --today-bg: #1c1915;
  --today-fg: #fbf9f4;
  --hover: rgba(28, 25, 21, 0.06);
  --range: rgba(28, 25, 21, 0.16);
  --sat-wash: rgba(29, 78, 150, 0.06);
  --sun-wash: rgba(163, 59, 50, 0.07);
  --shadow: 0 1px 0 rgba(28, 25, 21, 0.04);
  --pad-y: clamp(12px, 1.4vh, 22px);
  --pad-x: clamp(18px, 2.4vw, 56px);
  --bar: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141311;
    --card: #211f1b;
    --ink: #f4f0e6;
    --muted: #a39c90;
    --sat: #9ec0f5;
    --sun: #f0a79e;
    --line: rgba(244, 240, 230, 0.1);
    --line-strong: rgba(244, 240, 230, 0.34);
    --today-bg: #f4f0e6;
    --today-fg: #141311;
    --hover: rgba(244, 240, 230, 0.08);
    --range: rgba(244, 240, 230, 0.18);
    --sat-wash: rgba(158, 192, 245, 0.08);
    --sun-wash: rgba(240, 167, 158, 0.1);
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Segoe UI", "Helvetica Neue", sans-serif;
  font-synthesis: none;
}

::selection {
  background: var(--today-bg);
  color: var(--today-fg);
}

.feed {
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  overflow-anchor: none;
  scroll-behavior: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
  outline: none;
}

.topbar {
  position: fixed;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 max(env(safe-area-inset-right), var(--pad-x)) 0
    max(env(safe-area-inset-left), var(--pad-x));
  background: var(--bg);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.range-label {
  margin: 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--card);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.year-label {
  margin: 0;
  font-size: clamp(26px, 2.2vw, 40px);
  font-weight: 650;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.year {
  height: 100dvh;
  min-height: 100dvh;
  padding: calc(var(--bar) + 6px) var(--pad-x) var(--pad-y);
  display: flex;
  flex-direction: column;
}

.months {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 0.9vw, 16px);
}

.month {
  scroll-margin-top: calc(var(--bar) + 8px);
  container-type: inline-size;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: clamp(8px, 0.7vw, 12px) clamp(8px, 0.7vw, 12px) clamp(4px, 0.4vw, 8px);
}

.month.is-current {
  box-shadow: inset 0 3px 0 var(--ink);
}

.month h3 {
  margin: 0 0 4px;
  flex: none;
  font-size: clamp(16px, 4.6cqw, 26px);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

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

.dow {
  flex: none;
  margin-bottom: 2px;
}

.dow span {
  text-align: center;
  font-size: clamp(10px, 2.5cqw, 13px);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.4;
}

.dow .is-sat,
.cell.is-sat time {
  color: var(--sat);
}

.dow .is-sun,
.cell.is-sun time {
  color: var(--sun);
}

.grid {
  flex: 1;
  min-height: 0;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  container-type: size;
}

.cell {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
}

.cell:not(.is-empty) {
  cursor: pointer;
}

.cell.is-sat {
  background: var(--sat-wash);
}

.cell.is-sun {
  background: var(--sun-wash);
}

.cell time {
  width: 1.32em;
  height: 1.32em;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: clamp(15px, 11.4cqh, 34px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.cell.is-today time {
  background: var(--today-bg);
  color: var(--today-fg);
  font-weight: 700;
}

.cell.is-in-range,
.cell.is-in-range.is-sat,
.cell.is-in-range.is-sun {
  background: var(--range);
}

.cell.is-range-edge time,
.cell.is-sat.is-range-edge time,
.cell.is-sun.is-range-edge time,
.cell.is-today.is-range-edge time {
  background: var(--today-bg);
  color: var(--today-fg);
  font-weight: 700;
}

@media (hover: hover) {
  .cell:not(.is-empty):not(.is-today):not(.is-range-edge):hover time {
    background: var(--hover);
  }
}

.today-btn {
  flex: none;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.today-btn:hover {
  background: var(--ink);
  color: var(--card);
}

.today-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .year {
    height: auto;
    min-height: auto;
  }

  .months {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .month {
    min-height: 340px;
  }
}

@media (max-width: 680px) {
  .months {
    grid-template-columns: 1fr;
  }

  .month {
    min-height: 360px;
  }

}
