*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  color: #333;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ページヘッダー */
.page-header {
  flex-shrink: 0;
  padding: 1rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.page-header-inner {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  text-align: left;
  min-width: 0;
}

.page-header-brand {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.5rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  flex: 1 1 auto;
}

.page-header-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.page-header-title-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.page-header-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  color: #e60012;
}

.page-header-badge {
  font-size: 0.8125rem;
  font-weight: 400;
  color: #c41230;
  flex-shrink: 0;
  margin-top: 0.2rem;
}

/* 幅の狭い端末（iPhone SE など）：余白を詰め、ヘッダーを1行に収める */
@media (max-width: 430px) {
  .page-header {
    padding: 0.625rem 1rem;
  }

  .page-header-inner {
    gap: 0.35rem 0.5rem;
  }

  .page-header-brand {
    gap: 0.35rem;
  }

  .page-header-icon {
    width: 2rem;
    height: 2rem;
  }

  .page-header-title {
    font-size: 0.9375rem;
  }

  .page-header-badge {
    font-size: 0.6875rem;
  }

  .site-overview {
    padding: 0.5rem 1rem 0;
  }

  .affiliate-notice {
    padding: 0.3rem 1rem;
  }

  .page-container {
    padding: 1rem 1rem 1.5rem;
  }

  .calendar-nav {
    margin-bottom: 0.75rem;
  }

  .calendar-nav--bottom {
    margin-top: 0.75rem;
  }
}

/* ヘッダー直下：サイト概要 */
.site-overview {
  max-width: 560px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem 0;
}

.site-overview-text {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #555;
}

/* ファーストビュー：ヘッダー直下のアフィリエイト表記（境界ライン） */
.affiliate-notice {
  margin: 0;
  padding: 0.35rem 1.5rem;
  font-size: 0.7rem;
  color: #888;
  background: none;
  text-align: center;
  flex-shrink: 0;
}

.page-container {
  flex: 1 0 auto;
  padding: 1.5rem 1.5rem 2rem;
}

