:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  background: #fbfdfc;
  color: #24302d;
  --ink: #24302d;
  --muted: #7a8783;
  --line: #e6ece9;
  --panel: #ffffff;
  --soft: #f1f7f4;
  --focus: #ff7b6f;
  --focus-ink: #8a2c25;
  --today: #4aa79a;
  --term: #d78b37;
  --festival: #e16f86;
  --weekend: #fffaf3;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

.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;
}

body {
  min-height: 100svh;
}

button,
input {
  font: inherit;
}

.calendar-shell {
  width: 100%;
  height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(3px, 0.8vh, 8px);
  padding: clamp(4px, 1vw, 12px);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(6px, 1.2vw, 12px);
  min-height: 44px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.input-hint {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.focus-summary {
  min-width: 0;
  display: grid;
  gap: 3px;
  overflow: hidden;
}

.focus-title {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  font-size: clamp(16px, 1.9vw, 22px);
  font-weight: 700;
  line-height: 1.15;
}

.focus-subline {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
}

.focus-lunar {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  color: var(--today);
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(12px, 1.2vw, 14px);
  font-weight: 600;
  line-height: 1.2;
}

.share-url {
  flex: 0 0 auto;
  min-width: 88px;
  margin: 0;
  color: #8aa19c;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(10px, 1vw, 12px);
  font-style: italic;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.controls {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.control-row {
  display: grid;
  grid-template-columns: 150px 52px 52px;
  gap: 6px;
}

input[type="date"],
button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

input[type="date"] {
  width: 100%;
  padding: 0 9px;
  background: #ffffff;
}

button {
  padding: 0 8px;
  color: #fff;
  background: var(--today);
  border-color: var(--today);
  font-weight: 600;
  cursor: pointer;
}

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

#copyButton {
  color: #55706b;
  background: #eef8f5;
  border-color: #cfe7e0;
}

.copy-toast {
  position: fixed;
  left: 50%;
  top: 16px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid #cfe7e0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(50, 79, 73, 0.14);
  color: #426a63;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.copy-toast[hidden] {
  display: none;
}

.calendar-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 3px;
}

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

.weekday-row {
  gap: 2px;
}

.weekday-row span {
  min-width: 0;
  padding: 4px 2px 3px;
  border-radius: 8px;
  background: #eef6f3;
  color: #52615d;
  text-align: center;
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 600;
}

.calendar-grid {
  min-height: 0;
  gap: 2px;
  grid-template-rows: repeat(var(--week-rows, 14), minmax(0, 1fr));
}

.day-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-left-width: 2px;
  border-radius: 8px;
  background: var(--panel);
  padding: 4px 5px 4px 6px;
  overflow: hidden;
}

.day-cell.weekend {
  filter: saturate(1.03) brightness(0.99);
}

.day-cell.month-edge {
  box-shadow: inset 0 2px 0 rgba(74, 117, 107, 0.12);
}

.day-cell.has-festival {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 245, 247, 0.42));
}

.month-tone-0 {
  --month: #4aa79a;
  background: #f5fbf8;
  border-color: #d9eee8;
  border-left-color: var(--month);
}

.month-tone-1 {
  --month: #8a7fd0;
  background: #f8f7ff;
  border-color: #e5e1fa;
  border-left-color: var(--month);
}

.month-tone-2 {
  --month: #e0786d;
  background: #fff8f6;
  border-color: #f4ddd9;
  border-left-color: var(--month);
}

.month-tone-3 {
  --month: #caa35c;
  background: #fffdf1;
  border-color: #eee4bf;
  border-left-color: var(--month);
}

.month-tone-4 {
  --month: #6b9ed6;
  background: #f5faff;
  border-color: #dceaf8;
  border-left-color: var(--month);
}

.month-tone-5 {
  --month: #c58779;
  background: #fff9f4;
  border-color: #efdcd2;
  border-left-color: var(--month);
}

.empty-cell {
  min-width: 0;
  min-height: 0;
  border: 1px dashed transparent;
}

