:root {
  --brand-blue: #54c3f1;
  --brand-blue-deep: #1f7fa8;
  --brand-coral: #ec6d5e;
  --brand-gold: #fcb517;
  --brand-green: #67bb71;
  --bg-cream: #fff6e2;
  --bg-blue-tint: #eef9fe;
  --ink: #3a3a3a;
  --card-radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", YuGothic, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-blue-tint) 0%, var(--bg-cream) 100%);
  min-height: 100vh;
  position: relative;
}


.calendar-wrap {
  position: relative;
  max-width: 960px;
  margin: 16px auto;
  padding: 20px 22px 18px;
  background: #ffffff;
  border-radius: var(--card-radius);
  box-shadow: 0 12px 32px rgba(31, 127, 168, 0.14), 0 2px 8px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.calendar-wrap::before,
.calendar-wrap::after {
  content: "";
  position: absolute;
  z-index: 0;
  border-radius: 50%;
  pointer-events: none;
}

.calendar-wrap::before {
  width: 180px;
  height: 180px;
  background: var(--brand-blue);
  opacity: 0.12;
  top: -90px;
  left: -60px;
}

.calendar-wrap::after {
  width: 140px;
  height: 140px;
  background: var(--brand-gold);
  opacity: 0.14;
  bottom: -60px;
  right: -50px;
}

.crest-watermark {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: url("assets/school-crest.png");
  background-repeat: no-repeat;
  background-position: center 55%;
  background-size: min(60%, 360px);
  opacity: 0.4;
  pointer-events: none;
}

.calendar-header,
.legend,
.cal-grid,
.cal-list,
.recurring-section {
  position: relative;
  z-index: 1;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 2px dashed rgba(84, 195, 241, 0.4);
}

.calendar-header h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 900;
  min-width: 8em;
  text-align: center;
  color: var(--brand-blue-deep);
}

.calendar-header button {
  border: 2px solid var(--brand-blue);
  background: #fff;
  color: var(--brand-blue-deep);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.calendar-header button:hover {
  background: var(--brand-blue);
  color: #fff;
}

.calendar-header button:active {
  transform: scale(0.92);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  position: relative;
}

.cal-head {
  min-width: 0;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 0;
  color: var(--brand-blue-deep);
  background: var(--bg-blue-tint);
  border-radius: 8px;
}

.cal-cell {
  /* min-width:0 がないと、折り返さない長いイベント名（チップ・帯）の分だけ
     その曜日の列だけがグリッドの均等割り（1fr）を無視して広がってしまう */
  min-width: 0;
  min-height: 74px;
  border: 1px solid #eef2f5;
  border-radius: 10px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fff;
  transition: box-shadow 0.15s;
}

@media (hover: hover) {
  .cal-cell:not(.empty):hover {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.07);
  }
}

.cal-cell.empty {
  border: none;
  background: transparent;
}

.cal-date {
  font-size: 0.8rem;
  color: #555;
}

