/* Adapted from Missing Semester (github.com/missing-semester/missing-semester),
   Copyright (c) 2017 Anish Athalye, licensed CC BY-NC-SA 4.0. Modified for CS283:
   Stanford color tokens (see theme.css); Courier Prime (nav) and Lato
   (headings + body) fonts (via <head>). */

/* Basic styling */

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

html {
  font-family: "Lato", sans-serif;
  font-size: 14pt;
  line-height: 1.5;
}

body {
  margin: 0;
  color: #000;
  background-color: var(--cream);
  overflow-y: scroll;
}

/* Vertical rhythm: every level takes more space above than below, so a heading
   binds to the section it introduces rather than floating between two of them.
   h3-h6 previously carried no margin-top at all and sat equidistant from both. */
h1, h2, h3, h4, h5, h6 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-family: "Lato", sans-serif;
  font-weight: bold;
  color: var(--cardinal);
  line-height: 1.25;
  font-size: 1rem;
}

h1 {
  margin-top: 2rem;
  font-size: 1.5rem;
}

h2 {
  margin-top: 1.75rem;
  font-size: 1.1rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

strong {
  font-weight: bold;
}

em {
  font-style: italic;
}

ul {
  list-style-position: inside;
  padding-left: 1rem;
}

ol {
  margin-left: 1rem;
}

li > ul {
  padding-left: 2rem;
}

ul li {
  list-style-type: none;
}

ul, ol {
  margin-bottom: 1rem;
}

ul ul, ol ul, ul ol, ol ol {
  margin-bottom: inherit;
}

ul li:before {
  content: "\2013  "; /* note: extra space needed because first is consumed by css parser */
  position: absolute;
  margin-left: -1rem;
}

ul.double-spaced li {
  margin-top: 1rem;
}

pre, code {
  font-family: "Source Code Pro", "Menlo", "DejaVu Sans Mono", "Lucida Console", monospace;
}

code {
  background-color: rgba(27,31,35,.05);
  border-radius: 3px;
  padding: 0 0.2rem;
  font-size: 12pt;
}

pre {
  color: #000;
  margin: 1rem;
  padding: 0.5rem 0.7rem;
  border: 1px dashed #444;
  font-size: 11pt;
  overflow-x: auto;
}

pre code {
  color: inherit;
  background: none;
  font-size: 100%;
  padding: 0;
}

a {
  color: var(--cardinal);
  text-decoration: underline;
}

a:hover {
  color: #fff;
  background-color: var(--cardinal);
}

img, video {
  display: block;
  margin-left: auto;
  margin-right: auto;
  border-radius: 5px;
  max-width: 100%;
  max-height: 80vh;
}

video {
  margin-bottom: 1rem;
}

summary {
  outline: none;
  user-select: none;
}

hr {
  position: relative;
  margin: 1.5rem 0;
  border: 0;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #fff;
}

blockquote {
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  background-color: var(--cardinal-tint);
  border-left: 3px solid var(--cardinal);
}

blockquote p:last-child {
  margin-bottom: 0;
}

blockquote.epigraph {
  background: none;
  border: none;
  padding: 0;
  margin: 1.5rem 0 1.5rem 1rem;
}

blockquote.epigraph p {
  font-style: italic;
  margin-bottom: 0.5rem;
}

blockquote.epigraph footer {
  font-size: 0.9rem;
  text-align: right;
}

@media (min-width: 64rem) {
  #content {
    position: relative;
  }

  .sidenote-column {
    position: absolute;
    top: 0;
    left: calc(100% + 1.5rem);
    width: 14rem;
  }

  /* Hide inline sidenotes on desktop, show margin ones */
  .sidenote-inline {
    display: none;
  }

  .sidenote-margin {
    position: absolute;
    width: 100%;
    padding: 0.2rem 0.5rem 0.5rem 0.5rem;
    margin: 0;
    font-size: 0.8rem;
    color: #000;
    background: none;
    border: none;
    border-left: 2px solid var(--cardinal);
  }

  .sidenote-ref {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0.5rem 0;
    width: 100%;
    background-color: #e8e8e8;
    font-size: 0.7rem;
    line-height: 1.4;
    padding: 0.15rem 0.5rem;
    box-sizing: border-box;
  }

  .sidenote-arrows {
    color: var(--cardinal);
    letter-spacing: 0.1em;
  }

  .sidenote-label {
    color: #666;
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.05em;
  }

  .sidenote-num {
    color: var(--cardinal);
    font-size: 0.65rem;
    font-weight: bold;
    margin-right: 0.15rem;
    margin-bottom: 0.1rem;
    display: block;
  }

  .sidenote-back {
    color: var(--cardinal);
    text-decoration: none;
    font-size: 0.9em;
  }

  .sidenote-back:hover {
    text-decoration: underline;
  }
}

