:root {
  --tulasi: #1d3a2f;
  --tulasi-deep: #14291f;
  --saffron: #dd8500;
  --saffron-soft: #fdf3e0;
  --maroon: #7a2230;
  --ink: #23281f;
  --muted: #5f6a5c;
  --rule: #b9c4b0;
  --rule-strong: #43604f;
  --band: #edf1e4;
  --paper: #fffdf7;
  --wash: #e7ebdd;
  --focus: #1e6f8f;
  --ok: #1e6f45;
  --warn: #9a5800;
  --bad: #a32e2e;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: "Avenir Next", Avenir, Seravek, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--wash);
  color: var(--ink);
  font-family: var(--font-sans);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--wash);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--maroon);
  text-underline-offset: 3px;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-family: var(--font-serif);
  font-weight: 700;
}

h1 {
  font-size: clamp(1.3rem, 4vw, 1.85rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
}

h2 {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  line-height: 1.18;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 0;
  transform: translateY(-120%);
  z-index: 10;
  background: var(--tulasi);
  color: #fff;
  padding: 0.65rem 0.9rem;
}

.skip-link:focus {
  transform: translateY(0);
}

/* Letterhead: paper header under a saffron cloth band */
.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.85rem, env(safe-area-inset-top)) 1rem 0.8rem;
  background: var(--paper);
  color: var(--ink);
  border-top: 6px solid var(--saffron);
  border-bottom: 2px solid var(--rule-strong);
}

.brand-row,
.header-actions,
.panel-head,
.check-row {
  display: flex;
  align-items: center;
}

.brand-row {
  min-width: 0;
  gap: 0.75rem;
}

.brand-logo {
  width: 3rem;
  height: 3rem;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 0.25rem;
}

.brand-row h1 {
  color: var(--tulasi);
}

.header-actions {
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-view[hidden],
[hidden] {
  display: none !important;
}

.eyebrow {
  margin-bottom: 0.25rem;
  color: var(--maroon);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 2.2rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--rule);
  background: var(--band);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-pill.online {
  border-color: var(--ok);
  color: var(--ok);
  background: #eaf3ec;
}

.status-pill.offline {
  border-color: var(--saffron);
  color: var(--warn);
  background: var(--saffron-soft);
}

main,
.app-footer {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
}

/* Course banner: the one dark sheet on the page */
.course-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  align-items: stretch;
  margin: 1.2rem 0;
  border: 1px solid var(--tulasi-deep);
}

.course-copy {
  display: grid;
  align-content: center;
  min-height: 10rem;
  padding: 1.4rem 1.25rem;
  background: var(--tulasi);
  color: #fff;
}

.course-copy .eyebrow {
  color: var(--saffron);
}

.course-copy h2 {
  color: #fff;
}

.course-copy p:last-child {
  margin-top: 0.5rem;
  color: rgba(255, 255, 255, 0.78);
}

.course-image {
  width: 100%;
  height: 13rem;
  object-fit: cover;
  display: block;
  border-top: 1px solid var(--tulasi-deep);
}

.workbench,
.records-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.2rem;
  padding-bottom: 1.2rem;
  min-width: 0;
}

/* Sheets of paper, squared like the printed workbook */
.panel {
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  box-shadow: 2px 2px 0 rgba(29, 58, 47, 0.14);
}

.panel-head {
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.panel-note {
  margin: 0;
  padding: 0.75rem 1rem 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

form {
  display: grid;
  gap: 0.95rem;
  padding: 1rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--ink);
  font-weight: 600;
}

label span {
  font-size: 0.88rem;
}

label em {
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.7rem 0.8rem;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(30, 111, 143, 0.32);
  outline-offset: 2px;
  border-color: var(--focus);
}

textarea {
  min-height: 7rem;
  resize: vertical;
  line-height: 1.5;
}

.field-grid,
.admin-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.95rem;
}

.check-row {
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  font-weight: 500;
}

.check-row input {
  width: 1.25rem;
  min-height: 1.25rem;
  margin: 0;
  accent-color: var(--tulasi);
}

.bot-field {
  position: absolute;
  left: -9999px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 2.85rem;
  border-radius: 0;
  border: 1px solid transparent;
  padding: 0.7rem 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.primary-button {
  background: var(--tulasi);
  color: #fff;
  border-color: var(--tulasi-deep);
  box-shadow: 2px 2px 0 var(--saffron);
}

.primary-button:hover {
  background: var(--tulasi-deep);
}

.primary-button:disabled {
  opacity: 0.6;
  box-shadow: none;
  cursor: default;
}

.secondary-button {
  background: var(--saffron);
  color: #241503;
  border-color: #b06a00;
}

.secondary-button:hover {
  background: #c67700;
}

.ghost-button {
  background: transparent;
  color: var(--tulasi);
  border-color: var(--rule-strong);
}

.ghost-button:hover {
  background: var(--band);
}

.ghost-button.is-busy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  cursor: wait;
  background: var(--band);
}

