:root {
  --bg: #f4f6f8;
  --text: #17212b;
  --muted: #6b7785;
  --line: #d8dee6;
  --surface: #ffffff;
  --primary: #2386d1;
  --day: #ffd166;
  --night: #4056a1;
  --rest: #dfe7ee;
  --sleep: #9be7c0;
  --vacation: #f59ac2;
  --other: #c8b6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.languageWelcome {
  display: grid;
  gap: 18px;
  min-height: min(520px, calc(100vh - 32px));
  place-content: center;
  text-align: center;
}

.languageWelcome p {
  color: var(--muted);
  margin: 8px 0 0;
}

.welcomeLanguageButtons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 150px));
  gap: 10px;
  justify-content: center;
}

.welcomeLanguageButtons button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
}

.welcomeLanguageButtons button:hover {
  border-color: var(--primary);
}

.topbar,
.calendarHead,
.dialogHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 22px;
  text-align: center;
}

.primary,
.secondary,
.calendarHead button,
.dialogHead button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

.saveBottom {
  display: block;
  width: 100%;
  margin: 16px 0 0;
}

.secondary {
  background: #dfe7ee;
  color: var(--text);
}

.calendarHead button,
.dialogHead button {
  width: 44px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

.setup,
.reminders,
.custom,
.weekdayPanel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.reminders {
  grid-template-columns: 1.2fr 1fr 1fr;
}

.timePresets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-self: end;
}

.languageToggle {
  display: grid;
  grid-template-columns: 1fr 58px 58px;
  gap: 4px;
  align-items: end;
}

.topLanguage {
  grid-template-columns: repeat(2, minmax(0, 92px));
  border: 1px solid rgba(35, 134, 209, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 22px rgba(23, 33, 43, 0.08);
  padding: 3px;
}

.topLanguage > span {
  display: none;
}

.languageToggle > span {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
}

.languageToggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.languageToggle button.active {
  background: linear-gradient(135deg, #2386d1, #14c08a);
  box-shadow: 0 8px 18px rgba(35, 134, 209, 0.28);
  color: #fff;
  transform: translateY(-1px);
}

.flag {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.16), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.flag-ru {
  background-image: none;
  background: linear-gradient(to bottom, #fff 0 33.33%, #2f6edb 33.33% 66.66%, #e4313f 66.66% 100%);
}

.flag-uz {
  background-image: none;
  background: linear-gradient(to bottom, #28aee4 0 36%, #d83742 36% 40%, #fff 40% 60%, #d83742 60% 64%, #24a96b 64% 100%);
}

.timePresets button,
.weekdayPanel label {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.timePresets button {
  min-height: 32px;
  border-radius: 999px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
}

.weekdayPanel {
  grid-template-columns: 120px repeat(7, minmax(0, 1fr));
  align-items: center;
}

.weekdayPanel > span {
  color: var(--muted);
  font-size: 13px;
}

.weekdayPanel label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text);
}

.weekdayPanel input {
  width: 18px;
  min-height: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--text);
}

.toggle input {
  width: 20px;
  min-height: 20px;
}

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

.custom > span {
  color: var(--muted);
  font-size: 13px;
}

.custom p {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.cycleBuilder,
.cycleActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cycleActions button,
.cycleChip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
}

.cycleChip {
  font-weight: 700;
}

.hidden {
  display: none;
}

.calendarShell {
  margin-top: 10px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  margin-bottom: 12px;
  padding: 12px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.stat strong {
  display: block;
  font-size: 24px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

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

.weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.day {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.day.outside {
  opacity: 0.45;
}

.day.today {
  outline: 2px solid var(--primary);
}

.dateNum {
  display: block;
  color: var(--text);
  font-weight: 700;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 7px;
  padding: 2px 8px;
  color: #17212b;
  font-size: 12px;
  white-space: nowrap;
}

.kind-day .badge {
  background: var(--day);
}

.kind-night .badge {
  background: var(--night);
  color: #fff;
}

.kind-rest .badge {
  background: var(--rest);
}

.kind-sleep .badge {
  background: var(--sleep);
}

.kind-vacation .badge {
  background: var(--vacation);
}

.kind-other .badge {
  background: var(--other);
}

body.night {
  --bg: #121823;
  --text: #f4f7fb;
  --muted: #a9b4c2;
  --line: #2b3444;
  --surface: #1b2432;
  --primary: #4aa3ff;
  --day: #ffd166;
  --night: #6574d8;
  --rest: #344052;
  --sleep: #35c995;
  --vacation: #f072aa;
  --other: #a994ff;
}

body.night input,
body.night select,
body.night .day,
body.night .languageToggle button,
body.night .welcomeLanguageButtons button,
body.night .timePresets button,
body.night .weekdayPanel label,
body.night .cycleActions button,
body.night .cycleChip {
  background: #141c28;
  border-color: var(--line);
  color: var(--text);
}

body.night .dateNum {
  color: #f4f7fb;
}

body.night .secondary {
  background: #2b3444;
  color: var(--text);
}

body.night .summary {
  background: #141c28;
}

body.night .topLanguage {
  background: rgba(20, 28, 40, 0.9);
  border-color: var(--line);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

dialog {
  width: min(420px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.22);
}

dialog::backdrop {
  background: rgba(23, 33, 43, 0.35);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(80px);
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  padding: 10px 14px;
  opacity: 0;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 760px) {
  .app {
    padding: 12px;
  }

  .setup,
  .reminders,
  .weekdayPanel,
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .weekdayPanel > span {
    grid-column: 1 / -1;
  }

  .topbar {
    align-items: flex-start;
  }

  .topActions {
    flex-direction: column;
    align-items: flex-end;
  }

  .topLanguage {
    grid-template-columns: repeat(2, minmax(0, 82px));
  }

  h1 {
    font-size: 24px;
  }

  .day {
    min-height: 64px;
    padding: 6px;
  }

  .badge {
    width: 100%;
    padding: 2px 4px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .setup,
  .reminders,
  .weekdayPanel {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .weekdays,
  .calendar {
    gap: 4px;
  }

  .day {
    min-height: 58px;
  }

  .dateNum {
    margin-bottom: 6px;
  }

  .badge {
    font-size: 0;
    min-height: 22px;
    padding: 2px;
  }

  .badge::after {
    content: attr(data-short);
    font-size: 11px;
    line-height: 1;
  }
}
