/* ============================================
   ROOT VARIABLES & THEMING
   ============================================ */

:root {
  /* Color Variables */
  --primary-color: #02C1D8;
  --primary-hover: #029eb6;
  --primary-light: #67e8f9;

  /* Difficulty Level Colors */
  --difficulty-easy: #10b981;
  --difficulty-medium: #f59e0b;
  --difficulty-hard: #ef4444;

  /* Shadows for depth */
  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --card-shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.15);

  /* Neutral Colors */
  --text-primary: #1f2937;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --bg-light: #f8fafc;
  --bg-lighter: #f1f5f9;
  --border-color: #e2e8f0;
  --border-dark: #334155;
}

.dark {
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --bg-light: #334155;
  --bg-lighter: #475569;
  --border-color: #334155;
  --border-dark: #1e293b;
  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --card-shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.4);
}

/* ============================================
   LAYOUT & OVERFLOW FIXES
   ============================================ */

html, body {
  box-sizing: border-box;
  width: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

.container {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

main {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

nav {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Prevent layout shifts */
section, article, aside {
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Ensure relative containers don't cause layout issues */
.relative {
  max-width: 100%;
  width: 100%;
}

.min-h-screen {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
}

/* Prevent absolutely positioned children from causing overflow */
.relative .absolute,
.min-h-screen .absolute {
  max-width: 100%;
}

/* Ensure images and iframes don't cause overflow */
img, iframe, video {
  max-width: 100%;
  height: auto;
}

/* ============================================
   MODAL DIALOG STYLES
   ============================================ */

#modal {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeInModal 150ms ease;
}

#modal > .modal-underlay {
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

#modal > .modal-content {
  margin-top: 10vh;
  width: 80%;
  max-width: 600px;
  border: solid 1px #999;
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  background-color: white;
  padding: 20px;
  animation: zoomInModal 150ms ease;
}

#modal.closing {
  animation: fadeOutModal 150ms ease;
}

#modal.closing > .modal-content {
  animation: zoomOutModal 150ms ease;
}

.dark #modal > .modal-content {
  background-color: #1e293b;
  color: #f8fafc;
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fadeInModal {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes fadeOutModal {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes zoomInModal {
  0% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

@keyframes zoomOutModal {
  0% { transform: scale(1); }
  100% { transform: scale(0.9); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes taskCardEntry {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in {
  animation: fadeIn 1s ease-out;
}

.animate-slide-up {
  animation: slideUp 0.8s ease-out;
}

/* ============================================
   PROSE & TEXT STYLES
   ============================================ */

.prose {
  color: #374151;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  color: var(--text-primary);
  margin-bottom: 1rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.prose p {
  margin-bottom: 1.25rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.dark .prose {
  color: #e2e8f0;
}

code {
  font-family: monospace;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* ============================================
   BREADCRUMB NAVIGATION
   ============================================ */

.breadcrumb-nav {
  width: 100%;
  max-width: 100%;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
}

.breadcrumb-nav > div {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.breadcrumb-nav a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.breadcrumb-nav a:hover {
  color: var(--primary-hover);
  transform: translateX(2px);
}

.breadcrumb-nav span {
  color: var(--text-secondary);
  margin: 0 0.25rem;
}

.breadcrumb-nav .breadcrumb-current {
  color: var(--text-primary);
  font-weight: 600;
  cursor: default;
}

/* ============================================
   LAB HEADER SECTION
   ============================================ */

.lab-header-enhanced {
  margin-bottom: 2rem;
}

.lab-title-section {
  margin-bottom: 1.5rem;
}

.lab-title-section h1 {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.lab-title-theme-badge {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: white;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(2, 193, 216, 0.3);
}

/* ============================================
   LAB INFO CARD
   ============================================ */

.lab-info-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  background: white;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  margin-bottom: 2rem;
  transition: all 0.3s ease;
}

.dark .lab-info-card {
  background: #1e293b;
  border-color: var(--border-dark);
}

.lab-info-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: white;
  flex-shrink: 0;
}

.lab-info-icon svg {
  width: 32px;
  height: 32px;
}

.lab-info-content {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.lab-info-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.lab-info-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}

.lab-info-value {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1rem;
}

/* ============================================
   SECTION HEADERS
   ============================================ */

.section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
  position: relative;
}

.section-header::before {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: linear-gradient(90deg, var(--primary-color), var(--primary-hover));
}

.section-header-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-color);
  flex-shrink: 0;
}

.section-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================
   TASK CARD STYLES
   ============================================ */

.task-card-enhanced {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  position: relative;
  animation: taskCardEntry 0.5s ease-out;
}

.dark .task-card-enhanced {
  background: #1e293b;
  border-color: var(--border-dark);
}

.task-card-enhanced::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-color), var(--primary-hover));
  opacity: 0;
  transition: opacity 0.3s ease;
}

.task-card-enhanced:hover {
  box-shadow: var(--card-shadow-hover);
  border-color: var(--primary-color);
  transform: translateY(-4px);
}

.task-card-enhanced:hover::before {
  opacity: 1;
}

/* Stagger animation for multiple task cards */
.task-card-enhanced:nth-child(1) { animation-delay: 0.05s; }
.task-card-enhanced:nth-child(2) { animation-delay: 0.1s; }
.task-card-enhanced:nth-child(3) { animation-delay: 0.15s; }
.task-card-enhanced:nth-child(4) { animation-delay: 0.2s; }
.task-card-enhanced:nth-child(5) { animation-delay: 0.25s; }

.task-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.3s ease;
  user-select: none;
}

.task-card-enhanced:hover .task-card-header {
  background: var(--bg-light);
}

.task-card-title-group {
  flex: 1;
}

.task-card-title {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
  transition: color 0.3s ease;
}

.task-card-enhanced:hover .task-card-title {
  color: var(--primary-hover);
}

.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.task-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.task-meta-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ============================================
   DIFFICULTY & TIME BADGES
   ============================================ */

.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: white;
  transition: all 0.3s ease;
}

.difficulty-badge.easy {
  background: linear-gradient(135deg, var(--difficulty-easy), #059669);
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.difficulty-badge.medium {
  background: linear-gradient(135deg, var(--difficulty-medium), #d97706);
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}

.difficulty-badge.hard {
  background: linear-gradient(135deg, var(--difficulty-hard), #dc2626);
  box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.difficulty-badge:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.time-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--bg-lighter);
  color: #475569;
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.dark .time-badge {
  background: #334155;
  color: #cbd5e1;
  border-color: #475569;
}

.time-badge:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

/* ============================================
   TASK CHEVRON & EXPANDER
   ============================================ */

.task-chevron {
  width: 24px;
  height: 24px;
  color: #94a3b8;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s ease;
  flex-shrink: 0;
}

.dark .task-chevron {
  color: #64748b;
}

.task-card-enhanced:hover .task-chevron {
  color: var(--primary-color);
}

input[type="checkbox"]:checked ~ .task-card-header .task-chevron {
  transform: rotate(180deg);
  color: var(--primary-color);
}

.task-expander,
.task-expander-content {
  max-height: 0;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark .task-expander-content {
  background: #1e293b;
}

input[type="checkbox"]:checked ~ .task-expander,
input[type="checkbox"]:checked ~ .task-expander-content {
  max-height: 800px;
  padding: 1.25rem;
}

input[type="checkbox"]:checked ~ .task-expander-content {
  border-top: 1px solid var(--border-color);
}

.task-expander-content .blog-content {
  margin: 0;
  padding: 0;
  color: #374151;
}

.dark .task-expander-content .blog-content {
  color: #e2e8f0;
}

.task-expander-content .blog-content p {
  margin-bottom: 1rem;
}

.task-expander-content .blog-content p:last-child {
  margin-bottom: 0;
}

/* ============================================
   TABLE OF CONTENTS - TOGGLE BUTTON
   ============================================ */

.toc-toggle-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: white;
  border: none;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(2, 193, 216, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toc-toggle-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 15px 30px rgba(2, 193, 216, 0.5);
}

.toc-toggle-btn:active {
  transform: translateY(0) scale(1);
}

@media (min-width: 1024px) {
  .toc-toggle-btn {
    bottom: 1.5rem;
    right: 1.5rem;
  }
}

/* ============================================
   TABLE OF CONTENTS - OVERLAY
   ============================================ */

.toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(4px);
}

.toc-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   TABLE OF CONTENTS SIDEBAR
   ============================================ */

.toc-sidebar-wrapper {
  width: 100%;
  max-width: 100%;
}

/* Mobile: Hidden by default, shows as overlay when toggled */
@media (max-width: 1023px) {
  .toc-sidebar-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    z-index: 70;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-primary);
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
  }

  .toc-sidebar-wrapper.active {
    transform: translateX(0);
  }

  .dark .toc-sidebar-wrapper {
    background: var(--bg-secondary);
  }
}

/* Desktop: Static sidebar */
@media (min-width: 1024px) {
  .toc-sidebar-wrapper {
    width: 280px;
    flex-shrink: 0;
  }

  .toc-toggle-btn {
    display: none;
  }

  .toc-overlay {
    display: none;
  }
}

.toc-sidebar-enhanced {
  width: 100%;
  max-width: 100%;
  padding: 1.5rem;
}

/* Desktop: Sticky sidebar */
@media (min-width: 1024px) {
  .toc-sidebar-enhanced {
    position: sticky;
    top: 100px;
    align-self: flex-start;
  }
}

.toc-container {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  transition: all 0.3s ease;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.dark .toc-container {
  background: #1e293b;
  border-color: var(--border-dark);
}

.toc-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.toc-close-btn {
  margin-left: auto;
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toc-close-btn:hover {
  background: var(--bg-secondary);
  color: var(--primary-color);
}

.dark .toc-close-btn:hover {
  background: var(--bg-tertiary);
}

.toc-header-icon {
  width: 24px;
  height: 24px;
  color: var(--primary-color);
  flex-shrink: 0;
}

.toc-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================
   TOC PROGRESS BAR
   ============================================ */

.toc-progress {
  width: 100%;
  height: 3px;
  background: var(--border-color);
  border-radius: 2px;
  margin-bottom: 1rem;
  overflow: hidden;
  position: relative;
}

.toc-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--primary-hover));
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(2, 193, 216, 0.5);
}

/* ============================================
   TABLE OF CONTENTS LINKS
   ============================================ */

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

.toc li {
  position: relative;
  margin: 0;
}

.toc a {
  display: block;
  padding: 0.6rem 0.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.3s ease;
  position: relative;
}

.toc a:hover {
  color: var(--primary-color);
  background: var(--bg-lighter);
  transform: translateX(4px);
}

.toc a.active {
  color: var(--primary-color);
  background: rgba(2, 193, 216, 0.1);
  font-weight: 600;
  border-radius: 8px;
  padding-left: 1rem;
}

.toc a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--primary-color);
  border-radius: 2px;
}

.toc ul ul {
  margin-left: 1rem;
  margin-top: 0.25rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border-color);
  transition: border-color 0.3s ease;
}

