:root {
  --ink: #172033;
  --muted: #667085;
  --line-strong: #c9d1dc;
  --surface: #ffffff;
  --canvas: #eef2f7;
  --navy: #14243e;
  --accent: #5d5fef;
  --accent-dark: #4547cf;
  --cyan: #23b7c5;
  --danger-soft: #ffedf0;
  --radius: 20px;
  --shadow: 0 18px 50px rgba(25, 42, 70, 0.08);
}

html[data-theme="dark"] {
  --ink: #f7f9ff;
  --muted: #aeb7d3;
  --line-strong: rgba(255, 255, 255, 0.14);
  --surface: #141a2e;
  --canvas: #090d1f;
  --navy: #070b18;
  --accent: #8b5cf6;
  --accent-dark: #c4b5fd;
  --cyan: #22d3ee;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

button, input { color: inherit; font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin-top: 0; }
h1, h2 { letter-spacing: -0.025em; line-height: 1.16; }

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted { color: var(--muted); }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 11px;
  padding: 10px 18px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 20px rgba(93, 95, 239, 0.2);
  font-weight: 750;
}

.button-wide { width: 100%; }

.login-page {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  background: var(--surface);
}

.login-story {
  position: relative;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  padding: clamp(48px, 8vw, 120px);
  color: #fff;
  background:
    radial-gradient(circle at 82% 15%, rgba(35, 183, 197, 0.35), transparent 27%),
    radial-gradient(circle at 20% 92%, rgba(93, 95, 239, 0.38), transparent 31%),
    linear-gradient(145deg, #111e34, #172c4b 62%, #14243e);
}

.login-story::after {
  position: absolute;
  right: -100px;
  bottom: -100px;
  width: 360px;
  height: 360px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  box-shadow: 0 0 0 60px rgba(255, 255, 255, 0.025), 0 0 0 120px rgba(255, 255, 255, 0.018);
  content: "";
}

.login-story .eyebrow { color: #79deea; }

.login-story h1 {
  max-width: 640px;
  margin-top: 28px;
  margin-bottom: 22px;
  font-size: clamp(3rem, 6vw, 5.8rem);
  letter-spacing: -0.055em;
}

.login-lead {
  max-width: 600px;
  margin-bottom: 46px;
  color: #bdc9db;
  font-size: 1.12rem;
}

.brand-mark {
  display: inline-flex;
  width: 62px;
  height: 62px;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  box-shadow: 0 15px 32px rgba(35, 183, 197, 0.22);
  font-size: 1.1rem;
  font-weight: 900;
}

.flow-list {
  display: flex;
  max-width: 560px;
  flex-direction: column;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.flow-list li { display: flex; align-items: center; gap: 14px; color: #d9e1ec; }

.flow-list span {
  display: inline-flex;
  width: 40px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: #79deea;
  font-size: 0.7rem;
  font-weight: 800;
}

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(36px, 7vw, 100px);
  background: var(--surface);
}

.auth-card {
  display: flex;
  width: min(100%, 430px);
  flex-direction: column;
  gap: 22px;
}

.auth-card h2 { font-size: 2rem; }

.field { display: flex; flex-direction: column; gap: 7px; }

.field > span {
  color: #344054;
  font-size: 0.78rem;
  font-weight: 780;
}

.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

.field input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(93, 95, 239, 0.12);
}

.form-error {
  border: 1px solid #f5bdc6;
  border-radius: 10px;
  margin: 0;
  padding: 10px 12px;
  color: #a92d43;
  background: var(--danger-soft);
  font-size: 0.82rem;
  font-weight: 650;
}

.app-frame {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: start;
  flex-direction: column;
  padding: 24px 18px;
  color: #fff;
  background: var(--navy);
}
.school-chip { margin-top: 18px; }
.sidebar-logout { margin: 12px 0 0; }
.sidebar-logout .button { width: 100%; }

.side-link {
  color: #fff;
  font-weight: 750;
}

.workspace { display: flex; flex-direction: column; min-width: 0; padding: 0 0 40px; }
.workspace-main { padding: 24px 40px 40px; }
.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 16px 40px 0;
}
.topbar-user { display: flex; align-items: center; gap: 8px; }
.topbar-user small, .topbar-user strong { display: block; }
.topbar-user small { color: var(--muted); font-size: 0.75rem; }
.theme-toggle, .icon-button {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
}
.theme-toggle { padding: 6px 12px; }
#theme-toggle { display: inline-flex; width: 36px; height: 36px; align-items: center; justify-content: center; padding: 0; }
#theme-toggle svg { width: 18px; height: 18px; display: block; }
.icon-button { width: 36px; height: 36px; padding: 0; }
.history-filters { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.history-table-wrap { overflow: auto; border: 1px solid var(--line-strong); border-radius: 16px; background: var(--surface); }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line-strong); }
.history-table th { color: var(--muted); font-size: 13px; font-weight: 650; }
.history-table th[data-sort] { cursor: pointer; }
.history-table th[data-sort]:hover { color: var(--ink); }
.history-table th.is-desc::after { content: " ↓"; }
.history-table th.is-asc::after { content: " ↑"; }
.history-table a { color: var(--cyan); font-weight: 700; text-decoration: none; }
.type-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: rgba(139, 92, 246, 0.16); color: var(--accent-dark); font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.history-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.history-actions a { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px 8px; background: var(--surface); color: var(--accent-dark); font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }

