* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4f8;
  --text: #172033;
  --muted: #66758a;
  --border: #dbe4ec;
  --primary: #2367a6;
  --primary-dark: #174c7b;
  --accent: #e7a93b;
  --success: #2d7d5a;
  --danger: #b64040;
  --warning: #a96512;
  --shadow: 0 14px 36px rgba(23, 50, 77, 0.08);
  --font-scale: 1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: calc(16px * var(--font-scale));
  color: var(--text);
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% 0%, rgba(35, 103, 166, 0.09), transparent 34%),
    var(--bg);
}

body.dyslexia-mode {
  font-family: Arial, Verdana, sans-serif;
  letter-spacing: 0.025em;
  word-spacing: 0.08em;
  line-height: 1.65;
}

body.high-contrast {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f2f2f2;
  --text: #000000;
  --muted: #303030;
  --border: #000000;
  --primary: #003f8f;
  --primary-dark: #001f49;
  --accent: #8a4b00;
  --success: #005a2b;
  --danger: #8f0000;
}

body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after {
  scroll-behavior: auto !important;
  animation: none !important;
  transition: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-link:focus-visible {
  outline: 3px solid rgba(35, 103, 166, 0.3);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: 0.75rem clamp(1rem, 4vw, 2.2rem);
  color: white;
  background: #17324d;
  box-shadow: 0 6px 22px rgba(23, 50, 77, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  color: #17324d;
  background: #ffffff;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 0.08rem;
  color: #c7d7e7;
  font-size: 0.78rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.role-switcher select {
  min-width: 140px;
  border-color: rgba(255, 255, 255, 0.22);
  color: white;
  background: #264b6d;
}

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.sidebar {
  position: sticky;
  top: 72px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: calc(100vh - 72px);
  padding: 1rem 0.75rem;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

#mainNav {
  display: grid;
  gap: 0.3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  border: 0;
  border-radius: 0.75rem;
  padding: 0.75rem 0.85rem;
  color: var(--muted);
  background: transparent;
  font-weight: 720;
  text-align: left;
}

.nav-link:hover,
.nav-link.active {
  color: var(--primary-dark);
  background: #eaf2f8;
}

.sidebar-footer {
  display: grid;
  gap: 0.7rem;
}

.demo-note {
  padding: 0.7rem;
  border-radius: 0.7rem;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.75rem;
  line-height: 1.4;
}

.main-content {
  width: min(1480px, 100%);
  padding: clamp(1rem, 3vw, 2rem);
}

.page {
  animation: pageIn 180ms ease;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.page-header h1 {
  margin: 0.15rem 0 0;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
  line-height: 1.08;
}

.page-header p:not(.eyebrow) {
  margin: 0.45rem 0 0;
  color: var(--muted);
  max-width: 760px;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.header-actions,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-padding {
  padding: 1.1rem;
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr);
  gap: 1.2rem;
  padding: clamp(1.2rem, 3vw, 2rem);
  color: white;
  background:
    linear-gradient(125deg, rgba(23, 50, 77, 0.97), rgba(35, 103, 166, 0.9)),
    #17324d;
}

.hero-card h2 {
  margin: 0.25rem 0 0.55rem;
  font-size: clamp(1.55rem, 3vw, 2.5rem);
}

.hero-card p {
  margin: 0;
  color: #d7e4ef;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.hero-progress {
  align-self: center;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.08);
}

.hero-progress strong {
  display: block;
  font-size: 2.2rem;
}

.hero-progress span {
  color: #d7e4ef;
}

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

.stat-card {
  padding: 1rem;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-card strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.6rem;
}

.stat-card small {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
}

.grid-2,
.grid-3 {
  display: grid;
  gap: 1rem;
  align-items: start;
}

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

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

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.section-title h2,
.section-title h3 {
  margin: 0;
}

.section-title p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 42px;
  border: 0;
  border-radius: 0.7rem;
  padding: 0.68rem 0.95rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button-primary {
  color: white;
  background: var(--primary);
}

.button-primary:hover {
  background: var(--primary-dark);
}

.button-secondary {
  color: var(--text);
  background: var(--surface-soft);
}

.button-secondary:hover {
  background: #e1ebf2;
}

.button-light {
  color: #17324d;
  background: white;
}

.button-danger {
  color: white;
  background: var(--danger);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  color: inherit;
  background: rgba(255, 255, 255, 0.12);
  font-size: 1.2rem;
}

.menu-button {
  display: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #bdcbd8;
  border-radius: 0.68rem;
  padding: 0.72rem 0.8rem;
  color: var(--text);
  background: var(--surface);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 720;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8ef;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 250ms ease;
}

.progress-bar.success {
  background: var(--success);
}

.task-list,
.activity-list,
.simple-list,
.assignment-list {
  display: grid;
  gap: 0.65rem;
}

.task-item,
.activity-item,
.assignment-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: var(--surface);
}

.task-item.completed {
  opacity: 0.66;
}

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

.task-check {
  width: 22px;
  height: 22px;
}

.task-title,
.list-title {
  font-weight: 800;
}

.task-meta,
.list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  margin-top: 0.23rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 0.28rem 0.56rem;
  color: var(--primary-dark);
  background: #e7f0f8;
  font-size: 0.72rem;
  font-weight: 800;
}

.badge.high,
.badge.overdue {
  color: #8c2121;
  background: #fbeaea;
}

.badge.medium,
.badge.today {
  color: #80500c;
  background: #fff1d6;
}

.badge.low,
.badge.complete {
  color: #1f6849;
  background: #e2f4eb;
}

.empty-state {
  padding: 2.2rem 1rem;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 0.3rem;
  color: var(--text);
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.9rem;
}

.subject-card {
  padding: 1rem;
}

.subject-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.subject-icon {
  font-size: 2rem;
}

.subject-card h3 {
  margin: 0.65rem 0 0.25rem;
}

.subject-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.topic-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.topic-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: center;
  gap: 0.7rem;
}

