:root {
  color-scheme: light;
  --bg: #fafafd;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-soft: #f5f1ff;
  --line: rgba(95, 54, 198, 0.14);
  --line-strong: rgba(95, 54, 198, 0.22);
  --text: #1f1830;
  --muted: #766b90;
  --muted-soft: #aaa3ba;
  --berry: #5f36c6;
  --berry-soft: #efe8ff;
  --yellow: #ffe15b;
  --shadow: 0 10px 26px rgba(73, 43, 134, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: linear-gradient(180deg, #ffffff 0%, #fafafd 100%);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", "Noto Sans", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(239, 232, 255, 0.7), transparent 24%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
}

body.drawer-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 999px;
  min-height: 48px;
  padding: 0.8rem 1rem;
  font-weight: 700;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  background: #fcfbff;
  border-color: var(--line-strong);
}

button.strong {
  background: var(--berry);
  color: #ffffff;
  border-color: transparent;
}

button.strong:hover,
button.strong:focus-visible {
  background: #5427ba;
}

input {
  width: 100%;
  min-height: 54px;
  padding: 0.95rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.app-shell {
  padding: max(1rem, env(safe-area-inset-top)) 0.9rem max(2rem, env(safe-area-inset-bottom));
}

.topbar,
.settings-panel {
  backdrop-filter: blur(12px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  max-width: 720px;
  margin: 0 auto 0.9rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.3rem, 4.2vw, 2rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

h2 {
  font-size: clamp(1.15rem, 3.1vw, 1.7rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.main-layout {
  display: grid;
  gap: 0.95rem;
  max-width: 720px;
  margin: 0 auto;
}

.section-label,
.meta-label {
  margin: 0 0 0.3rem;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--berry);
}

.muted,
.field-help {
  color: var(--muted);
  line-height: 1.45;
}

.date-banner,
.list-section,
.calendar-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.date-banner {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 225, 91, 0.96), rgba(255, 225, 91, 0.9)),
    #fff2a8;
}

.date-banner-text {
  display: grid;
  gap: 0.2rem;
}

#selectedDateTitle {
  font-size: clamp(1.35rem, 3.6vw, 1.8rem);
  font-weight: 900;
  line-height: 1.1;
  color: #3b2d00;
}

#selectedDateSubtitle {
  color: rgba(59, 45, 0, 0.8);
  font-weight: 600;
}

.day-icons,
.top-meta,
.legend {
  display: none;
}

.day-nav-row,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.day-nav-row {
  flex-wrap: wrap;
}

.day-nav,
.month-nav,
.settings-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.list-section,
.calendar-section {
  padding: 1rem;
}

.list-head {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 90px 90px;
  gap: 0.8rem;
  padding: 0.85rem 0.8rem 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.week-list {
  display: grid;
}

.week-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 90px 90px;
  gap: 0.8rem;
  align-items: center;
  width: 100%;
  padding: 0.8rem;
  border: 0;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  position: relative;
}

.week-row::before {
  content: "";
  position: absolute;
  left: 0.2rem;
  top: 0.7rem;
  bottom: 0.7rem;
  width: 4px;
  border-radius: 999px;
  background: var(--fraction-color, var(--berry));
}

.week-row + .week-row {
  border-top: 1px solid rgba(95, 54, 198, 0.08);
}

.week-row:hover,
.week-row:focus-visible {
  background: rgba(239, 232, 255, 0.34);
}

.week-row.is-past {
  color: var(--muted-soft);
}

.week-row.is-past .week-fraction-name,
.week-row.is-past .week-date-main,
.week-row.is-past .week-day-main {
  color: var(--muted-soft);
}

.week-row.is-today {
  background: rgba(239, 232, 255, 0.58);
}

.week-col {
  min-width: 0;
}

.week-fraction {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-left: 0.55rem;
}

.week-fraction-name {
  font-weight: 500;
  color: var(--muted);
  line-height: 1.25;
}

.week-date-main,
.week-day-main {
  font-weight: 500;
  color: var(--muted);
}

.week-day-sub {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.08rem;
}

.week-row.is-today .week-fraction-name,
.week-row.is-today .week-date-main,
.week-row.is-today .week-day-main {
  color: var(--text);
  font-weight: 800;
}

.fraction-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(95, 54, 198, 0.1);
}

