:root {
  --accent: #4F46E5;
  --accent-hover: #4338CA;
  --accent-soft: #EEF2FF;
  --on-accent: #FFFFFF;
  --red: #DC2626;
  --red-dark: #B91C1C;
  --red-soft: #FEE2E2;
  --green: #16A34A;
  --green-soft: #DCFCE7;
  --amber: #B45309;
  --amber-soft: #FEF3C7;
  --ink: #0F172A;
  --ink-mid: #475569;
  --ink-light: #64748B;
  --border: #E2E8F0;
  --bg: #FFFFFF;
  --sidebar-bg: #F8FAFC;
  --surface: #FFFFFF;
  --reveal-bg: #1E1B3A;
  --reveal-fg: #EEF2FF;
  /* Dimensions grounded on outsystems.com: ~6-8px button radius, 8-12px card radius, ~1200px content width */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 8px rgba(15,23,42,.05);
  --shadow-hover: 0 4px 10px rgba(15,23,42,.08), 0 10px 28px rgba(15,23,42,.10);
  --elevation-1: 0 1px 3px rgba(79,70,229,.12), 0 1px 2px rgba(79,70,229,.08);
  --elevation-2: 0 3px 6px rgba(79,70,229,.14), 0 4px 14px rgba(79,70,229,.12);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  /* Bootstrap container breakpoints (lg/xl/xxl) */
  --container-lg: 960px;
  --container-xl: 1140px;
  --container-xxl: 1320px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #818CF8;
    --accent-hover: #A5B4FC;
    --accent-soft: rgba(129,140,248,.18);
    --on-accent: #FFFFFF;
    --red: #F87171;
    --red-dark: #FCA5A5;
    --red-soft: rgba(248,113,113,.16);
    --green: #4ADE80;
    --green-soft: rgba(74,222,128,.16);
    --amber: #FBBF24;
    --amber-soft: rgba(251,191,36,.16);
    --ink: #F1F5F9;
    --ink-mid: #94A3B8;
    --ink-light: #7C8798;
    --border: #334155;
    --bg: #0F172A;
    --sidebar-bg: #1E293B;
    --surface: #1E293B;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 8px rgba(0,0,0,.3);
    --shadow-hover: 0 4px 10px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.45);
    --elevation-1: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --elevation-2: 0 3px 6px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
  }
}

:root[data-theme="dark"] {
  --accent: #818CF8;
  --accent-hover: #A5B4FC;
  --accent-soft: rgba(129,140,248,.18);
  --on-accent: #FFFFFF;
  --red: #F87171;
  --red-dark: #FCA5A5;
  --red-soft: rgba(248,113,113,.16);
  --green: #4ADE80;
  --green-soft: rgba(74,222,128,.16);
  --amber: #FBBF24;
  --amber-soft: rgba(251,191,36,.16);
  --ink: #F1F5F9;
  --ink-mid: #94A3B8;
  --ink-light: #7C8798;
  --border: #334155;
  --bg: #0F172A;
  --sidebar-bg: #1E293B;
  --surface: #1E293B;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 8px rgba(0,0,0,.3);
  --shadow-hover: 0 4px 10px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.45);
  --elevation-1: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --elevation-2: 0 3px 6px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[x-cloak] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  transition: background-color .2s ease, color .2s ease;
}

/* TOPBAR */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 300;
  transition: background-color .2s ease, border-color .2s ease;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.profile { position: relative; }

.profile-btn {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
}

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}

.avatar-lg { width: 40px; height: 40px; font-size: 16px; }

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--elevation-2);
  padding: 8px;
  z-index: 300;
}

.profile-menu-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.profile-menu-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  margin-bottom: 4px;
  background: var(--sidebar-bg);
  border-radius: var(--radius-sm);
}

.profile-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 8px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background-color .15s;
}

.profile-menu-item:hover { background: var(--accent-soft); }

/* SHELL */
.shell {
  display: flex;
  align-items: flex-start;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  background: var(--accent);
  color: var(--on-accent);
  padding: 10px 16px;
  z-index: 1000;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

/* SIDEBAR (MD3-style navigation rail, becomes a bottom tab bar on mobile) */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
  align-self: flex-start;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  transition: background-color .2s ease, border-color .2s ease;
}

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 12px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-mid);
  text-align: left;
  width: 100%;
  transition: background-color .15s, color .15s;
}

.nav-tab:hover { background: var(--sidebar-bg); color: var(--ink); }
.nav-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* PAGES */
.content { flex: 1; min-width: 0; }
.page { padding: 40px 56px; max-width: 1140px; }

@media (min-width: 1440px) {
  .page { max-width: 1320px; padding: 48px 64px; }
}

/* FORM FIELDS */
.select-field {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s;
}

.select-field:hover { border-color: var(--accent); }

.select-field option {
  background: var(--surface);
  color: var(--ink);
}

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  transition: background-color .2s ease, border-color .2s ease;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--elevation-1); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--elevation-2); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--ink-mid); }
.btn-ghost:hover { color: var(--ink); background: var(--sidebar-bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* BADGES (kept semantic: red/amber/green convey real weak/medium/strong topic data) */
.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.badge-red { background: var(--red-soft); color: var(--red-dark); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--accent-soft); color: var(--accent); }
.badge-gray { background: var(--sidebar-bg); color: var(--ink-mid); border: 1px solid var(--border); }

/* TRACKER */
.tracker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.tracker-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: background-color .2s ease, border-color .2s ease, box-shadow .15s ease;
}

