/* 
 * Style for Semiconductor Quiz System 
 * Inspired by Yihui Xie's website style (Hugo XMin theme)
 * Minimalist, Typography-focused, Academic Booktabs aesthetics
 */

/* Fonts & Base */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, "Georgia", "Source Han Serif CN", "Songti SC", serif;
  font-size: 16px;
  line-height: 1.7;
  color: #333333;
  background-color: #fcfcfc;
  max-width: 820px;
  margin: 0 auto;
  padding: 2em 1.5em;
}

main,
header,
footer {
  min-width: 0;
}

img,
svg,
canvas,
video {
  max-width: 100%;
  height: auto;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, "Georgia", "Source Han Serif CN", "Songti SC", serif;
  color: #111111;
  font-weight: normal;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.25;
}

h1 { font-size: 1.8em; border-bottom: none; }
h2 { font-size: 1.5em; margin-top: 1.8em; }
h3 { font-size: 1.25em; }

/* Links */
a {
  color: #8f0000; /* Deep Crimson Accent */
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
  color: #c62828;
}

/* Header & Navigation */
header nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

header nav li {
  display: inline-block;
}

header nav .logo {
  font-size: 1.2em;
  font-weight: bold;
}

header nav .logo a {
  color: #111;
}

header nav .logo a:hover {
  text-decoration: none;
}

header nav .menu-items {
  display: flex;
  gap: 1.5em;
}

header nav .menu-items a {
  color: #555;
  font-size: 1em;
  padding-bottom: 2px;
}

header nav .menu-items a:hover,
header nav .menu-items a.active {
  color: #8f0000;
  text-decoration: none;
  border-bottom: 2px solid #8f0000;
}

/* Divider Lines */
hr {
  border: none;
  border-top: 1px solid #ddd;
  height: 0;
  margin: 1.5em 0;
}

/* Footer */
footer {
  margin-top: 3em;
  font-size: 0.85em;
  color: #777;
}

footer a {
  color: #666;
}

/* Forms, Inputs & Buttons */
button {
  background-color: transparent;
  border: 1px solid #8f0000;
  color: #8f0000;
  padding: 0.4em 1em;
  font-family: inherit;
  font-size: 0.9em;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 0; /* Keep it flat and sharp */
}

button:hover {
  background-color: #8f0000;
  color: #ffffff;
}

button.secondary {
  border-color: #666666;
  color: #444444;
}

button.secondary:hover {
  background-color: #666666;
  color: #ffffff;
}

button:disabled {
  border-color: #cccccc;
  color: #999999;
  cursor: not-allowed;
  background-color: transparent;
}

select, input[type="text"], input[type="number"], textarea {
  border: 1px solid #cccccc;
  background-color: #ffffff;
  padding: 0.4em 0.6em;
  font-family: inherit;
  font-size: 0.95em;
  color: #333333;
  width: 100%;
  box-sizing: border-box;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
  outline: none;
  border-color: #8f0000;
}

label {
  display: block;
  margin-bottom: 0.3em;
  font-weight: 500;
}

.form-group {
  margin-bottom: 1.2em;
}

/* Academic Tables (Booktabs style) */
table {
  border-collapse: collapse;
  margin: 1.5em 0;
  width: 100%;
  font-size: 0.95em;
}

th {
  border-top: 2px solid #555555;
  border-bottom: 1px solid #555555;
  padding: 0.6em 0.8em;
  text-align: left;
  font-weight: bold;
  color: #111111;
}

td {
  border-bottom: 1px solid #e0e0e0;
  padding: 0.6em 0.8em;
  color: #444444;
}

tr:last-child td {
  border-bottom: 2px solid #555555;
}

/* Question List & Navigation */
.chapter-section {
  margin-bottom: 1.5em;
}

.chapter-header {
  background-color: #f3f3f3;
  padding: 0.6em 1em;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  border-left: 3px solid #8f0000;
}

.chapter-header:hover {
  background-color: #e9e9e9;
}

