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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f0f4f8;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px;
}

.app {
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  overflow: hidden;
  align-self: flex-start;
}

/* ヘッダー */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #4a7fd4;
  color: #fff;
  padding: 14px 16px;
}

.month-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.nav-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 8px;
  border-radius: 4px;
  transition: background 0.15s;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.2);
}

/* 曜日ヘッダー */
.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #e8eef7;
}

.weekday {
  text-align: center;
  padding: 6px 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
}

.weekday.sun { color: #e05555; }
.weekday.sat { color: #4a7fd4; }

/* カレンダーグリッド */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid #e0e8f0;
}

.day-cell {
  min-height: 64px;
  padding: 4px;
  border-right: 1px solid #e0e8f0;
  border-bottom: 1px solid #e0e8f0;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.day-cell:nth-child(7n) {
  border-right: none;
}

.day-cell:hover {
  background: #f0f4fb;
}

.day-cell.empty {
  cursor: default;
  background: #fafafa;
}

.day-cell.empty:hover {
  background: #fafafa;
}

.day-cell.today .day-num {
  background: #4a7fd4;
  color: #fff;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.day-cell.sunday .day-num { color: #e05555; }
.day-cell.saturday .day-num { color: #4a7fd4; }
.day-cell.today .day-num { color: #fff; }

.day-num {
  font-size: 0.85rem;
  font-weight: 600;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.event-dots {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.event-dot {
  background: #4a7fd4;
  color: #fff;
  font-size: 0.65rem;
  border-radius: 3px;
  padding: 1px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* モーダル */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #4a7fd4;
  color: #fff;
  padding: 12px 16px;
}

.modal-date {
  font-size: 1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.modal-body {
  padding: 16px;
}

.event-list {
  list-style: none;
  margin-bottom: 12px;
  max-height: 200px;
  overflow-y: auto;
}

.event-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: #f0f4fb;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.event-item:last-child {
  margin-bottom: 0;
}

.event-text {
  flex: 1;
  word-break: break-all;
}

.delete-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 8px;
  flex-shrink: 0;
  transition: color 0.15s;
}

.delete-btn:hover {
  color: #e05555;
}

.no-events {
  text-align: center;
  color: #aaa;
  font-size: 0.85rem;
  padding: 12px 0;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #cdd;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.input-row input:focus {
  border-color: #4a7fd4;
}

.add-btn {
  padding: 8px 16px;
  background: #4a7fd4;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.add-btn:hover {
  background: #3a6fc4;
}

@media (max-width: 375px) {
  .day-cell {
    min-height: 52px;
    padding: 2px;
  }

  .day-num {
    font-size: 0.75rem;
    width: 22px;
    height: 22px;
  }

  .event-dot {
    font-size: 0.6rem;
  }

  .month-title {
    font-size: 1rem;
  }
}
