:root {
  --red: #c8102e;
  --red-dark: #a00d24;
  --gray-900: #111827;
  --gray-800: #1f2937;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-400: #9ca3af;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --white: #ffffff;
  --green: #16a34a;
  --yellow: #d97706;
  --blue: #1d4ed8;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--gray-900);
  color: var(--white);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }

/* ── LAYOUT ─────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: var(--gray-800);
  border-bottom: 2px solid var(--red);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--red);
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.logo span { color: var(--white); }

nav { display: flex; gap: 0.25rem; flex: 1; }

.nav-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}

.nav-btn:hover { background: var(--gray-700); color: var(--white); }
.nav-btn.active { background: var(--red); color: var(--white); }

.exam-toggle {
  display: flex;
  background: var(--gray-700);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
  margin-left: auto;
}

.exam-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.3rem 0.9rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font);
  transition: all 0.15s;
}

.exam-btn.active { background: var(--red); color: var(--white); }

main { flex: 1; display: flex; }

/* ── SIDEBAR ─────────────────────────────────────────── */

#sidebar {
  width: 280px;
  background: var(--gray-800);
  border-right: 1px solid var(--gray-700);
  overflow-y: auto;
  flex-shrink: 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}

.sidebar-search {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-700);
}

.sidebar-search input {
  width: 100%;
  background: var(--gray-700);
  border: 1px solid var(--gray-600);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  color: var(--white);
  font-family: var(--font);
  font-size: 0.85rem;
}

.sidebar-search input::placeholder { color: var(--gray-400); }
.sidebar-search input:focus { outline: none; border-color: var(--red); }

.domain-group { border-bottom: 1px solid var(--gray-700); }

.domain-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.domain-header:hover { background: var(--gray-700); }

.domain-badge {
  background: var(--red);
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
}

.domain-name {
  font-size: 0.875rem;
  font-weight: 600;
  flex: 1;
}

.domain-weight {
  font-size: 0.75rem;
  color: var(--gray-400);
}

.domain-chevron {
  color: var(--gray-400);
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.domain-group.open .domain-chevron { transform: rotate(90deg); }

.objective-list { display: none; }
.domain-group.open .objective-list { display: block; }

.obj-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 1rem 0.5rem 1.75rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--gray-400);
  line-height: 1.4;
  transition: all 0.1s;
}

.obj-item:hover { background: var(--gray-700); color: var(--white); }

.obj-item.active {
  background: rgba(200, 16, 46, 0.15);
  color: var(--white);
  border-left: 2px solid var(--red);
}

.obj-num {
  font-weight: 700;
  color: var(--red);
  flex-shrink: 0;
  font-size: 0.75rem;
}

/* ── CONTENT AREA ─────────────────────────────────────────── */

#content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  max-width: 900px;
}

/* ── HOME VIEW ─────────────────────────────────────────── */

#home-view {
  display: none;
}

.home-hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
}

.home-hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.home-hero h1 span { color: var(--red); }

.home-hero p {
  color: var(--gray-400);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

.exam-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  max-width: 700px;
  margin: 0 auto 3rem;
}

.exam-card {
  background: var(--gray-800);
  border: 1px solid var(--gray-700);
  border-radius: 12px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.exam-card:hover {
  border-color: var(--red);
  transform: translateY(-2px);
}

.exam-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.exam-card-sub {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-bottom: 1rem;
}

.exam-card-stats {
  display: flex;
  gap: 1rem;
}

.stat {
  font-size: 0.75rem;
  color: var(--gray-400);
}

.stat strong {
  display: block;
  font-size: 1.25rem;
  color: var(--white);
}

.domain-grid {
  max-width: 700px;
  margin: 0 auto;
}

.domain-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.domain-row-name { font-size: 0.875rem; width: 220px; flex-shrink: 0; }

.domain-bar-wrap {
  flex: 1;
  background: var(--gray-700);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.domain-bar {
  height: 100%;
  background: var(--red);
  border-radius: 999px;
}

.domain-row-pct { font-size: 0.8rem; color: var(--gray-400); width: 35px; text-align: right; }

/* ── STUDY VIEW ─────────────────────────────────────────── */

#study-view { display: none; }

.obj-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--gray-700);
}

.obj-tag {
  display: inline-block;
  background: var(--red);
  color: var(--white);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.obj-title {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.3;
}

.study-content h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--red);
  margin: 1.25rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

.study-content ul, .study-content ol {
  padding-left: 1.25rem;
  margin-bottom: 0.5rem;
}

.study-content li { margin-bottom: 0.25rem; font-size: 0.925rem; color: var(--gray-200); }

.study-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.875rem;
}

.study-content th {
  background: var(--gray-700);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
}

.study-content td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-700);
  color: var(--gray-200);
}

.study-content tr:last-child td { border-bottom: none; }

.study-content strong { color: var(--white); }

.study-nav {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-700);
}

.btn {
  background: var(--gray-700);
  border: none;
  color: var(--white);
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
}

.btn:hover { background: var(--gray-600); }
.btn.primary { background: var(--red); }
.btn.primary:hover { background: var(--red-dark); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── QUIZ VIEW ─────────────────────────────────────────── */

#quiz-view { display: none; }

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.quiz-meta { font-size: 0.85rem; color: var(--gray-400); }
.quiz-meta strong { color: var(--white); }

.quiz-scope {
  background: var(--gray-800);
  border: 1px solid var(--gray-700);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.quiz-scope h3 { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.05em; }

.scope-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.scope-chip {
  background: var(--gray-700);
  border: 1px solid var(--gray-600);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font);
  color: var(--gray-400);
  transition: all 0.15s;
}

.scope-chip.active { background: var(--red); border-color: var(--red); color: var(--white); }
.scope-chip:hover:not(.active) { border-color: var(--gray-400); color: var(--white); }

.flashcard-area {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.flashcard {
  width: 100%;
  max-width: 640px;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 220px;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--gray-800);
  border: 1px solid var(--gray-700);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  min-height: 220px;
}

.flashcard-back { transform: rotateY(180deg); }

.flashcard-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray-400);
  margin-bottom: 1rem;
}

.flashcard-front .flashcard-label { color: var(--red); }
.flashcard-back .flashcard-label { color: var(--green); }

.flashcard-text {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--white);
}

.flashcard-hint {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--gray-600);
}

.quiz-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.quiz-progress {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--gray-400);
}

.progress-bar-wrap {
  width: 100%;
  max-width: 640px;
  height: 4px;
  background: var(--gray-700);
  border-radius: 999px;
  margin: 0.75rem auto 0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--red);
  border-radius: 999px;
  transition: width 0.3s;
}

.quiz-empty {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--gray-400);
}

/* ── WELCOME PROMPT ─────────────────────────────────────────── */

#welcome-view {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 2rem;
}

.welcome-inner {
  text-align: center;
  max-width: 480px;
}

.welcome-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.welcome-inner h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.welcome-inner p { color: var(--gray-400); font-size: 0.95rem; }

/* ── RESPONSIVE ─────────────────────────────────────────── */

@media (max-width: 768px) {
  #sidebar { display: none; }
  #content { padding: 1.25rem; }
  .exam-cards { grid-template-columns: 1fr; }
}
