:root {
  --bg: #f4f7fc;
  --bg-elevated: #eef4ff;
  --surface: #ffffff;
  --surface-soft: #f8faff;
  --surface-elevated: rgba(255, 255, 255, 0.86);
  --line: #d9e2f2;
  --text: #11203a;
  --muted: #62708a;
  --blue: #2d6cdf;
  --blue-deep: #1f4fb3;
  --purple: #7a5cff;
  --shadow: 0 12px 30px rgba(33, 53, 90, 0.12);
  --shadow-soft: 0 8px 20px rgba(33, 53, 90, 0.08);
  --page-gradient: linear-gradient(180deg, #f8fbff 0%, #eef4ff 42%, #f4f7fc 100%);
  --grid-line: rgba(45, 108, 223, 0.03);
  --nav-hover: rgba(45, 108, 223, 0.08);
  --chip-bg: #eef3ff;
  --chip-border: #d9e5ff;
  --panel-gradient: linear-gradient(180deg, #ffffff, #f7f9ff);
  --icon-gradient: linear-gradient(135deg, rgba(45, 108, 223, 0.12), rgba(122, 92, 255, 0.12));
  --button-secondary-bg: #eff4ff;
  --button-secondary-border: #d9e5ff;
  --control-bg: #fbfcff;
  --control-text: #11203a;
  --control-placeholder: #7b8aa5;
  --table-head-bg: #f7f9ff;
  --task-bg: #f6f8ff;
  --task-border: #dce4f4;
  --radius: 8px;
}

[data-theme='dark'] {
  --bg: #0b1220;
  --bg-elevated: #101a2f;
  --surface: #101a2f;
  --surface-soft: #0f1728;
  --surface-elevated: rgba(16, 26, 47, 0.86);
  --line: #24324d;
  --text: #e8eefc;
  --muted: #9fb0ca;
  --blue: #6ea4ff;
  --blue-deep: #9bc0ff;
  --purple: #a68bff;
  --shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.24);
  --page-gradient: linear-gradient(180deg, #0e1727 0%, #0a1321 42%, #0b1220 100%);
  --grid-line: rgba(110, 164, 255, 0.06);
  --nav-hover: rgba(110, 164, 255, 0.12);
  --chip-bg: rgba(110, 164, 255, 0.12);
  --chip-border: rgba(110, 164, 255, 0.2);
  --panel-gradient: linear-gradient(180deg, #111b31, #0f182b);
  --icon-gradient: linear-gradient(135deg, rgba(110, 164, 255, 0.16), rgba(166, 139, 255, 0.16));
  --button-secondary-bg: rgba(110, 164, 255, 0.12);
  --button-secondary-border: rgba(110, 164, 255, 0.18);
  --control-bg: #0c1527;
  --control-text: #e8eefc;
  --control-placeholder: #8396b8;
  --table-head-bg: #111b31;
  --task-bg: #0e182c;
  --task-border: #24324d;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  color-scheme: light;
}

html[data-theme='dark'] {
  color-scheme: dark;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Trebuchet MS", Arial, sans-serif;
  background: var(--page-gradient);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), transparent 90%);
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.topbar {
  width: min(1120px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-elevated);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 12px;
  z-index: 10;
}

.topbar-landing {
  position: static;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: white;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  box-shadow: 0 10px 18px rgba(44, 107, 223, 0.28);
  overflow: hidden;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-text strong {
  font-size: 1rem;
}

.brand-text small {
  color: var(--muted);
  font-size: 0.82rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: flex-end;
}

.nav-links a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.94rem;
  padding: 10px 14px;
  border-radius: 999px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--nav-hover);
  color: var(--blue-deep);
}

.nav-links a[href*="logout"] {
  font-size: 0.88rem;
  color: var(--muted);
  padding: 8px 12px;
  min-height: 36px;
  opacity: 0.75;
}

.nav-links a[href*="logout"]:hover {
  opacity: 1;
  color: var(--muted);
  background: var(--nav-hover);
}

.nav-links .nav-upgrade-link,
.nav-links a[href*="upgrade"] {
  font-size: 0.85rem;
  font-weight: 800;
  padding: 8px 16px !important;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: white !important;
  border-radius: 999px;
  min-height: 36px;
  box-shadow: 0 4px 12px rgba(45, 108, 223, 0.2);
}

.nav-links .nav-upgrade-link:hover,
.nav-links a[href*="upgrade"]:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.nav-theme-toggle {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.nav-theme-toggle:hover {
  background: var(--surface-soft);
  border-color: var(--blue);
}

.nav-theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(45, 108, 223, 0.18);
}

.nav-hamburger {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-hamburger:hover {
  background: var(--surface-soft);
  border-color: var(--blue);
}

.nav-hamburger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(45, 108, 223, 0.18);
}

/* ===== Sidebar Navigation ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100dvh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-header .brand-mark {
  width: 38px;
  height: 38px;
  font-size: 0.9rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-nav a,
.sidebar-nav .quiz-nav-timer {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.94rem;
  padding: 10px 14px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  min-height: 40px;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-nav .quiz-nav-timer {
  cursor: default;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: var(--nav-hover);
  color: var(--blue-deep);
}

.sidebar-nav a[href*="logout"] {
  margin-top: auto;
  opacity: 0.75;
}

.sidebar-nav a[href*="logout"]:hover {
  opacity: 1;
}

.sidebar-nav .nav-upgrade-link,
.sidebar-nav a[href*="upgrade"] {
  font-size: 0.85rem;
  font-weight: 800;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: white !important;
  border-radius: 999px;
  min-height: 36px;
  box-shadow: 0 4px 12px rgba(45, 108, 223, 0.2);
  justify-content: center;
  margin-top: 8px;
}

.sidebar-nav .nav-upgrade-link:hover,
.sidebar-nav a[href*="upgrade"]:hover {
  opacity: 0.9;
}

.sidebar-footer {
  padding: 12px 10px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  border-top: 1px solid var(--line);
}

.sidebar-footer .nav-theme-toggle {
  width: 100%;
  justify-content: center;
}

.sidebar-legal {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
  padding: 0 4px 8px;
  font-size: 0.8rem;
}

.sidebar-legal a {
  color: var(--muted);
  text-decoration: none;
  padding: 2px 4px;
  transition: color 0.15s ease;
}

.sidebar-legal a:hover {
  color: var(--blue-deep);
}

.sidebar-legal .sep {
  color: var(--line);
  padding: 2px 2px;
  user-select: none;
}

/* Scrim overlay for mobile drawer */
.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 98;
}

