/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --white: #ffffff;
  --text: #333333;
  --text-muted: #666666;
  --text-light: #999999;
  --border: #dee2e6;
  --border-light: #e8e8e8;
  --blue: #0073aa;
  --blue-light: #d9edf7;
  --blue-border: #bce8f1;
  --yellow-light: #fcf8e3;
  --yellow-border: #faebcc;
  --green: #5cb85c;
  --green-check: #3c763d;
  --red: #d9534f;
  --red-bg: #f2dede;
  --red-border: #ebccd1;
  --sidebar-bg: #f9f9f9;
  --topbar-bg: #ffffff;
  --radius: 0px;
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Top Bar ===== */
.topbar {
  background: var(--topbar-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.topbar-logo-img {
  height: 19px;
  width: auto;
}

.topbar-nav {
  display: flex;
  gap: 1.25rem;
}
.topbar-nav a {
  color: var(--text-muted);
  font-size: 0.93rem;
  transition: color 0.15s;
}
.topbar-nav a:hover { color: var(--text); text-decoration: none; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.topbar-icon-svg {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  cursor: pointer;
}
.topbar-icon-svg:hover { color: var(--text); }
.topbar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #ddd;
  border: 2px solid var(--border);
}

/* ===== Screens ===== */
.screen { display: none; }
.screen.active { display: block; }

/* ===== Page Wrap ===== */
.page-wrap {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.breadcrumb a { color: var(--blue); }

.page-title {
  font-size: 1.6rem;
  font-weight: 400;
  margin-bottom: 1.25rem;
  color: var(--text);
}

/* ===== Info Table ===== */
.info-table {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.info-table table {
  width: 100%;
  border-collapse: collapse;
}
.info-table th,
.info-table td {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  font-size: 0.93rem;
}
.info-table tr:last-child th,
.info-table tr:last-child td { border-bottom: none; }
.info-table th {
  font-weight: 600;
  color: var(--text);
  width: 140px;
  background: var(--sidebar-bg);
}

/* ===== Buttons ===== */
.moodle-btn {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.93rem;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--white);
  color: var(--text);
}
.moodle-btn:hover { background: #e9e9e9; }

.moodle-btn-primary {
  background: #0073aa;
  color: #fff;
  border-color: #006799;
}
.moodle-btn-primary:hover { background: #005f8a; }

.moodle-btn-secondary {
  background: var(--white);
  color: var(--blue);
  border-color: var(--blue);
}
.moodle-btn-secondary:hover { background: #f0f7fb; }

/* ===== Overview / Start Page ===== */
.page-title-lg {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.section-nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.section-nav-row.section-nav-bottom {
  border-bottom: none;
  border-top: 1px solid var(--border-light);
  margin-bottom: 0;
  margin-top: 2rem;
  padding-top: 0.75rem;
}

.section-nav-link {
  color: var(--blue);
  font-size: 0.9rem;
}

.overview-text {
  margin-bottom: 1.25rem;
  font-size: 0.93rem;
  line-height: 1.65;
  color: var(--text);
}
.overview-text p { margin-bottom: 0.25rem; }

.overview-italic {
  color: var(--text-muted);
}

.overview-section {
  margin-bottom: 1.5rem;
}
.overview-heading {
  font-size: 1.05rem;
  font-weight: 700;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 0.5rem;
}
.overview-dates {
  font-size: 0.93rem;
  color: var(--text);
}

.minitest-list {
  margin-bottom: 1rem;
}
.minitest-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-light);
}
.minitest-item:last-child { border-bottom: none; }

.minitest-icon {
  width: 20px;
  height: 20px;
  color: var(--blue);
  flex-shrink: 0;
}
.minitest-item a {
  color: var(--blue);
  font-size: 0.95rem;
}

.jump-to-select {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--white);
  cursor: pointer;
}

/* ===== Category Grid ===== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.category-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 1.25rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  transition: all 0.15s;
}
.category-card:hover {
  border-color: var(--blue);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.category-name { font-weight: 600; font-size: 0.95rem; }
.category-count { font-size: 0.82rem; color: var(--text-muted); }

/* ===== Quiz Layout ===== */
.quiz-layout {
  display: flex;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  gap: 2rem;
  align-items: flex-start;
}

.quiz-main {
  flex: 1;
  min-width: 0;
}

/* ===== Question Block ===== */
.question-block {
  display: flex;
  gap: 0;
  margin-bottom: 1.75rem;
}

.question-block:has(+ .feedback-box.visible) {
  margin-bottom: 0;
}

/* Left info panel */
.question-info {
  width: 105px;
  min-width: 105px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.question-info .q-num {
  font-size: 0.8rem;
  color: var(--text);
  margin-bottom: 0.15rem;
}
.question-info .q-num strong {
  font-size: 1.15rem;
  display: inline;
}

.question-info .q-status {
  margin-top: 0.35rem;
  font-size: 0.8rem;
}

.question-info .q-points {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  line-height: 1.35;
}

/* Right content area */
.question-content {
  flex: 1;
  background: var(--blue-light);
  border: 1px solid var(--blue-border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1.25rem 1.5rem;
}

.question-text {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ===== Radio / Checkbox Options ===== */
.option-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
  font-size: 0.93rem;
}

.option-row input[type="radio"],
.option-row input[type="checkbox"] {
  accent-color: var(--blue);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.option-row label {
  cursor: pointer;
  user-select: none;
}

.option-row .correct-icon {
  color: var(--green-check);
  font-weight: bold;
  margin-left: 0.35rem;
}
.option-row .wrong-icon {
  color: var(--red);
  font-weight: bold;
  margin-left: 0.35rem;
}

/* Number input */
.number-input {
  width: 120px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
}
.number-input:focus { border-color: var(--blue); }

/* ===== Feedback Box ===== */
.feedback-box {
  margin-top: 0.5rem;
  margin-bottom: 1.75rem;
  margin-left: 105px;
  background: var(--yellow-light);
  border: 1px solid var(--yellow-border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  color: #8a6d3b;
  display: none;
}
.feedback-box.visible { display: block; }

.feedback-box.feedback-correct {
  background: #dff0d8;
  border-color: #d6e9c6;
  color: #3c763d;
}
.feedback-box.feedback-wrong {
  background: var(--yellow-light);
  border-color: var(--yellow-border);
  color: #8a6d3b;
}

/* ===== Answered states ===== */
.question-block.answered .question-content {
  pointer-events: none;
}

.question-block.answered-correct .question-info {
  border-color: #d6e9c6;
}
.question-block.answered-wrong .question-info {
  border-color: var(--red-border);
}

/* ===== Submit Bar ===== */
.submit-bar {
  text-align: center;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.submit-bar.hidden { display: none; }

/* ===== Results Summary ===== */
.results-summary { margin-top: 1rem; }
.results-summary.hidden { display: none; }
.results-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* ===== Sidebar ===== */
.quiz-sidebar {
  width: 220px;
  min-width: 220px;
  position: sticky;
  top: 65px;
}

.sidebar-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.sidebar-box h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.nav-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 1rem;
}

.nav-dot {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  background: var(--white);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  position: relative;
}
.nav-dot:hover {
  border-color: var(--blue);
  text-decoration: none;
}

.nav-dot.answered-correct {
  border-color: var(--green);
  background: #f0fff0;
}
.nav-dot.answered-correct::after {
  content: '✓';
  position: absolute;
  bottom: -2px;
  right: 1px;
  font-size: 0.6rem;
  color: var(--green);
}

.nav-dot.answered-wrong {
  border-color: var(--red);
  background: #fff5f5;
}
.nav-dot.answered-wrong::after {
  content: '✗';
  position: absolute;
  bottom: -2px;
  right: 1px;
  font-size: 0.6rem;
  color: var(--red);
}

.sidebar-links {
  font-size: 0.85rem;
}
.sidebar-links a {
  display: block;
  margin-top: 0.35rem;
}

/* ===== Responsive ===== */
@media (max-width: 850px) {
  .quiz-layout {
    flex-direction: column;
    padding: 1rem;
  }
  .quiz-sidebar {
    width: 100%;
    min-width: 0;
    position: static;
    order: -1;
  }
  .nav-grid { justify-content: flex-start; }
  .question-block { flex-direction: column; }
  .question-info {
    width: 100%;
    min-width: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    display: flex;
    gap: 1rem;
    align-items: center;
  }
  .question-content {
    border-left: 1px solid var(--blue-border);
    border-radius: 0 0 var(--radius) var(--radius);
  }
  .feedback-box { margin-left: 0; }
  .topbar-nav { display: none; }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.question-block {
  animation: fadeIn 0.3s ease;
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -10px;
  animation: confettiFall linear forwards;
  opacity: 0.9;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
