:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #555570;
  --text-dim: #8888a0;
  --accent: #E8562A;
  --accent-light: rgba(232, 86, 42, 0.08);
  --accent-mid: rgba(232, 86, 42, 0.18);
  --border: #e4e4ec;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
  --node-bg: #ffffff;
  --node-border: #d0d0dc;
  --node-text: #1a1a2e;
  --node-hover-bg: #fff8f5;
  --node-active-bg: #fff0ea;
  --edge-color: rgba(232, 86, 42, 0.22);
  --edge-hover: rgba(232, 86, 42, 0.7);
  --break-bg: rgba(232, 86, 42, 0.05);
  --break-border: rgba(232, 86, 42, 0.18);
  --tooltip-bg: #1a1a2e;
  --tooltip-text: #f0f0f0;
  --week-bg: rgba(232, 86, 42, 0.03);
  --week-border: rgba(232, 86, 42, 0.08);
  --week-text: #8888a0;
  --col-bg: rgba(232, 86, 42, 0.025);
  --search-bg: #ffffff;
  --search-border: #d0d0dc;
  --search-focus: rgba(232, 86, 42, 0.3);
  --highlight-bg: rgba(232, 86, 42, 0.08);
}

[data-theme="dark"] {
  --bg: #0e0e14;
  --bg-card: #181822;
  --text: #e4e4f0;
  --text-secondary: #a0a0b8;
  --text-dim: #6a6a82;
  --accent: #FF7A4A;
  --accent-light: rgba(255, 122, 74, 0.08);
  --accent-mid: rgba(255, 122, 74, 0.15);
  --border: #28283a;
  --shadow: 0 1px 3px rgba(0,0,0,0.25);
  --node-bg: #1c1c28;
  --node-border: #34344a;
  --node-text: #e4e4f0;
  --node-hover-bg: #241c1a;
  --node-active-bg: #2e1e18;
  --edge-color: rgba(255, 122, 74, 0.18);
  --edge-hover: rgba(255, 122, 74, 0.65);
  --break-bg: rgba(255, 122, 74, 0.05);
  --break-border: rgba(255, 122, 74, 0.12);
  --tooltip-bg: #e4e4f0;
  --tooltip-text: #1a1a2e;
  --week-bg: rgba(255, 122, 74, 0.03);
  --week-border: rgba(255, 122, 74, 0.08);
  --week-text: #6a6a82;
  --col-bg: rgba(255, 122, 74, 0.02);
  --search-bg: #1c1c28;
  --search-border: #34344a;
  --search-focus: rgba(255, 122, 74, 0.25);
  --highlight-bg: rgba(255, 122, 74, 0.06);
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

h1, h2, h3 {
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  line-height: 1.3;
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.05rem;
  box-shadow: var(--shadow);
  transition: background 0.3s, border-color 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
header {
  text-align: center;
  padding: 3rem 1.5rem 1rem;
  max-width: 680px;
  margin: 0 auto;
}

header h1 {
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

header p {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 500px;
  margin: 0 auto;
}

.course-link {
  display: inline-block;
  margin-top: 0.65rem;
  font-family: 'Sora', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent-mid);
  background: var(--accent-light);
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  transition: background 0.2s, border-color 0.2s;
}
.course-link:hover {
  background: var(--accent-mid);
  border-color: var(--accent);
}

/* Graph */
#graph-container {
  width: 100%;
  max-width: 1180px;
  margin: 1rem auto 1.5rem;
  padding: 0 0.75rem;
  position: relative;
}

#graph-svg {
  width: 100%;
  height: auto;
  display: block;
}

.graph-tooltip {
  position: fixed;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  font-size: 0.8rem;
  max-width: 280px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
  line-height: 1.45;
  font-family: 'Outfit', sans-serif;
}

.edge-label-tooltip {
  position: fixed;
  background: var(--accent);
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: 5px;
  font-size: 0.72rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  white-space: nowrap;
}

/* Search + controls bar */
.controls-bar {
  max-width: 700px;
  margin: 0 auto 1rem;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.search-wrap {
  flex: 1;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2rem;
  border: 1px solid var(--search-border);
  border-radius: 8px;
  background: var(--search-bg);
  color: var(--text);
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--search-focus);
}

.search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 0.85rem;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.1rem 0.2rem;
  display: none;
  line-height: 1;
}
.search-clear:hover { color: var(--text); }

.toggle-all-btn {
  font-family: 'Sora', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s;
}
.toggle-all-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.no-results {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  display: none;
}

/* Content */
main {
  max-width: 700px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.week-group {
  margin-bottom: 2rem;
}

.week-group.search-hidden { display: none; }

.week-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.week-label {
  font-family: 'Sora', sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--accent-mid);
  padding: 0.25rem 0.7rem;
  border-radius: 20px;
  white-space: nowrap;
}

.week-topic {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 500;
}

.week-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Section cards */
.section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.3s, box-shadow 0.3s;
}

.section.visible {
  opacity: 1;
  transform: translateY(0);
}

.section.highlighted {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-mid);
}

.section.search-hidden { display: none; }