.cal-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.chip {
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 4px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chip:hover {
  filter: brightness(0.92);
}

/* ===== 複数日にまたがる期間指定イベント（マイペース見学会など）の帯 ===== */
/* 帯が通る週は、日付欄の予定リストをその分だけ下にずらして帯とぶつからないようにする */
.cal-cell.has-band .cal-events {
  margin-top: 18px;
}

.cal-band {
  /* grid-row/grid-column を指定しつつ position:absolute にすることで、この帯をグリッドの
     自動配置（日付セルの並び）に影響させず見た目だけ重ねる。abspos な子要素は
     justify-self が効かないので、left/right を両方指定して列の幅いっぱいに広げる */
  position: absolute;
  left: 0;
  right: 0;
  margin-top: 22px;
  height: 14px;
  line-height: 14px;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  transition: filter 0.15s;
}

.cal-band.seg-start {
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  margin-left: 2px;
}

.cal-band.seg-end {
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  margin-right: 2px;
}

.cal-band:hover {
  filter: brightness(0.92);
}

.cal-error {
  grid-column: 1 / -1;
  text-align: center;
  color: #c0392b;
  padding: 24px;
}

/* 土日の色分け（グリッド） */
.cal-head.wd-sun {
  color: #c0392b;
}
.cal-head.wd-sat {
  color: #2f6fb0;
}
.cal-cell.wd-sun .cal-date {
  color: #c0392b;
}
.cal-cell.wd-sat .cal-date {
  color: #2f6fb0;
}

/* ===== モバイル向け: 日付ごとの縦積みリスト ===== */
.cal-list {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.list-day-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: linear-gradient(135deg, var(--bg-blue-tint), #ffffff);
  border: 1px solid rgba(84, 195, 241, 0.25);
  border-radius: 10px;
  padding: 8px 14px;
}

.list-day-num {
  font-size: 1.3rem;
  font-weight: 700;
}

.list-day-weekday {
  font-size: 0.95rem;
  color: #666;
  font-weight: 700;
}

.list-day-header.wd-sun .list-day-num,
.list-day-header.wd-sun .list-day-weekday {
  color: #c0392b;
}

.list-day-header.wd-sat .list-day-num,
.list-day-header.wd-sat .list-day-weekday {
  color: #2f6fb0;
}

.list-day-events {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--ev-color, #999);
  background: #fff;
  color: #222;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.15s, transform 0.1s;
}

.list-item::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--ev-color, #999);
}

.list-item-label {
  flex: 1 1 auto;
}

.list-item:active {
  transform: scale(0.98);
  background: #f7f7f7;
}

.list-empty {
  text-align: center;
  color: #888;
  padding: 32px 0;
}

/* イベントのキャッチコピー */
.catch-badge {
  flex: none;
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fff;
  background: var(--ev-color, var(--brand-coral));
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ===== 不定期開催イベント（マイペース見学会など）の専用ボタン ===== */
.recurring-section {
  margin-top: 16px;
}

.recurring-heading {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: #a9711c;
  background: var(--bg-cream);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.recurring-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.recurring-item {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border: 1.5px solid var(--ev-color, #999);
  background: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.15s, transform 0.1s;
}

.recurring-item-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  color: #222;
}

.recurring-item-title::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--ev-color, #999);
}

.recurring-item-note {
  font-size: 0.78rem;
  color: #555;
}

.recurring-item:active {
  transform: scale(0.98);
  background: #f7f7f7;
}

/* 700px以下でもグリッド表示のまま、セルとチップを小さくして収める */
@media (max-width: 700px) {
  .calendar-wrap {
    padding: 12px 8px 8px;
  }
  .calendar-header h2 {
    font-size: 1.35rem;
  }
  .calendar-header button {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }
  .cal-grid {
    gap: 3px;
  }
  .cal-head {
    font-size: 0.7rem;
    padding: 4px 0;
  }
  .cal-cell {
    min-height: 54px;
    padding: 2px;
    border-radius: 8px;
  }
  .cal-date {
    font-size: 0.68rem;
  }
  .chip {
    font-size: 0.56rem;
    padding: 1px 3px;
    border-radius: 4px;
  }
  .cal-cell.has-band .cal-events {
    margin-top: 14px;
  }
  .cal-band {
    margin-top: 17px;
    height: 11px;
    line-height: 11px;
    font-size: 0.48rem;
  }
}

@media (max-width: 420px) {
  .cal-cell {
    min-height: 46px;
  }
  .cal-date {
    font-size: 0.62rem;
  }
  .chip {
    font-size: 0.5rem;
  }
  .cal-cell.has-band .cal-events {
    margin-top: 13px;
  }
  .cal-band {
    margin-top: 16px;
    height: 10px;
    line-height: 10px;
    font-size: 0.44rem;
  }
}

@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(160deg, #1a2530 0%, #201b12 100%);
    color: #eee;
  }
  .crest-watermark {
    opacity: 0.28;
  }
  .calendar-wrap {
    background: #232323;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  }
  .cal-head {
    background: rgba(84, 195, 241, 0.12);
  }
  .cal-cell {
    background: #232323;
    border-color: #3a3a3a;
  }
  .calendar-header {
    border-bottom-color: rgba(84, 195, 241, 0.3);
  }
  .calendar-header button {
    background: #2a2a2a;
    color: #eee;
    border-color: #444;
  }
  .calendar-header button:hover {
    background: var(--brand-blue);
    color: #1b1b1b;
  }
  .list-day-header {
    background: rgba(84, 195, 241, 0.1);
    border-color: rgba(84, 195, 241, 0.25);
  }
  .list-day-weekday {
    color: #aaa;
  }
  .list-item {
    background: #1f1f1f;
    color: #eee;
  }
  .list-item:active {
    background: #262626;
  }
  .recurring-heading {
    color: #ffd98a;
    background: rgba(252, 181, 23, 0.15);
  }
  .recurring-item {
    background: #1f1f1f;
  }
  .recurring-item-title {
    color: #eee;
  }
  .recurring-item-note {
    color: #bbb;
  }
  .recurring-item:active {
    background: #262626;
  }
}
