:root {
  --bg: var(--tg-theme-bg-color, #f5f5f7);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --muted: var(--tg-theme-hint-color, #8b8b95);

  --accent: #7c3aed;
  --border: rgba(0, 0, 0, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "SF Pro Display",
    "Segoe UI",
    sans-serif;
}

.app {
  max-width: 700px;
  margin: 0 auto;
  padding: 22px 16px 40px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.logo {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  margin-bottom: 8px;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.04em;
}

.top p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.avatar {
  width: 48px;
  height: 48px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 16px;

  background: var(--accent);
  color: white;

  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 32px;
}

.stats > div {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.stats strong {
  font-size: 24px;
  letter-spacing: -0.04em;
}

.section-title {
  margin-bottom: 15px;
}

.section-title h2 {
  margin: 0;
  font-size: 20px;
}

.section-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.task {
  display: flex;
  gap: 14px;

  background: var(--card);
  border: 1px solid var(--border);

  border-radius: 19px;

  padding: 17px;
  margin-bottom: 10px;
}

.check {
  flex-shrink: 0;

  width: 26px;
  height: 26px;

  border-radius: 50%;

  border: 2px solid rgba(124, 58, 237, 0.3);

  background: transparent;

  cursor: pointer;

  color: white;
  font-weight: 800;
}

.completed .check {
  background: var(--accent);
  border-color: var(--accent);
}

.content {
  min-width: 0;
  flex: 1;
}

.subject {
  color: var(--accent);

  font-size: 11px;
  font-weight: 800;

  letter-spacing: 0.08em;
  text-transform: uppercase;

  margin-bottom: 5px;
}

.title {
  font-size: 16px;
  font-weight: 750;
}

.description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;

  margin-top: 6px;
}

.deadline {
  display: inline-block;

  margin-top: 10px;

  padding: 6px 9px;

  border-radius: 9px;

  background: rgba(124, 58, 237, 0.1);

  color: var(--accent);

  font-size: 11px;
  font-weight: 700;
}

.completed {
  opacity: 0.55;
}

.completed .title {
  text-decoration: line-through;
}

.loading,
.empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}

@media (max-width: 420px) {
  .stats {
    gap: 7px;
  }

  .stats > div {
    padding: 13px;
  }

  .stats strong {
    font-size: 21px;
  }
}

/* =========================
   ADD HOMEWORK
========================= */

.add-button {
  border: none;
  background: #7c3aed;
  color: white;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.add-button:active {
  transform: scale(0.96);
}


/* MODAL */

.modal {
  position: fixed;
  inset: 0;

  display: flex;
  align-items: flex-end;
  justify-content: center;

  background: rgba(0, 0, 0, 0.55);

  opacity: 0;
  pointer-events: none;

  transition: 0.2s ease;

  z-index: 1000;
}

.modal.open {
  opacity: 1;
  pointer-events: auto;
}


.modal-content {
  width: 100%;
  max-width: 700px;

  background: #111116;

  border-radius: 24px 24px 0 0;

  padding: 22px;

  box-sizing: border-box;

  transform: translateY(30px);

  transition: 0.2s ease;
}

.modal.open .modal-content {
  transform: translateY(0);
}


.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;

  margin-bottom: 22px;
}


.modal-title {
  font-size: 22px;
  font-weight: 800;
}


.modal-subtitle {
  margin-top: 4px;

  font-size: 13px;

  color: #8f8f9a;
}


.close-button {
  width: 36px;
  height: 36px;

  border: none;
  border-radius: 50%;

  background: #222229;
  color: #fff;

  font-size: 24px;

  cursor: pointer;
}


.modal form {
  display: flex;
  flex-direction: column;

  gap: 16px;
}


.modal label {
  display: flex;
  flex-direction: column;

  gap: 7px;

  font-size: 13px;
  font-weight: 600;

  color: #aaaab5;
}


.modal input,
.modal textarea {
  width: 100%;

  box-sizing: border-box;

  border: 1px solid #2b2b35;
  border-radius: 13px;

  background: #19191f;
  color: white;

  padding: 13px;

  font-size: 15px;

  outline: none;

  font-family: inherit;
}


.modal input:focus,
.modal textarea:focus {
  border-color: #7c3aed;
}


.modal textarea {
  resize: vertical;
}


.submit-button {
  margin-top: 4px;

  border: none;
  border-radius: 14px;

  padding: 14px;

  background: #7c3aed;
  color: white;

  font-size: 15px;
  font-weight: 800;

  cursor: pointer;
}


.submit-button:active {
  transform: scale(0.98);
}

.actions {
  display: flex;
  align-items: flex-start;
  margin-left: 4px;
}

.delete-button {
  width: 34px;
  height: 34px;

  border: none;
  border-radius: 10px;

  background: rgba(255, 59, 48, 0.08);

  font-size: 15px;

  cursor: pointer;

  opacity: 0.65;

  transition: 0.15s ease;
}

.delete-button:hover {
  opacity: 1;
  background: rgba(255, 59, 48, 0.14);
}

.delete-button:active {
  transform: scale(0.92);
}

.edit-button {
  width: 34px;
  height: 34px;

  border: none;
  border-radius: 10px;

  background: rgba(124, 58, 237, 0.08);

  font-size: 15px;

  cursor: pointer;

  opacity: 0.65;

  transition: 0.15s ease;
}

.edit-button:hover {
  opacity: 1;
  background: rgba(124, 58, 237, 0.14);
}

.edit-button:active {
  transform: scale(0.92);
}

/* =========================
   HOMEWORK CALENDAR
========================= */

.calendar-section {
  margin-bottom: 28px;

  padding: 20px;

  border-radius: 24px;

  background:
    linear-gradient(
      145deg,
      rgba(124, 58, 237, 0.18),
      rgba(124, 58, 237, 0.04)
    );

  border: 1px solid
    rgba(124, 58, 237, 0.16);

  overflow: hidden;
}


.calendar-top {
  display: flex;

  align-items: center;
  justify-content: space-between;

  margin-bottom: 20px;
}


.calendar-label {
  color: var(--accent);

  font-size: 11px;
  font-weight: 900;

  letter-spacing: 0.16em;

  margin-bottom: 5px;
}


.calendar-top h2 {
  margin: 0;

  font-size: 27px;

  letter-spacing: -0.04em;
}


.calendar-top p {
  margin: 5px 0 0;

  color: var(--muted);

  font-size: 14px;

  text-transform: capitalize;
}


.today-button {
  border: none;

  padding: 10px 13px;

  border-radius: 12px;

  background: rgba(
    124,
    58,
    237,
    0.14
  );

  color: var(--accent);

  font-size: 12px;
  font-weight: 800;

  cursor: pointer;
}


.calendar {
  display: flex;

  align-items: center;

  gap: 7px;

  touch-action: pan-y;
}


.days {
  display: grid;

  grid-template-columns:
    repeat(5, 1fr);

  gap: 7px;

  flex: 1;
}


.calendar-day {
  min-width: 0;

  height: 72px;

  display: flex;

  flex-direction: column;

  align-items: center;
  justify-content: center;

  gap: 4px;

  border: none;

  border-radius: 16px;

  background: rgba(
    255,
    255,
    255,
    0.045
  );

  color: var(--muted);

  cursor: pointer;

  transition:
    transform 0.15s ease,
    background 0.15s ease;
}


.calendar-day .day-name {
  font-size: 10px;

  font-weight: 800;

  letter-spacing: 0.05em;
}


.calendar-day strong {
  font-size: 20px;

  color: var(--text);
}


.calendar-day.selected {
  background: var(--accent);

  color: white;

  box-shadow:
    0 8px 24px
    rgba(124, 58, 237, 0.3);
}


.calendar-day.selected strong {
  color: white;
}


.calendar-day.today:not(.selected) {
  border:
    1px solid
    rgba(124, 58, 237, 0.5);
}


.calendar-arrow {
  flex-shrink: 0;

  width: 30px;
  height: 50px;

  border: none;

  background: transparent;

  color: var(--muted);

  font-size: 30px;

  cursor: pointer;
}


.calendar-arrow:active {
  transform: scale(0.85);
}


/* EMPTY DAY */

.calendar-empty {
  padding: 55px 20px;
}


.empty-icon {
  font-size: 38px;

  margin-bottom: 12px;
}


.empty-title {
  font-size: 16px;

  font-weight: 800;

  color: var(--text);
}


.empty-text {
  margin-top: 6px;

  font-size: 13px;

  color: var(--muted);
}


/* MOBILE */

@media (max-width: 480px) {

  .calendar-section {
    padding: 17px;
  }

  .calendar-top h2 {
    font-size: 24px;
  }

  .calendar-day {
    height: 67px;
  }

  .calendar-day strong {
    font-size: 18px;
  }

}

.day-indicator {
  width: 5px;
  height: 5px;

  border-radius: 50%;

  background: var(--accent);

  margin-top: 2px;
}

.day-indicator.overdue {
  background: #ff4d67;
}

.calendar-day.selected .day-indicator {
  background: white;
}

.calendar-day.selected .day-indicator.overdue {
  background: #ffb3bd;
}

/* FIX: длинный текст не вылезает за карточки */
html,
body {
  overflow-x: hidden;
}

.homework-card {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.homework-card * {
  max-width: 100%;
  box-sizing: border-box;
}

.homework-description {
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.homework-title {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.homework-subject {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* FIX длинного текста в карточках */
.homework-card {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.homework-card .content {
  min-width: 0;
  max-width: 100%;
}

.homework-card .subject,
.homework-card .title,
.homework-card .description {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Просроченная домашка */
.task.overdue {
  border-color: rgba(255, 77, 103, 0.35);
}

.task.overdue .deadline {
  color: #ff4d67;
}

/* Выполненная домашка */
.task.completed {
  opacity: 0.55;
}

.task.completed .title,
.task.completed .description {
  text-decoration: line-through;
}

.task.completed .deadline {
  text-decoration: none;
}