/* 14.33 Course Website Styles */

:root {
  --text: #1a1a1a;
  --muted: #666;
  --primary: #a31f34;        /* MIT red */
  --primary-hover: #8b1a2d;
  --secondary: #2c5aa0;      /* Blue for links */
  --border: #e0e0e0;
  --bg-subtle: #fafafa;
  --code-bg: #f8f8f8;
  --tab-inactive: #e8e8e8;
  --stata-accent: #1a5276;
  --r-accent: #276dc3;
  --python-accent: #3776ab;
  --success: #27ae60;
  --warning: #f39c12;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  font-family: "LM Roman 10", Georgia, Times, serif;
  font-size: 18px;
  color: var(--text);
  line-height: 1.7;
  background: #fff;
}

/* Links */
a { color: var(--secondary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary); }

/* ========== HOMEPAGE STYLES ========== */

.page-wrapper {
  max-width: 1000px;
  margin: 0 auto;
  padding: 40px 24px;
}

.course-header {
  text-align: center;
  padding-bottom: 32px;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 40px;
}

.course-header .course-number {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  letter-spacing: -1px;
}

.course-header .course-title {
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--text);
  margin: 8px 0;
}

.course-header .course-semester {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 6px 20px;
  border-radius: 20px;
  font-size: 1rem;
  margin-top: 12px;
}

/* Info Cards */
.info-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.info-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
}

.info-card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  margin: 0 0 12px;
}

.info-card p {
  margin: 4px 0;
  font-size: 1rem;
}

.info-card .name {
  font-weight: 600;
  font-size: 1.1rem;
}

/* Course Description */
.course-description {
  background: #fff;
  border-left: 4px solid var(--primary);
  padding: 24px 28px;
  margin-bottom: 40px;
  border-radius: 0 8px 8px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.course-description h2 {
  font-size: 1.3rem;
  margin: 0 0 16px;
  color: var(--text);
}

.course-description p {
  margin: 12px 0;
}

/* Resources Grid */
.resources-section h2 {
  font-size: 1.3rem;
  margin: 0 0 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.resource-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
}

.resource-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(163, 31, 52, 0.1);
}

.resource-card svg {
  width: 40px;
  height: 40px;
  fill: var(--primary);
  margin-bottom: 12px;
}

.resource-card span {
  font-weight: 600;
  font-size: 1rem;
}

.resource-card.featured {
  background: linear-gradient(135deg, var(--primary) 0%, #c42942 100%);
  color: #fff;
  border: none;
}

.resource-card.featured svg {
  fill: #fff;
}

.resource-card.featured:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(163, 31, 52, 0.25);
}

/* Footer */
.site-footer {
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--primary);
}

/* ========== TUTORIAL STYLES ========== */

.tutorial-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-header a {
  color: var(--text);
  font-size: 0.9rem;
}

.sidebar-header h1 {
  font-size: 1.3rem;
  margin: 8px 0 0;
  color: var(--primary);
}

.sidebar-nav {
  padding: 0 12px;
  flex: 1;
}

.nav-section {
  margin-bottom: 4px;
}

/* Collapsible section header */
.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
  user-select: none;
}

.nav-section-header:hover {
  background: rgba(163, 31, 52, 0.08);
}

.nav-section-header.active {
  background: var(--primary);
  color: #fff;
}

.nav-section-header .section-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

.nav-section-header.active .section-title {
  color: #fff;
}

.nav-section-header .chevron {
  font-size: 0.7rem;
  transition: transform 0.2s;
  color: var(--muted);
}

.nav-section-header.active .chevron {
  color: rgba(255,255,255,0.7);
}

.nav-section.open .nav-section-header .chevron {
  transform: rotate(90deg);
}

/* Collapsible content */
.nav-section-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-out;
}

.nav-section.open .nav-section-content {
  max-height: 500px;
}

.nav-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-section li a {
  display: block;
  padding: 6px 12px 6px 24px;
  color: var(--muted);
  font-size: 0.9rem;
  border-radius: 6px;
  transition: all 0.15s;
}

.nav-section li a:hover {
  background: rgba(163, 31, 52, 0.08);
  color: var(--primary);
}

.nav-section li a.active {
  color: var(--primary);
  font-weight: 500;
  background: rgba(163, 31, 52, 0.08);
}

/* Tutorial Content */
.tutorial-content {
  padding: 40px 60px;
  max-width: 900px;
  width: 100%;
  box-sizing: border-box;
}

.tutorial-content h1 {
  font-size: 2rem;
  margin: 0 0 8px;
  color: var(--text);
}

.tutorial-content .subtitle {
  font-size: 1.1rem;
  color: var(--muted);
  margin: 0 0 40px;
}

.tutorial-section {
  margin-bottom: 60px;
  padding-bottom: 40px;
  border-bottom: 1px solid var(--border);
}

.tutorial-section:last-child {
  border-bottom: none;
}

