:root {
  --bg-page: #f5f7fb;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;

  --correct: #059669;
  --correct-bg: #ecfdf5;
  --correct-border: #a7f3d0;

  --wrong: #dc2626;
  --wrong-bg: #fef2f2;
  --wrong-border: #fecaca;

  --partial: #d97706;
  --partial-bg: #fffbeb;
  --partial-border: #fde68a;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  overflow-x: clip;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

/* Top Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.brand-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-main);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.user-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.68rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 220px;
}

.user-name {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 7em;
}

.user-id {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Main Layout */
.main-container {
  max-width: 1200px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3.5rem;
}

.view-section {
  min-width: 0;
  max-width: 100%;
}

/* Alert Banner */
.alert-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--wrong-border);
  background: var(--wrong-bg);
  color: var(--wrong);
  font-size: 0.9rem;
}

.alert-banner.alert-info {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.alert-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.btn-sm {
  font-size: 0.82rem;
  padding: 0.38rem 0.75rem;
}

.btn-lg {
  font-size: 0.98rem;
  padding: 0.72rem 1.25rem;
}

.btn-block {
  width: 100%;
}

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

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

.btn-outline {
  background: #ffffff;
  border-color: var(--border-strong);
  color: var(--text-main);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: #94a3b8;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text-main);
}

/* Login Experience (Clean Minimalist Centered Card) */
body.is-login-view {
  background: linear-gradient(160deg, #f8fafc 0%, #eef2f8 100%);
}

body.is-login-view .topbar {
  display: none;
}

body.is-login-view .main-container {
  min-height: 100dvh;
  max-width: 440px;
  padding: 1.5rem 1rem 5vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

body.is-login-view .alert-banner {
  width: 100%;
  max-width: 400px;
}

.login-view {
  width: 100%;
  display: flex;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border-radius: 18px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  padding: 2.25rem 2rem 2.1rem;
  box-shadow:
    0 12px 32px -10px rgba(15, 23, 42, 0.08),
    0 2px 6px rgba(15, 23, 42, 0.03);
}

.login-brand-head {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-app-icon {
  width: 46px;
  height: 46px;
  margin: 0 auto 0.85rem;
  border-radius: 12px;
  background: var(--primary);
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.22);
}

.login-brand-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.32rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.login-brand-head p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.login-form .form-group {
  margin-bottom: 1.05rem;
}

.login-form label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 0.38rem;
  color: #334155;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.85rem;
  width: 18px;
  height: 18px;
  color: #94a3b8;
  pointer-events: none;
  transition: color 0.15s ease;
}

.input-with-icon:focus-within .input-icon {
  color: var(--primary);
}

.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%;
  height: 44px;
  padding: 0.6rem 0.9rem 0.6rem 2.5rem;
  font-size: 0.94rem;
  font-family: inherit;
  color: var(--text-main);
  background: #f8fafc;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-form input[type="text"]:focus,
.login-form input[type="password"]:focus {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.password-wrapper input {
  padding-right: 3.6rem;
}

.pwd-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.48rem;
  border-radius: 6px;
}

.pwd-toggle:hover {
  color: var(--primary);
  background: #eff6ff;
}

.form-row-inline {
  margin-bottom: 1.25rem;
}

.checkbox-label {
  display: inline-flex !important;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500 !important;
  font-size: 0.84rem !important;
  color: var(--text-secondary) !important;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

.login-submit-btn {
  border-radius: 10px;
  height: 45px;
  font-size: 0.95rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.login-submit-btn:hover:not(:disabled) {
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

/* Loading & Empty States */
.loading-box,
.empty-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-secondary);
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 0.85rem;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Exam List View */
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.section-title {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.section-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.exam-list-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.exam-group-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.exam-group-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

.exam-group-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.exam-group-title-wrap {
  flex: 1;
}

.exam-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
}

.badge-subject {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.badge-neutral {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.badge-unlocked {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.exam-group-title {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.4;
}

.exam-final-score {
  text-align: right;
  flex-shrink: 0;
}

.exam-final-score .label {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.exam-final-score .val {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.15;
}

.exam-final-score .unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.exam-sessions-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
}

.session-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.session-meta strong {
  color: var(--text-main);
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Detail View */
.detail-top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.detail-right-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: #fff;
  padding: 0.36rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  user-select: none;
}

/* Paper Hero Summary */
.paper-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.paper-hero-main {
  flex: 1;
  min-width: 0;
}

.paper-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}

.paper-title {
  margin: 0 0 0.65rem;
  font-size: 1.3rem;
  line-height: 1.35;
}

.paper-meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.paper-score-box {
  flex-shrink: 0;
  text-align: right;
  padding-left: 1.5rem;
  border-left: 1px solid var(--border-color);
}

.score-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.score-value-wrap {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.25rem;
  margin: 0.15rem 0 0.35rem;
}

.score-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.score-total {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

.score-stats {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  font-size: 0.78rem;
}

.stat-pill {
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
}

.stat-pill-correct {
  background: var(--correct-bg);
  color: var(--correct);
}

.stat-pill-wrong {
  background: var(--wrong-bg);
  color: var(--wrong);
}

.stat-pill-partial {
  background: var(--partial-bg);
  color: var(--partial);
}

/* Two-Column Paper Layout */
.paper-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 1.25rem;
  align-items: start;
  min-width: 0;
  max-width: 100%;
}

.paper-main-col {
  min-width: 0;
  max-width: 100%;
}

/* Filter Toolbar */
.filter-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.filter-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.filter-tab:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.filter-tab.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
}

.tab-count {
  padding: 0.05rem 0.42rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #e2e8f0;
  color: var(--text-main);
}

.filter-tab.active .tab-count {
  background: var(--primary);
  color: #fff;
}

.search-input-wrap {
  flex: 1;
  min-width: 180px;
  max-width: 260px;
}

.search-input-wrap input {
  width: 100%;
  padding: 0.42rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.search-input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

/* Section Blocks & Question Cards */
.paper-section-block {
  margin-bottom: 1.5rem;
  min-width: 0;
  max-width: 100%;
}

.paper-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.25rem 0.2rem;
}

.paper-section-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-main);
}

.paper-section-score {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.question-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
  max-width: 100%;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.3rem;
  box-shadow: var(--shadow-sm);
  scroll-margin-top: 76px;
  min-width: 0;
  max-width: 100%;
}

.question-card.status-correct {
  border-left-color: var(--correct);
}

.question-card.status-wrong {
  border-left-color: var(--wrong);
}

.question-card.status-partial {
  border-left-color: var(--partial);
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.q-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.q-index {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.q-type-tag {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.1rem 0.48rem;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.q-shuffle-tag {
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: var(--text-muted);
}

.q-id-tag {
  font-size: 0.72rem;
  color: #94a3b8;
}

.q-score-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
}

.q-score-pill.status-correct {
  background: var(--correct-bg);
  color: var(--correct);
  border: 1px solid var(--correct-border);
}

.q-score-pill.status-wrong {
  background: var(--wrong-bg);
  color: var(--wrong);
  border: 1px solid var(--wrong-border);
}

.q-score-pill.status-partial {
  background: var(--partial-bg);
  color: var(--partial);
  border: 1px solid var(--partial-border);
}

.q-score-pill.status-pending {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

/* Question Stem */
.q-stem {
  font-size: 0.98rem;
  color: var(--text-main);
  line-height: 1.85;
  margin-bottom: 0.95rem;
  overflow-wrap: break-word;
  min-width: 0;
  max-width: 100%;
}

.q-card-answer-zone {
  min-width: 0;
  max-width: 100%;
}

.q-stem mjx-container,
.q-option-body mjx-container,
.blank-std-val mjx-container,
.blank-stu-val mjx-container,
.q-hint-box mjx-container {
  max-width: 100%;
}

.q-stem mjx-container[display="true"],
.q-option-body mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

.q-stem p {
  margin: 0.35rem 0;
}

.q-stem img,
.q-option-body img,
.q-answer-img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  border-radius: 4px;
}

/* Inline Blank Chip inside Stem */
.inline-blank-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0 0.25rem;
  padding: 0.08rem 0.55rem;
  border-radius: 5px;
  font-size: 0.9rem;
  font-weight: 600;
  border-bottom: 2px solid var(--border-strong);
  background: var(--bg-subtle);
  color: var(--text-main);
  vertical-align: baseline;
}

.inline-blank-chip.blank-correct {
  background: var(--correct-bg);
  border-bottom-color: var(--correct);
  color: var(--correct);
}

.inline-blank-chip.blank-wrong {
  background: var(--wrong-bg);
  border-bottom-color: var(--wrong);
  color: var(--wrong);
}

.inline-blank-index {
  font-size: 0.72rem;
  opacity: 0.75;
}

/* Options List (Single / Multiple Choice / True-False) */
.q-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.q-options.tf-options {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.q-option-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  font-size: 0.94rem;
  min-width: 0;
  max-width: 100%;
}

.tf-options .q-option-item {
  min-width: 150px;
  flex: 0 1 auto;
  align-items: center;
}

.q-option-left {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  min-width: 0;
  max-width: 100%;
  flex: 1;
}

.q-option-letter {
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.q-option-body {
  overflow-wrap: break-word;
  min-width: 0;
  max-width: 100%;
  flex: 1;
}

.q-option-tags {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.opt-badge {
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
}

/* Option States */
.q-option-item.opt-correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
}

.q-option-item.opt-correct .q-option-letter {
  color: var(--correct);
}

.q-option-item.opt-wrong-pick {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
}

.q-option-item.opt-wrong-pick .q-option-letter {
  color: var(--wrong);
}

.opt-badge-std {
  background: #d1fae5;
  color: #065f46;
}

.opt-badge-stu-ok {
  background: #059669;
  color: #ffffff;
}

.opt-badge-stu-err {
  background: #dc2626;
  color: #ffffff;
}

/* Fill-in-the-blank & Subjective Answer Comparison Box */
.q-blanks-box,
.q-subjective-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.blank-row {
  display: grid;
  grid-template-columns: 72px 1fr 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.blank-row.subjective-row {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

.blank-row-label {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.blank-cell-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.1rem;
}

.blank-stu-val {
  font-weight: 600;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
}

.blank-stu-val.val-ok {
  color: var(--correct);
}

.blank-stu-val.val-err {
  color: var(--wrong);
}

.blank-std-val {
  font-weight: 600;
  color: var(--correct);
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
}

/* Answer Summary Footer inside Question Card */
.q-answer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem 1.25rem;
  padding-top: 0.7rem;
  border-top: 1px dashed var(--border-color);
  font-size: 0.86rem;
}

.ans-pair {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ans-label {
  color: var(--text-muted);
}

.ans-val {
  font-weight: 700;
}

.ans-val-ok {
  color: var(--correct);
}

.ans-val-err {
  color: var(--wrong);
}

.ans-val-std {
  color: var(--correct);
}

.q-hint-box {
  margin-top: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border-color);
  font-size: 0.86rem;
  color: var(--text-secondary);
}

/* Self-Test Mode (Mask Student/Standard Answers until hovered or clicked) */
body.self-test-mode .q-card-answer-zone {
  position: relative;
}

body.self-test-mode .question-card:not(.revealed) .q-option-item.opt-correct,
body.self-test-mode .question-card:not(.revealed) .q-option-item.opt-wrong-pick {
  background: var(--bg-subtle);
  border-color: var(--border-color);
}

body.self-test-mode .question-card:not(.revealed) .q-option-item .q-option-letter {
  color: var(--text-secondary);
}

body.self-test-mode .question-card:not(.revealed) .q-option-tags,
body.self-test-mode .question-card:not(.revealed) .q-score-pill,
body.self-test-mode .question-card:not(.revealed) .q-blanks-box,
body.self-test-mode .question-card:not(.revealed) .q-subjective-box,
body.self-test-mode .question-card:not(.revealed) .q-answer-footer,
body.self-test-mode .question-card:not(.revealed) .q-hint-box {
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
}

body.self-test-mode .question-card:not(.revealed) {
  border-left-color: var(--border-strong);
}

body.self-test-mode .question-card:not(.revealed) .inline-blank-chip {
  background: var(--bg-subtle);
  border-bottom-color: var(--border-strong);
  color: transparent;
}

.reveal-btn {
  display: none;
}

body.self-test-mode .reveal-btn {
  display: inline-flex;
  margin-top: 0.5rem;
}

/* Sidebar Answer Sheet Navigation */
.paper-side-col {
  position: sticky;
  top: 74px;
}

.nav-sheet-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.nav-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-color);
}

.nav-sheet-title-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex: 1;
  flex-wrap: wrap;
}

.nav-sheet-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.nav-sheet-close,
.nav-sheet-backdrop,
.mobile-bottom-bar {
  display: none;
}

.nav-legend {
  display: flex;
  gap: 0.45rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-correct {
  background: var(--correct);
}

.dot-partial {
  background: var(--partial);
}

.dot-wrong {
  background: var(--wrong);
}

.nav-sec-group {
  margin-bottom: 0.85rem;
}

.nav-sec-group:last-child {
  margin-bottom: 0;
}

.nav-sec-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.38rem;
}

.nav-num-btn {
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.nav-num-btn:hover {
  transform: translateY(-1px);
}

.nav-num-btn.status-correct {
  background: var(--correct-bg);
  color: var(--correct);
  border-color: var(--correct-border);
}

.nav-num-btn.status-wrong {
  background: var(--wrong-bg);
  color: var(--wrong);
  border-color: var(--wrong-border);
}

.nav-num-btn.status-partial {
  background: var(--partial-bg);
  color: var(--partial);
  border-color: var(--partial-border);
}

/* Responsive: Tablet & Mobile (<= 920px) */
@media (max-width: 920px) {
  body.drawer-open {
    overflow: hidden;
  }

  .main-container {
    padding: 1.15rem 1rem calc(5.2rem + env(safe-area-inset-bottom, 0px));
  }

  .paper-layout {
    grid-template-columns: 1fr;
  }

  /* Backdrop behind slide-up answer sheet */
  .nav-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(2px);
  }

  /* Slide-up Bottom Sheet Answer Card */
  .paper-side-col {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 60;
    transform: translateY(105%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
  }

  .paper-side-col.mobile-open {
    transform: translateY(0);
    pointer-events: auto;
  }

  .nav-sheet-card {
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    max-height: 74vh;
    padding: 1rem 1.1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.16);
  }

  .nav-sheet-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
  }

  .nav-grid {
    grid-template-columns: repeat(7, 1fr);
    gap: 0.45rem;
  }

  .nav-num-btn {
    height: 38px;
    font-size: 0.86rem;
  }

  /* Floating Bottom Bar on Mobile/Tablet */
  .mobile-bottom-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
    z-index: 45;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.38rem;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.14);
    width: max-content;
    max-width: calc(100vw - 1.5rem);
  }

  .mobile-dock-btn {
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 600;
    padding: 0.5rem 0.95rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-subtle);
    color: var(--text-main);
    white-space: nowrap;
  }

  .mobile-dock-primary {
    background: var(--primary);
    color: #ffffff;
  }

  .mobile-dock-sub {
    font-size: 0.76rem;
    opacity: 0.9;
    padding: 0.05rem 0.42rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
  }
}