.chapter-title {
  margin: 0;
  font-size: 1.1em;
  color: #222;
}

.chapter-content {
  padding: 0.5em 0.5em 0.5em 1.5em;
  border: 1px solid #e5e5e5;
  border-top: none;
}

/* Question Item */
.question-card {
  padding: 1.5em 0;
  border-bottom: 1px dashed #cccccc;
}

.question-card:last-child {
  border-bottom: none;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.8em;
}

.question-meta {
  font-size: 0.85em;
  color: #666666;
  background-color: #eaeaea;
  padding: 0.15em 0.5em;
  font-family: sans-serif;
}

.question-stem {
  font-size: 1.05em;
  color: #111111;
  margin-bottom: 1em;
  word-wrap: break-word;
}

/* Options */
.options-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.2em 0;
}

.option-item {
  padding: 0.5em 0.8em;
  border: 1px solid #e0e0e0;
  margin-bottom: 0.5em;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.6em;
  background-color: #ffffff;
}

.option-item:hover {
  background-color: #fafaf9;
  border-color: #a8a8a8;
}

.option-item.selected {
  background-color: #f7eded;
  border-color: #8f0000;
}

.option-item input[type="radio"],
.option-item input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  flex: 0 0 auto;
}

.option-item label {
  min-width: 0;
}

.option-item-display {
  padding: 0.35em 0;
  word-break: break-word;
}

/* Answer & Explanation */
.answer-box {
  margin-top: 1em;
  padding: 1em;
  background-color: #f9f9f9;
  border-left: 3px solid #8f0000;
  font-size: 0.95em;
}

.answer-box p {
  margin-top: 0;
}

.text-success {
  color: #2e7d32;
  font-weight: bold;
}

.text-danger {
  color: #c62828;
  font-weight: bold;
}

/* Actions Row */
.question-actions {
  display: flex;
  gap: 1em;
  margin-top: 0.8em;
}

/* Search bar */
.search-container {
  display: flex;
  gap: 1em;
  margin-bottom: 1.5em;
}

.search-input {
  flex: 1;
}

/* Exam Module Specifics */
.exam-setup-card {
  padding: 2em;
  background-color: #ffffff;
  border: 1px solid #dddddd;
  margin-bottom: 2em;
}

.exam-grid-container {
  display: grid;
  grid-template-columns: 3fr 1fr;
  gap: 2em;
}

@media (max-width: 768px) {
  .exam-grid-container {
    grid-template-columns: 1fr;
  }
}

.exam-content-panel {
  min-width: 0; /* Prevents flex items from overflowing */
}

.exam-question-item,
.exam-paper-item {
  border: 1px solid #dddddd;
  padding: 1.5em;
  background-color: #ffffff;
}

.exam-sidebar-panel {
  border-left: 1px solid #eeeeee;
  padding-left: 1.5em;
}

@media (max-width: 768px) {
  .exam-sidebar-panel {
    border-left: none;
    border-top: 1px solid #eeeeee;
    padding-left: 0;
    padding-top: 1.5em;
  }
}

.exam-progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 0.5em;
  margin-top: 1em;
  margin-bottom: 1.5em;
}

.progress-dot {
  width: 32px;
  height: 32px;
  border: 1px solid #cccccc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85em;
  font-family: sans-serif;
  cursor: pointer;
  transition: all 0.15s ease;
  background-color: #ffffff;
}

.progress-dot:hover {
  background-color: #f0f0f0;
}

.progress-dot.answered {
  background-color: #eaeaea;
  border-color: #888888;
}

.progress-dot.current {
  background-color: #f7eded;
  border-color: #8f0000;
  font-weight: bold;
}

.progress-dot.correct {
  background-color: #e8f5e9;
  border-color: #2e7d32;
  color: #2e7d32;
}

.progress-dot.incorrect {
  background-color: #ffebee;
  border-color: #c62828;
  color: #c62828;
}

.exam-nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5em;
}