@media (max-width: 63.99rem) {
  /* Hide margin sidenotes and column on mobile, show inline ones */
  .sidenote-column {
    display: none;
  }

  .sidenote-inline {
    display: block;
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    background-color: #faf8fc;
    border-left: 3px solid var(--cardinal);
  }

  .sidenote-ref {
    display: none;
  }
}

/* Classes */

.title {
  font-size: 2rem;
}

.subtitle {
  /* Explicit, not a negative offset against h2's margin-top -- that only nets
     out for one particular value of it. */
  margin-top: 0.25rem;
  font-size: 1.25rem;
}

.small {
  font-size: 0.75rem;
}

.small p {
  margin-bottom: 0;
}

.center {
  text-align: center;
}

.padded {
  padding: 10rem 0;
}

.bordered {
  border: 1px solid #ccc;
}

.accent {
  color: #8c0038;
}

.youtube-wrapper {
  position: relative;
  height: 0;
  margin-bottom: 1rem;
  background: black;
}

.youtube-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.construction {
  display: block;
  padding: .5em 1em;
  background: rgba(0, 0, 0, 0.1);
  border-left: 2px solid var(--cardinal);
}

/* Elements */

#content {
  max-width: 35rem;
  margin: auto;
  margin-bottom: 2rem;
  padding: 1.5rem 1rem 0 1rem;
}

/* The padding above owns the gap under the nav bar. Without this the leading
   heading's own margin-top adds to it, and only on layouts that open with one --
   `page` started 1.25rem lower than `lecture`, which opens with the eyebrow. */
#content > :first-child,
.lecture-main > :first-child {
  margin-top: 0;
}

/* Match the footer to the content column so their left/right edges line up. */
#site-footer {
  max-width: 35rem;
  margin: 0 auto 2rem;
  padding: 0 1rem;
}

/* Pages that need more than the 35rem measure opt in with `wide: true` in front
   matter (default.html turns that into this body class). Content and footer
   widen together so their edges keep lining up. */
body.is-wide #content,
body.is-wide #site-footer {
  max-width: 53rem;
}

/* Course staff (home page): responsive grid of headshot cards, cs231n-style.
   .staff-photo is a CSS-drawn placeholder circle — swap for real <img> later. */
.staff-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.staff-card {
  width: 6rem;
  text-align: center;
}

.staff-photo {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  background: var(--cardinal-tint);
  margin: 0 auto 0.4rem;
}

.staff-name {
  font-weight: bold;
  font-size: 0.85rem;
}

.staff-role {
  font-size: 0.75rem;
  color: #555;
}

.demo {
  margin-top: 2em;
  margin-bottom: 2em;
}

#nav-bg {
  position: relative;
  margin: 0;
  padding: 0.25rem 1rem;
  font-family: "Courier Prime", monospace;
  background: var(--cardinal);
  color: #fff;
}

/* Stanford mark, anchored far-left and vertically centered on the nav bar.
   Portrait mark → size by height so it stays a narrow badge beside the links. */
.nav-logo {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  height: 1.5rem;
  width: auto;
  margin: 0;
  border-radius: 0;
}

/* Light/dark toggle — sliding sun/moon pill (design adapted from
   vitalik.eth.limo). Anchored far-right and vertically centered on the nav bar.
   The knob position is driven by the data-theme attribute (see the dark block),
   so it's correct pre-paint; the hidden checkbox is the accessible control that
   theme.js keeps in sync. Icons stroke via currentColor = the nav foreground. */
#color-mode-switch {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  color: #fff;
}

#color-mode-switch .cms-icon {
  width: 20px;
  height: 20px;
  margin: 0 5px;
  flex: none;
}

/* Visually-hidden checkbox; the label is the pill the user clicks. */
#color-mode-switch input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}

/* The pill track. Gray reads well on both the cardinal (light) and
   cardinal-light (dark) nav bar. */
#color-mode-switch label {
  cursor: pointer;
  text-indent: -9999px;
  width: 42px;
  height: 21px;
  border-radius: 30px;
  background: #9a9a9a;
  display: block;
  position: relative;
  margin: 0;
}