.catalog-block { margin: 0 0 28px; }
.catalog-block h2 { font-size: 1.35rem; }

.brand { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; }
.brand small, .school-chip small { display: block; color: #c9d4e4; font-size: 0.75rem; }
.main-nav { display: grid; gap: 6px; margin: 28px 0; }
.main-nav a { color: #fff; text-decoration: none; padding: 8px 0; }
.sponsor-badge {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: auto 0 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
}
.sponsor-badge span { color: #c9d4e4; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.sponsor-badge strong { color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: 0.32em; text-transform: uppercase; }
.sidebar-footer { margin-top: auto; }
.school-chip { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.avatar { display: inline-flex; width: 36px; height: 36px; align-items: center; justify-content: center; border-radius: 50%; background: #5d5fef; }
.generator-layout {
  display: block;
  max-width: 980px;
}
.generator-main { display: grid; gap: 18px; }
.panel {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 22px;
}
.section-heading { display: flex; gap: 12px; align-items: flex-start; }
.section-number {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--accent-dark);
  background: #eeeeff;
  font-size: 0.68rem;
  font-weight: 800;
}
.form-grid, .option-grid, .segmented-control { display: grid; gap: 10px; }
.form-grid { grid-template-columns: 1fr 1fr; }
.field-span { grid-column: 1 / -1; }
.option-grid { grid-template-columns: 1fr 1fr; }
.option-card, .segmented-control label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  padding: 11px;
  min-width: 0;
}
.choice-text { display: grid; gap: 2px; min-width: 0; }
.choice-text small, .choice-text span { font-weight: 450; }
.segmented-control .choice-text { display: flex; flex-wrap: wrap; gap: 0 4px; align-items: baseline; }
.segmented-control { grid-template-columns: 1fr 1fr; }
.segmented-field { border: 0; margin: 18px 0 10px; padding: 0; }
.button-secondary { color: var(--ink); background: var(--surface); border-color: var(--line-strong); box-shadow: none; }
.generation-summary { display: grid; gap: 8px; }
.generation-summary div { display: flex; justify-content: space-between; gap: 12px; }
select, textarea { color: inherit; font: inherit; }
.history-filters input,
.history-filters select,
.field input,
.field select,
.field textarea {
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line-strong);
}
@media (max-width: 879px) {
  .generator-layout, .form-grid, .option-grid { grid-template-columns: 1fr; }
}

@media (max-width: 879px) {
  .login-page { display: block; }
  .login-story { min-height: auto; padding: 42px 25px; }
  .login-story h1 { margin-top: 22px; font-size: 2.9rem; }
  .flow-list { display: none; }
  .login-panel { padding: 40px 24px 60px; }
}

#lesson-sections p,
#lesson-sections li {
  white-space: normal;
}

#lesson-sections .lesson-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
}

