:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #142029;
  --muted: #5f6f7a;
  --brand: #035a67;
  --brand-2: #0d8f95;
  --good: #237a3e;
  --bad: #a43a25;
}

/* --- Indexing banner --- */
.index-banner {
  background: linear-gradient(90deg, #023e4a, var(--brand-2));
  color: #fff;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.index-banner-error {
  background: var(--bad);
}

.index-banner-inner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  max-width: 1440px;
  margin: 0 auto;
}

.index-paper-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  opacity: 0.85;
}

.index-paper-list li::before { content: "• "; }

@keyframes spin { to { transform: rotate(360deg); } }
.index-spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #d8ecef, transparent 40%), var(--bg);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: linear-gradient(90deg, var(--brand), #023e4a);
  position: relative;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-right: 1rem;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
}

.back-btn:active {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0.98);
}

.back-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.site-header a {
  color: #fff;
  text-decoration: none;
  margin-left: 1rem;
}

.logo {
  font-weight: 800;
}

.container {
  max-width: 90vw;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
}

.hero {
  background: var(--panel);
  padding: 2rem;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(20, 32, 41, 0.08);
}

.badge {
  display: inline-block;
  background: #d8f2f1;
  color: #0b5f65;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.card {
  background: var(--panel);
  padding: 1.3rem;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(20, 32, 41, 0.07);
  margin-bottom: 1rem;
}

.narrow {
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

.btn {
  display: inline-block;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  color: white;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn.ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
}

.btn-microsoft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid #cfcfcf;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 700;
  padding: 0.65rem 1rem;
  font-size: inherit;
  line-height: 1;
}
.btn-microsoft::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 21 21'%3E%3Crect x='1' y='1' width='9' height='9' fill='%23f25022'/%3E%3Crect x='11' y='1' width='9' height='9' fill='%237fba00'/%3E%3Crect x='1' y='11' width='9' height='9' fill='%2300a4ef'/%3E%3Crect x='11' y='11' width='9' height='9' fill='%23ffb900'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.actions {
  display: flex;
  gap: 0.7rem;
}

textarea,
input,
select {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid #b7c3c9;
  border-radius: 8px;
}

.grid-form p {
  margin-bottom: 0.8rem;
}

.flash {
  background: #d8f2f1;
  border-left: 4px solid var(--brand);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.feedback-list {
  list-style: none;
  padding: 0;
}

.feedback-list li {
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.4rem;
  border-radius: 8px;
}

.feedback-list li.ok {
  background: #ddf4e3;
  color: var(--good);
}

.feedback-list li.missed {
  background: #f8e0dc;
  color: var(--bad);
}

.feedback-list li.not-attempted {
  background: #f1f3f5;
  color: #6b7280;
}

.feedback-list li.ai-feedback {
  background: #edf3fb;
  color: #1a4a7a;
  font-style: italic;
  border-left: 3px solid #4a90d9;
}

.whole-question {
  background: #f7fbfc;
  border: 1px solid #d2e5ea;
  padding: 0.8rem;
  border-radius: 10px;
  max-height: 340px;
  overflow: auto;
  margin-bottom: 1rem;
}

.paper-frame-wrap {
  margin: 0.8rem 0 1rem;
  border: 1px solid #c8d6dc;
  border-radius: 10px;
  overflow: hidden;
  background: #f1f4f7;
}

.paper-frame {
  width: 100%;
  height: 550px;
  border: 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(7, 25, 31, 0.62);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 40;
}

.modal.open {
  display: flex;
}

.modal-panel {
  width: min(1440px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 22px 48px rgba(10, 19, 24, 0.28);
}

/* Ensure modal action buttons are consistent in size, font and alignment */
.modal-panel .actions {
  flex-wrap: wrap;
  gap: 0.8rem;
}

.modal-panel .actions .btn,
.modal-panel .actions .btn.ghost,
.modal-panel .actions a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.68rem 1.15rem;
  font-size: 0.96rem;
  font-weight: 700;
  border-radius: 10px;
  height: 44px;
  line-height: 1;
  box-sizing: border-box;
  text-decoration: none;
  cursor: pointer;
  flex: 0 1 auto;
  min-width: 130px;
}


.part-answer-box {
  border: 1px solid #d6e3e8;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.85rem;
  background: #fbfdfe;
}

/* Row containing the submit button */
.form-actions-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}

/* Banner shown after the form when a previous attempt exists */
.feedback-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  padding: 0.75rem 1.1rem;
  margin-top: 1rem;
}

.feedback-banner-score {
  font-size: 0.9rem;
  color: #0369a1;
}

.part-prompt {
  margin: 0.35rem 0 0.5rem;
  color: var(--ink);
}

.mcq {
  display: grid;
  gap: 0.75rem;
}

.mcq-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid #d6e3e8;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  background: #ffffff;
}

.mcq-choice input[type="radio"],
.mcq-choice input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex: 0 0 auto;
}

