:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --line: #dce4eb;
  --text: #17212b;
  --muted: #6b7a89;
  --primary: #1395ee;
  --primary-dark: #0878c4;
  --good: #16825d;
  --bad: #ce3d3d;
  --warn: #a86c00;
  --shadow: 0 18px 45px rgba(30, 48, 66, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.modal h3 {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
  letter-spacing: 0;
}

.brand p,
.topbar p {
  color: var(--muted);
}

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

.stats-grid div {
  min-width: 0;
  padding: 12px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  text-align: center;
}

.stats-grid strong {
  display: block;
  font-size: 20px;
  line-height: 1.2;
}

.stats-grid span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.overview-panel {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.overview-card,
.type-list div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.overview-card h2 {
  margin: 0;
  font-size: 18px;
}

.overview-card p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.type-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.type-list span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.type-list strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.main-panel {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 82px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar > div {
  min-width: 0;
  flex: 1;
}

.topbar h2 {
  margin-top: 3px;
  font-size: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 28px 0;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(64px, auto));
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--primary);
  color: #fff;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(360px, 45vw);
  min-height: 46px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-box span {
  color: var(--muted);
  font-size: 14px;
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
}

.question-list {
  display: grid;
  gap: 14px;
  padding: 18px 28px 36px;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(20, 30, 40, 0.03);
  overflow: hidden;
}

.question-card.flagged {
  border-color: #f0be55;
}

.question-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 18px 18px 12px;
}

.question-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.question-index {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.question-copy h3 {
  margin: 4px 0 0;
  min-width: 0;
  font-size: 17px;
  line-height: 1.55;
}

.source-link {
  display: inline-flex;
  margin-top: 8px;
  color: var(--primary-dark);
  font-size: 13px;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.question-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.type-tag,
.result-tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.result-tag.correct {
  background: rgba(22, 130, 93, 0.12);
  color: var(--good);
}

.result-tag.wrong {
  background: rgba(206, 61, 61, 0.12);
  color: var(--bad);
}

.mark-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.mark-btn.active {
  border-color: #f0be55;
  background: #fff7e3;
  color: var(--warn);
}

.options {
  display: grid;
  gap: 8px;
  padding: 0 18px 16px;
}

.option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.option input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

.option.correct {
  border-color: rgba(22, 130, 93, 0.5);
  background: rgba(22, 130, 93, 0.08);
}

.option.wrong {
  border-color: rgba(206, 61, 61, 0.45);
  background: rgba(206, 61, 61, 0.08);
}

.answer-box {
  display: none;
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px solid rgba(19, 149, 238, 0.28);
  border-radius: 8px;
  background: rgba(19, 149, 238, 0.07);
}

.answer-box.visible {
  display: block;
}

.answer-box strong {
  color: var(--primary-dark);
}

.answer-box p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border-radius: 8px;
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    border-color 0.15s ease;
}

.primary-btn {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.ghost-btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

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

.primary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: #fff;
}

.icon-btn span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  background: var(--text);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 420px;
  padding: 24px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 24px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.modal {
  width: min(860px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(13, 24, 35, 0.45);
}

.modal-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-card textarea {
  width: 100%;
  min-height: 430px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
}

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

.close-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

body.sidebar-open .sidebar {
  transform: translateX(0);
}

@media (max-width: 920px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    width: min(320px, 88vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .icon-btn {
    display: block;
    flex: 0 0 auto;
  }

  .topbar {
    padding: 14px 16px;
  }

  .topbar h2 {
    font-size: 20px;
  }

  .toolbar {
    display: grid;
    padding: 14px 16px 0;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
  }

  .segmented button {
    padding: 0 8px;
  }

  .search-box {
    width: 100%;
  }

  .question-list {
    padding: 14px 16px 28px;
  }

  .question-head {
    grid-template-columns: 1fr;
  }

  .question-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 10px;
  }

  .topbar .primary-btn {
    min-width: 92px;
    padding: 0 10px;
  }

  .question-title {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .question-copy h3 {
    font-size: 16px;
  }

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

/* ── Topbar right section ── */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Member badge ── */
.member-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(22, 130, 93, 0.12);
  color: var(--good);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* ── Member active button state ── */
.member-active {
  background: var(--good) !important;
  border-color: var(--good) !important;
  cursor: default;
}

/* ── Activation form ── */
.activate-form {
  display: grid;
  gap: 12px;
}

.activate-desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.activate-input {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
  letter-spacing: 2px;
  outline: none;
}

.activate-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(19, 149, 238, 0.15);
}

.login-error {
  margin: 0;
  color: var(--bad);
  font-size: 14px;
  min-height: 20px;
}

.login-status {
  margin: 0;
  color: var(--good);
  font-size: 14px;
  min-height: 20px;
}

/* ── Paywall ── */
.paywall {
  display: grid;
  place-items: center;
  padding: 24px;
}

.paywall-card {
  display: grid;
  gap: 12px;
  justify-items: center;
  max-width: 420px;
  padding: 36px 24px;
  background: var(--surface);
  border: 2px dashed var(--line);
  border-radius: 12px;
  text-align: center;
}

.paywall-card h3 {
  margin: 0;
  font-size: 22px;
}

.paywall-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.paywall-sub {
  font-size: 13px;
}

.paywall-activate-btn {
  min-height: 44px;
  padding: 0 24px;
  margin-top: 8px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.paywall-activate-btn:hover {
  transform: translateY(-1px);
}

@media (max-width: 920px) {
  .topbar-right .member-badge {
    display: none !important;
  }
}