#lesson-sections .is-full,
#lesson-sections .lesson-result-title {
  grid-column: 1 / -1;
}

#lesson-sections .lesson-card {
  background: #fff;
  border: 1px solid rgba(43, 55, 84, 0.1);
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(24, 32, 54, 0.06);
  padding: 20px;
}

#lesson-sections .lesson-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#lesson-sections .lesson-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.16);
  flex: 0 0 auto;
}

#lesson-sections .lesson-card h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #182036;
}

#lesson-sections .lesson-badge {
  margin-left: auto;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(43, 55, 84, 0.06);
  color: #5e6986;
}

#lesson-sections .lesson-badge.is-accent {
  background: rgba(139, 92, 246, 0.16);
  color: #6d28d9;
}

#lesson-sections .lesson-prose {
  color: #5e6986;
  font-size: 15px;
  line-height: 1.6;
}

#lesson-sections .lesson-prose h3,
#lesson-sections .lesson-prose h4,
#lesson-sections .lesson-prose strong {
  color: #182036;
}

#lesson-sections .lesson-prose h3 { font-size: 20px; margin: 0.8em 0 0.4em; }
#lesson-sections .lesson-prose h4 { font-size: 17px; margin: 0.8em 0 0.4em; }
#lesson-sections .lesson-prose p { margin: 0.55em 0; }
#lesson-sections .lesson-prose ul,
#lesson-sections .lesson-prose ol { margin: 0.55em 0; padding-left: 1.3em; }
#lesson-sections .lesson-prose blockquote {
  margin: 0.8em 0;
  padding: 8px 14px;
  border-left: 3px solid #8b5cf6;
  background: rgba(139, 92, 246, 0.08);
  border-radius: 0 8px 8px 0;
}
#lesson-sections .lesson-prose table { width: 100%; border-collapse: collapse; margin: 0.8em 0; }
#lesson-sections .lesson-prose th,
#lesson-sections .lesson-prose td { border: 1px solid rgba(43, 55, 84, 0.12); padding: 6px 10px; text-align: left; }
#lesson-sections .lesson-prose th { background: rgba(43, 55, 84, 0.04); color: #182036; }
#lesson-sections .lesson-prose code { background: rgba(43, 55, 84, 0.06); padding: 1px 5px; border-radius: 4px; }
#lesson-sections .quiz-question {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(43, 55, 84, 0.1);
  border-radius: 12px;
  background: rgba(243, 246, 251, 0.8);
}
#lesson-sections .quiz-head { display: flex; justify-content: space-between; gap: 12px; color: #182036; font-weight: 650; }
#lesson-sections .quiz-option.is-correct { color: #15803d; font-weight: 700; }
#lesson-sections .answer-key { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: rgba(34, 197, 94, 0.1); }
#lesson-sections .answer-key-title { margin: 0; font-size: 12px; font-weight: 700; color: #15803d; }
#lesson-sections .quiz-footer { display: flex; gap: 16px; margin-top: 10px; font-size: 13px; }
#lesson-panel[data-audience="student"] .teacher-only,
#lesson-panel[data-audience="student"] .answer-key { display: none; }
#lesson-panel[data-audience="student"] .quiz-option.is-correct { color: inherit; font-weight: inherit; }

@media (max-width: 760px) {
  #lesson-sections .lesson-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-frame { display: block; }
  .sidebar { height: auto; }
}

