/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-2: #F8F8F8;
  --surface-3: #F0F0F0;
  --ink: #1C2B4A;
  --ink-soft: #49536A;
  --ink-mute: #8B8F9C;
  --line: #DADADA;
  --line-strong: #CCCCCC;

  --blue: #375F9E;
  --green: #2C7355;
  --amber: #B0660F;
  --connector: #333333;

  --required-bg: #E4ECF7;

  --shadow-sm: 0 1px 2px rgba(28, 43, 74, 0.06);
  --shadow-md: 0 4px 18px -6px rgba(28, 43, 74, 0.16);
  --shadow-lg: 0 18px 48px -16px rgba(28, 43, 74, 0.28);

  --r-sm: 8px;
  --r-md: 12px;

  --font-display: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SFMono-Regular', ui-monospace, 'Cascadia Code', Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #10182A;
  --surface: #1A2540;
  --surface-2: #202C4B;
  --surface-3: #27345A;
  --ink: #ECE9DF;
  --ink-soft: #AEB6C7;
  --ink-mute: #727A8E;
  --line: #2C3A5E;
  --line-strong: #3A4A72;

  --blue: #7397D2;
  --green: #5BAE86;
  --amber: #D58A3C;
  --connector: #B0B0B0;

  --required-bg: #1E3158;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 18px -6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 48px -16px rgba(0, 0, 0, 0.6);
}

/* ============================================================
   BASE
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 0.35s ease, color 0.35s ease;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

select { font-family: inherit; font-size: 14px; color: var(--ink); }

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  gap: 12px;
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.015em;
}

.brand .subtitle {
  font-size: 11px;
  color: var(--ink-mute);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.header-controls { display: flex; align-items: center; gap: 10px; }

.header-select {
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-weight: 500;
  min-width: 220px;
  transition: border-color 0.15s;
}
.header-select:focus { border-color: var(--blue); outline: none; }

.btn-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  padding: 8px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--surface-3); color: var(--ink); }
.btn-icon svg { width: 17px; height: 17px; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  color: var(--ink-mute);
}

.empty-icon { margin-bottom: 24px; opacity: 0.4; }

.empty-state h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.empty-state p {
  max-width: 420px;
  font-size: 14px;
  line-height: 1.6;
}

/* ============================================================
   FLOWCHART
   ============================================================ */
.flowchart {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Controls bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}

.controls-left { display: flex; align-items: center; gap: 12px; }

.major-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
}

.course-count {
  font-size: 12px;
  color: var(--ink-mute);
  background: var(--surface-3);
  padding: 2px 10px;
  border-radius: 20px;
}

.controls-right { display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--surface-3); color: var(--ink); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }


/* Legend bar */
.legend-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 5px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-mute);
  flex-shrink: 0;
}

.legend-item { display: flex; align-items: center; gap: 6px; }

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-line {
  width: 20px; height: 0;
  border-top: 2px solid var(--ink-mute);
  flex-shrink: 0;
}
.legend-line.dashed { border-top-style: dashed; }

/* ============================================================
   LEVEL GRID
   ============================================================ */
.main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.level-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 1;
  padding: 12px 20px 24px;
  gap: 20px;
}

.level-row {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: 0 1px 3px rgba(28, 43, 74, 0.05);
  overflow: visible;
  flex-shrink: 0;
  width: 100%;
}

.level-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 2px solid var(--line);
  background: var(--surface);
}

.level-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.level-sub {
  font-size: 11px;
  color: var(--ink-mute);
  font-weight: 500;
}

/* Flow arrow indicators between level rows */
.level-row:not(:last-child) { position: relative; }
.level-row:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 50%;
  width: 10px;
  height: 10px;
  border-right: 2.5px solid var(--connector);
  border-bottom: 2.5px solid var(--connector);
  transform: translateX(-50%) rotate(45deg);
  z-index: 4;
  opacity: 0.5;
}

.level-courses {
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 60px;
  align-content: flex-start;
}


/* ============================================================
   COURSE CARD
   ============================================================ */
.course-card {
  position: relative;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border-left: 4px solid transparent;
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.25s, background 0.15s;
  z-index: 2;
  min-width: 160px;
  width: 175px;
  flex-shrink: 0;
  min-height: 100px;
  display: flex;
  flex-direction: column;
}

