:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #171a1f;
  --muted: #68727e;
  --line: #dfe4e9;
  --line-strong: #c9d0d8;
  --accent: #e5484d;
  --accent-soft: #fff0f1;
  --blue: #2563eb;
  --blue-soft: #edf5ff;
  --shadow: 0 20px 60px rgba(25, 35, 50, .09);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, rgba(37, 99, 235, .065), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background .25s ease, color .25s ease;
}

button, input { font: inherit; }

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 44px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  font-weight: 850;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}

#yearTitle {
  display: block;
  margin-top: 2px;
  font-size: 25px;
  line-height: 1;
  letter-spacing: -.045em;
}

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

.icon-btn, .today-btn, .download-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  font-size: 18px;
}

.today-btn {
  height: 40px;
  padding: 0 15px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 750;
}

.icon-btn:hover, .today-btn:hover, .download-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 6px 18px rgba(25, 35, 50, .08);
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 40px;
  margin-bottom: 24px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .11em;
  text-transform: uppercase;
}

h1 {
  max-width: 700px;
  margin: 0;
  font-size: clamp(31px, 4.2vw, 51px);
  line-height: 1.01;
  letter-spacing: -.06em;
}

.subhead {
  max-width: 680px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.year-picker { flex: 0 0 auto; }

.year-picker label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.year-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 11px 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.year-input-wrap input {
  width: 82px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

.year-input-wrap span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.calendar-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.calendar-toolbar strong {
  display: block;
  font-size: 12px;
}

.calendar-toolbar span:not(.leap-badge) {
  color: var(--muted);
  font-size: 10px;
}

#selectionHint {
  display: block;
  margin-top: 3px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.leap-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.download-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  background: var(--text);
  color: var(--surface);
  font-size: 10px;
  font-weight: 750;
}

.month-map {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr)) repeat(7, minmax(68px, 1.25fr));
  min-width: 900px;
  min-height: 166px;
  border-bottom: 1px solid var(--line-strong);
}

.month-column {
  min-width: 0;
  padding: 12px 8px 10px;
  border-right: 1px solid var(--line);
}

.month-column:last-child { border-right: 0; }
.month-column.empty { background: var(--surface-2); }

.month-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  margin: 0 0 5px;
  padding: 0 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 780;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
}

.month-item:last-child { margin-bottom: 0; }

.month-item:hover {
  transform: translateY(-2px);
  border-color: var(--line);
  background: var(--surface-2);
}

.month-item.current-month {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #ffd3d5;
}

.month-item.selected-month {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #c9ddff;
}

.month-item.current-month.selected-month {
  color: var(--accent);
  border-color: #ffd3d5;
}

.grid-wrap { overflow-x: auto; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr)) repeat(7, minmax(68px, 1.25fr));
  min-width: 900px;
}

.cell {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 650;
}

.cell:nth-child(12n) { border-right: 0; }

.header-cell {
  min-height: 46px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.date-number {
  border-left: 0;
  border-top: 0;
  border-radius: 0;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background .13s ease, color .13s ease, box-shadow .13s ease;
}

.date-number:hover:not(:disabled) {
  background: var(--blue-soft);
  color: var(--blue);
}

.date-number.empty {
  cursor: default;
}

.weekend { color: var(--accent); }

.current-weekday {
  background: var(--blue-soft);
  color: var(--blue);
}

.today-cell {
  position: relative;
  z-index: 2;
  color: var(--accent) !important;
  background: var(--accent-soft) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
  font-weight: 900;
}

.today-cell::after {
  content: "TODAY";
  position: absolute;
  top: 3px;
  right: 4px;
  color: var(--accent);
  font-size: 6px;
  font-weight: 900;
  letter-spacing: .08em;
}

.legend {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 13px 18px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.today-dot { background: var(--accent); }
.weekday-dot { background: var(--blue); }
.tip { margin-left: auto; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 15px;
  color: var(--muted);
  font-size: 10px;
}

.page-transition {
  animation: calendarIn .28s cubic-bezier(.2,.8,.25,1);
}

@keyframes calendarIn {
  0% { opacity: .25; transform: translateY(8px) scale(.996); filter: blur(1px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

/* Dark mode */
body.dark {
  --bg: #0b0e13;
  --surface: #121720;
  --surface-2: #171d27;
  --text: #edf2f7;
  --muted: #8d99a8;
  --line: #29313d;
  --line-strong: #394452;
  --accent: #ff6b70;
  --accent-soft: #321c20;
  --blue: #70a7ff;
  --blue-soft: #142746;
  --shadow: 0 20px 60px rgba(0, 0, 0, .28);
}

body.dark .brand-mark,
body.dark .download-btn {
  background: #edf2f7;
  color: #121720;
}

@media (max-width: 720px) {
  .app {
    width: calc(100% - 20px);
    padding-top: 16px;
  }

  .topbar {
    margin-bottom: 30px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
  }

  h1 { font-size: 36px; }

  .calendar-card { border-radius: 15px; }

  .calendar-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .month-map {
    min-height: 142px;
  }

  .month-column {
    padding: 8px 4px;
  }

  .month-item {
    min-height: 34px;
    font-size: 10px;
  }

  .legend {
    flex-wrap: wrap;
    gap: 9px 15px;
  }

  .tip {
    width: 100%;
    margin-left: 0;
  }

  footer {
    flex-direction: column;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body {
    background: white !important;
    color: black !important;
  }

  .app {
    width: 100%;
    padding: 0;
  }

  .topbar { margin-bottom: 10px; }
  .brand-mark, .controls, .year-picker, .kicker, .subhead,
  .calendar-toolbar .toolbar-actions, footer, .legend {
    display: none !important;
  }

  h1 {
    max-width: none;
    font-size: 25px;
  }

  .hero {
    margin-bottom: 8px;
  }

  .calendar-card {
    border: 1px solid #aaa;
    border-radius: 0;
    box-shadow: none;
  }

  .calendar-toolbar {
    padding: 7px 10px;
    background: white !important;
  }

  .month-map, .calendar-grid {
    min-width: 0;
  }

  .month-map { min-height: 0; }

  .month-column, .month-item, .cell {
    color: black !important;
    background: white !important;
    box-shadow: none !important;
  }

  .today-cell {
    outline: 2px solid #222;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
