:root {
  --bg-color: #f0f7ff;
  --text-color: #333;
  --header-color: #2563eb;
  --card-bg: #fff;
  --card-shadow: rgba(0, 0, 0, 0.08);
  --accordion-header-bg: #eef2ff;
  --quiz-card-border: #e0e0e0;
  --answer-bg: #f0f0f0;
  --answer-hover-bg: #e0e0e0;
  --footer-text: #6c757d;
}

/* Dark mode defaults to system preference */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a202c;
    color: #e2e8f0;
  }
}

body.dark-mode {
  --bg-color: #1a202c;
  --text-color: #e2e8f0;
  --header-color: #60a5fa;
  --card-bg: #2d3748;
  --card-shadow: rgba(0, 0, 0, 0.4);
  --accordion-header-bg: #4a5568;
  --quiz-card-border: #4a5568;
  --answer-bg: #4a5568;
  --answer-hover-bg: #718096;
  --footer-text: #a0aec0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  transition: background-color 0.3s, color 0.3s;
}

.page-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative; 
  background: var(--bg-color);
  z-index: 10;
  padding: 10px 20px;
  box-shadow: 0 2px 5px var(--card-shadow);
}

.home-button {
  background-color: var(--header-color);
  color: white;
  padding: 8px 15px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: bold;
  white-space: nowrap;
}

.header-title-container {
    text-align: center;
    flex-grow: 1;
    margin: 0 20px;
}

.main-header h1 {
  font-size: 1.5em;
  color: var(--header-color);
  margin: 0;
}

.theme-btn {
  background: none;
  border: none;
  font-size: 1.5em;
  cursor: pointer;
  padding: 0;
}

main {
  flex: 1;
  padding: 30px 20px;
}

.main-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 12px var(--card-shadow);
}

.card h2 {
  color: var(--header-color);
  margin-top: 0;
  border-bottom: 2px solid var(--header-color);
  padding-bottom: 10px;
  margin-bottom: 20px;
}

blockquote {
  background-color: var(--accordion-header-bg);
  border-left: 5px solid var(--header-color);
  margin: 1em 0;
  padding: 1em;
  border-radius: 4px;
}

/* --- Accordion Styles --- */
.accordion-item {
  border: 1px solid var(--quiz-card-border);
  border-radius: 8px;
  margin-bottom: 15px;
  overflow: hidden;
}
.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  background: var(--accordion-header-bg);
  cursor: pointer;
  font-weight: bold;
}
.accordion-header .icon {
  font-size: 1.2em;
  transition: transform 0.3s;
}
.accordion-item[aria-expanded="true"] .icon {
  transform: rotate(45deg);
}
.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease-out, padding 0.5s ease-out;
  padding: 0 20px;
}
.accordion-item[aria-expanded="true"] .accordion-content {
  max-height: 2000px;
  padding: 20px;
}

.content-image {
  max-width: 500px;
  width: 100%;
  height: auto;
  display: block;
  margin: 15px auto;
  border-radius: 8px;
  border: 1px solid #eee;
}

.table-wrapper {
  overflow-x: auto;
}
.table-wrapper table {
  min-width: 500px;
  width: 100%;
  border-collapse: collapse;
}
.table-wrapper th, .table-wrapper td {
  border: 1px solid var(--quiz-card-border);
  padding: 8px;
  text-align: center;
}
.table-wrapper th {
  background-color: var(--accordion-header-bg);
}

/* --- Simulation Styles --- */
.simulation-wrapper {
  position: relative;
  padding-bottom: 75%; /* 4:3 aspect ratio */
  height: 0;
  overflow: hidden;
}
.simulation-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* --- Quiz Styles --- */
#quiz-toggle {
  cursor: pointer;
}
#quiz-content {
  border-top: 1px solid var(--quiz-card-border);
  margin-top: 10px;
  padding-top: 10px;
}
.quiz-question {
  margin-bottom: 20px;
}
.question-text {
  font-weight: bold;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
}
.question-number {
  background: var(--header-color);
  color: white;
  border-radius: 50%;
  width: 25px;
  height: 25px;
  min-width: 25px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  font-weight: bold;
  margin-right: 10px;
}
.answers label {
  display: block;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--answer-bg);
  border: 2px solid transparent;
  cursor: pointer;
  transition: background-color 0.3s;
}
.answers label:hover,
.answers label:focus-within {
  background: var(--answer-hover-bg);
  outline: 2px solid var(--header-color);
}
.answers label.correct {
  background-color: #d4edda;
  color: #155724;
  border-color: #c3e6cb;
}
.answers label.incorrect {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}
.quiz-actions {
  text-align: center;
  margin-top: 10px;
}
.quiz-actions button {
  background: var(--header-color);
  color: white;
  border: none;
  padding: 10px 20px;
  margin: 0 5px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
}
#results {
  text-align: center;
  margin-top: 20px;
  font-weight: bold;
}

/* --- Footer --- */
footer {
  text-align: center;
  padding: 20px;
  margin-top: auto;
  color: var(--footer-text);
  font-size: 0.9em;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
  .main-header {
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 15px;
    gap: 15px;
  }
  .header-title-container {
    order: 3; /* This will make the title appear last in the flex order */
    width: 100%; /* Make the title container take the full width */
    text-align: center;
    margin: 0;
    padding: 0;
  }
  .home-button {
    order: 1; /* First item */
  }
  .theme-btn {
    order: 2; /* Second item */
  }
  .main-header h1 {
    font-size: 1.2em;
  }
  .card {
    padding: 15px;
  }
}

@media (max-width: 600px) {
  section {
    margin-bottom: 2rem;
  }
}