/* ============================================
   ACCESSIBILITY & FOCUS STATES
   ============================================ */

.task-card-header:focus,
.task-card-header:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.toc a:focus,
.toc a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.breadcrumb-nav a:focus,
.breadcrumb-nav a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

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

@media (max-width: 1024px) {
  .lab-header-enhanced {
    margin-bottom: 1.5rem;
  }

  .lab-info-card {
    grid-template-columns: 1fr;
    padding: 1.25rem 1.5rem;
  }

  .lab-info-icon {
    width: 50px;
    height: 50px;
  }

  .task-card-header {
    padding: 1rem;
  }

  .toc-container {
    padding: 1.25rem;
  }
}

@media (max-width: 768px) {
  .breadcrumb-nav {
    font-size: 0.85rem;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .lab-title-section h1 {
    font-size: 1.75rem;
  }

  .lab-title-theme-badge {
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
  }

  .lab-info-card {
    padding: 1rem;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .lab-info-icon {
    width: 45px;
    height: 45px;
  }

  .lab-info-icon svg {
    width: 24px;
    height: 24px;
  }

  .section-header {
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
  }

  .section-header h2 {
    font-size: 1.25rem;
  }

  .task-meta-item {
    font-size: 0.8rem;
  }

  .difficulty-badge {
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
  }

  .time-badge {
    font-size: 0.8rem;
    padding: 0.35rem 0.7rem;
  }

  .toc-container {
    padding: 1.25rem;
  }

  .toc-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .toc-header h3 {
    font-size: 1rem;
  }

  .toc a {
    padding: 0.5rem 0.6rem;
    font-size: 0.85rem;
  }

  .toc ul ul {
    margin-left: 0.75rem;
    padding-left: 0.4rem;
  }
}

@media (max-width: 480px) {
  .breadcrumb-nav {
    font-size: 0.8rem;
    gap: 0.35rem;
  }

  .breadcrumb-nav span {
    margin: 0 0.1rem;
  }

  .lab-title-section h1 {
    font-size: 1.5rem;
    gap: 0.5rem;
  }

  .lab-info-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .task-card-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.85rem;
  }

  .task-card-meta {
    width: 100%;
    gap: 0.75rem;
    margin-top: 0.5rem;
  }

  .task-chevron {
    margin-left: auto;
    margin-top: -2rem;
  }

  .toc-container {
    padding: 1rem;
  }
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