.sidebar-scrim.is-visible {
  display: block;
}

/* Main content area — sits beside sidebar on desktop */
.main-content {
  min-height: 100vh;
}

/* Mobile top bar (hidden on desktop) */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 90;
  align-items: center;
  padding: 0 12px;
}

.mobile-hamburger {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mobile-hamburger:hover {
  background: var(--surface-soft);
  border-color: var(--blue);
}

.mobile-hamburger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(45, 108, 223, 0.18);
}

/* Desktop: sidebar visible, content offset */
@media (min-width: 1024px) {
  .main-content {
    margin-left: 260px;
  }
}

/* Mobile: sidebar becomes off-canvas drawer */
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    width: 80vw;
    max-width: 320px;
    transition: transform 0.25s ease-out;
    z-index: 99;
  }

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

  .mobile-topbar {
    display: flex;
  }

  .main-content {
    padding-top: 56px;
  }

  body.drawer-open {
    overflow: hidden;
  }
}

/* ===== Legal / Policy Page Typography ===== */
.legal-content {
  max-width: 780px;
  margin-inline: auto;
}

.legal-content h2 {
  margin: 32px 0 12px;
  font-size: 1.15rem;
  color: var(--text);
  line-height: 1.3;
}

.legal-content p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.7;
}

.legal-content ul {
  margin: 0 0 16px;
  padding-left: 24px;
  list-style: none;
}

.legal-content li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.6;
}

.legal-content li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line);
}

.legal-content a {
  color: var(--blue-deep);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.legal-content a:hover {
  color: var(--blue);
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 22px;
  align-items: stretch;
  padding-top: 18px;
}

.hero-copy,
.hero-panel,
.auth-copy {
  padding: 12px 2px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--purple);
  font-size: 0.84rem;
  font-weight: 700;
}

.hero h1,
.section-head h1 {
  margin: 14px 0 8px;
  font-size: clamp(2.2rem, 5vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.hero-tagline {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--blue-deep);
}

.hero-text,
.section-head p,
.auth-copy p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.7;
  max-width: 60ch;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.hero-pills,
.soft-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.pill,
.soft-list span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--blue-deep);
  font-size: 0.9rem;
  border: 1px solid var(--chip-border);
}

