/* ==========================================================================
   CELE N086 — Introduction to Algorithms
   University of Nottingham Ningbo China — course website stylesheet
   Visual language modelled on the UNNC web style: Nottingham navy #10263B,
   cyan accent #009BBD, dark-grey text, flat surfaces, hairline dividers,
   bold geometric sans headings. No trademarked university assets are used.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --navy: #10263b;          /* Nottingham blue — headers, footer, links */
  --navy-deep: #0b1c2c;
  --cyan: #009bbd;          /* accent only (decorative; not body-text) */
  --cyan-deep: #007a96;     /* AA-compliant teal for text accents on white */
  --ink: #333333;
  --ink-strong: #0a0a0a;
  --ink-soft: #555f68;
  --surface: #ffffff;
  --surface-alt: #f5f7f9;
  --hairline: #e6e6e6;
  --tint-exam: #f0f7f9;
  --focus: #b3591f;         /* high-contrast focus ring */
  --radius: 2px;            /* flat, near-square corners */
  --max-width: 74rem;
  --sans: "Circular Std", "CircularStd", "Avenir Next", "Segoe UI",
          "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem; /* clear the sticky header on anchor jumps */
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--surface);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  font-family: var(--sans);
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
}

h2 { font-size: clamp(1.8rem, 3.5vw, 2.6rem); }
h3 { font-size: 1.3rem; margin-top: 2.25rem; }
h4 { font-size: 1.05rem; }

p, ul, ol { margin: 0 0 1rem; }
ul, ol { padding-left: 1.4rem; }
li { margin-bottom: 0.4rem; }

a { color: var(--navy); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--cyan-deep); }

a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  left: 1rem;
  top: -3.5rem;
  z-index: 100;
  background: var(--navy);
  color: #fff;
  padding: 0.6rem 1rem;
  text-decoration: none;
  transition: top 0.15s ease-in-out;
}

.skip-link:focus {
  top: 0;
}

/* ---------- Header / navigation (white bar, navy logo block) ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--navy);
}

.nav-brand-block {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
}

.nav-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.nav-brand-text strong {
  font-size: 1.02rem;
  letter-spacing: 0.02em;
}

.nav-brand-text small {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.nav-brand:hover .nav-brand-text strong { color: var(--cyan-deep); }

.nav-menu {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem;
  margin: 0;
  padding: 0;
}

.nav-menu a {
  display: block;
  color: var(--navy);
  text-decoration: none;
  padding: 0.55rem 0.65rem;
  font-size: 0.94rem;
  font-weight: 500;
  border-bottom: 3px solid transparent;
}

.nav-menu a:hover,
.nav-menu a:focus-visible {
  color: var(--cyan-deep);
  border-bottom-color: var(--cyan);
}

/* Current section (set by script.js) */
.nav-menu a[aria-current="true"] {
  color: var(--navy);
  font-weight: 700;
  border-bottom-color: var(--cyan);
}

.nav-toggle {
  display: none;
  align-items: center;
  gap: 0.5rem;
  background: var(--navy);
  color: #fff;
  border: 1px solid var(--navy);
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.nav-toggle-bar {
  display: inline-block;
  width: 18px;
  height: 2px;
  background: currentColor;
  position: relative;
}

.nav-toggle-bar::before,
.nav-toggle-bar::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.nav-toggle-bar::before { top: -6px; }
.nav-toggle-bar::after { top: 6px; }

/* ---------- Hero (flat Nottingham navy band) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--navy);
  color: #f2f6fa;
  padding: 4.5rem 0 4rem;
}

.hero-graph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--cyan);
  opacity: 0.4;
  pointer-events: none;
}

.hero-inner {
  position: relative;
  max-width: 50rem;
}

.hero-kicker {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.85rem;
  font-weight: 700;
  color: #7fd4e4; /* light cyan on navy — AA on #10263B */
  margin-bottom: 1.25rem;
}

.hero h1 {
  color: #fff;
  font-size: clamp(2rem, 5.5vw, 3.4rem);
  margin-bottom: 1rem;
}

.hero-code {
  display: block;
  font-size: 0.42em;
  letter-spacing: 0.14em;
  font-weight: 700;
  color: #7fd4e4;
  margin-bottom: 0.5rem;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  font-size: 1rem;
  color: #cdd9e4;
  margin-bottom: 1.25rem;
}

.hero-desc {
  color: #dbe5ee;
  margin-bottom: 2rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-block;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  font-size: 0.98rem;
  text-decoration: none;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: #fff;
  border-color: #fff;
  color: var(--navy);
}

.btn-primary:hover {
  background: #7fd4e4;
  border-color: #7fd4e4;
  color: var(--navy);
}

.btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.65);
  color: #fff;
}

.btn-ghost:hover {
  border-color: #7fd4e4;
  color: #7fd4e4;
  background: transparent;
}

/* ---------- Sections ---------- */
.section {
  padding: 4rem 0;
}

.section-alt {
  background: var(--surface-alt);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

/* UNNC-style big heading with full hairline + short cyan underline */
.section h2 {
  position: relative;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 1.75rem;
}

.section h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 4.5rem;
  height: 4px;
  background: var(--cyan);
}

