:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f1efff;
  --surface-muted: #f3f4f7;
  --text: #111827;
  --text-2: #5b6475;
  --text-3: #818898;
  --accent: #5b3df5;
  --accent-2: #4a2fe4;
  --accent-soft: #efecff;
  --border: #e6e8ef;
  --danger: #d92d20;
  --danger-soft: #fff1f0;
  --warning: #9a6700;
  --warning-soft: #fff7dc;
  --success: #137a45;
  --shadow: 0 8px 28px rgba(17, 24, 39, 0.07);
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --tap: 44px;
  --content: 560px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.35;
}
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(91, 61, 245, 0.24);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.app-shell {
  min-height: 100dvh;
  width: 100%;
}

.screen {
  width: min(100%, var(--content));
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.topbar {
  min-height: calc(64px + env(safe-area-inset-top));
  padding: calc(12px + env(safe-area-inset-top)) var(--space-4) 8px;
  display: flex;
  align-items: flex-end;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(230,232,239,.72);
}

.context-button {
  min-height: var(--tap);
  max-width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.context-button__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: calc(100vw - 68px);
}
.chevron { width: 18px; height: 18px; flex: 0 0 auto; }

.main {
  padding: 0 var(--space-4) var(--space-8);
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: var(--space-3) 0 var(--space-6);
}
.day-chip {
  min-height: 58px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.day-chip__dow { font-size: 12px; font-weight: 650; }
.day-chip__date { font-size: 18px; font-weight: 750; color: var(--text); }
.day-chip.is-active { background: var(--accent); color: #fff; }
.day-chip.is-active .day-chip__date { color: #fff; }
.day-chip.is-today:not(.is-active) { background: var(--accent-soft); }

.section-heading {
  margin: 0 0 var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.section-heading h1, .section-heading h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.015em;
}
.today-return {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.schedule-list { display: grid; gap: 10px; }
.lesson-card {
  width: 100%;
  min-height: 84px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: left;
  color: inherit;
  position: relative;
}
.lesson-card.is-changed { border-color: #f0b429; background: #fffdf7; }
.lesson-card.is-cancelled { border-color: #f2b8b5; background: var(--danger-soft); }
.lesson-card.is-review { border-style: dashed; }
.pair-number {
  font-size: 26px;
  line-height: 1;
  font-weight: 760;
  padding-top: 2px;
  color: var(--text);
}
.lesson-content { min-width: 0; }
.lesson-block + .lesson-block {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 10px;
}
.lesson-subject {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 730;
  letter-spacing: -0.008em;
}
.lesson-teacher, .lesson-meta {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-2);
}
.room-chip {
  min-width: 38px;
  height: 32px;
  padding: 0 9px;
  border-radius: 9px;
  background: var(--surface-muted);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 720;
  white-space: nowrap;
  align-self: start;
}
.review-chip, .change-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
}
.review-chip { background: var(--warning-soft); color: var(--warning); }
.change-chip { background: var(--accent-soft); color: var(--accent); }
.cancel-chip { background: var(--danger-soft); color: var(--danger); }

.free-row {
  min-height: 40px;
  padding: 8px 12px 8px 56px;
  color: var(--text-3);
  font-size: 14px;
  display: flex;
  align-items: center;
}
.end-note, .empty-state {
  color: var(--text-2);
  font-size: 14px;
  padding: 18px 2px 8px;
}
.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  text-align: center;
  margin-top: 12px;
}
.empty-state h2 { margin: 0 0 6px; font-size: 18px; color: var(--text); }
.empty-state p { margin: 0; }

.week-page-title, .changes-title { margin: 18px 0 4px; font-size: 24px; }
.week-range { margin: 0 0 20px; color: var(--text-2); font-size: 14px; }
.agenda-day { margin: 0 0 24px; }
.agenda-day__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.agenda-day__header h2 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .045em; }
.agenda-count { color: var(--text-3); font-size: 13px; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, var(--content));
  height: calc(68px + env(safe-area-inset-bottom));
  padding: 7px 10px env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.nav-button {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--text-3);
  min-height: 54px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 680;
  cursor: pointer;
}
.nav-button svg { width: 22px; height: 22px; }
.nav-button.is-active { color: var(--accent); }
.badge {
  position: absolute;
  top: 1px;
  left: calc(50% + 7px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  border: 2px solid #fff;
}

/* Onboarding */
.onboarding {
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
  padding: calc(32px + env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 34px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand-mark svg { width: 22px; height: 22px; }
.brand-name { font-size: 22px; font-weight: 800; }
.step-kicker { color: var(--accent); font-size: 13px; font-weight: 760; margin: 0 0 8px; }
.onboarding h1 { margin: 0 0 8px; font-size: 28px; line-height: 1.15; letter-spacing: -.025em; }
.onboarding-intro { margin: 0 0 24px; color: var(--text-2); }
.choice-grid { display: grid; gap: 12px; }
.choice-button {
  width: 100%;
  min-height: 68px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  padding: 16px;
  text-align: left;
  font-weight: 720;
  cursor: pointer;
}
.choice-button:hover { border-color: #cbc4ff; background: #fbfaff; }
.choice-button.is-selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.search-field {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 12px;
}
.scroll-choices { max-height: 52dvh; overflow: auto; padding: 2px; }
.course-grid { grid-template-columns: repeat(2, 1fr); }
.course-grid .choice-button { text-align: center; min-height: 84px; font-size: 17px; }
.back-button {
  margin-top: 18px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

/* Dialog / bottom sheet */
dialog {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(100% - 24px, 520px);
  max-width: none;
  color: var(--text);
}
dialog::backdrop { background: rgba(17, 24, 39, .36); backdrop-filter: blur(2px); }
.profile-sheet {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  max-height: min(82dvh, 720px);
  overflow: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.icon-button { width: 44px; height: 44px; border: 0; background: var(--surface-muted); border-radius: 12px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-muted); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.segmented button { min-height: 40px; border: 0; background: transparent; border-radius: 9px; color: var(--text-2); font-weight: 700; cursor: pointer; }
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(17,24,39,.06); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--text-2); }
.field select, .field input { width: 100%; min-height: 48px; border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; background: var(--surface); color: var(--text); }
.primary-button { width: 100%; min-height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 760; cursor: pointer; }
.primary-button:hover { background: var(--accent-2); }

.change-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}
.change-card__meta { color: var(--text-3); font-size: 12px; margin-bottom: 6px; }
.change-card h3 { margin: 0 0 8px; font-size: 17px; }
.change-card p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.loading, .fatal {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--text-2);
}
.fatal strong { display: block; color: var(--text); margin-bottom: 6px; }

@media (min-width: 700px) {
  body { padding: 24px 0; }
  .screen, .onboarding { min-height: calc(100dvh - 48px); border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); }
  .topbar { border-radius: 24px 24px 0 0; }
  .bottom-nav { bottom: 24px; border-radius: 0 0 24px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