.calendar {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

/* 前の月・次の月リンク（カレンダー上下） */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.calendar-nav--bottom {
  margin-bottom: 0;
  margin-top: 1rem;
}

.calendar-nav--top .calendar-title {
  margin: 0;
  flex: 0 0 auto;
}

.calendar-nav-link {
  font-size: 0.9375rem;
  color: #e60012;
  text-decoration: none;
  flex-shrink: 0;
}

.calendar-nav-link:hover {
  text-decoration: underline;
}

.calendar-nav-link--disabled {
  color: #999;
  cursor: default;
  pointer-events: none;
}

/* 曜日と日付で同じ列幅にするため、共通のグリッド定義 */
.calendar-body {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #000;
}

.calendar-weekdays {
  display: contents;
}

/* 曜日行: グレー・やや小さいフォント・薄い背景・下線で日付と区別 */
.calendar-weekdays span {
  padding: 0.35rem 0;
  font-size: 0.8rem;
  font-weight: 400;
  color: #666;
  text-align: center;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
}

.calendar-grid {
  display: contents;
}

.day {
  aspect-ratio: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  font-size: 0.9375rem;
  color: #000;
  background: transparent;
  border-radius: 6px;
  min-height: 0;
  overflow: hidden;
}

/* 日付エリア: 白背景・縦幅固定(比率)・上下左右センタリング ※倍率の有無で共通 */
.day-date {
  flex: 0 0 45%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 6px 6px 0 0;
  font-size: 0.9375rem;
  color: inherit;
}

/* 倍率エリア: 縦幅固定(比率)・上詰め ※倍率表示の有無で同じ高さに統一 */
.day-multiplier {
  flex: 0 0 55%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2px 2px 4px;
  background: #fff;
  border-radius: 0 0 6px 6px;
  overflow: hidden;
}

.day.highlight-gray .day-date {
  background: #fff;
}

.day.highlight-gray .day-multiplier {
  background: #e8e8e8;
}

/* 倍率表示がある日: 日付・倍率全体を黄色の枠で囲む */
.day.highlight-yellow {
  box-shadow: 0 0 0 1px #e6d32a;
}

.day.highlight-yellow .day-multiplier {
  background: #fdf6b0;
}

.day.other-month .day-date,
.day.other-month .day-multiplier {
  background: transparent;
  color: #999;
}

/* 前月・翌月も日付/倍率の2段レイアウトは同じ（背景のみ透明） */
.day.other-month .day-date {
  border-radius: 6px 6px 0 0;
}

.day.other-month .day-multiplier {
  padding: 2px 2px 4px;
}

/* 最終週で翌月が不要な場合の空セル（グリッド維持用） */
.day--empty {
  pointer-events: none;
  cursor: default;
  visibility: hidden;
}

.day--empty .day-date,
.day--empty .day-multiplier {
  background: transparent;
}

/* 過去の日付: 文字・倍率を薄いグレーで弱める */
.day.past .day-date,
.day.past .day-multiplier,
.day.past .date-sub {
  color: #a0a0a0;
}

.day.past.highlight-gray .day-multiplier {
  background: #eee;
}

.day.past.highlight-yellow .day-multiplier {
  background: #f5f0d4;
}

/* 今日: 楽天クリムゾンレッドの枠で強調 */
.day.today {
  box-shadow: 0 0 0 2px #e60012;
}

/* 倍率行: FIX/MAX 合計。翌日以降は予想表記。MAX のみの翌日以降は「予想」＋「Max +N倍」で2行 */
.day .date-sub {
  display: block;
  font-size: clamp(0.5rem, 2vw, 0.75rem);
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.day .date-sub:first-of-type {
  margin-top: 0;
}

.day .date-sub + .date-sub {
  margin-top: 1px;
}

/* 日付クリックでポップアップ表示 */
.day {
  cursor: pointer;
}

/* ポップアップオーバーレイ */
.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.popup-overlay[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
}

body.popup-is-open {
  overflow: hidden;
}

.popup-backdrop {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

.popup-box {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.popup-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: #666;
  cursor: pointer;
}

.popup-close:hover {
  color: #000;
}

.popup-title {
  margin: 0;
  padding: 1rem 1rem 0.25rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: #000;
}

.popup-disclaimer {
  margin: 0;
  padding: 0 1rem 0.5rem;
  font-size: 0.75rem;
  color: #888;
}

.popup-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 1rem 1rem;
}

.campaign-empty {
  margin: 0;
  padding: 1rem 0;
  font-size: 0.875rem;
  color: #666;
}

/* キャンペーン一覧 */
.campaign-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.campaign-block {
  padding: 0.75rem 0;
  border-bottom: 1px solid #e8e8e8;
}

.campaign-block:last-child {
  border-bottom: none;
}

.campaign-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.campaign-name {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #000;
}

/* ポップアップ内の倍率バッジ：キャンペーン名と区別しやすく */
.campaign-rate-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #c41230;
  background: #fde8eb;
  border: 1px solid #e60012;
  border-radius: 4px;
  padding: 0.15em 0.5em;
  vertical-align: baseline;
}

/* ポップアップ内の未確定バッジ（Tentative=1）：倍率バッジの右隣 */
.campaign-tentative-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #5a4a00;
  background: #f5f0d4;
  border: 1px solid #d4c44a;
  border-radius: 4px;
  padding: 0.15em 0.4em;
  vertical-align: baseline;
}

.campaign-entry {
  font-size: 0.8125rem;
  color: #e60012;
  text-decoration: none;
}

.campaign-entry:hover {
  text-decoration: underline;
}

.campaign-period {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  color: #666;
}

/* アコーディオン（開閉） */
.campaign-accordion {
  margin: 0;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.campaign-accordion summary {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #333;
  background: #f5f5f5;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.campaign-accordion summary::-webkit-details-marker {
  display: none;
}

.campaign-accordion summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 0.35rem;
  font-size: 0.65rem;
  transition: transform 0.2s;
}

.campaign-accordion[open] summary::before {
  transform: rotate(90deg);
}

.campaign-accordion .campaign-desc {
  margin: 0;
  padding: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: #333;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}

/* ページフッター */
.page-footer {
  flex-shrink: 0;
  padding: 1.5rem;
  background: #f5f5f5;
  border-top: 1px solid #e0e0e0;
}

.page-footer-inner {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.page-footer-links {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-footer-links a {
  font-size: 0.8125rem;
  color: #666;
  text-decoration: none;
}

.page-footer-links a:hover {
  color: #e60012;
  text-decoration: underline;
}

/* キャッシュ更新フォーム */
.update-cache-form {
  max-width: 400px;
  margin: 2rem auto;
  padding: 2rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.update-cache-form h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  box-sizing: border-box;
}

.form-input:focus {
  outline: none;
  border-color: #e60012;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background-color: #e60012;
  color: white;
}

.btn-primary:hover {
  background-color: #cc0010;
}

.alert {
  padding: 1rem;
  margin-bottom: 1.5rem;
  border-radius: 4px;
}

.alert-error {
  background-color: #fee;
  color: #c33;
  border: 1px solid #fcc;
}

.alert-success {
  background-color: #efe;
  color: #3c3;
  border: 1px solid #cfc;
}