/* The knob. Base = light position (left, by the sun). */
#color-mode-switch label::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  background: #fff;
  border-radius: 90px;
  transition: 0.3s;
}

#color-mode-switch label:active::after {
  width: 30px;
}

#top-nav {
  /* Wide enough to hold the whole centered nav row (logo + 5 links) on one
     line in Courier Prime before the mobile menu collapses at 40rem. */
  max-width: 48rem;
  margin: auto;
  text-align: center;
}

#top-nav a {
  color: #fff;
  text-decoration: none;
}

#top-nav a:hover {
  color: #000;
  background-color: #fff;
}

a#logo {
  color: #f3d9d9;
}

a:hover#logo {
  color: #000;
}

#menu-icon {
  display: none;
}

.trigger {
  display: none;
}

input[type=checkbox]:checked ~ .trigger {
  display:block;
  margin: auto;
}

.menu-label {
  font-family: "Courier Prime", monospace;
}

input[type=checkbox] ~ .menu-label:after {
  content: "(+)";
}

input[type=checkbox]:checked ~ .menu-label:after {
  content: "(-)";
}

.nav-link {
  display: block;
}

.trigger-child {
  display: inline-block;
  text-align: initial;
}

.nav-link:before {
  content: "- ";
}

/* in terms of our fixed-width layout; if smaller than this, we want to
 * collapse the menu */
@media (min-width: 40rem) {
  /* Logo + links share one centered row (cs283 home | schedule | …). */
  .menu-label {
    display: none;
  }

  .trigger {
    display: inline;
    padding-top: inherit;
  }

  .trigger-child {
    display: inline;
    text-align: initial;
  }

  input[type=checkbox]:checked ~ .trigger {
    display: inline;
  }

  .nav-link {
    display: initial;
  }

  .nav-link:before {
    content: "| ";
  }
}

/* Dark theme. Applied via the data-theme attribute on <html>, which an inline
   script in head.html sets pre-paint from localStorage or the OS preference, and
   the nav toggle (assets/js/theme.js) flips. Nested so the whole block keys off
   the one attribute selector. */
:root[data-theme="dark"] {

  body {
    background-color: #303030;
    color: #ddd
  }

  /* Icons match the dark nav foreground; knob slides right, toward the moon. */
  #color-mode-switch {
    color: #202020;
  }

  #color-mode-switch label::after {
    left: calc(100% - 3px);
    transform: translateX(-100%);
  }

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

  a:hover {
    color: #000;
    background-color: var(--cardinal-light);
    text-decoration: none;
  }

  h1, h2, h3, h4, h5, h6 {
    color: var(--cardinal-light);
  }

  #nav-bg, a#logo, #top-nav a {
    background-color: var(--cardinal-light);
    color: #202020;
  }

  a:hover > code  {
    background-color: var(--cardinal-light);
  }

  .accent {
    color: #F92672;
  }

  .staff-role {
    color: #aaa;
  }

  .construction {
    background: rgba(0, 0, 0, 0.5);
    border-left: 2px solid var(--cardinal-light);
  }

  blockquote {
    background-color: var(--cardinal-tint);
    border-left-color: var(--cardinal-light);
  }

  .sidenote-margin {
    color: #bbb;
    border-left-color: var(--cardinal-light);
  }

  .sidenote-inline {
    border-left-color: var(--cardinal-light);
  }

  .sidenote-ref {
    background-color: #404040;
  }

  .sidenote-arrows {
    color: var(--cardinal-light);
  }

  .sidenote-label {
    color: #aaa;
  }

  .sidenote-num {
    color: var(--cardinal-light);
  }

  .sidenote-back {
    color: var(--cardinal-light);
  }
}

@media (min-width: 64rem) {
  :root[data-theme="dark"] .sidenote-margin {
    background: none;
    color: #ddd;
  }
}

@media (max-width: 63.99rem) {
  :root[data-theme="dark"] .sidenote-inline {
    background-color: var(--cardinal-tint);
  }
}