.hero-panel {
  background: var(--panel-gradient);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel-title {
  font-weight: 800;
  margin-bottom: 14px;
}

.panel-grid,
.feature-grid,
.quick-grid,
.cheat-grid,
.notes-area {
  display: grid;
  gap: 14px;
}

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

.mini-card,
.feature-card,
.status-card,
.note-card,
.cheat-card,
.info-card,
.day-block,
.redirect-card,
.result-message,
.card,
.info-surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.mini-card {
  display: block;
  text-decoration: none;
  padding: 16px;
}

.mini-card strong,
.feature-card strong,
.note-card strong,
.cheat-card strong,
.info-card strong,
.day-block strong {
  display: block;
  margin-bottom: 6px;
}

.mini-card span,
.feature-card p,
.note-card p,
.cheat-card p,
.info-card span,
.day-block .task,
.result-message p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.section-block {
  margin-top: 26px;
}

.section-head {
  margin-bottom: 16px;
}

.section-head h2,
.section-head h1 {
  margin: 0;
}

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

.feature-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
  padding: 18px;
}

.feature-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--icon-gradient);
  color: var(--blue-deep);
  font-weight: 800;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 13px 20px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  min-height: 44px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  box-shadow: 0 12px 24px rgba(45, 108, 223, 0.24);
}

.btn-secondary,
.btn-ghost {
  color: var(--blue-deep);
  background: var(--button-secondary-bg);
  border-color: var(--button-secondary-border);
}

.btn-ghost {
  background: var(--surface-elevated);
}

.btn-large {
  padding: 15px 24px;
}

.btn-small {
  padding: 11px 14px;
  font-size: 0.9rem;
  min-height: 40px;
}

.btn-block {
  width: 100%;
  margin-top: 16px;
}

.auth-shell,
.split-layout {
  display: grid;
  gap: 20px;
}

.auth-grid,
.split-layout {
  grid-template-columns: 1.1fr 0.9fr;
}

.form-card {
  padding: 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

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

label {
  display: grid;
  gap: 8px;
  font-size: 0.94rem;
  color: var(--text);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--control-bg);
  color: var(--control-text);
  font: inherit;
  outline: none;
  caret-color: var(--control-text);
}

input::placeholder,
textarea::placeholder {
  color: var(--control-placeholder);
  opacity: 1;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(45, 108, 223, 0.1);
}

.aside-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.status-card {
  padding: 18px;
}

.status-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.status-card strong {
  font-size: 1.4rem;
}

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

.dashboard-card {
  min-height: 154px;
}

.quiz-stack {
  display: grid;
  gap: 16px;
}

.question-card {
  padding: 18px;
}

.question-card legend {
  font-weight: 800;
  padding: 0 0 10px;
  color: var(--text);
}

.question-card label {
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.question-card input {
  width: auto;
}

.result-message {
  padding: 22px;
  margin-top: 16px;
}

.result-message strong {
  display: block;
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.result-actions {
  margin-top: 18px;
}

.notes-area,
.cheat-grid {
  margin-top: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.note-card,
.cheat-card,
.info-card {
  padding: 18px;
}

.table-card {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 650px;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--blue-deep);
  font-size: 0.92rem;
  background: var(--table-head-bg);
}

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

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 14px;
}

.day-block {
  padding: 16px;
  min-height: 180px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.task {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--task-bg);
  border: 1px solid var(--task-border);
  color: var(--muted);
}

.redirect-card {
  width: min(480px, calc(100% - 32px));
  margin: 12vh auto 0;
  padding: 24px;
  text-align: center;
}

.redirect-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

@media (max-width: 1080px) {
  .hero,
  .auth-grid,
  .split-layout {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 720px) {
  .page-shell,
  .topbar {
    width: min(100%, calc(100% - 20px));
  }

  .topbar {
    padding: 10px 14px;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 9;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
    padding: 10px;
    justify-content: flex-start;
  }

  .nav-links.is-open {
    display: flex;
  }

  .nav-links a,
  .nav-links .nav-upgrade-link,
  .nav-links a[href*="upgrade"],
  .nav-links a[href*="logout"] {
    width: 100%;
    justify-content: center;
    padding: 12px 14px !important;
    min-height: 44px;
    font-size: 0.94rem !important;
    opacity: 1;
  }

  .nav-links .nav-theme-toggle {
    width: 100%;
    justify-content: center;
    padding: 12px 14px;
    min-height: 44px;
    margin-top: 4px;
  }

  .nav-hamburger {
    display: inline-flex;
    margin-left: auto;
  }

  .brand-text small {
    display: none;
  }

  .panel-grid,
  .feature-grid,
  .quick-grid,
  .status-strip,
  .form-grid,
  .notes-area,
  .cheat-grid,
  .week-grid {
    grid-template-columns: 1fr;
  }

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

  .hero h1,
  .section-head h1 {
    font-size: 2.2rem;
  }
}