.mcq-content {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.mcq-text {
  color: var(--ink);
  line-height: 1.25;
  font-size: 1.02rem;
  font-weight: 600;
}

.mcq-snippet {
  display: block;
  max-height: 160px;
  max-width: 420px;
  width: auto;
  border: 1px solid #d6e3e8;
  border-radius: 6px;
  background: #fff;
  padding: 6px;
}

/* ── Processing overlay ── */
.processing-panel {
  text-align: center;
  padding: 2.5rem 2rem;
  max-width: 420px;
  margin: 0 auto;
}

.proc-spinner {
  width: 52px;
  height: 52px;
  border: 5px solid #d2eae9;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  margin: 0 auto 1.2rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.proc-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--ink);
}

.proc-sub {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}

/* ── Grouped result parts ── */
.result-part {
  border: 1px solid #d8e6eb;
  border-radius: 10px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.result-part-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  gap: 0.6rem;
  font-weight: 700;
}

.result-part-id { font-size: 0.84rem; color: #274350; font-weight: 600; }

/* pill-style score badge */
.result-part-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  font-weight: 800;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  background: #e2eff2;
  color: #063a4c;
  border: 2px solid transparent;
  min-width: 58px;
  height: 26px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.result-part-score--skipped {
  background: #f1f3f5;
  color: #6b7280;
}

/* header band colours per state */
.result-part--full    .result-part-header { background: #dcfce7; }
.result-part--zero    .result-part-header { background: #fee2e2; }
.result-part--partial .result-part-header { background: #fef9c3; }
.result-part--skipped .result-part-header { background: #f1f5f9; }

/* coloured pills per state – high-specificity to win inside modal */
.result-part.result-part--full    .result-part-score { background: #16a34a; color: #fff; border-color: #15803d; }
.result-part.result-part--zero    .result-part-score { background: #ef4444; color: #fff; border-color: #dc2626; }
.result-part.result-part--partial .result-part-score { background: #f59e0b; color: #fff; border-color: #d97706; }
.result-part.result-part--skipped .result-part-score { background: #e2e8f0; color: #64748b; border-color: #cbd5e1; }

.result-part-feedback {
  border-top: 1px solid #e4ecef;
  margin: 0;
  padding: 0.4rem 0;
}

.result-part-feedback li {
  padding: 0.4rem 0.9rem;
  margin: 0;
  border-radius: 0;
}

/* ── Total row ── */
.result-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.9rem;
  font-size: 1.05rem;
  font-weight: 800;
  border-top: 2px solid #c8d8de;
  margin-top: 0.25rem;
  margin-bottom: 1rem;
  background: #f4f8fa;
  border-radius: 0 0 10px 10px;
}

.score {
  font-size: 1.1rem;
  font-weight: 700;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #e2e8ea;
  text-align: left;
  padding: 0.55rem;
}

@media (max-width: 760px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

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

  .paper-frame {
    height: 400px;
  }
}

/* --- Dashboard --- */
.dash-overview h2 {
  margin: 0 0 1rem;
}

.dash-summary {
  display: flex;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.dash-stat {
  display: flex;
  flex-direction: column;
}

.dash-stat-val {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.dash-denom {
  font-size: 1.1rem;
  color: var(--muted);
}

.dash-stat-lbl {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.3rem;
}

/* Score colour helpers */
.score-good { color: var(--good); }
.score-ok   { color: #a06800; }
.score-bad  { color: var(--bad); }

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #e2e8ea;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 0.5rem 1.1rem;
  border: 0;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.88rem;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover,
.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Progress table */
.prog-table {
  width: 100%;
  border-collapse: collapse;
}

.prog-table th,
.prog-table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid #e2e8ea;
}

.prog-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

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

.prog-table th.sortable:hover {
  color: var(--brand);
}

.prog-table th.th-asc::after  { content: " ↑"; color: var(--brand); }
.prog-table th.th-desc::after { content: " ↓"; color: var(--brand); }

.of-total {
  color: var(--muted);
  font-size: 0.88em;
}

/* Score bar */
.score-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.score-bar {
  flex: 1;
  max-width: 140px;
  height: 7px;
  border-radius: 999px;
  background: #e4ecef;
  position: relative;
  overflow: hidden;
}

.score-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: var(--val, 0%);
  background: currentColor;
  border-radius: 999px;
}

.score-pct {
  font-weight: 700;
  font-size: 0.88rem;
  min-width: 3.2rem;
  text-align: right;
}

.empty-hint {
  color: var(--muted);
  font-style: italic;
  padding: 1rem 0;
}

@media (max-width: 600px) {
  .dash-summary {
    gap: 1.5rem;
  }

  .tab-btn {
    padding: 0.45rem 0.7rem;
    font-size: 0.82rem;
  }

  .score-bar {
    display: none;
  }
}

/* Two-column layout for question detail: viewer on the left, inputs on the right */
.question-detail-layout {
  display: grid;
  grid-template-columns: 52% 48%;
  gap: 1.25rem;
  align-items: start;
  min-height: calc(100vh - 140px);
}
.viewer-column {
  position: sticky;
  top: 0;
  height: calc(100vh - 140px);
  overflow: hidden;
}
.viewer-column .paper-frame-wrap {
  /* keep viewer tall enough for reading the PDF */
  height: 100%;
  min-height: 420px;
  overflow: hidden;
}
.viewer-column .paper-frame {
  width: 100%;
  height: 100%;
}
.content-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.5rem;
}
.content-column > * {
  flex-shrink: 0;
}

@media (max-width: 920px) {
  .question-detail-layout {
    grid-template-columns: 1fr;
  }
  .viewer-column .paper-frame-wrap {
    height: 420px;
  }
  .whole-question {
    max-height: 260px;
  }
}

/* --- Draw canvas for drawing questions --- */
.draw-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.draw-canvas-wrapper {
  border: 2px solid var(--brand-2);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.draw-canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
  width: 100%;
  height: auto;
  background: #ffffff;
}

.draw-canvas:hover {
  background: #fafbfc;
}

.draw-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.draw-info {
  color: var(--muted);
  font-size: 0.9rem;
}
