/* Light: Night Owl Light–inspired. Dark: Night Owl (classic) editor tones. */
:root {
  color-scheme: light;
  --bg: #fbfbfb;
  --surface: #ffffff;
  --text: #403f53;
  --muted: #6c6885;
  --line: #e4e2ed;
  --primary: #1f8a63;
  --primary-strong: #156f50;
  --link: #6f42c1;
  --link-hover: #5a3599;
  --shadow: 0 10px 28px rgba(64, 63, 83, 0.09);
  --radius: 14px;
  --code-bg: #f3f2f8;
  --lightbox-backdrop: rgba(64, 63, 83, 0.78);
  --lightbox-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --btn-text: #ffffff;
  --close-bg: rgba(22, 34, 56, 0.08);
  --close-bg-hover: rgba(22, 34, 56, 0.14);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #011627;
  --surface: #132a40;
  --text: #e8f1fa;
  --muted: #a8bdd4;
  --line: #2a4d6f;
  --primary: #7fdbca;
  --primary-strong: #5dc9b4;
  --link: #d4b5f5;
  --link-hover: #ead5ff;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  --code-bg: #1d3b53;
  --lightbox-backdrop: rgba(1, 22, 39, 0.88);
  --lightbox-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --btn-text: #011627;
  --close-bg: rgba(214, 222, 235, 0.12);
  --close-bg-hover: rgba(214, 222, 235, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
}

.site-nav {
  max-width: 1024px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.site-nav-brand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.site-nav-sep {
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.35rem;
  min-height: 2.1rem;
  padding: 0.38rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.theme-toggle__icons {
  position: relative;
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}

.theme-toggle__icon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

html:not([data-theme="dark"]) .theme-toggle__icon--sun {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

html[data-theme="dark"] .theme-toggle__icon--moon {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.wrapper {
  max-width: 1024px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

.wrapper--project {
  max-width: 1180px;
}

.project-page {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.project-toc {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}

.project-toc-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.project-toc-item {
  margin: 0;
  padding: 0;
}

.project-toc-item--article .project-toc-link {
  font-weight: 600;
  color: var(--text);
}

.project-toc-item--nested {
  padding-left: 0.65rem;
  border-left: 2px solid var(--line);
  margin-left: 0.2rem;
}

.project-toc-link {
  display: block;
  padding: 0.28rem 0;
  font-size: 0.88rem;
  color: var(--muted);
  border-radius: 6px;
}

.project-toc-link:hover {
  color: var(--primary);
}

.project-toc-link.is-active {
  color: var(--primary);
  font-weight: 600;
}

.project-main {
  min-width: 0;
}

.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.eyebrow {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3.8vw, 2.8rem);
  line-height: 1.2;
  margin: 0.35rem 0 0.8rem;
}

h2 {
  margin-top: 0;
  margin-bottom: 0.6rem;
}

.lead {
  color: var(--muted);
  max-width: 58ch;
  margin-bottom: 1.2rem;
}

.btn {
  display: inline-block;
  padding: 0.62rem 0.95rem;
  border-radius: 10px;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: var(--btn-text);
}

.btn-primary:hover {
  background: var(--primary-strong);
  color: var(--btn-text);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.home-section {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
}

.home-section h2 {
  margin: 0 0 0.5rem;
}

.home-section p {
  margin: 0;
  color: var(--muted);
}

.home-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.subpage-grid {
  width: min(1024px, calc(100% - 2rem));
  margin: 1rem auto 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  overflow: hidden;
}

.card--with-thumb {
  padding-top: 0;
}

.card-thumb {
  display: block;
  margin: 0 -1.2rem 1rem;
  aspect-ratio: 16 / 9;
  background: var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: 1.15rem;
  line-height: 1.3;
}

.card h2 a {
  color: var(--text);
}

.card h2 a:hover {
  color: var(--link);
}

.card p {
  color: var(--muted);
  margin-top: 0;
}

.card-link {
  font-weight: 600;
}

.project {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.project-header {
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.project-subtitle {
  color: var(--muted);
  margin-top: 0.35rem;
}

.project-course {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.project-meta {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.project-report {
  margin: 1rem 0 0;
}

.project-body {
  max-width: 72ch;
}

.project-body h2 {
  margin-top: 2rem;
  margin-bottom: 0.65rem;
  padding-top: 0.25rem;
  font-size: 1.28rem;
  scroll-margin-top: 1rem;
}

.project-body h2:first-child {
  margin-top: 0;
}

.project-body h3 {
  margin-top: 1.35rem;
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
  scroll-margin-top: 1rem;
}

.project-body p,
.project-body ul,
.project-body ol {
  color: var(--text);
}

.project-body pre {
  padding: 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--code-bg);
  overflow-x: auto;
  font-size: 0.88rem;
}

/* Keep long display equations inside the content column. */
.project-body mjx-container[display="true"] {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.2rem;
}

.project-body mjx-container[display="true"] > mjx-math {
  white-space: nowrap;
}

.project-body img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.writeup-section {
  margin-top: 2rem;
}

.writeup-section:first-of-type {
  margin-top: 0;
}

/* Figures: default = natural image size, capped to content width (not forced full-bleed).
   Add a size class on <figure> when you want explicit width, e.g. class="figure-block figure-block--md" */
.figure-block {
  margin: 1.25rem 0;
  padding: 0;
  max-width: 100%;
}

.figure-block img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}

.figure-block figcaption {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
  text-align: center;
}

.figure-block--wide {
  max-width: none;
}

.figure-block--wide img {
  width: 100%;
  max-width: 100%;
}

.figure-block--sm {
  max-width: 22rem;
  margin-inline: auto;
}

.figure-block--md {
  max-width: 32rem;
  margin-inline: auto;
}

.figure-block--lg {
  max-width: 42rem;
  margin-inline: auto;
}

.figure-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1.25rem 0;
  align-items: flex-start;
  justify-content: center;
}

.figure-row .figure-block {
  flex: 1 1 220px;
  margin: 0;
  min-width: min(100%, 220px);
  max-width: min(100%, 28rem);
}

.figure-row .figure-block img {
  width: 100%;
  max-width: 100%;
  height: clamp(160px, 24vw, 260px);
  object-fit: contain;
  background: color-mix(in srgb, var(--line) 20%, transparent);
  border-radius: 8px;
}

/* Legacy CS180 project report layout compatibility */
.project-body .img-row-header {
  margin: 1rem 0 0.5rem;
  font-weight: 700;
  color: var(--text);
}

.project-body .img-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: center;
  margin: 1rem 0 1.25rem;
}

.project-body .img-container {
  flex: 1 1 220px;
  max-width: min(100%, 18rem);
}

.project-body .img-container img {
  display: block;
  width: 100%;
  height: clamp(160px, 24vw, 260px);
  object-fit: contain;
  background: color-mix(in srgb, var(--line) 20%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.project-body .img-container .caption {
  margin-top: 0.45rem;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}

.figure-block img {
  cursor: zoom-in;
}

.project-body img[data-lightbox="on"] {
  cursor: zoom-in;
}

body.image-lightbox-open {
  overflow: hidden;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(5vw, 2rem);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.image-lightbox.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.image-lightbox-backdrop {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--lightbox-backdrop);
  cursor: pointer;
}

.image-lightbox-panel {
  position: relative;
  z-index: 1;
  max-width: min(88vw, 1500px);
  width: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem 1rem;
  border-radius: 14px;
  background: var(--surface, #ffffff);
  box-shadow: var(--lightbox-shadow);
}

.image-lightbox-close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 2;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 10px;
  background: var(--close-bg);
  color: var(--text, #403f53);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.image-lightbox-close:hover {
  background: var(--close-bg-hover);
}

.image-lightbox-img {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
  border-radius: 10px;
  cursor: default;
  flex-shrink: 0;
}

.image-lightbox-caption {
  margin: 0;
  max-width: 62ch;
  font-size: 0.92rem;
  color: var(--muted, #6c6885);
  text-align: center;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .project-page {
    grid-template-columns: 1fr;
  }

  .project-toc {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .site-nav,
  .wrapper {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .hero {
    padding: 1.35rem;
  }
}
