:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-weak: #fafafa;
  --control: #ffffff;
  --control-hover: #f8fbff;
  --text: #1d2433;
  --muted: #6b7280;
  --faded: #9ca3af;
  --line: #d9dee8;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --weekend: #c2410c;
  --danger: #b42318;
  --danger-line: #f2b8b5;
  --danger-soft: #fff4f2;
  --focus: rgba(37, 99, 235, 0.16);
  --shadow: 0 18px 50px rgba(25, 31, 45, 0.1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --panel: #191d24;
  --panel-weak: #151922;
  --control: #202633;
  --control-hover: #263044;
  --text: #eef2f8;
  --muted: #aeb7c7;
  --faded: #788397;
  --line: #303746;
  --accent: #74a7ff;
  --accent-soft: #1d2f52;
  --weekend: #ffb076;
  --danger: #ff9b92;
  --danger-line: #7a3638;
  --danger-soft: #321e22;
  --focus: rgba(116, 167, 255, 0.22);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 180ms ease, color 180ms ease;
}

button,
input {
  font: inherit;
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.calendar,
.details {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.calendar {
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.month-title {
  min-width: 170px;
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-button,
.today-button,
.theme-button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.icon-button {
  width: 38px;
  font-size: 20px;
  line-height: 1;
}

.today-button,
.theme-button {
  padding: 0 14px;
  font-weight: 650;
}

.theme-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 86px;
  justify-content: center;
}

.icon-button:hover,
.today-button:hover,
.theme-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--control-hover);
}

.weekdays,
.days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.weekday:first-child,
.weekday:last-child {
  color: var(--weekend);
}

.day {
  position: relative;
  min-height: 118px;
  padding: 10px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

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

.day:hover {
  background: var(--control-hover);
}

.day.other-month {
  background: var(--panel-weak);
  color: var(--faded);
}

.day.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  background: var(--accent-soft);
}

.day.today .date-number {
  background: var(--accent);
  color: var(--panel);
}

.date-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  font-weight: 750;
}

.note-preview {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}

.note-dot {
  position: absolute;
  right: 10px;
  top: 18px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

.details {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
  padding: 18px;
  min-height: 280px;
}

.selected-summary {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 240px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
}

.selected-month,
.selected-weekday {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.selected-day {
  margin: 8px 0;
  color: var(--accent);
  font-size: 92px;
  font-weight: 850;
  line-height: 0.95;
  letter-spacing: 0;
}

.todo-panel {
  min-width: 0;
}

.todo-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.todo-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.todo-count {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.todo-form {
  margin-bottom: 16px;
}

.todo-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

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

#todoInput {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--text);
}

#todoInput::placeholder {
  color: var(--faded);
}

#todoInput:focus {
  border-color: var(--accent);
  outline: 3px solid var(--focus);
}

.add-button {
  height: 42px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--panel);
  cursor: pointer;
  font-weight: 750;
}

.add-button:hover {
  filter: brightness(0.96);
}

.todo-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.todo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
}

.todo-check {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  gap: 10px;
  cursor: pointer;
}

.todo-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.todo-text {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.todo-item.done .todo-text {
  color: var(--muted);
  text-decoration: line-through;
}

.empty-message {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.delete-button {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--danger-line);
  border-radius: 8px;
  background: var(--control);
  color: var(--danger);
  cursor: pointer;
  font-weight: 650;
}

.delete-button:hover {
  background: var(--danger-soft);
}

@media (max-width: 840px) {
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .day {
    min-height: 92px;
    padding: 8px;
  }

  .note-preview {
    display: none;
  }

  .details {
    grid-template-columns: 1fr;
  }

  .selected-summary {
    min-height: auto;
  }

  .selected-day {
    font-size: 72px;
  }
}

@media (max-width: 520px) {
  .app {
    width: min(100% - 16px, 1180px);
    margin: 8px auto;
  }

  .month-title {
    font-size: 20px;
  }

  .controls {
    width: 100%;
  }

  .theme-button {
    min-width: 78px;
  }

  .weekday {
    padding: 10px 4px;
  }

  .day {
    min-height: 62px;
  }

  .date-number {
    width: 28px;
    height: 28px;
  }

  .todo-input-row {
    flex-direction: column;
  }

  .add-button {
    width: 100%;
  }
}
