:root {
  --navy: #17233d;
  --navy-2: #243354;
  --accent: #e11d74;
  --accent-dark: #c01562;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1c2434;
  --muted: #5c6b82;
  --good: #0f9f6e;
  --good-bg: #e6f7f0;
  --bad: #dc2626;
  --bad-bg: #fdecec;
  --busy: #d97706;
  --line: #d5dbe6;
  --shadow: 0 10px 30px rgba(23, 35, 61, 0.08);
  --radius: 16px;
}

html {
  font-size: 16px;
  position: relative;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  margin-bottom: 72px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

/* ---------------------------------------------------------------- header / footer */

.app-header {
  position: relative;
  background: linear-gradient(120deg, var(--navy), var(--navy-2));
  color: #fff;
}

.app-header .navbar {
  padding: 0.85rem 0;
}

.app-header .navbar-brand,
.app-header .nav-link,
.app-header .navbar-brand:hover,
.app-header .nav-link:hover {
  color: #fff;
}

.app-header .navbar-brand {
  font-weight: 700;
}

.app-header .nav-link {
  opacity: 0.85;
}

.app-header .nav-link:hover {
  opacity: 1;
}

.app-header .nav-link.active {
  opacity: 1;
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.app-header .navbar-toggler {
  border-color: rgba(255, 255, 255, 0.45);
}

.app-header .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255,255,255,0.9%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

.user-nav {
  flex-shrink: 0;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  margin: 0;
}

.lang-switch button {
  min-width: 2.15rem;
  height: 2.15rem;
  padding: 0 0.35rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.lang-switch button:hover,
.lang-switch button:focus {
  background: rgba(255, 255, 255, 0.12);
}

.lang-switch button.is-active {
  background: rgba(255, 255, 255, 0.2);
}

.signalr-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.signalr-status[hidden] {
  display: none;
}

.signalr-status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.signalr-status.is-online .signalr-status-dot {
  background: #22c55e;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 0 8px rgba(34, 197, 94, 0.75);
}

.signalr-status.is-connecting .signalr-status-dot {
  animation: signalr-pulse 1s ease-in-out infinite;
}

@keyframes signalr-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.app-footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 1.1rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.build-info {
  font-size: 0.65rem;
  line-height: 1.25;
  color: rgba(255, 255, 255, 0.6);
  text-align: right;
  white-space: nowrap;
  cursor: help;
}

/* Shown in the header when a newer version of the app is available. */
.new-version-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: #fde68a;
  color: #78350f;
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  animation: new-version-pulse 2s ease-in-out infinite;
}

.new-version-badge:hover {
  background: #fcd34d;
  color: #78350f;
}

.new-version-badge[hidden] {
  display: none;
}

@keyframes new-version-pulse {
  50% { box-shadow: 0 0 0 4px rgba(253, 230, 138, 0.35); }
}

.build-info code {
  color: inherit;
  font-size: inherit;
}

.env-stamp {
  margin-left: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #fde68a;
  color: #78350f;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- generic */

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
}

.card {
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-wrap {
  max-width: 520px;
  margin: 2rem auto;
}

.auth-split {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-split::before,
.auth-split::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.page-narrow {
  max-width: 620px;
}

.page-narrow.wide {
  max-width: 900px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-pill {
  display: inline-block;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  background: #e8edf7;
  color: var(--navy-2);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.source-pill {
  display: inline-block;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  border: 1px solid #c7d2e5;
  background: #fff;
  color: var(--navy-2);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

a.source-pill {
  text-decoration: none;
  cursor: pointer;
}

a.source-pill:hover,
a.source-pill:focus-visible {
  background: #e8edf7;
  border-color: var(--navy-2);
  color: var(--navy);
}

.source-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  vertical-align: middle;
}

.source-url-list {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
}

.source-url-list li + li {
  margin-top: 0.15rem;
}

.source-url-list a {
  word-break: break-all;
}

.review-source-badges {
  display: inline-flex;
}

.review-source-urls {
  margin: 0 0 0.85rem;
}

/* ---------------------------------------------------------------- question content */

.question-body {
  line-height: 1.55;
}

.question-body > :last-child {
  margin-bottom: 0;
}

.question-body img,
.question-body svg {
  max-width: 100%;
  height: auto;
}

.question-body img {
  display: block;
  margin: 0.75rem 0;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.question-body pre,
.option-text pre {
  margin: 0.6rem 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  background: #f6f8fa;
}

.question-body pre code,
.option-text pre code {
  display: block;
  padding: 0.75rem 1rem;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre;
}

.question-body :not(pre) > code,
.option-text :not(pre) > code {
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  background: #eef1f6;
  color: #9c1c5b;
  font-size: 0.88em;
}

.option-text p {
  margin: 0;
}

.option-text pre {
  margin: 0.25rem 0;
}

.option-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: grid;
  gap: 0.6rem;
}

/* Answer buttons (student room) */
.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  text-align: left;
  color: var(--text);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #fff7fb;
}

.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.option-btn.is-selected {
  border-color: var(--accent);
  background: #fdeaf3;
  box-shadow: 0 0 0 3px rgba(225, 29, 116, 0.15);
  opacity: 1;
}

/* Submitted (final) answer: green frame + badge, clearly different from a selected-but-not-submitted answer (pink). */
.option-btn.is-final {
  border-color: #16a34a;
  background: #ecfdf3;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
  opacity: 1;
}

.option-btn.is-final .option-number {
  background: #16a34a;
}

.option-badge {
  flex: 0 0 auto;
  align-self: center;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: #16a34a;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.option-badge[hidden] {
  display: none;
}

.option-number {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

.option-btn.is-selected .option-number {
  background: var(--accent);
}

.option-text {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 0.2rem;
}

/* Review (result pages, preview) */
.option-row {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.6rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.option-row.is-correct {
  border-color: var(--good);
  background: var(--good-bg);
}

.option-row.is-wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}

.option-flags {
  flex: 0 0 auto;
  display: flex;
  gap: 0.3rem;
  padding-top: 0.2rem;
}

.review-card {
  margin-bottom: 1.25rem;
  padding: 1.1rem 1.25rem;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 6px solid var(--line);
}

.review-card.is-right {
  border-left-color: var(--good);
}

.review-card.is-wrong {
  border-left-color: var(--bad);
}

.review-card.is-unanswered {
  border-left-color: var(--busy);
}

.review-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.review-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

.review-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.01em;
}

.review-verdict {
  font-weight: 700;
}

.review-head.is-toggle {
  cursor: pointer;
  user-select: none;
}

.review-head.is-toggle:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 3px;
  border-radius: 6px;
}

.review-chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  color: #64748b;
}

.review-card.is-collapsed .review-chevron {
  transform: rotate(-90deg);
}

/* Collapsed: only show the first text part of the question (options, code, explanation hidden). */
.review-card.is-collapsed .review-body > :not(.question-body) {
  display: none;
}

.review-card.is-collapsed .review-body > .question-body > :not(:first-child) {
  display: none;
}

.review-card.is-collapsed .review-body > .question-body > :first-child {
  margin-bottom: 0;
  color: #475569;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.review-card.is-collapsed .review-body > .question-body > pre:first-child {
  display: none;
}

.review-card.is-right .review-verdict {
  color: #0b7d57;
}

.review-card.is-wrong .review-verdict {
  color: var(--bad);
}

.explanation {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  background: #f1f5fb;
  border: 1px solid #dbe4f3;
}

.explanation-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--navy-2);
  margin-bottom: 0.3rem;
}

/* ---------------------------------------------------------------- student room */

.room-card {
  padding: 1.25rem 1.5rem;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Question number + remaining time stay visible while scrolling through a long question. */
.room-sticky-head {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -1.25rem -1.5rem 1rem;
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}

.room-progress {
  margin-top: 0.5rem;
}

.room-timer {
  display: inline-block;
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.room-timer.is-low {
  background: var(--bad);
}

/* Bootstrap utilities such as .d-flex use !important and would otherwise defeat the hidden attribute. */
.d-flex[hidden] {
  display: none !important;
}

/* Self-paced quizzes: question navigator (one chip per question). */
.question-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.nav-chip {
  min-width: 2.1rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--bs-border-color, #ced4da);
  border-radius: 0.4rem;
  background: #fff;
  color: inherit;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.nav-chip:hover {
  border-color: var(--navy);
}

.nav-chip.is-answered {
  background: #e3f4ea;
  border-color: #7cc79b;
}

.nav-chip.is-current {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* ---------------------------------------------------------------- question picker */

.picker-layout {
  display: grid;
  grid-template-columns: minmax(230px, 280px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .picker-layout {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 901px) {
  .picker-filters {
    position: sticky;
    top: 0.75rem;
  }
}

.question-row .q-check {
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
}

.min-w-0 {
  min-width: 0;
}

.tag-filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 260px;
  overflow-y: auto;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--navy-2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.tag-chip:hover {
  border-color: var(--accent);
}

.tag-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tag-chip .tag-count {
  opacity: 0.7;
  font-weight: 500;
}

.question-list {
  max-height: 620px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.question-table {
  font-size: 0.85rem;
}

/* The header stays visible while the list scrolls. */
.question-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8f9fc;
  white-space: nowrap;
}

.question-table td,
.question-table th {
  padding: 0.45rem 0.6rem;
}

.question-row {
  cursor: pointer;
}

.question-row:hover > td {
  background: #fafbfe;
}

.question-row.is-selected > td {
  background: #fdf1f7;
}

.question-row.is-hidden {
  display: none;
}

.question-table .q-col-check {
  width: 2rem;
  text-align: center;
}

.question-table .q-title {
  min-width: 14rem;
  font-weight: 600;
}

.question-table .source-pill,
.question-table .tag-pill {
  display: inline-block;
  margin: 0 0.25rem 0.2rem 0;
}

.difficulty-dots {
  letter-spacing: 1px;
  color: var(--accent);
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

/* ---------------------------------------------------------------- teacher dashboard / session */

.link-code {
  font-size: 0.78rem;
  word-break: break-all;
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  background: #64748b;
  white-space: nowrap;
}

/* One distinct colour per quiz status. */
.status-badge.status-InProgress { background: #ea580c; } /* orange */
.status-badge.status-Due { background: #2563eb; }        /* blue */
.status-badge.status-Finished { background: #0f9f6e; }   /* green */
.status-badge.status-Scheduled { background: #7c3aed; }  /* purple */
.status-badge.status-Canceled { background: #dc2626; }   /* red */
.status-badge.status-Expired { background: #6b7280; }    /* grey */

.matrix-wrap {
  overflow-x: auto;
}

.matrix-table th,
.matrix-table td {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.sortable-th:hover { color: var(--accent); }

.results-filter { width: 20rem; max-width: 100%; }

.results-filter-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  margin: .2rem 0 0;
  padding: .25rem 0;
  list-style: none;
  max-height: 14rem;
  overflow-y: auto;
  background: #fff;
  color: var(--text, #1f2937);
  border: 1px solid #d1d5db;
  border-radius: .5rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .15);
}

.results-filter-list[hidden] { display: none; }

.results-filter-list li {
  padding: .35rem .75rem;
  font-size: .9rem;
  cursor: pointer;
}

.results-filter-list li[hidden] { display: none; }
.results-filter-list li:hover,
.results-filter-list li.is-active { background: #fdf2f8; color: var(--accent); }

.content-hash {
  font-size: .8rem;
  color: #475569;
  background: #f1f5f9;
  padding: .1rem .35rem;
  border-radius: .25rem;
  cursor: help;
}

.sortable-th .sort-ind {
  display: inline-block;
  min-width: 1em;
  margin-left: .25em;
  font-size: .75em;
  color: var(--accent);
}

.sortable-th[aria-sort="ascending"] .sort-ind::after { content: "\25B2"; }
.sortable-th[aria-sort="descending"] .sort-ind::after { content: "\25BC"; }

.matrix-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.matrix-table th.is-current,
.matrix-table td.is-current {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.matrix-table td.cell-correct {
  background: var(--good-bg);
  color: #0b7a55;
  font-weight: 700;
}

.matrix-table td.cell-wrong {
  background: var(--bad-bg);
  color: var(--bad);
  font-weight: 700;
}

.matrix-table td.cell-pending {
  background: #fff4d6;
  color: #92400e;
  font-weight: 700;
}

.matrix-table td.cell-none {
  color: #9aa5b8;
}

.matrix-table td.cell-missed {
  color: #c4cbd8;
}

/* A part of a matrix cell that has its own tooltip: dotted underline, highlighted on hover. */
.cell-tip {
  cursor: help;
  padding: 0 0.25rem;
  border-radius: 4px;
  text-decoration: underline dotted rgba(23, 35, 61, 0.45);
  text-underline-offset: 3px;
  transition: background 0.1s, box-shadow 0.1s;
}

.cell-tip:hover {
  background: rgba(255, 213, 79, 0.55);
  box-shadow: 0 0 0 2px rgba(255, 213, 79, 0.55);
  color: var(--text);
}

.presence-dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #cbd5e1;
  margin-right: 0.35rem;
}

.presence-dot.is-online {
  background: #22c55e;
}

.current-question-box {
  padding: 1rem 1.25rem;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.history-student {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 0.75rem;
}

.history-student > summary {
  cursor: pointer;
  padding: 0.7rem 1rem;
  font-weight: 600;
}

.history-student[open] > summary {
  border-bottom: 1px solid var(--line);
}

.history-student .history-body {
  padding: 1rem;
}