.section-lead {
  max-width: 54rem;
  color: var(--ink-soft);
  margin-bottom: 2rem;
}

/* ---------- Overview ---------- */
.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr);
  gap: 2.5rem;
  align-items: start;
  margin-bottom: 1rem;
}

.overview-text h3:first-child { margin-top: 0; }

.fact-card {
  background: var(--navy);
  color: #eef3f8;
  border-radius: var(--radius);
  padding: 1.6rem;
}

.fact-card h3 {
  color: #7fd4e4;
  margin-top: 0;
  font-size: 1.1rem;
}

.fact-list {
  margin: 0;
}

.fact-list div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.fact-list div:last-child { border-bottom: 0; }

.fact-list dt {
  font-weight: 600;
  color: #b9c8d6;
  flex-shrink: 0;
}

.fact-list dd {
  margin: 0;
  text-align: right;
}

.prereq-list { max-width: 54rem; }

/* Highlighted note (add-code guidance) */
.note-box {
  max-width: 54rem;
  background: var(--tint-exam);
  border: 1px solid var(--hairline);
  border-left: 4px solid var(--cyan);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin: 1.25rem 0 0;
}

.note-box h4 { margin: 0 0 0.35rem; }
.note-box p { margin: 0; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.97rem;
}

caption { text-align: left; }

th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.8rem 0.95rem;
  border-bottom: 1px solid var(--hairline);
}

thead th {
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

tbody th[scope="row"] {
  font-weight: 700;
  color: var(--navy);
  background: var(--surface-alt);
}

tbody tr:last-child th,
tbody tr:last-child td { border-bottom: 0; }

tbody tr:nth-child(even) td { background: var(--surface-alt); }

/* Exam weeks: cyan edge + tint + bold label, not colour alone */
.row-exam td,
.row-exam th[scope="row"] {
  background: var(--tint-exam) !important;
}

.row-exam th[scope="row"] {
  box-shadow: inset 4px 0 0 var(--cyan);
}

/* ---------- Milestone tags ---------- */
.tag {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius);
  border: 1.5px solid;
  white-space: nowrap;
  margin: 0.1rem 0.15rem 0.1rem 0;
}

.tag-hw { color: #114a75; border-color: #114a75; background: #e9f2fa; }
.tag-due { color: #205a2d; border-color: #2e7d43; background: #e9f5ec; }
.tag-review { color: #5c5013; border-color: #8b7a24; background: #f8f4dd; }
.tag-exam { color: #7a2e1d; border-color: #a5432c; background: #fbeae5; }

/* ---------- Outcomes ---------- */
.outcome-grid {
  list-style: none;
  counter-reset: outcome;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: 1rem;
  padding: 0;
  margin: 0;
}

.outcome-card {
  counter-increment: outcome;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-top: 4px solid var(--cyan);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.1rem 3.1rem;
  position: relative;
  margin: 0;
}

.outcome-card::before {
  content: counter(outcome);
  position: absolute;
  left: 1rem;
  top: 1.05rem;
  width: 1.6rem;
  height: 1.6rem;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Assessment ---------- */
.assessment-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.assessment-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.3rem;
}

.assessment-card h3 {
  margin-top: 0;
  font-size: 1.08rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.assessment-card .weight {
  color: var(--navy);
  font-size: 1.35rem;
  white-space: nowrap;
}

.weight-bar {
  height: 0.5rem;
  background: #e2ebf0;
  overflow: hidden;
  margin-bottom: 0.9rem;
}

.weight-bar span {
  display: block;
  height: 100%;
  background: var(--cyan);
}

.assessment-card p { margin-bottom: 0; font-size: 0.95rem; }

.expectation-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.expectation-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-left: 4px solid var(--navy);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.expectation-card h4 { margin: 0 0 0.4rem; }
.expectation-card p { margin: 0; font-size: 0.95rem; }

/* ---------- Policies ---------- */
.policy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1.25rem;
}

.policy-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.4rem;
}

.policy-card h3 {
  margin-top: 0;
  font-size: 1.12rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--cyan);
}

.policy-card p:last-child,
.policy-card ul:last-child { margin-bottom: 0; }

/* ---------- Resources ---------- */
.resource-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1.25rem;
}

.resource-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.4rem;
}

.resource-primary {
  border: 2px solid var(--navy);
}

.resource-status {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--navy);
  background: #e9f2fa;
  border-radius: var(--radius);
  padding: 0.15rem 0.7rem;
  margin: 0 0 0.7rem;
}

.resource-primary .resource-status {
  color: #fff;
  background: var(--navy);
}

.resource-card h3 { margin: 0 0 0.3rem; font-size: 1.15rem; }

.resource-authors {
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin-bottom: 0.6rem;
}

.resource-card p:last-child { margin-bottom: 0; font-size: 0.95rem; }

/* UNNC systems grid */
.unnc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
}

.unnc-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-top: 4px solid var(--navy);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