.tracker-item:hover { box-shadow: var(--shadow); }

.tracker-item .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-mid);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .4s ease;
}

.progress-fill.red { background: var(--red); }
.progress-fill.amber { background: var(--amber); }
.progress-fill.green { background: var(--green); }

.tracker-stats {
  font-size: 12px;
  color: var(--ink-light);
  display: flex;
  justify-content: space-between;
}

/* QUIZ */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.quiz-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-light);
}

.topic-tag {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  display: inline-block;
}

.question-text {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 20px;
  color: var(--ink);
}

.options { display: flex; flex-direction: column; gap: 8px; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  background: var(--surface);
  text-align: left;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  font-family: inherit;
}

.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option:disabled { cursor: default; }

.option-letter {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-light);
  min-width: 18px;
  margin-top: 1px;
}

.explanation {
  margin-top: 16px;
  padding: 14px;
  background: var(--sidebar-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  font-size: 13px;
  color: var(--ink-mid);
  line-height: 1.6;
  display: none;
}

.explanation.show { display: block; }
.explanation strong { color: var(--ink); }

.quiz-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.progress-text {
  font-size: 13px;
  color: var(--ink-light);
}

/* TIMER */
.timer {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: .02em;
}

.timer.warning { color: var(--amber); }
.timer.danger { color: var(--red); }

/* RESULT */
.result-circle {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  margin: 0 auto 20px;
  font-size: 26px;
  font-weight: 600;
}

.result-circle.pass { background: var(--green-soft); color: var(--green); border: 2px solid var(--green); }
.result-circle.fail { background: var(--red-soft); color: var(--red-dark); border: 2px solid var(--red); }

.result-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }

/* FLASHCARDS */
.flashcard-wrap { perspective: 1000px; }

.flashcard {
  width: 100%;
  min-height: 200px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.4,0,.2,1);
  cursor: pointer;
  border-radius: var(--radius);
}

.flashcard:hover { box-shadow: var(--shadow-hover); }
.flashcard.flipped { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  width: 100%;
  min-height: 200px;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: center;
}

.flashcard-front {
  background: var(--surface);
}

.flashcard-back {
  background: var(--reveal-bg);
  color: var(--reveal-fg);
  transform: rotateY(180deg);
  border-color: var(--reveal-bg);
}

.flashcard-front .card-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-light);
  margin-bottom: 16px;
}

.flashcard-front .card-q {
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.5;
}

.flashcard-back .card-a {
  font-size: 15px;
  line-height: 1.6;
  color: rgba(240,243,246,.92);
}

.flashcard-hint {
  font-size: 12px;
  color: var(--ink-light);
  text-align: center;
  margin-top: 10px;
  margin-bottom: 20px;
}

.fc-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.fc-counter {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-mid);
  min-width: 60px;
  text-align: center;
}

/* RULES */
.rules-topic {
  margin-bottom: 10px;
}

.rules-topic summary {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  transition: border-color .15s;
}

.rules-topic summary:hover { border-color: var(--accent); }
.rules-topic summary::-webkit-details-marker { display: none; }
.rules-topic[open] summary { border-radius: var(--radius-sm) var(--radius-sm) 0 0; border-bottom-color: transparent; }

.rules-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 14px 16px;
}

.rules-body ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.rules-body li {
  display: flex;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-mid);
  line-height: 1.5;
}

.rules-body li::before {
  content: "→";
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}

/* MODE SELECTOR */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 20px 0;
}

.mode-card {
  padding: 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  text-align: left;
  transition: all .15s;
  font-family: inherit;
}

.mode-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.mode-card.selected { border-color: var(--accent); background: var(--accent-soft); }

.mode-card .mode-icon { font-size: 24px; margin-bottom: 8px; }
.mode-card .mode-name { font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.mode-card .mode-desc { font-size: 12px; color: var(--ink-mid); line-height: 1.4; }

/* TOPIC FILTER */
.topic-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0;
}

.filter-chip {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all .15s;
  color: var(--ink-mid);
  font-family: inherit;
}

.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* PAGE TITLE */
.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--ink-light);
  margin-bottom: 24px;
}

/* DIVIDER */
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* UTILITY */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none; }
.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;
}
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--ink-light); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.font-semibold { font-weight: 600; }

/* MOBILE: sidebar becomes a fixed bottom tab bar, topbar stays on top */
@media (max-width: 700px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-height: auto;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    z-index: 200;
  }

  .nav-tabs {
    flex: 1;
    flex-direction: row;
    justify-content: space-around;
    padding: 0;
    gap: 0;
  }

  .nav-tab {
    flex-direction: column;
    gap: 2px;
    font-size: 10px;
    padding: 8px 4px;
    min-height: 48px;
    border-radius: var(--radius-sm);
    justify-content: center;
  }

  .profile-menu { width: calc(100vw - 32px); max-width: 280px; }

  .content { padding-bottom: 76px; }
  .page { padding: 20px 16px; }
  .mode-cards { grid-template-columns: 1fr; }
  .tracker-grid { grid-template-columns: 1fr; }
}

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