.ghost-button.is-busy::before {
  content: "";
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.compact {
  min-height: 2.35rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.86rem;
}

.form-message {
  min-height: 1.3rem;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.45;
}

.form-message.ok {
  color: var(--ok);
}

.form-message.warn {
  color: var(--warn);
}

.form-message.bad {
  color: var(--bad);
}

.muted {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.session-list,
.record-list,
.summary-grid {
  display: grid;
  gap: 0.65rem;
  padding: 1rem;
}

.session-item,
.record-item,
.summary-item {
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem;
  border: 1px solid var(--rule);
  background: #fff;
}

.session-item.active {
  border-color: var(--saffron);
  border-left: 4px solid var(--saffron);
  background: var(--saffron-soft);
}

.session-item strong,
.record-item strong {
  font-size: 0.98rem;
}

.session-item span,
.record-item span,
.summary-item span {
  color: var(--muted);
  font-size: 0.88rem;
}

.sync-tag {
  display: inline-flex;
  width: fit-content;
  padding: 0.18rem 0.55rem;
  border: 1px solid var(--ok);
  color: var(--ok);
  background: #eaf3ec;
  font-size: 0.78rem;
  font-weight: 700;
}

.sync-tag.pending {
  border-color: var(--saffron);
  background: var(--saffron-soft);
  color: var(--warn);
}

/* ------------------------------------------------------------------ */
/* Assessment: styled after the printed IDC workbook the class knows  */
/* ------------------------------------------------------------------ */

.exam-questions {
  display: grid;
  gap: 1.1rem;
  counter-reset: none;
}

.exam-question {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0 0 0.85rem;
  border: 1px solid var(--rule-strong);
  border-left: 4px solid var(--saffron);
  background: #fff;
}

/* Shaded question header, like the grey bars on the paper */
.exam-question legend,
.exam-question > span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  width: 100%;
  margin: 0;
  padding: 0.6rem 0.85rem;
  background: var(--band);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--tulasi);
}

.q-marks {
  flex-shrink: 0;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--maroon);
  white-space: nowrap;
}

fieldset.exam-question {
  padding-top: 0;
  min-inline-size: 0;
}

fieldset.exam-question legend {
  float: left;
}

fieldset.exam-question legend + p {
  clear: both;
}

.exam-question p,
.exam-question em {
  margin: 0;
  padding: 0 0.85rem;
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
  font-size: 0.92rem;
}

.exam-question .question-help {
  display: block;
  margin: -0.1rem 0 0.25rem;
  padding: 0 0.85rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.exam-question textarea {
  width: calc(100% - 1.7rem);
  margin: 0 0.85rem;
}

/* True/False rows: ruled rows with tappable chips */
.exam-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0.85rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--rule);
}

.exam-item:first-of-type {
  border-top: 0;
}

.exam-item > span {
  line-height: 1.45;
}

.choice-inline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule);
  background: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

.choice-inline:has(input:checked) {
  background: var(--tulasi);
  border-color: var(--tulasi-deep);
  color: #fff;
}

.choice-inline:focus-within {
  outline: 3px solid rgba(30, 111, 143, 0.32);
  outline-offset: 1px;
}

.choice-inline input {
  width: 1.05rem;
  min-height: 1.05rem;
  margin: 0;
  accent-color: var(--saffron);
}

/* Checkbox option rows */
.choice-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0 0.85rem;
  padding: 0.6rem 0.65rem;
  border: 1px solid var(--rule);
  background: #fff;
  font-weight: 500;
  line-height: 1.45;
  cursor: pointer;
}

.choice-row + .choice-row {
  margin-top: 0.4rem;
}

.choice-row:has(input:checked) {
  background: var(--band);
  border-color: var(--rule-strong);
  border-left: 4px solid var(--tulasi);
  padding-left: calc(0.65rem - 3px);
}

.choice-row:focus-within {
  outline: 3px solid rgba(30, 111, 143, 0.32);
  outline-offset: 1px;
}

.choice-row input {
  width: 1.2rem;
  min-height: 1.2rem;
  margin-top: 0.12rem;
  flex-shrink: 0;
  accent-color: var(--tulasi);
}