/* Responsive: Mobile Phones (<= 640px) */
@media (max-width: 640px) {
  .hide-mobile {
    display: none;
  }

  .topbar-inner {
    padding: 0.55rem 0.75rem;
    gap: 0.45rem;
  }

  .brand {
    gap: 0.45rem;
    min-width: 0;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  .brand-title {
    font-size: 0.92rem;
    white-space: nowrap;
  }

  .brand-subtitle {
    display: none;
  }

  .user-bar {
    gap: 0.32rem;
    flex-wrap: nowrap;
  }

  .user-meta {
    padding: 0.22rem 0.52rem;
    font-size: 0.8rem;
    max-width: 112px;
  }

  .user-name {
    max-width: 5.5em;
  }

  .user-id {
    display: none;
  }

  .topbar .btn-sm {
    padding: 0.3rem 0.52rem;
    font-size: 0.78rem;
  }

  .main-container {
    padding: 0.9rem 0.75rem calc(5.2rem + env(safe-area-inset-bottom, 0px));
  }

  /* Login View Mobile: Full-bleed native screen (no nested popup card) */
  body.is-login-view {
    background: #ffffff;
  }

  body.is-login-view .main-container {
    max-width: none;
    justify-content: flex-start;
    align-items: stretch;
    padding: max(11vh, 3.25rem) 1.5rem calc(2rem + env(safe-area-inset-bottom, 0px));
  }

  body.is-login-view .alert-banner {
    max-width: none;
  }

  .login-card {
    max-width: none;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .login-brand-head {
    text-align: left;
    margin-bottom: 2rem;
  }

  .login-app-icon {
    width: 46px;
    height: 46px;
    margin: 0 0 1rem;
    border-radius: 12px;
    font-size: 1.3rem;
  }

  .login-brand-head h1 {
    font-size: 1.45rem;
    margin-bottom: 0.35rem;
  }

  .login-brand-head p {
    font-size: 0.9rem;
  }

  .login-form .form-group {
    margin-bottom: 1.15rem;
  }

  /* 16px prevents iOS Safari auto-zoom on focus */
  .login-form input[type="text"],
  .login-form input[type="password"] {
    height: 48px;
    font-size: 16px;
    border-radius: 12px;
  }

  .search-input-wrap input {
    font-size: 16px;
  }

  .login-submit-btn,
  .btn-lg {
    height: 48px;
    min-height: 48px;
    border-radius: 12px;
    font-size: 1rem;
  }

  /* Exam List Mobile */
  .section-title {
    font-size: 1.2rem;
  }

  .section-desc {
    font-size: 0.84rem;
  }

  .exam-group-card {
    padding: 1rem;
    border-radius: var(--radius-md);
  }

  .exam-group-header {
    gap: 0.75rem;
    padding-bottom: 0.85rem;
  }

  .exam-group-title {
    font-size: 1.04rem;
  }

  .exam-final-score .val {
    font-size: 1.5rem;
  }

  .session-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.8rem 0.85rem;
  }

  .session-meta {
    flex-direction: column;
    gap: 0.28rem;
    font-size: 0.82rem;
  }

  .session-actions {
    width: 100%;
  }

  .session-actions .view-paper-btn {
    width: 100%;
    min-height: 42px;
    font-size: 0.88rem;
  }

  /* Detail Top Actions Mobile */
  .detail-top-actions {
    gap: 0.5rem;
    margin-bottom: 0.75rem;
  }

  .detail-top-actions #backToListBtn {
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
  }

  .detail-right-actions {
    gap: 0.45rem;
  }

  .toggle-switch {
    padding: 0.36rem 0.6rem;
    font-size: 0.8rem;
  }

  #printPaperBtn {
    display: none;
  }

  /* Paper Hero Card Mobile */
  .paper-hero-card {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 1.05rem;
    gap: 0.85rem;
    margin-bottom: 0.9rem;
    border-radius: var(--radius-md);
  }

  .paper-title {
    font-size: 1.08rem;
    margin-bottom: 0.45rem;
  }

  .paper-meta-list {
    gap: 0.25rem 0.85rem;
    font-size: 0.8rem;
  }

  .paper-score-box {
    width: 100%;
    padding-left: 0;
    padding-top: 0.75rem;
    border-left: none;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    text-align: left;
  }

  .score-label {
    display: none;
  }

  .score-value-wrap {
    margin: 0;
    justify-content: flex-start;
  }

  .score-value {
    font-size: 1.75rem;
  }

  .score-stats {
    justify-content: flex-end;
    gap: 0.35rem;
  }

  /* Filter Toolbar Mobile */
  .filter-toolbar {
    padding: 0.6rem;
    gap: 0.55rem;
    margin-bottom: 0.85rem;
  }

  .filter-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.3rem;
  }

  .filter-tab {
    justify-content: center;
    padding: 0.42rem 0.3rem;
    font-size: 0.8rem;
    gap: 0.25rem;
    white-space: nowrap;
  }

  .search-input-wrap {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  /* Section & Question Cards Mobile */
  .paper-section-header {
    flex-wrap: wrap;
    gap: 0.2rem 0.5rem;
  }

  .paper-section-title {
    font-size: 0.98rem;
  }

  .paper-section-score {
    font-size: 0.8rem;
  }

  .question-card {
    padding: 0.9rem 0.9rem;
    scroll-margin-top: 62px;
  }

  .q-header {
    gap: 0.45rem;
    margin-bottom: 0.6rem;
  }

  .q-score-pill {
    font-size: 0.76rem;
    padding: 0.15rem 0.52rem;
  }

  .q-stem {
    font-size: 0.94rem;
    line-height: 1.8;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.1rem 0;
  }

  .q-option-item {
    flex-wrap: wrap;
    padding: 0.58rem 0.7rem;
    gap: 0.4rem 0.55rem;
    font-size: 0.9rem;
  }

  .q-option-left {
    flex: 1 1 200px;
  }

  .q-option-body {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .q-option-tags {
    margin-left: auto;
  }

  .q-options.tf-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .tf-options .q-option-item {
    min-width: 0;
    padding: 0.55rem 0.6rem;
  }

  .blank-row,
  .blank-row.subjective-row {
    grid-template-columns: 1fr;
    gap: 0.45rem;
    padding: 0.6rem 0.75rem;
  }

  .blank-row-label {
    padding-bottom: 0.2rem;
    border-bottom: 1px dashed var(--border-color);
  }

  .q-answer-footer {
    font-size: 0.82rem;
    gap: 0.4rem 0.85rem;
  }

  .nav-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 380px) {
  .q-options.tf-options {
    grid-template-columns: 1fr;
  }

  .nav-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* Print Styles */
@media print {
  body {
    background: #fff;
  }

  .topbar,
  .no-print,
  .alert-banner {
    display: none !important;
  }

  .main-container {
    max-width: 100%;
    padding: 0;
  }

  .paper-layout {
    display: block;
  }

  .question-card,
  .paper-hero-card {
    box-shadow: none;
    break-inside: avoid;
  }
}