.exam-score-banner {
  padding: 1.5em;
  text-align: center;
  background-color: #f7eded;
  border: 1px solid #8f0000;
  margin-bottom: 2em;
}

.exam-score-title {
  font-size: 2.2em;
  color: #8f0000;
  margin: 0.2em 0;
}

.exam-mode-toggle {
  display: flex;
  gap: 1.5em;
  margin-bottom: 1em;
}

/* Statistics Module */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5em;
  margin-bottom: 2em;
  text-align: center;
}

@media (max-width: 576px) {
  .stats-summary {
    grid-template-columns: 1fr;
    gap: 1em;
  }
}

.stat-card {
  padding: 1.5em;
  background-color: #fafaf9;
  border: 1px solid #e0e0e0;
}

.stat-value {
  font-size: 2.2em;
  color: #8f0000;
  line-height: 1.1;
  margin-bottom: 0.2em;
}

.stat-label {
  font-size: 0.9em;
  color: #666666;
}

.chart-container {
  margin: 2em 0;
}

.bar-row {
  margin-bottom: 1.2em;
}

.bar-label {
  font-size: 0.95em;
  margin-bottom: 0.3em;
  display: flex;
  justify-content: space-between;
}

.bar-track {
  height: 14px;
  background-color: #eeeeee;
  width: 100%;
}

.bar-fill {
  height: 100%;
  background-color: #8f0000;
  transition: width 0.8s ease;
  width: 0%;
}

/* Blockquote formatting for Yihui style */
blockquote {
  border-left: 3px solid #8f0000;
  margin: 1.5em 0;
  padding-left: 1.5em;
  color: #555555;
  font-style: italic;
}

/* Code block & inline code styling */
code {
  font-family: "Courier New", Courier, monospace;
  background-color: #f5f5f5;
  padding: 0.1em 0.3em;
  font-size: 0.9em;
}

pre {
  background-color: #f5f5f5;
  padding: 1em;
  overflow-x: auto;
  border: 1px solid #e5e5e5;
}

pre code {
  background-color: transparent;
  padding: 0;
  font-size: 0.85em;
}

/* Utils */
.center-text {
  text-align: center;
}

.mt-2 { margin-top: 2em; }
.mb-2 { margin-bottom: 2em; }

.badge {
  display: inline-block;
  padding: 0.1em 0.4em;
  font-size: 0.8em;
  font-weight: 500;
  background-color: #eaeaea;
  color: #555;
  margin-right: 0.5em;
}

.badge.objective {
  background-color: #e1f5fe;
  color: #0288d1;
}

.badge.subjective {
  background-color: #efebe9;
  color: #5d4037;
}

.badge.wrong {
  background-color: #ffebee;
  color: #c62828;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.5em;
  margin-top: 0.5em;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-weight: normal;
  font-size: 0.95em;
  cursor: pointer;
}

.checkbox-label input {
  margin: 0;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333333;
  color: #ffffff;
  padding: 0.6em 1.2em;
  font-size: 0.9em;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 0.9;
}

