:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #5f6874;
  --faint: #9299a3;
  --line: #dde2e8;
  --primary: #4b2e83;
  --primary-dark: #372163;
  --gold: #b38b2d;
  --clinical-blue: #256d85;
  --ok: #2f7a4d;
  --warn: #a46f18;
  --bad: #b23a3a;
  --shadow: 0 10px 28px rgba(28, 31, 36, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(75, 46, 131, 0.06), transparent 280px),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1,
h2,
p,
ol {
  margin: 0;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 18px;
  border: 1px solid var(--line);
  border-top: 5px solid var(--primary);
  border-radius: 8px;
  background: var(--panel);
  padding: 28px;
  box-shadow: var(--shadow);
}

.system-mark {
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 750;
}

.login-card h1,
.action-row h1,
.panel h1 {
  font-size: 20px;
  line-height: 1.25;
}

.login-card p,
.helper-text {
  color: var(--muted);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 0 rgba(28, 31, 36, 0.02);
}

.brand {
  font-weight: 750;
  letter-spacing: 0;
}

.subbrand {
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status,
.meta,
.sources,
.badge,
.review-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.status {
  color: var(--muted);
}

.workspace {
  width: min(1040px, calc(100vw - 32px));
  margin: 24px auto 48px;
}

.role-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-width: auto;
  min-height: 40px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--gold);
  color: var(--primary);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.action-row,
.control-row,
.answer-zone {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 14px;
}

.control-row {
  grid-template-columns: minmax(260px, 1fr) 150px 96px auto auto;
}

.answer-zone {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.count-field input {
  text-align: center;
}

input,
select,
button {
  border-radius: 6px;
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 11px;
}

textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(75, 46, 131, 0.55);
  outline: 3px solid rgba(75, 46, 131, 0.12);
}

button {
  min-height: 40px;
  min-width: 144px;
  border: 1px solid var(--primary);
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: white;
}

button.primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--primary);
}

button.compact {
  min-width: auto;
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

button:disabled {
  border-color: #c9ced3;
  background: #d9dde1;
  color: #6d747c;
  cursor: not-allowed;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.panel + .panel,
.view + .panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

h2 {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.question-text {
  min-height: 70px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.48;
}

.question-text.loading-message {
  display: flex;
  align-items: baseline;
  gap: 1px;
  color: var(--muted);
  font-weight: 650;
}

.loading-dots {
  display: inline-flex;
  min-width: 18px;
}

.loading-dots span {
  animation: loadingDot 1.1s infinite ease-in-out;
  opacity: 0.18;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes loadingDot {
  0%,
  70%,
  100% {
    opacity: 0.18;
  }
  35% {
    opacity: 1;
  }
}

.question-text:empty::before,
#gradeWhy:empty::before,
#gradeCorrection:empty::before {
  color: var(--faint);
  content: "Pending";
}

.expected,
.choices,
.sources {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.choices {
  display: grid;
  gap: 8px;
}

.choice {
  display: grid;
  grid-template-columns: 18px 34px 1fr;
  gap: 10px;
  align-items: start;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.choice:hover {
  border-color: rgba(75, 46, 131, 0.35);
}

.choice input {
  min-height: auto;
  margin: 4px 0 0;
  padding: 0;
}

.choice-id {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  background: #f0edf7;
  color: var(--primary);
  font-weight: 800;
}

.choice-text {
  overflow-wrap: anywhere;
}

.choice.selected {
  border-color: rgba(75, 46, 131, 0.55);
  background: #faf8ff;
}

.choice.correct {
  border-color: rgba(47, 122, 77, 0.48);
  background: #f5faf7;
}

.choice.incorrect {
  border-color: rgba(178, 58, 58, 0.42);
  background: #fff7f7;
}

.sources summary {
  color: var(--muted);
  cursor: pointer;
}

.source-item {
  display: grid;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.source-item:last-child {
  border-bottom: 0;
}

.source-title {
  color: var(--text);
}

.source-meta {
  color: var(--muted);
}

.grade-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  min-width: 92px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: #f7f8f9;
}

.badge.correct {
  border-color: rgba(47, 122, 77, 0.32);
  color: var(--ok);
}

.badge.partial {
  border-color: rgba(164, 111, 24, 0.36);
  color: var(--warn);
}

.badge.incorrect {
  border-color: rgba(178, 58, 58, 0.32);
  color: var(--bad);
}

.review-list,
.user-list {
  display: grid;
  gap: 10px;
}

.review-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.account-role-select {
  min-width: 140px;
}

.review-copy h2 {
  margin: 4px 0 8px;
  color: var(--text);
  font-size: 16px;
}

.review-copy ol {
  display: grid;
  gap: 4px;
  padding-left: 18px;
}

.review-copy li {
  padding-left: 4px;
}

.review-actions {
  display: grid;
  gap: 8px;
  min-width: 148px;
}

.review-action-select {
  min-width: 148px;
}

.revision-editor {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.revision-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.revision-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.review-meta,
.correct-line,
.reference-line,
.user-row span {
  color: var(--muted);
}

.reference-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
}

.account-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 150px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 8px;
}

.empty-state,
.form-error {
  color: var(--muted);
}

.form-error {
  min-height: 20px;
  color: var(--bad);
  font-size: 13px;
}

@media (max-width: 760px) {
  .topbar,
  .topbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    width: min(100vw - 24px, 1040px);
    margin-top: 18px;
  }

  .action-row,
  .control-row,
  .answer-zone,
  .grade-grid,
  .account-form,
  .review-item,
  .user-row {
    grid-template-columns: 1fr;
  }

  .role-tabs {
    overflow-x: auto;
  }

  .panel-actions,
  .revision-actions {
    flex-wrap: wrap;
  }

  .review-actions,
  .revision-choice-grid {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