.fraction-icon {
  width: 1.2rem;
  height: 1.2rem;
  display: block;
}

.empty-state {
  padding: 1rem 0.8rem;
  color: var(--muted);
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday-row {
  margin-top: 1rem;
  margin-bottom: 0.45rem;
  padding: 0 0.25rem;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.weekday-row span {
  text-align: center;
}

.calendar-grid {
  gap: 0.35rem;
}

.calendar-day {
  min-height: 74px;
  padding: 0.55rem;
  border-radius: 14px;
  border: 1px solid rgba(95, 54, 198, 0.1);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
}

.calendar-day.is-outside {
  opacity: 0.46;
}

.calendar-day.is-today {
  border-color: rgba(95, 54, 198, 0.34);
  box-shadow: inset 0 0 0 1px rgba(95, 54, 198, 0.14);
}

.calendar-day.is-selected {
  background: linear-gradient(180deg, var(--berry), #5427ba);
  color: #ffffff;
  border-color: transparent;
}

.calendar-day-number {
  font-size: 0.92rem;
  font-weight: 800;
}

.calendar-markers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.18rem;
}

.calendar-marker {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: currentColor;
}

.icon-button {
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.icon-button span {
  position: absolute;
  width: 1.2rem;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

#menuButton span:nth-child(1) {
  transform: translateY(-5px);
}

#menuButton span:nth-child(3) {
  transform: translateY(5px);
}

.close-button span:nth-child(1) {
  transform: rotate(45deg);
}

.close-button span:nth-child(2) {
  transform: rotate(-45deg);
}

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 21, 51, 0.28);
  backdrop-filter: blur(8px);
  z-index: 30;
}

.settings-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(420px, 100vw);
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1.4rem, env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(247, 244, 255, 0.97)),
    rgba(255, 255, 255, 0.9);
  box-shadow: -18px 0 40px rgba(63, 34, 109, 0.16);
  transform: translateX(102%);
  transition: transform 220ms ease;
  z-index: 40;
  display: grid;
  align-content: start;
  gap: 1rem;
}

.settings-panel.is-open {
  transform: translateX(0);
}

.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.settings-block {
  display: grid;
  gap: 0.45rem;
  padding: 0.95rem;
  border-radius: 16px;
  border: 1px solid rgba(95, 54, 198, 0.1);
  background: var(--surface-strong);
}

.settings-status {
  background: rgba(239, 231, 255, 0.76);
}

.field-label {
  font-size: 1rem;
  font-weight: 700;
}

code {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
}

@media (max-width: 720px) {
  .topbar,
  .section-head,
  .day-nav-row {
    flex-direction: column;
    align-items: stretch;
  }

  .day-nav,
  .month-nav,
  .settings-actions {
    justify-content: stretch;
  }

  .day-nav button,
  .month-nav button {
    flex: 1 1 0;
  }

  .list-head,
  .week-row {
    grid-template-columns: minmax(0, 1.35fr) 96px 104px;
    gap: 0.55rem;
  }

  .week-row {
    padding: 0.75rem 0.55rem;
  }

  .week-fraction {
    gap: 0.45rem;
    padding-left: 0.45rem;
  }

  .week-fraction-name,
  .week-date-main,
  .week-day-main {
    font-size: 0.97rem;
  }

  .week-day-sub {
    font-size: 0.82rem;
  }

  .calendar-day {
    min-height: 68px;
    border-radius: 12px;
  }
}

@media (max-width: 400px) {
  body {
    font-size: 15px;
  }

  h2 {
    font-size: 1.05rem;
  }

  #selectedDateTitle {
    font-size: 1.2rem;
  }

  .section-label,
  .meta-label,
  .list-head,
  .weekday-row {
    font-size: 0.68rem;
  }

  .week-fraction-name,
  .week-date-main,
  .week-day-main {
    font-size: 0.88rem;
  }

  .week-day-sub {
    font-size: 0.76rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }

  button,
  .settings-panel {
    transition: none;
  }
}
