:root {
  color-scheme: light;
  --bg: #f5f8ff;
  --ink: #111827;
  --muted: #607086;
  --line: #d5e0ef;
  --panel: #ffffff;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eff6ff;
  --good: #16794f;
  --bad: #b23b3b;
  --warn: #936d18;
  --shadow: 0 18px 50px rgba(30, 64, 175, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(14, 165, 233, 0.12), transparent 28%),
    var(--bg);
}

.page-watermark {
  position: fixed;
  right: 18px;
  bottom: 14px;
  z-index: 20;
  color: rgba(37, 99, 235, 0.18);
  font-size: 28px;
  font-weight: 800;
  pointer-events: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: 0.18s ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 5vw, 56px);
  line-height: 1;
}

.manual-button,
.login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 128px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.24);
}

.manual-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent-dark);
}

.workspace {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(213, 224, 239, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.import-panel {
  padding: 16px;
}

.drop-zone {
  position: relative;
  min-height: 198px;
  border: 1px dashed #9fb4d2;
  border-radius: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
  background: #fbfdff;
  cursor: pointer;
  transition: 0.18s ease;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone:hover {
  border-color: var(--accent);
  background: #f4f8ff;
}

.drop-zone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-mark {
  width: 72px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: linear-gradient(160deg, #2563eb 0%, #0284c7 100%);
  color: #fff;
  font-weight: 800;
  line-height: 1.25;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.24);
}

.drop-zone strong {
  color: var(--ink);
  max-width: 260px;
  overflow-wrap: anywhere;
}

.drop-zone span {
  max-width: 260px;
  font-size: 13px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.status-grid div {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  align-content: center;
  justify-items: center;
  background: #fff;
}

.status-grid span {
  color: var(--muted);
  font-size: 13px;
}

.status-grid strong {
  margin-top: 4px;
  font-size: 28px;
}

.actions,
.api-actions,
.migration-actions,
.mode-actions,
.quiz-actions {
  display: flex;
  gap: 10px;
}

.actions button,
.api-actions button,
.migration-actions button,
.migration-actions label,
.mode-actions button,
.quiz-actions button {
  flex: 1;
}

.api-actions {
  margin-top: 10px;
}

.migration-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.import-progress-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.migration-actions button,
.migration-actions .import-progress-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  box-shadow: none;
}

.migration-actions button:hover,
.migration-actions .import-progress-button:hover {
  border-color: var(--accent);
  background: #f4f8ff;
}

.import-progress-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.api-actions button.is-enabled {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.api-actions button.is-synced {
  border-color: var(--accent);
  background: #eaf2ff;
  color: var(--accent-dark);
  font-weight: 800;
}

.mode-actions {
  margin-top: 10px;
}

.mode-actions button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.type-filter {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.type-filter label {
  color: var(--muted);
  font-weight: 700;
}

.type-filter select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
}

.library-section {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

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

.library-head h2 {
  font-size: 16px;
}

.library-head span {
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.library-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.library-empty {
  min-height: 62px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.library-item {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 42px 12px 10px;
  text-align: left;
}

.library-item.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.library-main {
  min-width: 0;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.library-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

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

.library-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--bad);
}

.library-more-wrap {
  position: relative;
  align-self: center;
}

.library-more {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 900;
}

.library-menu {
  position: absolute;
  z-index: 4;
  top: 38px;
  right: 0;
  width: 128px;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 28px rgba(30, 64, 175, 0.16);
}

.library-menu button {
  width: 100%;
  border: 0;
  padding: 8px 10px;
  text-align: left;
}

.message {
  min-height: 40px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.quiz-panel {
  min-height: 620px;
  padding: 22px;
}

.editor-panel {
  display: grid;
  gap: 16px;
}

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

.editor-actions {
  display: flex;
  gap: 10px;
}

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

.edit-question-item,
.question-editor-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.edit-question-title {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  border: 0;
  padding: 0;
  text-align: left;
}

.edit-question-title span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.edit-question-title strong {
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.edit-question-meta {
  margin: 8px 0 0 44px;
  color: var(--muted);
  font-size: 13px;
}

.edit-question-controls {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.danger-button {
  color: var(--bad);
}

.question-editor-form {
  display: grid;
  gap: 12px;
  background: var(--accent-soft);
}

.question-editor-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.question-editor-form input,
.question-editor-form textarea,
.question-editor-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px;
  font: inherit;
}

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

.option-editor-row {
  display: grid !important;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 8px;
}

.option-editor-row span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #eaf2ff;
  color: var(--accent-dark);
  font-weight: 800;
}

.option-editor-row button {
  color: var(--bad);
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.empty-state {
  min-height: 574px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  color: var(--muted);
}

.ring {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  border: 18px solid #dbeafe;
  border-top-color: var(--accent);
}

.empty-state h2 {
  font-size: 20px;
}

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

.question-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

.question-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.question-type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

#questionText {
  font-size: 24px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

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

.option {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px 14px;
}

.option .letter {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #eaf2ff;
  color: var(--accent-dark);
  font-weight: 800;
}

.option .text {
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.option.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option.is-selected .letter {
  background: var(--accent);
  color: #fff;
}

.option.is-correct {
  border-color: rgba(22, 121, 79, 0.72);
  background: #effaf4;
}

.option.is-wrong {
  border-color: rgba(178, 59, 59, 0.7);
  background: #fff1f1;
}

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

.judge-option {
  min-height: 132px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.judge-option .letter {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #eaf2ff;
  color: var(--accent-dark);
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}

.judge-option .text {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.judge-option.is-selected,
.judge-option.is-correct {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.judge-option.is-selected .letter,
.judge-option.is-correct .letter {
  background: var(--accent);
  color: #fff;
}

.judge-option.is-wrong {
  border-color: rgba(178, 59, 59, 0.7);
  background: #fff1f1;
}

.answer-box {
  border-left: 4px solid var(--good);
  padding: 12px 14px;
  border-radius: 8px;
  background: #f2faf5;
  color: #174b31;
  line-height: 1.55;
}

.answer-box.is-wrong {
  border-left-color: var(--bad);
  background: #fff4f4;
  color: #712525;
}

.explanation-box {
  margin-top: 12px;
  border-top: 1px solid rgba(22, 121, 79, 0.18);
  padding-top: 12px;
  white-space: pre-wrap;
}

.explanation-box strong {
  display: block;
  margin-bottom: 6px;
}

.wrong-answer-actions,
.explanation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.remove-wrong-button,
.keep-wrong-button,
.generate-explanation-button,
.retry-explanation-button {
  width: fit-content;
  border-color: var(--accent);
  background: #fff;
  color: var(--accent-dark);
  font-weight: 700;
}

.retry-explanation-button {
  display: block;
  margin-top: 10px;
}

.keep-wrong-button {
  border-color: var(--line);
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.settings-dialog {
  width: min(520px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.auth-dialog {
  width: min(440px, calc(100% - 32px));
}

.auth-dialog .dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-dialog .dialog-actions button {
  min-height: 42px;
}

.settings-dialog::backdrop {
  background: rgba(15, 23, 42, 0.34);
}

.settings-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.settings-dialog label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.settings-dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.settings-dialog button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.manual-dialog {
  width: min(680px, calc(100% - 32px));
}

.admin-invite-box {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.admin-invite-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.admin-invite-box strong {
  color: var(--accent-dark);
  font-size: 24px;
  letter-spacing: 0.08em;
}

.manual-content {
  max-height: min(62vh, 560px);
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 6px;
}

.manual-content h3 {
  margin: 8px 0 0;
  color: var(--text);
  font-size: 16px;
}

.manual-content p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.dialog-hint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.dialog-status {
  min-height: 20px;
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.inline-toggle {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.inline-toggle input {
  width: auto;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 16px 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1;
  }

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

  .migration-actions {
    grid-template-columns: 1fr;
  }

  .quiz-panel {
    min-height: 520px;
    padding: 16px;
  }

  .empty-state {
    min-height: 410px;
  }

  #questionText {
    font-size: 20px;
  }
}