@media print {
  #nav-bg, #logo, #top-nav { display: none; }
  h1.title ~ p.center.padded.bordered { display: none; }
  .youtube-wrapper { display: none; }
  .sidenote-column { display: none; }
  .sidenote-ref { display: none; }
  .sidenote-inline {
    display: block;
    background: none;
    border-left: 2px solid #999;
    padding: 0 0 0 0.75rem;
    margin: 1rem 0;
  }
  html { font-size: 1em; font-family: sans-serif; }
  body { background: none; }
  #content { max-width: none; }
  h1.title { text-align: center; }
  h1, h2, h3, h4, h5, h6 { break-after: avoid-page; page-break-after: avoid; }
  #content hr:last-of-type { display: none; }
  #content pre { break-inside: avoid-page; page-break-inside: avoid; white-space: pre-wrap; }
  #content div.small:last-of-type { display: none; }
  a[href^="https://"]::after, a[href^="http://"]::after {
    content: "("attr(href)")"; font-family: monospace; margin: 0 .25em;
  }
}

/* ---- Home page ----------------------------------------------------------
   Course codes, logistics, and the instructor bio cards. */

.course-codes {
  font-family: "Courier Prime", monospace;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--cardinal);
  border-top: 2px solid var(--cardinal);
  border-bottom: 1px solid rgba(0, 0, 0, 0.14);
  padding: 0.5rem 0;
  margin-top: 0;
}

.logistics {
  display: grid;
  grid-template-columns: max-content 1fr;
  /* Each dt/dd pair is its own grid row; centering here optically aligns the
     small-caps label with the larger body text beside it. */
  align-items: center;
  gap: 0.2rem 1rem;
  margin: 0 0 1rem;
}

.logistics dt {
  font-family: "Courier Prime", monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #666;
}

.logistics dd {
  margin: 0;
}

.course-note {
  font-size: 0.8rem;
  font-style: italic;
  color: #666;
  border-left: 2px solid var(--cardinal-tint);
  padding-left: 0.75rem;
}

/* Person cards (instructors, TAs): headshot beside name, role, and contact. Overrides
   the compact .staff-card used for the plain headshot grid; the compound
   selectors keep the override from depending on source order. */
.staff-grid.staff-grid--people {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  /* Row gap here, not margin-bottom on the card -- one mechanism, and it stops
     the card margin from stacking with this grid's own margin-bottom. */
  gap: 1.5rem 1.75rem;
}

.staff-card.staff-card--person {
  display: flex;
  gap: 1rem;
  width: auto;
  text-align: left;
  border-top: 1px solid rgba(0, 0, 0, 0.14);
  padding-top: 1rem;
}

/* The headshots are mixed aspect ratios (square, tall portrait, and landscape),
   so cover-crop them into the circle instead of letting them squash. */
.staff-card--person .staff-photo {
  flex: 0 0 auto;
  width: 4rem;
  height: 4rem;
  object-fit: cover;
  object-position: center top;
  margin: 0.2rem 0 0;
}

.staff-card--person .staff-name {
  font-size: 1rem;
}

.staff-card--person .staff-role {
  margin-bottom: 0.4rem;
}

.staff-contact {
  font-size: 0.78rem;
  line-height: 1.5;
  color: #555;
  margin: 0;
}

@media (max-width: 44rem) {
  .staff-grid.staff-grid--people {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 26rem) {
  .staff-card.staff-card--person {
    display: block;
  }

  .staff-card--person .staff-photo {
    margin-bottom: 0.5rem;
  }
}

:root[data-theme="dark"] {
  .course-codes {
    color: var(--cardinal-light);
    border-top-color: var(--cardinal-light);
    border-bottom-color: rgba(255, 255, 255, 0.14);
  }

  .logistics dt,
  .course-note,
  .staff-contact {
    color: #aaa;
  }

  .staff-card.staff-card--person {
    border-top-color: rgba(255, 255, 255, 0.14);
  }
}

/* Assignment milestones: a definition list where the due date sits at the end
   of each description, set in the utility face like the readings ledger. */
.milestones {
  margin-bottom: 1.75rem;
}

.milestones dt {
  font-weight: 700;
  margin-top: 0.9rem;
}

.milestones dt:first-child {
  margin-top: 0;
}

.milestones dd {
  font-size: 0.9rem;
  margin: 0.2rem 0 0 1rem;
}

.milestone-due {
  font-family: "Courier Prime", monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cardinal);
  white-space: nowrap;
}

:root[data-theme="dark"] .milestone-due {
  color: var(--cardinal-light);
}

/* ---- Collapsible tracks (/assignments/) ---------------------------------
   Native <details>, no JS. The disclosure marker follows the (+)/(-) idiom the
   mobile nav menu already uses rather than introducing a second one. */