.exam-result {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 2px solid var(--rule-strong);
}

.exam-progress {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.progress-track {
  display: block;
  height: 0.55rem;
  background: var(--band);
  border: 1px solid var(--rule);
}

.progress-fill {
  display: block;
  height: 100%;
  background: var(--tulasi);
}

/* ------------------------------------------------------------------ */
/* Admin ledger                                                        */
/* ------------------------------------------------------------------ */

.admin-controls {
  padding: 1rem;
  border-bottom: 1px solid var(--rule);
}

form.admin-controls {
  border-bottom: 0;
}

.summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-item {
  border-left: 4px solid var(--saffron);
}

.summary-item strong {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--tulasi);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--band);
  color: var(--tulasi);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-top: 2px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
}

.answer-row td {
  background: var(--band);
}

.answer-review {
  display: grid;
  gap: 0.65rem;
  max-height: 34rem;
  overflow: auto;
}

.answer-review-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--rule);
  background: var(--paper);
}

.answer-review-tools .muted {
  font-size: 0.86rem;
}

.answer-item {
  display: grid;
  gap: 0.45rem;
  padding: 0.75rem;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--saffron);
  background: #fff;
}

.answer-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.answer-item-head strong {
  font-family: var(--font-serif);
  color: var(--tulasi);
}

.answer-item-head span {
  color: var(--maroon);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.answer-item p {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
  font-size: 0.92rem;
}

.admin-review-message {
  padding: 0.6rem 1rem 0;
}

.admin-progress {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.65rem 1rem 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--saffron);
  background: var(--saffron-soft);
  color: var(--warn);
  font-weight: 700;
  line-height: 1.4;
}

.admin-progress::before {
  content: "";
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.admin-note {
  margin-top: 0;
  border-top: 1px solid var(--rule);
}

.answer-note {
  color: var(--muted) !important;
  font-size: 0.86rem !important;
}

.question-prompt {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.correct-answer {
  display: grid;
  gap: 0.35rem;
  padding: 0.65rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
}

.correct-answer strong {
  color: var(--tulasi);
}

.correct-answer ul {
  margin: 0;
  padding-left: 1.1rem;
}

.exam-reference-panel {
  grid-column: 1 / -1;
}

.exam-reference-list {
  display: grid;
  gap: 0.75rem;
  padding: 0 1rem 1rem;
}

.reference-item {
  display: grid;
  gap: 0.5rem;
  padding: 0.8rem;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--tulasi);
  background: #fff;
}

.method-tag {
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border: 1px solid var(--rule-strong);
  background: var(--band);
  color: var(--tulasi);
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
}

.adjust-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--rule);
}

.adjust-row .muted {
  margin-right: auto;
  font-size: 0.84rem;
}

.adjust-score {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.adjust-score input {
  width: 5.5rem;
  min-height: 2.35rem;
  padding: 0.3rem 0.5rem;
}

.adjusted-tag {
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border: 1px solid var(--saffron);
  background: var(--saffron-soft);
  color: var(--warn);
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
}

.app-footer {
  display: grid;
  gap: 0.35rem;
  padding: 0.9rem 0 max(1.25rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.88rem;
}

@media (min-width: 740px) {
  .app-header {
    padding-left: 1.4rem;
    padding-right: 1.4rem;
  }

  .course-strip {
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 0.7fr);
  }

  .course-copy {
    padding: 1.7rem 1.6rem;
  }

  .course-image {
    height: 100%;
    min-height: 12rem;
    border-top: 0;
    border-left: 1px solid var(--tulasi-deep);
  }

  .workbench {
    grid-template-columns: minmax(0, 1.15fr) minmax(19rem, 0.85fr);
  }

  .records-grid {
    grid-template-columns: minmax(18rem, 0.75fr) minmax(0, 1.25fr);
  }

  .field-grid,
  .admin-controls {
    grid-template-columns: 1fr 1fr;
  }

  .admin-controls {
    align-items: end;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .status-pill {
    white-space: normal;
  }

  main,
  .app-footer {
    width: min(100% - 1rem, 1180px);
  }

  .exam-item {
    grid-template-columns: 1fr 1fr;
  }

  .exam-item > span {
    grid-column: 1 / -1;
  }

  .exam-item .choice-inline {
    justify-content: center;
  }

  .answer-review-tools {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .primary-button,
  .secondary-button,
  .ghost-button,
  .choice-inline,
  .choice-row {
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ghost-button.is-busy::before,
  .admin-progress::before {
    animation: none;
  }
}

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