:root {
  --primary: #3b82f6;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --border: #e2e8f0;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  margin: 0;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 32px 12px;
  min-height: 100vh;
}

/* PDF 区域包裹（标题 + 日历） */
#pdfArea {
  max-width: 1300px;          /* 更宽一点 */
  margin: 0 auto 32px;
  padding-bottom: 0;
}

/* === Header === */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 0 8px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.month-title {
  font-size: 28px;            /* 原来 20px，接近之前放大后的效果 */
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  width: 52px;                /* 原 36px */
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:active {
  transform: scale(0.92);
  background: #f1f5f9;
}

.btn-today {
  font-size: 14px;
  font-weight: 600;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
}

/* Print button 只是普通图标按钮，沿用 .btn-icon */
.btn-print i {
  font-size: 20px;
}

.btn-settings {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.btn-settings:active {
  transform: scale(0.96);
}

/* === 明日バナー === */
.tomorrow-banner {
  margin: 0 0 20px;
  padding: 14px 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.28);
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tomorrow-banner i {
  font-size: 20px;
  margin-top: 2px;
}

.tomorrow-banner .banner-content {
  display: flex;
  flex-direction: column;
}

.tomorrow-banner small {
  font-size: 12px;
  opacity: 0.9;
  font-weight: 400;
  margin-top: 4px;
}

/* === カレンダー本体 === */
.calendar-container {
  background: var(--bg-card);
  border-radius: 20px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
  border: 2px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.calendar-inner {
  width: 100%;
  max-width: 900px;           /* 桌面最多 900px，窄屏缩小 */
  margin: 0 auto;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
}

.weekdays div {
  padding: 14px 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sub);
}

.weekdays div.sun {
  color: #ef4444;
}

.weekdays div.sat {
  color: #3b82f6;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  auto-rows: minmax(120px, auto);   /* 原 85px，更高一点 */
}

.day-cell {
  border-right: 1.8px solid var(--border);
  border-bottom: 1.8px solid var(--border);
  padding: 6px;
  position: relative;
  background: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: background 0.1s;
}

.day-cell:nth-child(7n) {
  border-right: none;
}

.day-cell:active {
  background: #f1f5f9;
}

.day-cell.today {
  background: #fffbeb;
  position: relative;
}

.day-cell.today::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid #fbbf24;
  pointer-events: none;
  z-index: 1;
}

body.exporting-pdf .day-cell.today::after {
  display: none;
}

.date-num {
  text-align: center;
  font-size: 18px;           /* 原 14px */
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}

.day-cell.sun .date-num {
  color: #ef4444;
}

.day-cell.sat .date-num {
  color: #3b82f6;
}

/* 祝日：日曜日以外でも赤字にする */
.day-cell.holiday .date-num {
  color: #ef4444;
}

.day-cell.other-month {
  background: #fcfcfc;
  opacity: 0.5;
  pointer-events: none;
}

.labels-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.mini-label {
  font-size: 12px;           /* 原 10px */
  padding: 3px 6px;
  border-radius: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  line-height: 1.3;
}

/* === Legend === */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
  justify-content: center;
  padding-bottom: 24px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-sub);
  background: white;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* === Modal 共通 === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: white;
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  border-radius: 20px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
}

.modal-close-btn {
  background: #f1f5f9;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* === Settings === */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setting-group {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.setting-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 15px;
  justify-content: space-between;
}

.setting-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-indicator {
  width: 4px;
  height: 18px;
  border-radius: 2px;
}

.delete-type-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
}

/* 無効バッジ */
.badge-muted {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #6b7280;
}

.mode-selector {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.mode-option {
  flex: 1;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-sub);
  transition: all 0.2s;
  font-weight: 500;
}

.mode-option.active {
  background: white;
  color: var(--text-main);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  font-weight: 700;
}

