:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --ink: #182230;
  --muted: #667488;
  --border: #dbe3ee;
  --primary: #1f5bd5;
  --primary-soft: #e9f0ff;
  --success: #0b9a6e;
  --success-soft: #ebfbf5;
  --danger: #d03244;
  --danger-soft: #fff1f3;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Manrope", system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.page-shell {
  margin: 0 auto;
  max-width: 1280px;
  padding: 32px 20px 72px;
}

.page-shell-form {
  max-width: 920px;
}

.page-header {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-header-copy {
  max-width: 720px;
}

.page-kicker {
  color: var(--primary);
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.page-title {
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.85rem, 3vw, 2.6rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.page-subtitle {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
  margin-top: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.section-head,
.modal-header {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}

.section-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

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

.question-form-modal {
  max-height: min(78vh, 860px);
  overflow: auto;
  padding-right: 4px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

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

.field-grid-details {
  grid-template-columns: 1.3fr 0.9fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.field label .hint {
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
}

.required {
  color: var(--danger);
}

input,
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  min-height: 46px;
  padding: 12px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: #98a5b8;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(31, 91, 213, 0.45);
  box-shadow: 0 0 0 3px rgba(31, 91, 213, 0.1);
  outline: none;
}

textarea {
  min-height: 124px;
  resize: vertical;
}

.textarea-compact {
  min-height: 110px;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23667488'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-repeat: no-repeat;
  padding-right: 36px;
}

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

.option-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 36px minmax(0, 1fr) auto auto;
}

.option-letter {
  align-items: center;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary);
  display: flex;
  font-size: 13px;
  font-weight: 800;
  height: 36px;
  justify-content: center;
  width: 36px;
}

.option-letter.correct {
  background: var(--success-soft);
  color: var(--success);
}

.option-fixed {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 46px;
  padding: 12px 14px;
}

.option-toggle,
.option-remove,
.text-action,
.icon-button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  min-height: 44px;
  padding: 10px 12px;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.option-toggle {
  font-size: 12px;
  font-weight: 700;
}

.option-toggle:hover {
  border-color: var(--success);
  color: var(--success);
}

.option-toggle.active {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.option-remove {
  font-size: 16px;
  min-width: 44px;
  padding: 0;
}

.option-remove:hover {
  background: var(--danger-soft);
  border-color: #f3c6d0;
  color: var(--danger);
}

.text-action {
  align-self: flex-start;
  background: transparent;
  border-style: dashed;
  border-radius: 999px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  min-height: auto;
}

.text-action:hover {
  background: var(--primary-soft);
  border-color: rgba(31, 91, 213, 0.35);
}

.tag-editor {
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: text;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 110px;
  padding: 10px;
}

.tag-editor:focus-within {
  border-color: rgba(31, 91, 213, 0.45);
  box-shadow: 0 0 0 3px rgba(31, 91, 213, 0.1);
}

.tag-editor input {
  border: 0;
  box-shadow: none;
  min-height: 30px;
  min-width: 120px;
  padding: 6px 4px;
}

.tag-editor input:focus {
  box-shadow: none;
}

.tag-chip {
  align-items: center;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
  padding: 6px 10px;
}

.tag-chip button {
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.tag-chip button:hover {
  color: var(--danger);
}

.form-footer {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

.form-actions,
.toolbar-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  max-width: 360px;
}

.btn {
  align-items: center;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 800;
  gap: 8px;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #194ebe;
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.btn-outline:hover:not(:disabled) {
  border-color: rgba(31, 91, 213, 0.38);
  color: var(--primary);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #0a8b64;
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #f3c6d0;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #ffe7ec;
}

.manage-toolbar {
  display: grid;
  gap: 16px;
}

.toolbar-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 2fr) repeat(4, minmax(160px, 1fr));
}

.toolbar-field {
  display: grid;
  gap: 8px;
}

.toolbar-field label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.toolbar-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

.results-summary {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.table-frame {
  margin-top: 18px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

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

.questions-table thead th {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 12px 14px;
  text-align: left;
  text-transform: uppercase;
}

.questions-table tbody td {
  border-bottom: 1px solid var(--border);
  padding: 13px 14px;
  vertical-align: top;
}

.questions-table tbody tr:last-child td {
  border-bottom: 0;
}

.question-title {
  font-weight: 700;
  line-height: 1.45;
}

.question-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.difficulty-pill {
  align-items: center;
  background: var(--surface-muted);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  margin-right: 8px;
  padding: 4px 8px;
  text-transform: uppercase;
}

.row-action {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
}

.row-action:hover {
  border-color: rgba(31, 91, 213, 0.38);
  color: var(--primary);
}

.row-action-danger:hover {
  border-color: #f3c6d0;
  color: var(--danger);
}

.preview-row td {
  background: var(--surface-muted);
  padding: 0;
}

.preview-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.preview-block {
  display: grid;
  gap: 10px;
}

.preview-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.preview-question {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.6;
}

.preview-options {
  display: grid;
  gap: 8px;
}

.preview-option {
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: 30px minmax(0, 1fr);
  padding: 10px 12px;
}

.preview-option.correct {
  background: var(--success-soft);
  border-color: rgba(11, 154, 110, 0.28);
}

.preview-option-letter {
  align-items: center;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.preview-option.correct .preview-option-letter {
  background: #d3f7ea;
  color: var(--success);
}

.preview-stack {
  display: grid;
  gap: 8px;
}

.preview-answer {
  font-weight: 700;
  line-height: 1.6;
}

.preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty-state {
  align-items: center;
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 56px 20px;
  text-align: center;
}

.empty-state-icon {
  font-size: 40px;
}

.empty-state-title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.1rem;
}

.empty-state-copy {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  max-width: 360px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 30;
}

.modal-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.26);
  max-width: 980px;
  padding: 24px;
  width: min(980px, 100%);
}

.icon-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 14px;
  font-weight: 700;
  height: 40px;
  justify-content: center;
  width: 40px;
}

.icon-button:hover {
  border-color: rgba(31, 91, 213, 0.38);
  color: var(--primary);
}

.toast {
  border-radius: 14px;
  bottom: 24px;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.18);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  padding: 14px 18px;
  pointer-events: none;
  position: fixed;
  right: 24px;
  transform: translateY(80px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: var(--primary);
}

[hidden] {
  display: none !important;
}

@media (max-width: 1120px) {
  .toolbar-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .field-grid-meta,
  .field-grid-details,
  .toolbar-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .page-shell {
    padding: 22px 12px 56px;
  }

  .card,
  .modal-card {
    padding: 18px;
  }

  .field-grid-meta,
  .field-grid-details,
  .toolbar-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-meta,
  .form-footer,
  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .questions-table,
  .questions-table thead,
  .questions-table tbody,
  .questions-table tr,
  .questions-table th,
  .questions-table td {
    display: block;
    width: 100%;
  }

  .questions-table thead {
    display: none;
  }

  .questions-table tbody td {
    border-bottom: 0;
    padding: 10px 14px;
  }

  .questions-table tbody tr {
    border-bottom: 1px solid var(--border);
  }

  .preview-row td {
    padding-top: 0;
  }

  .option-row {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .option-toggle,
  .option-remove {
    grid-column: 2;
    justify-self: start;
  }
}