@media print {
  .sidebar, .topbar, #generator-form, #lesson-timer, .theme-toggle, .icon-button { display: none !important; }
  .app-frame, .workspace { display: block; background: #fff; }
  #lesson-panel { display: block; }
  #lesson-panel[data-audience="student"] .teacher-only,
  #lesson-panel[data-audience="student"] .answer-key { display: none !important; }
}

.calendar-layout { display: block; }
.calendar-toolbar, .month-actions, .agenda-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.calendar-toolbar { justify-content: space-between; }
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-day, .calendar-day { min-width: 0; border: 1px solid var(--line-strong); border-radius: 12px; padding: 8px; background: var(--surface); }
.week-day h3, .week-day p { margin: 0 0 6px; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); min-width: 640px; }
.calendar-day { overflow: hidden; color: inherit; text-decoration: none; }
.weekdays span { padding: 6px; color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.calendar-day { min-height: 88px; border-radius: 0; }
.calendar-day.outside { opacity: 0.45; }
.calendar-day.today .day-number { color: #fff; background: var(--accent); border-radius: 50%; padding: 2px 7px; }
.mini-event { display: block; overflow: hidden; margin-top: 4px; padding: 2px 4px; border-radius: 6px; background: rgba(93, 95, 239, 0.12); font-size: 11px; white-space: normal; }
.mini-event .mini-time { display: block; font-weight: 700; }
.mini-held { background: rgba(34, 197, 94, 0.16); }
.mini-not_held { background: rgba(245, 158, 11, 0.18); }
.mini-cancelled { background: var(--danger-soft); text-decoration: line-through; }
.agenda-item { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-strong); }
.agenda-item time { display: flex; flex-direction: column; gap: 2px; }
.agenda-item h3, .agenda-item p { margin: 0; }
.more-events { display: block; margin-top: 2px; font-size: 11px; }
.text-button { border: 0; padding: 0; background: transparent; color: var(--accent-dark); cursor: pointer; }
.calendar-side { display: grid; gap: 14px; }
.calendar-scroll { overflow-x: auto; }
.hour-grid { display: grid; grid-template-columns: 64px repeat(7, minmax(0, 1fr)); gap: 0; min-width: 760px; }
.hour-scale { display: flex; flex-direction: column; color: var(--muted); font-size: 11px; }
.hour-spacer, .hour-head { height: 48px; }
.hour-mark { position: relative; height: 48px; }
.hour-mark span { position: absolute; top: 0; right: 8px; transform: translateY(-50%); line-height: 1; white-space: nowrap; }
.hour-day { min-width: 0; }
.hour-head { display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 6px; }
.hour-day h3, .hour-day p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; text-align: center; }
.cal-nav, .cal-steps { display: inline-flex; align-items: center; }
.cal-nav { gap: 8px; }
.cal-today, .cal-switch, .cal-steps a { display: inline-flex; align-items: center; justify-content: center; height: 34px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 650; }
.cal-today, .cal-switch { padding: 0 12px; border-radius: 8px; }
.cal-steps a { width: 34px; }
.cal-steps a:first-child { border-radius: 8px 0 0 8px; }
.cal-steps a:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.event-dialog { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: rgba(8, 12, 24, 0.55); }
.event-dialog form { width: min(760px, 100%); overflow: visible; display: grid; gap: 12px; }
.event-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.event-note { margin: 0; }
.event-actions { display: flex; gap: 8px; justify-content: flex-end; }
.event-dialog .button-wide { width: auto; }
.hour-column { position: relative; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); background: var(--surface); }
.hour-day:first-of-type .hour-column { border-left: 1px solid var(--line-strong); }
.hour-slot { position: absolute; left: 0; right: 0; height: 48px; border-top: 1px solid var(--line-strong); }
.hour-event { position: absolute; z-index: 1; overflow: hidden; padding: 2px 4px; border-radius: 6px; background: rgba(93, 95, 239, 0.18); font-size: 11px; }
.hour-event.mini-held { background: rgba(34, 197, 94, 0.16); }
.hour-event.mini-not_held { background: rgba(245, 158, 11, 0.18); }
.hour-event.mini-cancelled { background: var(--danger-soft); }
.hour-event strong, .hour-event span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) { .calendar-layout, .week-grid { grid-template-columns: 1fr; } }