.week-selector,
.nth-selector {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.toggle-btn {
  flex: 1;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn.active {
  background: var(--text-main);
  color: white;
  border-color: var(--text-main);
}

.hidden {
  display: none !important;
}

.btn-save {
  background: var(--text-main);
  color: white;
  padding: 10px 26px;
  border-radius: 99px;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.btn-reset {
  background: transparent;
  color: #ef4444;
  padding: 10px 16px;
  border-radius: 99px;
  border: none;
  font-size: 13px;
  cursor: pointer;
}

.btn-add-type {
  background: #3b82f6;
  color: white;
  padding: 8px 16px;
  border-radius: 999px;
  border: none;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin-bottom: 12px;
}

/* === 詳細モーダル === */
.detail-date {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
}

.detail-meta {
  color: var(--text-sub);
  font-size: 14px;
  margin-bottom: 18px;
}

.detail-item {
  display: flex;
  align-items: center;
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 10px;
  background: #f8fafc;
  border: 1px solid transparent;
}

.detail-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-right: 14px;
}

.detail-name {
  font-weight: 700;
  font-size: 16px;
}

.detail-empty {
  text-align: center;
  padding: 32px;
  color: var(--text-sub);
  background: #f8fafc;
  border-radius: 12px;
  border: 1px dashed var(--border);
}

/* === PDF 出力用スタイル調整 === */
body.exporting-pdf #bannerContainer,
body.exporting-pdf .legend {
  display: none !important; /* 明日バナーと凡例は非表示 */
}

body.exporting-pdf .btn-icon,
body.exporting-pdf .btn-settings {
  display: none !important; /* すべてのボタンを隠す（前月・次月・今日・印刷・設定） */
}

body.exporting-pdf .header {
  justify-content: center;
}

body.exporting-pdf .month-nav {
  justify-content: center;
}

body.exporting-pdf .month-title {
  font-size: 30px;
}

/* PDF 用：レイアウトはそのまま */
body.exporting-pdf #pdfArea {
  margin-bottom: 24px;
}

/* === Responsive === */
@media (max-width: 480px) {
  body {
    padding-left: 8px;
    padding-right: 8px;
  }

  #pdfArea {
    max-width: 100%;
    margin-bottom: 24px;
  }

  .calendar-inner {
    min-width: 0;
    width: 100%;
  }

  .weekdays div {
    padding: 10px 0;
    font-size: 12px;
  }

  .days-grid {
    auto-rows: minmax(90px, auto);
  }

  .date-num {
    font-size: 15px;
  }

  .mini-label {
    font-size: 10px;
    white-space: normal;
    line-height: 1.2;
  }
}

/* =========================================
   📱 手机端：标题分两行 & 按钮统一大小
   ========================================= */
@media (max-width: 480px) {

  /* 标题整体改成纵向排列（两行） */
  .header {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  /* 第一行：月份切换 & 标题 */
  .month-nav {
    width: 100%;
    justify-content: center;
    gap: 14px;
  }

  /* 第二行：按钮（今日 / 打印 / 设置） */
  .header-actions {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-top: 4px;
  }

  .btn-icon,
  .btn-settings {
    width: 52px !important;
    height: 52px !important;
    font-size: 18px;
  }

  /* 设置按钮背景为白色（与其他统一）*/
  .btn-settings {
    background: #ffffff !important;
    color: var(--text-main) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  }
}

/* (オプション) ダークモード簡易対応 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #0f172a;
    --bg-card: #020617;
    --text-main: #e5e7eb;
    --text-sub: #9ca3af;
    --border: #1f2933;
  }

  body {
    background-color: var(--bg-body);
    color: var(--text-main);
  }

  .calendar-container,
  .setting-group,
  .modal-card,
  .legend-item,
  .day-cell {
    background-color: var(--bg-card);
    border-color: var(--border);
  }

  .weekdays {
    background: #020617;
  }

  .detail-empty {
    background: #020617;
  }

  .btn-icon {
    background: #020617;
  }
}

/* === Fix header overflow while keeping calendar scrollable === */

/* Prevent the whole page from horizontal overflow  */
/*
body {
  overflow-x: hidden;
}
*/

/* Make header & controls not affected by wide calendar */
.header, .month-nav, .header-actions {
  max-width: 100%;
  overflow-x: hidden;
}