.tutorial-section h2 {
  font-size: 1.6rem;
  margin: 0 0 20px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tutorial-section h2::before {
  content: '';
  width: 5px;
  height: 28px;
  background: var(--primary);
  border-radius: 3px;
}

.tutorial-section h3 {
  font-size: 1.2rem;
  margin: 28px 0 12px;
  color: var(--text);
}

.tutorial-section p {
  margin: 16px 0;
}

/* Key Principles Box */
.key-principle {
  background: linear-gradient(135deg, #fff8f0 0%, #fff5eb 100%);
  border: 1px solid #f0d9c4;
  border-left: 4px solid var(--warning);
  border-radius: 0 8px 8px 0;
  padding: 20px 24px;
  margin: 24px 0;
}

.key-principle h4 {
  color: #8b5a2b;
  margin: 0 0 12px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.key-principle p {
  margin: 8px 0;
  color: #5a4a3a;
}

/* Learning Objectives */
.learning-objectives {
  background: #f0f7ff;
  border: 1px solid #d0e3f7;
  border-radius: 8px;
  padding: 20px 24px;
  margin: 24px 0;
}

.learning-objectives h4 {
  color: var(--secondary);
  margin: 0 0 12px;
  font-size: 1rem;
}

.learning-objectives ul {
  margin: 0;
  padding-left: 20px;
}

.learning-objectives li {
  margin: 6px 0;
}

/* Code Blocks with Tabs */
.code-block {
  margin: 24px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--code-bg);
  max-width: 100%;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #e8e8e8;
  padding: 0 12px 0 0;
}

.code-tabs {
  display: flex;
}

.code-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  border-top: 3px solid transparent;
  transition: all 0.15s;
}

.code-tab:hover {
  background: rgba(0,0,0,0.05);
}

.code-tab.active {
  background: var(--code-bg);
  color: var(--text);
  font-weight: 600;
}

.code-tab[data-lang="stata"].active {
  border-top-color: var(--stata-accent);
}

.code-tab[data-lang="r"].active {
  border-top-color: var(--r-accent);
}

.code-tab[data-lang="python"].active {
  border-top-color: var(--python-accent);
}

.copy-btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}

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

.copy-btn.copied {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.code-content {
  display: none;
  margin: 0;
}

.code-content.active {
  display: block;
}

.code-content pre {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: 'Fira Code', 'Source Code Pro', Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  max-width: 100%;
  box-sizing: border-box;
}

.code-content code {
  font-family: inherit;
}

/* Inline code */
code:not([class*="language-"]) {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
}

/* Common Mistakes */
.common-mistakes {
  background: #fff5f5;
  border: 1px solid #f5d0d0;
  border-radius: 8px;
  padding: 20px 24px;
  margin: 24px 0;
}

.common-mistakes h4 {
  color: #c0392b;
  margin: 0 0 12px;
}

.common-mistakes ul {
  margin: 0;
  padding-left: 20px;
}

/* Exercise Box */
.exercise {
  background: #f0fff4;
  border: 1px solid #c6f6d5;
  border-radius: 8px;
  padding: 20px 24px;
  margin: 24px 0;
}

.exercise h4 {
  color: var(--success);
  margin: 0 0 12px;
}

/* Mobile Menu Toggle */
.mobile-menu-btn {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 100;
  font-size: 1.5rem;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* Global Language Toggle */
.global-lang-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.global-lang-toggle span {
  font-size: 0.85rem;
  color: var(--muted);
}

.lang-toggle-btns {
  display: flex;
  gap: 4px;
}

.lang-toggle-btns button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.lang-toggle-btns button {
  border-radius: 0;
  margin-left: -1px;
}

.lang-toggle-btns button:first-child {
  border-radius: 4px 0 0 4px;
  margin-left: 0;
}

.lang-toggle-btns button:last-child {
  border-radius: 0 4px 4px 0;
}

.lang-toggle-btns button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Comparison grids (wide/long, expected/unexpected, etc.) */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 20px 0;
}

.comparison-grid > div {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 900px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .tutorial-layout {
    grid-template-columns: 1fr;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tutorial-content {
    padding: 20px 16px;
    max-width: 100vw;
    width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  .tutorial-content h1 {
    font-size: 1.6rem;
  }

  .code-block {
    margin-left: -16px;
    margin-right: -16px;
    border-radius: 0;
    border-left: none;
    border-right: none;
    width: calc(100% + 32px);
    max-width: calc(100% + 32px);
  }

  .code-content {
    max-width: 100%;
    overflow-x: auto;
  }

  .code-content pre {
    font-size: 0.8rem;
    padding: 16px;
    max-width: 100%;
    white-space: pre;
    word-wrap: normal;
  }

  .code-tab {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

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

@media (max-width: 600px) {
  .page-wrapper {
    padding: 24px 16px;
  }

  .course-header .course-number {
    font-size: 2.5rem;
  }

  .course-header .course-title {
    font-size: 1.2rem;
  }

  .info-cards {
    grid-template-columns: 1fr;
  }

  .tutorial-content {
    padding: 16px 12px;
  }

  .tutorial-content h1 {
    font-size: 1.4rem;
  }

  .tutorial-section h2 {
    font-size: 1.3rem;
  }

  .tutorial-section h3 {
    font-size: 1.1rem;
  }

  .key-principle,
  .learning-objectives,
  .common-mistakes,
  .exercise {
    padding: 16px;
    margin-left: -12px;
    margin-right: -12px;
    border-radius: 0;
  }

  .code-content pre {
    font-size: 0.75rem;
    padding: 12px;
  }

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

  .tutorial-content h1 {
    font-size: 1.6rem;
  }

  .code-content pre {
    font-size: 0.8rem;
    padding: 16px;
  }
}

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-footer a {
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-footer a:hover {
  color: var(--primary);
}