.topic-row label {
  display: block;
  color: var(--text);
  font-size: 0.8rem;
}

.topic-row input[type="range"] {
  padding: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.toolbar input,
.toolbar select {
  min-width: 180px;
}

.flashcard-study {
  display: grid;
  gap: 1rem;
}

.study-card {
  display: grid;
  place-items: center;
  min-height: 300px;
  padding: 2rem;
  border: 2px dashed #aabccc;
  border-radius: 1.1rem;
  background: linear-gradient(145deg, #ffffff, #eef4f8);
  text-align: center;
}

.study-card .study-topic {
  margin-bottom: 0.7rem;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.study-card h2 {
  max-width: 760px;
  margin: 0;
  line-height: 1.35;
}

.study-card p {
  max-width: 800px;
  margin: 0.8rem 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.study-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.quiz-shell {
  max-width: 900px;
  margin: 0 auto;
}

.quiz-question {
  padding: clamp(1rem, 3vw, 1.6rem);
}

.quiz-options {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.quiz-option {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.85rem;
  color: var(--text);
  background: var(--surface);
  text-align: left;
}

.quiz-option:hover,
.quiz-option.selected {
  border-color: var(--primary);
  background: #edf5fb;
}

.quiz-option.correct {
  border-color: var(--success);
  background: #e8f5ee;
}

.quiz-option.incorrect {
  border-color: var(--danger);
  background: #fbeaea;
}

.focus-panel {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(1.2rem, 4vw, 2.4rem);
  text-align: center;
}

.timer-display {
  margin: 0.5rem 0;
  font-size: clamp(4rem, 15vw, 8rem);
  font-weight: 900;
  letter-spacing: -0.06em;
}

.timer-mode {
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.timer-settings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
  margin-top: 1.2rem;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.8rem;
}

.note-card {
  display: flex;
  flex-direction: column;
  min-height: 220px;
  padding: 1rem;
}

.note-card h3 {
  margin: 0.25rem 0 0.6rem;
}

.note-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}

.note-card .inline-actions {
  margin-top: auto;
  padding-top: 0.8rem;
}

.data-table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.8rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.73rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mini-progress {
  min-width: 120px;
}

.mini-progress span {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.76rem;
}

.insight-box {
  padding: 0.9rem;
  border-left: 4px solid var(--primary);
  border-radius: 0.7rem;
  background: #edf5fb;
}

.insight-box strong {
  display: block;
  margin-bottom: 0.25rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr);
  gap: 1rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row strong,
.setting-row span {
  display: block;
}

.setting-row span {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.switch {
  position: relative;
  width: 48px;
  height: 27px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #b9c6d2;
  transition: 150ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  transition: 150ms ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(21px);
}

dialog {
  width: min(760px, calc(100% - 1.2rem));
  max-height: calc(100vh - 1.2rem);
  border: 0;
  border-radius: 1rem;
  padding: 0;
  box-shadow: 0 28px 80px rgba(23, 50, 77, 0.32);
}

dialog::backdrop {
  background: rgba(15, 34, 51, 0.58);
  backdrop-filter: blur(3px);
}

.dialog-form {
  padding: 1.2rem;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-header h2 {
  margin: 0.15rem 0 0;
}

.dialog-header .icon-button {
  color: var(--text);
  background: var(--surface-soft);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-top: 1rem;
}

.full-width {
  grid-column: 1 / -1;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 1rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  max-width: min(420px, calc(100% - 2rem));
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  color: white;
  background: #17324d;
  box-shadow: 0 16px 44px rgba(23, 50, 77, 0.28);
  font-weight: 750;
}

.danger-text {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1050px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .settings-grid,
  .hero-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    width: min(290px, 86vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 18px 0 44px rgba(23, 50, 77, 0.2);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 72px 0 0 0;
    z-index: 35;
    background: rgba(15, 34, 51, 0.45);
  }

  .menu-button {
    display: grid;
  }

  .brand span {
    display: none;
  }

  .main-content {
    padding: 1rem;
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 610px) {
  .topbar {
    gap: 0.5rem;
  }

  .brand strong {
    display: none;
  }

  .role-switcher select {
    min-width: 0;
    width: 130px;
  }

  .topbar-actions {
    gap: 0.4rem;
  }

  #installButton {
    display: none !important;
  }

  .topbar .button {
    min-height: 38px;
    padding: 0.55rem 0.7rem;
    font-size: 0.82rem;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .stat-card {
    padding: 0.8rem;
  }

  .stat-card strong {
    font-size: 1.35rem;
  }

  .task-item,
  .activity-item,
  .assignment-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .task-item > :last-child,
  .activity-item > :last-child,
  .assignment-item > :last-child {
    grid-column: 2;
  }

  .timer-settings,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .full-width {
    grid-column: auto;
  }

  .study-card {
    min-height: 260px;
    padding: 1.2rem;
  }
}
