:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #192024;
  --muted: #627078;
  --line: #dbe1e4;
  --accent: #116a72;
  --accent-strong: #0b5157;
  --good: #167345;
  --bad: #b83232;
  --warn: #a36111;
  --blue: #245f9e;
  --shadow: 0 10px 24px rgba(25, 32, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 320px minmax(0, 1fr);
}

#app[hidden] {
  display: none;
}

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

.auth-shell[hidden] {
  display: none;
}

.auth-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-brand {
  margin-bottom: 20px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-switcher {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.form-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfc;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 22px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.filter-stack {
  display: grid;
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input[type="search"],
input[type="text"],
input[type="file"],
textarea,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row span {
  margin: 0;
  text-transform: none;
  font-size: 14px;
  font-weight: 600;
}

.side-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 248, 0.95);
  padding: 16px 24px;
  backdrop-filter: blur(8px);
}

.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 3px;
}

.tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 6px 14px;
  color: var(--muted);
  font-weight: 700;
}

.tab.active {
  background: var(--accent);
  color: white;
}

.queue-status {
  color: var(--muted);
  font-size: 14px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.collections-shell {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.collection-create-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.65fr);
  gap: 18px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.collection-create-panel h2 {
  margin: 0;
  font-size: 26px;
}

.create-collection-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.collection-list {
  display: grid;
  gap: 10px;
}

.collection-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.collection-row.active {
  border-color: rgba(17, 106, 114, 0.55);
  box-shadow: 0 0 0 3px rgba(17, 106, 114, 0.08);
}

.collection-row h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

.collection-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.review-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  padding: 24px;
}

.question-panel,
.context-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.question-panel {
  padding: 28px;
}

.context-panel {
  align-self: start;
  padding: 18px;
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.question-panel h2 {
  margin: 16px 0 20px;
  max-width: 980px;
  font-size: 28px;
  line-height: 1.25;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--warn);
  font-size: 20px;
}

.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.image-frame {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f3;
}

.image-frame img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
}

.image-frame figcaption {
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

.options {
  display: grid;
  gap: 12px;
}

.option-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 58px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  text-align: left;
}

.option-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.option-button:disabled {
  cursor: default;
}

.option-letter {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #eef2f3;
  color: var(--muted);
  font-weight: 800;
}

.option-button.correct {
  border-color: rgba(22, 115, 69, 0.45);
  background: #f0f8f4;
}

.option-button.correct .option-letter {
  background: var(--good);
  color: white;
}

.option-button.wrong {
  border-color: rgba(184, 50, 50, 0.45);
  background: #fff3f3;
}

.option-button.wrong .option-letter {
  background: var(--bad);
  color: white;
}

.feedback {
  min-height: 44px;
  margin-top: 16px;
  font-weight: 800;
}

.feedback.good {
  color: var(--good);
}

.feedback.bad {
  color: var(--bad);
}

.explanations {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.explanation {
  border-left: 4px solid var(--line);
  padding: 10px 14px;
  background: #fafbfb;
}

.explanation.correct {
  border-left-color: var(--good);
}

.explanation.selected-wrong {
  border-left-color: var(--bad);
}

.explanation h4 {
  margin: 0 0 6px;
  font-size: 14px;
}

.explanation p,
.explanation li {
  line-height: 1.5;
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: default;
  opacity: 0.62;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.compact-button {
  min-height: 34px;
  padding: 6px 10px;
}

.danger-button {
  border-color: rgba(184, 50, 50, 0.35);
  color: var(--bad);
}

.context-panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-list {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.mini-queue {
  display: grid;
  gap: 6px;
  max-height: 420px;
  overflow: auto;
}

.mini-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px;
  color: var(--muted);
  font-size: 13px;
}

.mini-item.active {
  border-color: var(--accent);
  color: var(--ink);
}

.browser-list {
  display: grid;
  gap: 10px;
  padding: 24px;
}

.admin-shell {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.admin-panel {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
}

.admin-panel h2 {
  margin: 0;
  font-size: 24px;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfb;
  padding: 12px;
}

.admin-row h3 {
  margin: 0 0 5px;
  font-size: 15px;
}

.admin-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.invite-result {
  overflow-wrap: anywhere;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.question-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  text-align: left;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.question-row:hover {
  border-color: rgba(17, 106, 114, 0.45);
  box-shadow: 0 6px 16px rgba(25, 32, 36, 0.06);
}

.question-row h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.question-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.row-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill.bad {
  border-color: rgba(184, 50, 50, 0.28);
  color: var(--bad);
}

.pill.due {
  border-color: rgba(17, 106, 114, 0.35);
  color: var(--accent);
}

.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(25, 32, 36, 0.42);
  padding: 24px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(980px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(25, 32, 36, 0.22);
  padding: 22px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.modal-header p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

.modal-options {
  display: grid;
  gap: 12px;
}

.modal-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfb;
  padding: 14px;
}

.modal-option.correct {
  border-color: rgba(22, 115, 69, 0.45);
  background: #f0f8f4;
}

.modal-option h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.modal-option p {
  margin: 0 0 8px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 14px;
}

.question-form {
  display: grid;
  gap: 14px;
}

.image-upload-field {
  display: grid;
  gap: 10px;
}

.image-upload-actions {
  display: flex;
  justify-content: flex-start;
}

.form-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.form-section-header span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.upload-preview-item {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfb;
  padding: 10px;
}

.upload-preview-item img {
  width: 96px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef2f3;
  object-fit: contain;
}

.upload-preview-meta {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.upload-preview-meta strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.upload-preview-meta span {
  color: var(--muted);
  font-size: 12px;
}

.option-editor-list {
  display: grid;
  gap: 12px;
}

.option-editor-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfb;
  padding: 12px;
}

.correct-choice {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.correct-choice span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #eef2f3;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.correct-choice input:checked + span {
  background: var(--accent);
  color: white;
}

.option-editor-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 12px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  max-width: min(340px, calc(100vw - 44px));
  border: 1px solid rgba(17, 106, 114, 0.32);
  border-radius: 8px;
  background: var(--accent);
  box-shadow: var(--shadow);
  color: white;
  padding: 12px 14px;
  font-weight: 800;
}

.toast[hidden] {
  display: none;
}

@media (max-width: 1020px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .review-shell {
    grid-template-columns: 1fr;
  }

  .collection-create-panel {
    grid-template-columns: 1fr;
  }

  .context-panel {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-right,
  .user-menu {
    align-items: flex-start;
    flex-direction: column;
  }

  .review-shell,
  .browser-list,
  .collections-shell,
  .admin-shell {
    padding: 14px;
  }

  .collection-create-panel,
  .admin-row,
  .collection-row,
  .create-collection-form {
    grid-template-columns: 1fr;
  }

  .question-panel {
    padding: 18px;
  }

  .question-panel h2 {
    font-size: 22px;
  }

  .question-row {
    grid-template-columns: 1fr;
  }

  .row-stats {
    justify-content: flex-start;
  }

  .modal {
    max-height: 92vh;
    padding: 16px;
  }

  .modal-header,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .option-editor-row,
  .option-editor-fields {
    grid-template-columns: 1fr;
  }

  .correct-choice {
    justify-items: start;
  }

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

  .upload-preview-item img {
    width: 100%;
  }
}