.unnc-card h4 { margin: 0 0 0.35rem; color: var(--navy); }
.unnc-card p { margin: 0; font-size: 0.93rem; }

/* ---------- Instructor ---------- */
.instructor-card {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 46rem;
}

.instructor-avatar {
  flex-shrink: 0;
  width: 4.5rem;
  height: 4.5rem;
  background: var(--navy);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.instructor-card h3 { margin: 0 0 0.2rem; }

.instructor-role {
  color: var(--cyan-deep);
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.instructor-card p:last-child { margin-bottom: 0; }

/* Departmental contact */
.contact-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-left: 4px solid var(--cyan);
  border-radius: var(--radius);
  padding: 1.4rem;
  max-width: 46rem;
}

.contact-card h4 { margin: 0 0 0.6rem; font-size: 1.1rem; }

.contact-list { margin: 0 0 0.9rem; }

.contact-list div {
  display: flex;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--hairline);
}

.contact-list div:last-child { border-bottom: 0; }

.contact-list dt {
  font-weight: 700;
  min-width: 6.5rem;
  color: var(--navy);
}

.contact-list dd { margin: 0; }

.contact-note {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* ---------- Footer (Nottingham navy) ---------- */
.site-footer {
  background: var(--navy);
  color: #c3d0dc;
  padding: 2.5rem 0;
  text-align: center;
  font-size: 0.95rem;
}

.site-footer p { margin-bottom: 0.35rem; }

.footer-course {
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
}

.footer-tagline {
  color: #7fd4e4;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.footer-note {
  margin-top: 0.6rem;
  color: #93a6b8;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 920px) {
  .nav-toggle { display: inline-flex; }

  .nav-menu {
    display: none;
    flex-direction: column;
    width: 100%;
    padding: 0.5rem 0;
    gap: 0.1rem;
    border-top: 1px solid var(--hairline);
    margin-top: 0.5rem;
  }

  .nav-menu.is-open { display: flex; }

  .nav-menu a { border-bottom: 0; padding: 0.65rem 0.25rem; }

  .nav-menu a[aria-current="true"] {
    border-left: 4px solid var(--cyan);
    padding-left: 0.6rem;
  }

  .overview-grid { grid-template-columns: 1fr; }

  .fact-card { order: -1; }
}

@media (max-width: 640px) {
  .section { padding: 2.75rem 0; }

  /* Stack table rows as labelled cards on small screens */
  .table-wrap { border: 0; background: transparent; }

  table, tbody, tr, th, td { display: block; width: 100%; }

  thead { display: none; }

  tr {
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: hidden;
    background: var(--surface);
  }

  tbody tr:nth-child(even) td { background: transparent; }

  th[scope="row"], td {
    border-bottom: 1px solid var(--hairline);
    padding: 0.6rem 0.9rem;
  }

  tr > :last-child { border-bottom: 0; }

  td[data-label]::before,
  th[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-soft);
    margin-bottom: 0.15rem;
  }

  .row-exam th[scope="row"] { box-shadow: inset 0 4px 0 var(--cyan); }

  .instructor-card { flex-direction: column; }

  .contact-list div { flex-direction: column; gap: 0; }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Print stylesheet — clean syllabus summary
   ========================================================================== */
@media print {
  body {
    font-size: 10.5pt;
    color: #000;
    background: #fff;
  }

  .site-header,
  .hero-actions,
  .skip-link,
  .hero-graph { display: none; }

  .hero {
    background: none;
    color: #000;
    padding: 0 0 1rem;
  }

  .hero h1, .hero-kicker, .hero-code, .hero-meta, .hero-desc { color: #000; }

  .section { padding: 1rem 0; }

  .section-alt { background: none; border: 0; }

  .section h2 { border-bottom-color: #000; }
  .section h2::after { display: none; }

  a { color: #000; text-decoration: none; }

  .table-wrap { overflow: visible; border: 0; }

  table { font-size: 9pt; }

  thead th { background: #fff !important; color: #000; border-bottom: 2px solid #000; }

  tbody th[scope="row"], tbody tr:nth-child(even) td, .row-exam td, .row-exam th[scope="row"] {
    background: #fff !important;
    box-shadow: none;
  }

  tr, .outcome-card, .policy-card, .resource-card, .assessment-card, .expectation-card,
  .unnc-card, .contact-card, .note-box {
    break-inside: avoid;
  }

  .outcome-card, .policy-card, .resource-card, .assessment-card, .expectation-card,
  .instructor-card, .fact-card, .unnc-card, .contact-card, .note-box {
    border: 1px solid #999;
  }

  .fact-card { background: #fff; color: #000; }
  .fact-card h3, .fact-list dt { color: #000; }
  .fact-list div { border-bottom-color: #ccc; }

  .outcome-card::before, .instructor-avatar, .nav-brand-block {
    background: #fff;
    color: #000;
    border: 1px solid #000;
  }

  .tag { border-color: #666; color: #000; background: #fff; }

  .weight-bar { display: none; }

  .site-footer { background: #fff; color: #000; border-top: 1px solid #000; }
  .footer-course, .footer-note, .footer-tagline { color: #000; }
}
