:root {
  --bg-color: #fdfaf6;
  --text-color: #2c1f14;
  --primary-color: #4a7c59;
  --sunday-bg: #fbeaea;
  --saturday-bg: #e8f1f8;
  --today-border: 2px solid #a4d4a4;
  --event-bg: #a0cba0;
  --dark-bg: #122212;
  --dark-text: #a6d6a6;
  --dark-primary: #7db87d;
}
@media (prefers-color-scheme: dark) {
  body {
    background: var(--dark-bg);
    color: var(--dark-text);
  }
  header h1, #calendar-header button {
    color: var(--dark-primary);
  }
  table, th, td {
    border-color: #4a7c59;
  }
  td.sunday { background: #330000; color: #ff8888; }
  td.saturday { background: #001144; color: #88ccff; }
  td.today { border: 2px solid #7db87d; background: #224422; }
  #modal, #settings-modal {
    background: #223322;
    color: var(--dark-text);
  }
  #modal-bg, #settings-modal-bg {
    background: rgba(10,30,10,0.85);
  }
  button {
    background: var(--dark-primary);
    color: var(--dark-bg);
  }
  button:hover {
    background: #a4d4a4;
    color: var(--dark-bg);
  }
}
body {
  background: var(--bg-color);
  color: var(--text-color);
  font-family: "Yu Mincho", serif;
  margin: 0; padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
#header-icon {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 0 1px #333);
}
h1 {
  color: var(--primary-color);
  margin: 0;
  font-size: 1.6rem;
}
#settings-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  margin-left: auto;
  color: var(--primary-color);
  transition: color 0.3s ease;
}
#settings-btn:hover, #settings-btn:focus {
  color: #357a32;
  outline: none;
}
#calendar {
  max-width: 720px;
  width: 100%;
  background: white;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(0,0,0,0.1);
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}
#calendar-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
#month-year {
  font-weight: bold;
  font-size: 1.2rem;
  min-width: 140px;
  text-align: center;
}
button {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.3s ease;
}
button:hover {
  background-color: #357a32;
}
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  word-break: break-word;
}
th, td {
  border: 1px solid #ccc;
  padding: 6px;
  height: 80px;
  text-align: left;
  vertical-align: top;
  user-select: none;
  overflow: hidden;
}
td.sunday { background: var(--sunday-bg); color: #d00; }
td.saturday { background: var(--saturday-bg); color: #0078d7; }
td.today { border: var(--today-border); background: #e6f4e6; }
td.adjacent-month {
  color: #999;
  background: #f0f0f0;
  cursor: default !important;
}
.event {
  background: var(--event-bg);
  color: #111;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 13px;
  margin: 4px 0 2px 0;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event-tag {
  padding: 0 4px;
  margin-left: 6px;
  border-radius: 4px;
  font-size: 0.75em;
  color: white;
  display: inline-block;
}
.modal-bg, #settings-modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}
#modal, #settings-modal {
  background: white;
  border-radius: 10px;
  padding: 20px;
  width: 90%;
  max-width: 480px;
  box-sizing: border-box;
  max-height: 90vh;
  overflow-y: auto;
}
textarea, input[type="time"], input[type="color"], input[type="text"] {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 14px;
  box-sizing: border-box;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 6px;
  resize: vertical;
}
.modal-buttons {
  text-align: right;
}
.modal-buttons button {
  margin-left: 8px;
  font-size: 14px;
}
#today-button {
  margin: 15px auto 30px auto;
  width: 140px;
}
#tag-color-list > div {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#tag-color-list label {
  flex-grow: 1;
  font-weight: bold;
}
#tag-color-list input[type="color"] {
  width: 40px;
  height: 30px;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 4px;
}
.tag-row {
  border: 1px solid #ccc;
  padding: 6px 8px;
  border-radius: 6px;
  background: #f7f7f7;
}
.tag-row:hover {
  background: #e0e0e0;
}
.tag-row button {
  background: #4a7c59;
  border: none;
  color: white;
  cursor: pointer;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.85em;
}
.tag-row button:hover {
  background: #357a32;
}
@media (max-width: 600px) {
  #calendar {
    padding: 8px;
  }
  th, td {
    font-size: 12px;
    height: 60px;
    padding: 4px;
  }
  #month-year {
    font-size: 1rem;
  }
  button {
    padding: 5px 8px;
    font-size: 14px;
  }
  textarea, input[type="time"] {
    font-size: 13px;
  }
}
