html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  width: 100vw;
  overflow: hidden;
  background: #fafbfc;
  font-family: 'Segoe UI', 'Yu Gothic', 'Meiryo', sans-serif;
}

/* 余白を画面端から固定：上下36px、左右はautoで中央 */
.calendar-container {
  position: absolute;
  top: 36px;
  bottom: 36px;
  left: 0; right: 0;
  margin: auto;
  /* 余白を除いた最大高でアスペクト比フィット */
  height: calc(100vh - 72px);
  max-height: calc(100vh - 72px);
  aspect-ratio: 7 / 6.5;
  max-width: 98vw;
  width: auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px #0002;
  padding: 2vw 1vw 2vw 1vw;
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  overflow: hidden;
}

/* カレンダーのヘッダー */
.calendar-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 0.4em;
  min-height: 2.5em;
}
.calendar-header span {
  flex: 1;
  text-align: center;
  font-weight: bold;
  font-size: min(2.2vw,1.2em,22px);
  letter-spacing: 2px;
}
.calendar-header button {
  font-size: min(2.4vw,1.3em,28px);
  background: #f0f0f0;
  border: none;
  border-radius: 6px;
  width: 2.3em;
  height: 2.3em;
  cursor: pointer;
  margin: 0 10px;
  transition: background 0.2s;
}
.calendar-header button:hover {
  background: #e0e0e0;
}

/* カレンダー本体テーブル */
table.calendar {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
  font-size: min(1.8vw,17px);
  flex: 1 1 auto;
}
table.calendar th, table.calendar td {
  vertical-align: top;
  padding: 0.25em 0.2em 0.25em 0.2em;
  border: 1px solid #eee;
  height: calc((100% - 2.5em - 1.6em) / 6);
  min-width: 20px;
  max-width: 60px;
  box-sizing: border-box;
  position: relative;
  transition: background 0.2s;
  background-clip: padding-box;
  overflow: visible;
  font-size: min(1.8vw,16px);
}
table.calendar th {
  background: #f6f6f6;
  font-weight: bold;
  font-size: min(1.2vw,14px);
  color: #666;
  letter-spacing: 0.5em;
  padding-right: 0.6em;
  text-align: center;
  height: 2.2em;
}

/* 曜日・祝日・記念日色 */
.sunday, .holiday { color: #e50000 !important; }
.saturday { color: #0066cc !important; }
.anniversary { color: #c99700 !important; }

.cell-today { background: #e0fffe !important; z-index: 2;}
.cell-holiday, .cell-sunday { background: #ffe0e0 !important; }
.cell-saturday { background: #b5ceff !important; }
.cell-anniversary { background: #fffbe6 !important; }

/* 前月・翌月セル */
.outside-month {
  color: #bbb !important;
  background: #f7f7f7 !important;
  opacity: 0.7;
}
.outside-month .holiday-label,
.outside-month .anniversary-label {
  color: #ccc !important;
  filter: grayscale(0.3);
  opacity: 0.9;
}
.outside-month .day-number {
  color: #bbb !important;
}

/* 日付右上 */
.day-number {
  font-size: min(1.3vw,11px);
  font-weight: bold;
  position: absolute;
  top: 6px;
  right: 9px;
  width: 1.3em;
  height: 1.3em;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: 1;
  background: transparent;
  pointer-events: none;
  user-select: none;
  color: inherit;
}

/* ラベル複数行対応 */
.label-container {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: auto;
  max-width: 93%;
}
.holiday-label, .anniversary-label {
  font-size: min(1.3vw,12px);
  display: block;
  text-align: left;
  white-space: normal;
  overflow: hidden;
  line-height: 1.2;
  font-weight: normal;
  pointer-events: none;
  user-select: none;
  border-radius: 4px;
  padding: 0 2px;
}
.holiday-label { color: #e50000; background: none; }
.anniversary-label { color: #c99700; background: none; }

/* ポップアップラベル（中央表示、複数行対応） */
.popup-label-container {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 91%;
  min-height: 2.8em;
  padding: 0.45em 0.5em;
  background: #fff;
  border-radius: 1.1em;
  box-shadow: 0 4px 20px #0003, 0 1.5px 4px #0001;
  border: 2px solid #f0f0f0;
  transform: translate(-50%, -50%);
  z-index: 40;
  text-align: center;
  white-space: normal;
  line-height: 1.35;
  font-weight: bold;
  pointer-events: none;
  user-select: none;
  font-size: min(2vw,18px);
}
td.has-label:hover .popup-label-container,
td.has-label.active .popup-label-container {
  display: flex;
}
.popup-label-holiday { color: #e50000; }
.popup-label-anniversary { color: #c99700; }

/* スマホ対応 */
@media (max-width: 600px), (max-height: 600px) {
  .calendar-container {
    top: 12px;
    bottom: 12px;
    height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    aspect-ratio: 7 / 7.1;
    min-height: 60vw;
    max-width: 99vw;
    padding: 2vw 1vw 2vw 1vw;
  }
  table.calendar th, table.calendar td {
    font-size: min(3vw,13px);
    min-width: 14px;
    max-width: 24vw;
    height: auto;
    padding: 3px 1px 2px 2px;
  }
  .day-number { font-size: min(2.5vw,9.5px); top: 2px; right: 3px; }
  .holiday-label, .anniversary-label { font-size: min(2.7vw,11px); }
  .label-container { max-width: 96%; }
  .popup-label-container { font-size: min(3vw,16px); min-height: 2.1em; }
  .calendar-header span { font-size: min(4vw,1em); }
}
@media (max-width: 400px) {
  .calendar-header span { font-size: min(5vw,0.92em); }
  table.calendar th, table.calendar td { font-size: min(3vw,9.5px); }
  .holiday-label, .anniversary-label { font-size: min(3vw,8px); }
}