@media (max-width: 768px) {
  body {
    max-width: none;
    padding: 1em;
  }

  h2 {
    font-size: 1.35em;
    margin-top: 1.2em;
  }

  h3 {
    font-size: 1.15em;
  }

  header nav ul {
    align-items: flex-start;
    gap: 0.8em;
  }

  header nav .logo {
    width: 100%;
    line-height: 1.35;
  }

  header nav .menu-items {
    width: 100%;
    gap: 0.45em;
    overflow-x: auto;
    padding-bottom: 0.25em;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  header nav .menu-items::-webkit-scrollbar {
    display: none;
  }

  header nav .menu-items li,
  header nav .menu-items a {
    flex: 0 0 auto;
  }

  header nav .menu-items a {
    display: block;
    padding: 0.35em 0.65em;
    border: 1px solid transparent;
    font-size: 0.95em;
    white-space: nowrap;
  }

  header nav .menu-items a:hover,
  header nav .menu-items a.active {
    border: 1px solid #8f0000;
    border-bottom: 1px solid #8f0000;
  }

  hr {
    margin: 1em 0;
  }

  button {
    min-height: 44px;
    padding: 0.55em 0.9em;
    font-size: 1em;
  }

  select,
  input[type="text"],
  input[type="number"],
  textarea {
    min-height: 44px;
    font-size: 16px;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th,
  td {
    min-width: 8em;
  }

  .search-container {
    display: grid;
    grid-template-columns: 1fr 5.5em 5.5em;
    gap: 0.5em;
    align-items: stretch;
  }

  .chapter-header {
    padding: 0.7em 0.8em;
  }

  .chapter-title {
    font-size: 1em;
  }

  .chapter-content {
    padding: 0.25em 0.75em;
  }

  .question-card {
    padding: 1.1em 0;
  }

  .question-header {
    flex-direction: column;
    gap: 0.45em;
  }

  .question-meta {
    max-width: 100%;
    word-break: break-word;
  }

  .question-stem {
    font-size: 1em;
    line-height: 1.75;
  }

  .options-list {
    margin-bottom: 1em;
  }

  .option-item {
    align-items: flex-start;
    gap: 0.55em;
    padding: 0.7em 0.75em;
    min-height: 44px;
  }

  .option-item input[type="radio"],
  .option-item input[type="checkbox"] {
    margin-top: 0.35em;
  }

  .option-item-display {
    line-height: 1.65;
  }

  .question-actions {
    flex-direction: column;
    gap: 0.6em;
  }

  .question-actions button {
    width: 100%;
  }

  .answer-box {
    padding: 0.85em;
    overflow-wrap: anywhere;
  }

  .exam-setup-card {
    padding: 1em;
  }

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

  .checkbox-label {
    align-items: flex-start;
    min-height: 36px;
  }

  .checkbox-label input {
    margin-top: 0.35em;
    flex: 0 0 auto;
  }

  .exam-mode-toggle {
    flex-direction: column;
    gap: 0.6em;
  }

  #start-exam-btn {
    width: 100%;
  }

  .exam-grid-container {
    gap: 1.2em;
  }

  .exam-question-toolbar {
    flex-wrap: wrap;
    gap: 0.5em;
  }

  .exam-question-item,
  .exam-paper-item {
    padding: 1em !important;
  }

  .paper-questions-list {
    gap: 1.2em !important;
  }

  .exam-sidebar-panel {
    padding-top: 1em;
  }

  .exam-progress-grid {
    grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
    gap: 0.45em;
  }

  .progress-dot {
    width: 100%;
    min-width: 38px;
    height: 38px;
  }

  .exam-nav-buttons {
    gap: 0.75em;
  }

  .exam-nav-buttons button {
    flex: 1 1 0;
  }

  .exam-score-banner {
    padding: 1em;
  }

  .exam-score-title,
  .stat-value {
    font-size: 1.8em;
  }

  .stats-summary {
    grid-template-columns: 1fr;
    gap: 0.9em;
  }

  .stat-card {
    padding: 1em;
  }

  .bar-label {
    flex-direction: column;
    gap: 0.2em;
  }

  .chart-container {
    margin: 1.4em 0;
  }

  blockquote {
    margin: 1.2em 0;
    padding-left: 1em;
  }

  .toast {
    left: 1em;
    right: 1em;
    bottom: 14px;
    transform: none;
    text-align: center;
  }

  footer {
    text-align: center;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0.85em;
    font-size: 15.5px;
  }

  .search-container {
    grid-template-columns: 1fr 1fr;
  }

  .search-input {
    grid-column: 1 / -1;
  }

  .chapter-content {
    padding: 0.2em 0.55em;
  }

  .question-actions,
  .exam-nav-buttons {
    gap: 0.5em;
  }

  .exam-progress-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: dark) {
  body {
    color: #d8d2c8;
    background-color: #161616;
  }

  h1, h2, h3, h4, h5, h6,
  header nav .logo a,
  .question-stem,
  th {
    color: #f1eee8;
  }

  a,
  header nav .menu-items a:hover,
  header nav .menu-items a.active,
  button,
  .stat-value,
  .exam-score-title {
    color: #ff8a8a;
  }

  a:hover {
    color: #ffb3b3;
  }

  header nav .menu-items a {
    color: #b9b1a7;
  }

  header nav .menu-items a:hover,
  header nav .menu-items a.active {
    border-color: #ff8a8a;
    border-bottom-color: #ff8a8a;
  }

  hr {
    border-top-color: #343434;
  }

  footer,
  footer a,
  .question-meta,
  .stat-label {
    color: #a9a198;
  }

  button {
    border-color: #ff8a8a;
    background-color: transparent;
  }

  button:hover {
    background-color: #ff8a8a;
    color: #181818;
  }

  button.secondary {
    border-color: #8d8780;
    color: #d0c8be;
  }

  button.secondary:hover {
    background-color: #8d8780;
    color: #161616;
  }

  button:disabled {
    border-color: #4a4a4a;
    color: #777;
    background-color: transparent;
  }

  select,
  input[type="text"],
  input[type="number"],
  textarea {
    border-color: #4a4a4a;
    background-color: #202020;
    color: #eee8df;
  }

  select:focus,
  input[type="text"]:focus,
  input[type="number"]:focus,
  textarea:focus {
    border-color: #ff8a8a;
  }

  th {
    border-top-color: #8b8379;
    border-bottom-color: #8b8379;
  }

  td {
    color: #d8d2c8;
    border-bottom-color: #333;
  }

  tr:last-child td {
    border-bottom-color: #8b8379;
  }

  .chapter-header,
  .question-meta,
  .badge {
    background-color: #242424;
  }

  .chapter-header {
    border-left-color: #ff8a8a;
  }

  .chapter-header:hover {
    background-color: #2e2e2e;
  }

  .chapter-title {
    color: #eee8df;
  }

  .chapter-content,
  .exam-setup-card,
  .exam-question-item,
  .exam-paper-item,
  .stat-card,
  .option-item,
  .progress-dot {
    background-color: #1d1d1d !important;
    border-color: #3a3a3a;
  }

  .question-card {
    border-bottom-color: #3a3a3a;
  }

  .option-item:hover,
  .progress-dot:hover {
    background-color: #262626;
    border-color: #777;
  }

  .option-item.selected,
  .progress-dot.current,
  .exam-score-banner {
    background-color: #3a2020;
    border-color: #ff8a8a;
  }

  .answer-box {
    background-color: #202020;
    border-left-color: #ff8a8a;
  }

  .text-success {
    color: #7bd88f;
  }

  .text-danger {
    color: #ff8a8a;
  }

  .exam-sidebar-panel {
    border-left-color: #333;
  }

  .progress-dot.answered {
    background-color: #2b2b2b;
    border-color: #777;
  }

  .progress-dot.correct {
    background-color: #17331e;
    border-color: #7bd88f;
    color: #7bd88f;
  }

  .progress-dot.incorrect {
    background-color: #3a2020;
    border-color: #ff8a8a;
    color: #ff8a8a;
  }

  .bar-track {
    background-color: #2b2b2b;
  }

  .bar-fill {
    background-color: #ff8a8a;
  }

  blockquote {
    border-left-color: #ff8a8a;
    color: #bfb7ad;
  }

  code,
  pre {
    background-color: #242424;
  }

  pre {
    border-color: #3a3a3a;
  }

  .badge {
    color: #d6d0c7;
  }

  .badge.objective {
    background-color: #123142;
    color: #8bd6ff;
  }

  .badge.subjective {
    background-color: #352923;
    color: #e7c3a5;
  }

  .badge.wrong {
    background-color: #3a2020;
    color: #ff8a8a;
  }

  .toast {
    background-color: #eee8df;
    color: #161616;
  }

  @media (max-width: 768px) {
    .exam-sidebar-panel {
      border-top-color: #333;
    }
  }
}
