/* MCB Study Hub — UC Berkeley brand system */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #14212b;
  --text-secondary: #57636f;
  --rule: #dde3e8;
  --accent: #003262;
  --accent-hover: #3b7ea1;
  --amber: #c4820e;
  --success: #003262;
  --danger: #b3261e;

  --font-heading: "Inter", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 16px;
  --r-pill: 999px;

  --dur: 150ms;
  --ease: ease;

  --header-h: 64px;
}

:root[data-theme="dark"] {
  --bg: #10161c;
  --surface: #182028;
  --text: #eef1f4;
  --text-secondary: #9aa7b2;
  --rule: #29333c;
  --accent: #3b7ea1;
  --accent-hover: #5ea3c9;
  --amber: #fdb515;
  --success: #3b7ea1;
  --danger: #e2574b;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  margin: 0;
}

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

/* ---------- Masthead (always visible) ---------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  height: var(--header-h);
  display: flex;
  align-items: center;
}

.masthead-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.masthead-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.masthead-title {
  font-size: 22px;
  letter-spacing: -0.01em;
}

.masthead-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--rule);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}
.theme-toggle svg {
  width: 18px;
  height: 18px;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-toggle .icon-sun {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: inline;
}
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--rule);
  border-radius: var(--r-xs);
  background: var(--surface);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.menu-toggle span {
  width: 18px;
  height: 2px;
  background: var(--text);
  display: block;
}
.menu-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 48px;
  align-items: start;
}

.course-outline {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  padding: 24px 0;
  max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto;
}

.outline-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 12px;
}

.outline-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.outline-item {
  border-bottom: 1px solid var(--rule);
}
.outline-item:last-child {
  border-bottom: none;
}

.outline-part {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  padding: 16px 0 6px;
}
.outline-part:first-child {
  padding-top: 0;
}

.outline-item a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 10px 0;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--dur) var(--ease);
}
.outline-item a:hover {
  color: var(--accent);
}
.outline-item a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.outline-marker {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  width: 20px;
  flex-shrink: 0;
}

.outline-item.active a {
  color: var(--text);
  font-weight: 500;
}
.outline-item.active .outline-marker {
  color: var(--accent);
}

.content {
  min-width: 0;
  max-width: 720px;
  padding: 48px 0 24px;
}

/* ---------- Chapters ---------- */

.chapter {
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.chapter-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  display: block;
  margin-bottom: 10px;
}

.chapter-title {
  font-size: 30px;
  margin-bottom: 16px;
}

.chapter p {
  color: var(--text);
  margin: 0 0 20px;
}

.key-concepts {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}
.key-concepts li {
  padding: 10px 0 10px 20px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  font-size: 14px;
}
.key-concepts li:last-child {
  border-bottom: none;
}
.key-concepts li::before {
  content: "\2013";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-family: var(--font-mono);
}

.key-concepts.checklist li {
  padding-left: 26px;
}
.key-concepts.checklist li::before {
  content: "\2610";
  font-size: 13px;
}

.subsection-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 12px;
}

.steps-list {
  list-style: none;
  counter-reset: step;
  margin: 0 0 20px;
  padding: 0;
}
.steps-list li {
  counter-increment: step;
  position: relative;
  padding: 10px 0 10px 34px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
}
.steps-list li:last-child {
  border-bottom: none;
}
.steps-list li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 13px;
}

.note-text {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ---------- Data table ---------- */

.data-table-wrap {
  overflow-x: auto;
  margin: 0 0 24px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th,
.data-table td {
  text-align: left;
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.data-table th {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-weight: 500;
}
.data-table td:first-child,
.data-table th:first-child {
  color: var(--text);
  font-weight: 500;
}

.ecg-divider {
  width: 100%;
  height: 22px;
  display: block;
  margin: 24px 0;
}
.ecg-divider path {
  fill: none;
  stroke: var(--rule);
  stroke-width: 1.5;
}

/* ---------- Notice banner ---------- */

.notice-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: baseline;
  border-left: 3px solid var(--amber);
  background: var(--surface);
  padding: 14px 18px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin: 24px 0;
}
.notice-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--amber);
  flex-shrink: 0;
}
.notice-banner p {
  margin: 0;
  font-size: 14px;
  min-width: 0;
  flex: 1 1 220px;
}

/* ---------- Case-reasoning block ---------- */

.case-block {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 32px;
  margin: 32px 0;
}
.case-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
.case-step {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule);
}
.case-step:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.case-step p {
  margin: 0;
}
.case-step-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--amber);
  margin-bottom: 8px;
  display: block;
}

/* ---------- Evidence-graded references ---------- */

.refs-section {
  padding-bottom: 8px;
}
.refs {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
}
.refs li {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: baseline;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}
.refs li:last-child {
  border-bottom: none;
}
.grade {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 3px 7px;
  border-radius: var(--r-xs);
  color: var(--surface);
  background: var(--accent);
  white-space: nowrap;
}
.grade.b {
  background: var(--amber);
}
.grade.c {
  background: var(--text-secondary);
}
.ref-text {
  font-size: 14px;
  min-width: 0;
  flex: 1 1 220px;
}

/* ---------- Hub / landing page ---------- */

.hub-main {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.footer-divider {
  margin-top: auto;
}

.hub-intro {
  max-width: 720px;
  margin-bottom: 48px;
}
.hub-intro p {
  color: var(--text-secondary);
  margin: 0;
}

.hub-section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 16px;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 48px;
}

.course-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease);
}
.course-card:hover {
  border-color: var(--accent);
}
.course-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.course-card-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  display: block;
  margin-bottom: 10px;
}
.course-card-title {
  font-family: var(--font-heading);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.3;
  min-height: 2.6em;
  margin-bottom: 8px;
}
.course-card-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  flex: 1;
}
.course-card-meta {
  display: flex;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---------- Footer ---------- */

.site-footer {
  padding: 2px 0 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.footer-mark {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.footer-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.footer-title {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 500;
}
.footer-meta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-secondary);
  flex: 1;
  text-align: center;
}
.footer-stamp {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  padding: 6px 12px;
  transform: rotate(-2deg);
  white-space: nowrap;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .menu-toggle {
    display: flex;
  }

  .course-outline {
    position: sticky;
    top: var(--header-h);
    z-index: 40;
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
    max-height: none;
    padding: 16px 0;
    display: none;
  }
  .course-outline.open {
    display: block;
  }

  .outline-list {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .outline-item {
    border-bottom: none;
    flex-shrink: 0;
  }
  .outline-item a {
    padding: 8px 14px;
    border: 1px solid var(--rule);
    border-radius: var(--r-pill);
    white-space: nowrap;
  }
  .outline-item.active a {
    border-color: var(--accent);
  }

  .outline-part {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 10px;
    align-self: center;
  }

  .content {
    max-width: 100%;
    padding: 32px 0 24px;
  }
}

@media (max-width: 640px) {
  .masthead-title {
    font-size: 18px;
  }
  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
  }
  .footer-meta {
    text-align: left;
  }
  .footer-stamp {
    transform: none;
    align-self: flex-start;
  }
  .chapter-title {
    font-size: 24px;
  }
}

/* ---------- Motion & accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  * {
    transition: none !important;
  }
}

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