.track {
  border-top: 1px solid rgba(0, 0, 0, 0.14);
  margin: 0;
}

.track:last-of-type {
  border-bottom: 1px solid rgba(0, 0, 0, 0.14);
  margin-bottom: 1.5rem;
}

.track > summary {
  cursor: pointer;
  list-style: none;
  font-family: "Lato", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--cardinal);
  padding: 0.7rem 0.2rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

/* Hide the native triangle in both engines. */
.track > summary::-webkit-details-marker {
  display: none;
}

.track > summary::before {
  content: "(+)";
  font-family: "Courier Prime", monospace;
  font-size: 0.8rem;
  font-weight: 400;
}

.track[open] > summary::before {
  content: "(-)";
}

.track > summary:hover {
  background-color: var(--cardinal-tint);
}

.track > summary:focus-visible {
  outline: 2px solid var(--cardinal);
  outline-offset: 2px;
}

.track-body {
  padding: 0 0.2rem 0.5rem;
}

/* The first heading inside an opened track shouldn't push off the summary. */
.track-body > :first-child {
  margin-top: 0;
}

:root[data-theme="dark"] {
  .track,
  .track:last-of-type {
    border-color: rgba(255, 255, 255, 0.14);
  }

  .track > summary {
    color: var(--cardinal-light);
  }

  .track > summary:focus-visible {
    outline-color: var(--cardinal-light);
  }
}

/* ---- Lectures dropdown --------------------------------------------------
   Reveals the whole course from the nav bar. Shown on hover and on
   :focus-within so it is reachable by keyboard, not mouse only. */

.nav-link--lectures {
  position: relative;
}

.nav-dropdown {
  /* Hidden with visibility, not display, so the close can be delayed: the
     transition below holds the panel open for .45s after the pointer leaves,
     which makes the diagonal trip from "lectures" down to a row forgiving. */
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s linear 0.45s, visibility 0s linear 0.57s;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  width: 20rem;
  max-width: calc(100vw - 2rem);
  margin-top: 0.25rem;
  padding: 0.3rem 0;
  text-align: left;
  background: var(--cream);
  border: 1px solid var(--cardinal);
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

/* Invisible bridge across the margin-top gap, so crossing it does not count as
   leaving the trigger and start the close timer. */
.nav-dropdown:before {
  content: "";
  position: absolute;
  top: -0.45rem;
  left: 0;
  right: 0;
  height: 0.45rem;
}

.nav-link--lectures:hover .nav-dropdown,
.nav-link--lectures:focus-within .nav-dropdown {
  visibility: visible;
  opacity: 1;
  /* Opening is immediate; only the close is delayed. */
  transition: opacity 0.08s linear 0s, visibility 0s linear 0s;
}

.nav-dropdown-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
  line-height: 1.5;
}

/* #top-nav a paints its links white for the cardinal bar; the panel sits on the
   page background, so its links take the page's link colour instead. */
#top-nav .nav-dropdown-item {
  color: var(--cardinal);
}

#top-nav .nav-dropdown-item:hover {
  color: #fff;
  background-color: var(--cardinal);
}

.nav-dropdown-num {
  flex: 0 0 1.4rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  text-align: right;
  color: #999;
}

.nav-dropdown-item:hover .nav-dropdown-num {
  color: #f3d9d9;
}

/* One line each: 19 lectures fit without scrolling. Entries are the short
   `nav_title` from each lecture's front matter, so nothing clips at 20rem; the
   truncation below is the fallback for a lecture that only has a full title. */
.nav-dropdown-title {
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Lato", sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Below 40rem the nav is the checkbox menu and there is no hover: "lectures"
   stays a plain link to the index. */
@media (max-width: 39.99rem) {
  .nav-dropdown {
    display: none !important;
  }
}

:root[data-theme="dark"] {
  .nav-dropdown {
    background: #383838;
    border-color: var(--cardinal-light);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  }

  #top-nav .nav-dropdown-item {
    color: var(--cardinal-light);
    background-color: transparent;
  }

  #top-nav .nav-dropdown-item:hover {
    color: #202020;
    background-color: var(--cardinal-light);
  }

  .nav-dropdown-num {
    color: #888;
  }

  .nav-dropdown-item:hover .nav-dropdown-num {
    color: #5a2020;
  }
}

@media print {
  .nav-dropdown { display: none; }
}