.course-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  background: var(--surface);
}

.course-card.required {
  border-left-color: var(--blue);
  background: var(--required-bg);
}
.course-card.elective { border-left-color: var(--green); }

.course-card .card-header-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.course-card .card-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.card-badge {
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.4;
}

.required-badge {
  background: color-mix(in srgb, var(--blue) 15%, transparent);
  color: var(--blue);
}

.optional-badge {
  background: color-mix(in srgb, var(--amber) 15%, transparent);
  color: var(--amber);
}

.course-card.required .card-code { color: var(--blue); }
.course-card.elective .card-code { color: var(--green); }

.course-card .card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
}

.course-card .card-meta {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  font-size: 10px;
  color: var(--ink-mute);
}

/* Prerequisite tags */
.card-prereqs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}

.prereq-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-mute);
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.prereq-tag.or {
  border: 1px dashed var(--line-strong);
  background: transparent;
}

/* States — no dimming, color contrast only */
.course-card.highlighted {
  background: color-mix(in srgb, var(--amber) 18%, var(--surface));
  box-shadow: 0 0 0 2px var(--blue), var(--shadow-md);
  transform: translateY(-1px);
  z-index: 10;
}

.course-card.selected {
  background: color-mix(in srgb, var(--blue) 22%, var(--surface));
  box-shadow: 0 0 0 3px var(--blue), var(--shadow-lg);
  transform: translateY(-2px);
  z-index: 10;
}

/* Ghost cards — external prerequisites from other majors */
.course-card.ghost-card {
  border-left-color: var(--amber);
  background: color-mix(in srgb, var(--amber) 8%, var(--surface-2));
  opacity: 0.82;
  border: 1px dashed var(--amber);
  border-left: 4px solid var(--amber);
}

.course-card.ghost-card .card-code { color: var(--amber); }

.ghost-badge {
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.4;
  background: color-mix(in srgb, var(--amber) 15%, transparent);
  color: var(--amber);
}

.course-card.ghost-card.highlighted {
  background: color-mix(in srgb, var(--amber) 22%, var(--surface));
  box-shadow: 0 0 0 2px var(--blue), var(--shadow-md);
  opacity: 1;
}

/* Hover preview — subtle glow on prerequisites */
.course-card.hover-prereq {
  background: color-mix(in srgb, var(--amber) 10%, var(--surface-2));
  box-shadow: 0 0 0 1.5px var(--amber), var(--shadow-sm);
}

/* ============================================================
   YEAR 4 SUMMARY
   ============================================================ */
.year4-summary {
  padding: 12px 10px;
  background: color-mix(in srgb, var(--blue) 8%, var(--surface-2));
  border-left: 4px solid var(--blue);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin-bottom: 8px;
}

/* ============================================================
   SVG ARROWS
   ============================================================ */
.arrows-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  overflow: visible;
}

.prereq-line {
  stroke: var(--connector);
  stroke-width: 2.5;
  fill: none;
  transition: stroke 0.2s, stroke-width 0.2s, opacity 0.25s;
}

.prereq-line.or-prereq { stroke-dasharray: 6 4; }

.arrow-head {
  fill: var(--connector);
  transition: fill 0.2s, opacity 0.25s;
}

/* ============================================================
   COURSE DETAIL PANEL
   ============================================================ */

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .course-card {
    width: 165px;
    min-width: 150px;
  }
}

@media (max-width: 900px) {
  .course-card {
    width: 155px;
    min-width: 140px;
  }
  .level-grid { gap: 18px; }
}

@media (max-width: 600px) {
  .header-content { padding: 12px 16px; }
  .brand h1 { font-size: 16px; }
  .header-select { min-width: 160px; }
  .controls-bar { flex-direction: column; gap: 8px; padding: 10px 16px; }
  .legend-bar { flex-wrap: wrap; gap: 12px; padding: 8px 16px; }
  .level-grid { padding: 10px 12px; gap: 16px; }
  .course-card {
    width: calc(50% - 4px);
    min-width: 120px;
    flex-shrink: 1;
  }
  .level-row { width: 100%; }
}
