:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-border: #d9dee3;
  --text: #111111;
  --muted: #6f7780;
  --accent: #2596a6;
  --accent-soft: #dff3f6;
  --danger: #d62828;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --weekday: #20252b;
  --day-size: 52px;
  --gap: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

input[type="date"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
  outline: none;
}

input[type="date"]:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 150, 166, 0.12);
}

input[type="color"] {
  width: 100%;
  height: 46px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: #fff;
  padding: 4px;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  margin-bottom: 14px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 32px;
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.content {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.controls {
  padding: 16px;
}

.control-group + .control-group {
  margin-top: 14px;
}

.control-group label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-btn,
.mode-btn,
.apply-btn,
.nav-btn {
  transition: 0.18s ease;
}

.preset-btn {
  padding: 11px 16px;
  border-radius: 14px;
  background: #eef2f5;
  color: #222;
  border: 1px solid transparent;
  font-weight: 700;
}

.preset-btn:hover {
  background: #e5edf1;
}

.preset-btn.active {
  background: var(--accent-soft);
  color: #0e5560;
  border-color: rgba(37, 150, 166, 0.35);
}

.custom-cycle-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.mini-label {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.apply-btn {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.apply-btn:hover {
  transform: translateY(-1px);
  filter: brightness(0.98);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.toggle-row {
  margin-top: 14px;
  display: inline-flex;
  gap: 8px;
  background: #edf1f4;
  border-radius: 16px;
  padding: 5px;
}

.mode-btn {
  padding: 10px 16px;
  border-radius: 12px;
  color: #2b3138;
  font-weight: 700;
}

.mode-btn.active {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  overflow: hidden;
}

.summary-box {
  padding: 18px 16px;
  text-align: center;
  border-right: 1px solid var(--panel-border);
}

.summary-box:last-child {
  border-right: none;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 6px;
}

.summary-box strong {
  font-size: 28px;
  line-height: 1;
}

.calendar-panel {
  padding: 16px;
}

.calendar-header {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.calendar-title-wrap {
  text-align: center;
}

.calendar-title-wrap h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.05;
}

.calendar-title-wrap p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.nav-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: #eef2f5;
  font-size: 30px;
  line-height: 1;
  color: #28313a;
}

.nav-btn:hover {
  background: #e5edf1;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--gap);
  margin-bottom: 10px;
  padding: 0 2px;
}

.weekdays div {
  text-align: center;
  font-weight: 800;
  color: var(--weekday);
  font-size: 15px;
}

.calendar-container {
  display: grid;
  gap: 28px;
}

.month-block {
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 18px 14px 14px;
}

.month-title {
  margin: 0 0 14px;
  text-align: center;
  font-size: 28px;
  line-height: 1.05;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--gap);
  justify-items: center;
}

.day-cell {
  width: 100%;
  display: flex;
  justify-content: center;
}

.day-empty {
  width: var(--day-size);
  height: var(--day-size);
}

.day-btn {
  width: var(--day-size);
  height: var(--day-size);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  line-height: 1;
  color: #111;
  background: transparent;
  border: 2px solid transparent;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.day-btn.filled {
  color: var(--filled-text, #fff);
}

.day-btn.selected {
  box-shadow: 0 0 0 4px rgba(214, 40, 40, 0.15);
  transform: scale(1.03);
}

.day-btn.today-ring {
  border-color: rgba(37, 150, 166, 0.5);
}

.legend-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 14px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.legend-dot {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.year-grid .month-title {
  font-size: 22px;
}

.year-grid .day-btn,
.year-grid .day-empty {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.footer-space {
  height: 4px;
}

@media (max-width: 760px) {
  :root {
    --day-size: 46px;
    --gap: 8px;
  }

  .app {
    padding: 12px;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .calendar-title-wrap h2 {
    font-size: 24px;
  }

  .month-title {
    font-size: 24px;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  .summary-box {
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }

  .summary-box:last-child {
    border-bottom: none;
  }

  .color-grid {
    grid-template-columns: 1fr;
  }

  .custom-cycle-row {
    grid-template-columns: 1fr 1fr;
  }

  .custom-cycle-action {
    grid-column: 1 / -1;
  }

  .apply-btn {
    width: 100%;
  }

  .year-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  :root {
    --day-size: 42px;
    --gap: 6px;
  }

  .controls,
  .calendar-panel {
    padding: 14px;
  }

  .calendar-header {
    grid-template-columns: 44px 1fr 44px;
  }

  .nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    font-size: 26px;
  }

  .weekdays div {
    font-size: 13px;
  }

  .day-btn {
    font-size: 17px;
  }

  .month-block {
    padding: 16px 10px 12px;
  }
}