.section.search-match .section-body mark {
  background: var(--accent-mid);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

.section-header {
  display: flex;
  align-items: center;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  gap: 0.65rem;
}

.section-header:hover { background: var(--accent-light); }
.section-header:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.section-header h2 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.lecture-badge {
  font-family: 'Sora', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.collapse-icon {
  font-size: 0.9rem;
  color: var(--text-dim);
  transition: transform 0.25s;
  flex-shrink: 0;
  width: 1rem;
  text-align: center;
}

.section.collapsed .collapse-icon { transform: rotate(-90deg); }

.section-body {
  padding: 0 1.1rem 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.section.collapsed .section-body {
  max-height: 0 !important;
  padding-top: 0;
  padding-bottom: 0;
}

.section-body p { margin-bottom: 0.55rem; }
.section-body strong { color: var(--text); font-weight: 600; }
.section-body code {
  background: var(--accent-light);
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.87em;
}
.section-body ul, .section-body ol {
  margin: 0.4rem 0 0.65rem 1.1rem;
}
.section-body li { margin-bottom: 0.2rem; }

/* Locked / under construction lectures */
.section.locked .section-header { cursor: default; }
.section.locked .section-header:hover { background: transparent; }
.section.locked .lecture-badge { background: var(--text-dim); }
.section.locked .collapse-icon { display: none; }
.section.locked .section-body { max-height: none !important; padding: 0 1.1rem 1rem; }
.section.locked.visible { opacity: 0.55; }

.locked-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
}
.locked-banner svg { flex-shrink: 0; }

/* Back link */
.back-link {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.back-link:hover { opacity: 1; text-decoration: underline; }

/* Break banner */
.break-banner {
  background: var(--break-bg);
  border: 1px dashed var(--break-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  text-align: center;
  margin-bottom: 2rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.break-banner.visible { opacity: 1; transform: translateY(0); }
.break-banner span {
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--accent);
}

/* Mobile graph */
.mobile-graph {
  display: none;
  padding: 0 0.25rem;
}

.mobile-graph .mg-week {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.mobile-graph .mg-label {
  font-family: 'Sora', sans-serif;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: 2.5rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-graph .mg-nodes {
  display: flex;
  gap: 0.4rem;
  flex: 1;
}

.mobile-graph .mg-node {
  flex: 1;
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}

.mobile-graph .mg-node:hover {
  border-color: var(--accent);
  background: var(--node-hover-bg);
}

.mobile-graph .mg-node.mg-active {
  border-color: var(--accent);
  background: var(--node-active-bg);
}

.mobile-graph .mg-node .mg-num {
  font-family: 'Sora', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
}

.mobile-graph .mg-node .mg-title {
  font-size: 0.7rem;
  color: var(--node-text);
  margin-top: 0.15rem;
  line-height: 1.3;
}

.mobile-graph .mg-node.mg-locked {
  opacity: 0.45;
  cursor: default;
  border-style: dashed;
}
.mobile-graph .mg-node.mg-locked .mg-num { color: var(--text-dim); }
.mobile-graph .mg-node.mg-locked:hover {
  border-color: var(--node-border);
  background: var(--node-bg);
}

.mobile-graph .mg-break {
  text-align: center;
  padding: 0.5rem;
  font-family: 'Sora', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  opacity: 0.6;
  margin-bottom: 0.5rem;
}

/* Lecture summary modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(4px);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 600px;
  width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  transform: translateY(16px) scale(0.97);
  transition: transform 0.25s ease;
  position: relative;
}
.modal-overlay.active .modal-card {
  transform: translateY(0) scale(1);
}
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-dim);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover {
  background: var(--accent-light);
  color: var(--accent);
}
.modal-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-family: 'Sora', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}
.modal-title {
  font-family: 'Sora', sans-serif;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 1.25rem;
  padding-right: 2rem;
}
.modal-section {
  margin-bottom: 1.25rem;
}
.modal-section-label {
  font-family: 'Sora', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.modal-section p {
  font-family: 'Outfit', sans-serif;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}
.modal-section p strong {
  color: var(--text);
  font-weight: 500;
}
.modal-prereqs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.3rem;
}
.modal-prereq-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent-light);
  border: 1px solid var(--accent-mid);
  border-radius: 8px;
  padding: 0.25rem 0.6rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}
.modal-prereq-chip:hover {
  background: var(--accent-mid);
}
.modal-prereq-chip .chip-num {
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--accent);
}
.modal-connection-arrow {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--week-bg);
  border: 1px solid var(--week-border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.4rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.modal-connection-arrow .conn-label {
  font-weight: 500;
  color: var(--text);
}
.modal-connection-arrow .conn-arrow {
  color: var(--accent);
  font-size: 0.9rem;
}
.modal-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.modal-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.modal-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}
.modal-progress-text {
  font-family: 'Sora', sans-serif;
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 640px) {
  header { padding: 2.5rem 1rem 0.75rem; }
  main { padding: 0 1rem 3rem; }
  .controls-bar { padding: 0 1rem; }
  .section-header { padding: 0.75rem 0.9rem; }
  .section-body { padding: 0 0.9rem 0.9rem; }
  #graph-svg { display: none; }
  .mobile-graph { display: block; }
  .modal-card { padding: 1.5rem 1.25rem; }
}