.month-mark {
  color: var(--month);
  font-size: clamp(9px, 0.9vw, 12px);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.solar-row {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
}

.solar-day {
  min-width: 0;
  color: var(--ink);
  font-size: clamp(17px, 2.1vw, 28px);
  font-weight: 700;
  line-height: 0.9;
}

.day-meta {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}

.day-meta.has-pair {
  gap: 2px;
}

.lunar-day,
.event-badge {
  min-width: 0;
  font-size: clamp(10px, 1vw, 13px);
  line-height: 1;
  white-space: nowrap;
}

.lunar-day {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #4d5a56;
}

.event-badge {
  flex: 0 0 auto;
  max-width: none;
  padding: 1px 3px;
  border-radius: 4px;
  color: #fff;
  text-align: center;
  font-weight: 700;
  overflow: hidden;
  text-overflow: clip;
}

.day-meta.has-pair .event-badge {
  max-width: 34px;
  padding: 1px 2px;
  font-size: clamp(8px, 0.9vw, 12px);
}

.day-meta.has-pair .event-badge.term {
  max-width: 30px;
}

.event-badge.festival {
  background: var(--festival);
}

.event-badge.term {
  background: var(--term);
}

.day-cell.is-today::after {
  content: "";
  position: absolute;
  right: 6px;
  top: 6px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--today);
}

.day-cell.is-focus {
  background: #ffebe7;
  border-color: #e35f54;
  border-left-color: #d33c31;
  border-left-width: 4px;
  box-shadow: inset 0 0 0 2px rgba(227, 95, 84, 0.28), 0 0 0 1px rgba(227, 95, 84, 0.08);
}

.day-cell.is-focus .month-mark,
.day-cell.is-focus .solar-day {
  color: #7d1f18;
}

.day-cell.is-focus .lunar-day {
  color: #6f4a46;
}

.day-cell.is-focus .event-badge.term {
  background: #e18745;
}

.day-cell.is-focus .event-badge.festival {
  background: #d94d68;
}

.day-cell.out-of-input-range {
  background-image: repeating-linear-gradient(
    135deg,
    transparent 0,
    transparent 7px,
    rgba(23, 33, 31, 0.04) 7px,
    rgba(23, 33, 31, 0.04) 14px
  );
}

@media (max-width: 760px) {
  .calendar-shell {
    gap: 3px;
    padding: 4px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px;
    align-items: stretch;
    min-height: 0;
    padding-bottom: 4px;
  }

  .focus-summary {
    display: grid;
    gap: 2px;
    line-height: 1.1;
  }

  .focus-title {
    font-size: 14px;
  }

  .focus-lunar {
    font-size: 11px;
  }

  .share-url {
    min-width: 0;
    font-size: 9px;
  }

  .controls {
    width: auto;
  }

  .input-hint {
    display: none;
  }

  .control-row {
    grid-template-columns: 128px 42px 42px;
    gap: 4px;
  }

  input[type="date"],
  button {
    min-height: 38px;
    border-radius: 9px;
    font-size: 12px;
  }

  button {
    padding: 0 5px;
  }

  .copy-toast {
    top: 10px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .weekday-row,
  .calendar-grid {
    gap: 2px;
  }

  .weekday-row span {
    padding: 3px 0;
    border-radius: 5px;
    font-size: 10px;
  }

  .calendar-panel {
    gap: 2px;
  }

  .day-cell {
    border-left-width: 2px;
    border-radius: 6px;
    padding: 2px 3px 2px 4px;
    gap: 1px;
  }

  .month-mark {
    font-size: 8px;
  }

  .solar-day {
    font-size: clamp(15px, 4.7vw, 20px);
  }

  .lunar-day,
  .event-badge {
    font-size: clamp(8px, 2.5vw, 10px);
  }

  .event-badge {
    max-width: none;
    padding: 1px 2px;
  }

  .day-meta.has-pair .event-badge {
    max-width: 28px;
    padding: 1px;
    font-size: clamp(7px, 2.2vw, 8px);
  }

  .day-meta.has-pair .event-badge.term {
    max-width: 20px;
  }

  .day-cell.is-today::after {
    right: 4px;
    top: 4px;
    width: 4px;
    height: 4px;
  }
}

@media (max-height: 650px) {
  .calendar-shell {
    gap: 4px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .weekday-row span {
    padding-top: 3px;
    padding-bottom: 3px;
  }

  .day-cell {
    padding-top: 1px;
    padding-bottom: 1px;
  }
}
