:root {
  --primary: #2f6fed;
  --primary-dark: #1f57c3;
  --primary-soft: #eaf0ff;
  --green: #16a34a;
  --green-soft: #e8f7ee;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #d97706;
  --amber-soft: #fdf3e2;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1c2434;
  --muted: #6b7485;
  --border: #e4e8f0;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(28, 36, 52, 0.06);
  --font: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }
p { margin: 0; }
ul, ol { margin: 0; padding-left: 20px; }
code { background: #f1f3f8; border-radius: 4px; padding: 1px 5px; font-size: 0.92em; }
mark { background: #fff1a8; color: inherit; padding: 0 2px; border-radius: 2px; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------------------------------------------------------------- Layout */

.layout { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: clamp(200px, 15vw, 248px);
  flex: 0 0 clamp(200px, 15vw, 248px);
  background: #101a2f;
  color: #c8d2e4;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 0 10px 18px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #7aa2ff);
  display: grid;
  place-items: center;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: #fff;
}

.sidebar nav { display: flex; flex-direction: column; gap: 3px; }
.sidebar .nav-section {
  padding: 14px 12px 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: #64728c;
  text-transform: uppercase;
}
.sidebar nav a {
  color: #b8c3d9;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; font-weight: 500; }
.sidebar nav .nav-ico { width: 18px; text-align: center; opacity: 0.9; }
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; font-size: 12px; color: #71809c; }

.main {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: clamp(16px, 1.8vw, 32px) clamp(16px, 2.2vw, 40px) 56px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.topbar-title { min-width: 180px; }
.topbar h1 { font-size: clamp(20px, 1.6vw, 26px); }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.topbar-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-search { display: flex; gap: 8px; align-items: center; }
.topbar-search input { width: clamp(180px, 22vw, 340px); }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.topbar-user form { margin: 0; }
.user-name { white-space: nowrap; }

.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.breadcrumb a { color: var(--muted); }

/* ---------------------------------------------------------------- Cards */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(14px, 1.2vw, 22px);
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }
.card-head .hint { color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.grid.dashboard-analysis { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.grid.question-layout { grid-template-columns: minmax(0, 1fr) clamp(260px, 20vw, 340px); align-items: start; }

/* auto-fill：数量不足时也保持卡片固定宽度，避免单卡被拉成长条 */
.papers-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}
.questions-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
}
.papers-grid > .card + .card,
.questions-grid > .card + .card { margin-top: 0; }

.question-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.question-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.question-card-head .q-order { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.question-card-title {
  flex: 1;
  font-size: 14px;
  line-height: 1.65;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.question-card-title:hover { color: var(--primary); }
.question-card-meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.question-card-meta span {
  background: #f4f6fa;
  border-radius: 6px;
  padding: 2px 7px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.question-card-actions { display: flex; gap: 8px; align-items: center; padding-top: 10px; border-top: 1px solid #eef1f6; flex-wrap: wrap; }
.question-card-actions form { margin: 0; }
.question-card.row-highlight { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.12); }

.stat-card { padding: 18px 20px; }
.stat-card.compact { padding: 14px 16px; }
.stat-card .label { color: var(--muted); font-size: 13px; }
.stat-card .value { font-size: clamp(24px, 2.1vw, 32px); font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.stat-card .value.small-value { font-size: clamp(18px, 1.4vw, 22px); }
.stat-card .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.stat-card .foot { color: var(--muted); font-size: 12px; margin-top: 6px; }
/* 待刷清单顶部统计：固定四等分，避免 auto-fit 在三列/两列之间跳动。 */
.review-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 980px) {
  .review-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

/* ---------------------------------------------------------------- Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fd; text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-soft { background: var(--primary-soft); border-color: transparent; color: var(--primary-dark); }
.btn-soft:hover { background: #dce7ff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 10px; }
.btn-ghost:hover { background: #eef1f7; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------------------------------------------------------------- Badges */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  padding: 2px 9px;
  background: #eef1f7;
  color: var(--muted);
  white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-gray { background: #eef1f7; color: var(--muted); }

/* ---------------------------------------------------------------- Forms */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.13);
}
textarea { min-height: 90px; resize: vertical; line-height: 1.6; }
.field { margin-bottom: 14px; min-width: 0; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row > .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px 16px; }
.form-grid > .field { margin-bottom: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.required { color: var(--red); }
.hint { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 4px; line-height: 1.5; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { width: 200px; }
.readonly-field { padding: 9px 12px; border: 1px dashed var(--border); border-radius: 9px; color: var(--muted); background: #fafbfd; overflow-wrap: anywhere; }
.narrow-field { max-width: 360px; }
.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 12px;
  align-items: end;
}
.toolbar > .field { margin-bottom: 0; }
.toolbar > .history-filter { max-width: 280px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-bottom: 8px; }
.checkbox-line input { width: auto; }
input[type="file"] { font-size: 13px; max-width: 100%; }

.option-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.option-edit { display: flex; align-items: center; gap: 8px; }
.option-edit .option-letter {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 600;
}
.option-edit input:disabled { background: #f4f6fa; color: var(--muted); }

/* ---------------------------------------------------------------- Tabs */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a, .tabs button {
  padding: 10px 14px;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
  background: transparent;
  cursor: pointer;
}
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs a.active, .tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.tab-count { display: inline-block; margin-left: 4px; font-size: 11px; color: var(--muted); background: #eef1f7; border-radius: 999px; padding: 0 6px; }

/* ---------------------------------------------------------------- Tables */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid #eef1f6; vertical-align: middle; overflow-wrap: anywhere; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafcff; }
.table .num { font-variant-numeric: tabular-nums; }
.cell-main { min-width: 220px; max-width: 560px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.row-highlight td { background: #fffbea; }
.answer-key {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- Pager */

.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.pager-info { color: var(--muted); font-size: 12px; }
.pager-btns { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  color: var(--text);
  background: #fff;
  text-decoration: none;
}
.pager-btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pager-btn.disabled { color: #b3bac7; background: #fafbfd; pointer-events: none; }
.pager-current { font-size: 12px; color: var(--muted); padding: 0 6px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- Progress / chart */

.progress { height: 8px; background: #edf0f6; border-radius: 999px; overflow: hidden; }
.progress > span, .progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #7aa2ff); border-radius: 999px; }
.progress.green > span, .progress.green > i { background: linear-gradient(90deg, var(--green), #4ade80); }
.progress.red > span, .progress.red > i { background: linear-gradient(90deg, var(--red), #f87171); }

.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 8px; }
.bar-chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 16px; height: 100%; }
.bar-chart .bar i {
  display: block;
  width: 100%;
  max-width: 26px;
  background: linear-gradient(180deg, #7aa2ff, var(--primary));
  border-radius: 5px 5px 2px 2px;
  min-height: 3px;
  flex: 0 0 auto;
}
.bar-chart .bar span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.trend-chart { height: 160px; }
.trend-chart .bar i { background: linear-gradient(180deg, #a5c0ff, #5b8def); }
.trend-chart .bar i.has-data { background: linear-gradient(180deg, #7aa2ff, var(--primary)); }
.trend-chart .bar span { font-size: 10px; letter-spacing: -0.3px; }

.mastery-list { display: flex; flex-direction: column; gap: 12px; }
.mastery-row { display: flex; flex-direction: column; gap: 5px; }
.mastery-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 13px; }
.mastery-head a { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- Lists */

.list { display: flex; flex-direction: column; }
.list-item { padding: 13px 0; border-bottom: 1px solid #eef1f6; display: flex; justify-content: space-between; gap: 14px; align-items: center; min-width: 0; }
.list-item:last-child { border-bottom: none; }
.list-item > div:first-child { min-width: 0; }
.list-item .title { font-size: 14px; color: var(--text); overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item .meta { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.list-item .side { display: flex; gap: 8px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }

/* 本卷历史错题：与移动端一致，选项和答案分开查看 */
.review-item { padding: 16px 0; border-bottom: 1px solid #eef1f6; }
.review-item:last-child { border-bottom: none; }
.review-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.review-head > div:first-child { min-width: 0; flex: 1; }
.review-head .side { display: flex; gap: 8px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }
.review-title { font-size: 14px; line-height: 1.7; color: var(--text); overflow-wrap: anywhere; }
.review-title a { color: inherit; }
.review-meta { color: var(--muted); font-size: 12px; margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.review-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.review-panel { margin-top: 10px; padding: 12px 14px; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; line-height: 1.7; color: var(--text); }
.review-panel[hidden] { display: none; }
.review-options { display: flex; flex-direction: column; gap: 6px; }
.review-opt { display: flex; gap: 8px; align-items: flex-start; }
.review-opt b { flex-shrink: 0; width: 18px; color: var(--primary); }
.review-line { margin-top: 6px; }
.review-line:first-child { margin-top: 0; }
.review-line b { color: var(--text); }
.review-mine { color: #c2410c; }
.review-correct { color: var(--green); }
.review-parsing { margin-top: 10px; white-space: pre-line; }
.review-ai { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.review-ai-status { margin-top: 6px; font-size: 12px; line-height: 1.6; color: var(--muted); }
.review-ai-status:empty { display: none; }
.review-ai-status.is-error { color: var(--red); cursor: pointer; }
.review-ai-box { background: #fff; }

.empty { text-align: center; padding: 54px 20px; color: var(--muted); }
.empty.compact { padding: 28px 16px; }
.empty .icon { font-size: 34px; margin-bottom: 10px; opacity: 0.55; }
.empty h3 { color: var(--text); font-size: 15px; margin-bottom: 6px; }
.empty p { font-size: 13px; margin-bottom: 16px; }

/* ---------------------------------------------------------------- Paper cards */

.paper-summary { display: flex; flex-direction: column; gap: 14px; }
.paper-primary-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.paper-secondary-links {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: center;
  border-top: 1px dashed var(--border); padding-top: 10px; font-size: 12px;
}
.paper-secondary-links a { color: var(--muted); }

.paper-card { position: relative; display: flex; flex-direction: column; gap: 10px; }
.paper-card .chapter { color: var(--primary); font-size: 12px; font-weight: 500; }
.paper-card h3 { font-size: 15px; overflow-wrap: anywhere; }
.paper-card h3 a { color: inherit; }
.paper-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.paper-meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; align-items: center; }
.paper-card .foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: auto; padding-top: 4px; flex-wrap: wrap; }
.paper-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.paper-card-actions .btn { flex: 1; justify-content: center; }
.paper-card-links {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  margin-top: auto; padding-top: 10px;
  border-top: 1px dashed var(--border); font-size: 12px;
}
.paper-card-links form { margin: 0; }
.paper-card-links a,
.link-btn {
  color: var(--muted); font: inherit; font-size: 12px;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.paper-card-links a:hover,
.link-btn:hover { color: var(--primary); }
.link-btn.danger:hover { color: var(--red); }
.wrong-filter { margin: 0; }
.wrong-filter select { height: 36px; min-width: 140px; }
.gap-10 { gap: 10px; }
.meta-row { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.score-pill { font-variant-numeric: tabular-nums; font-weight: 600; }
.score-pill.good { color: var(--green); }
.score-pill.bad { color: var(--red); }

.paper-edit { border-top: 1px dashed var(--border); padding-top: 10px; }
.paper-edit summary { cursor: pointer; color: var(--primary); font-size: 13px; user-select: none; }
.paper-edit form { margin-top: 10px; }
.paper-edit .field { margin-bottom: 10px; }

.subject-card { display: flex; flex-direction: column; gap: 8px; }
.subject-card .children { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-card .children a { font-size: 12px; }
.subject-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.12); }

.home-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.home-action {
  display: flex; align-items: center; gap: 14px; color: var(--text);
  text-decoration: none; transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.home-action:hover {
  color: var(--text); text-decoration: none; border-color: #cddbf7;
  transform: translateY(-1px); box-shadow: 0 10px 26px rgba(28, 36, 52, 0.08);
}
.home-action-ico {
  width: 46px; height: 46px; flex: 0 0 46px; display: grid; place-items: center;
  border-radius: 13px; background: var(--primary-soft); color: var(--primary-dark);
  font-size: 21px; line-height: 1;
}
.home-action-ico.red { background: var(--red-soft); color: var(--red); }
.home-action-ico.amber { background: var(--amber-soft); color: var(--amber); }
.home-action h2 { font-size: 16px; }
.home-action p { margin-top: 2px; }
.home-action-go { margin-left: auto; color: var(--primary); font-size: 13px; white-space: nowrap; }

.train-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  background: linear-gradient(120deg, #fff8f2 0%, #fff 58%);
  border-color: #f3ddc8;
}
.train-hero-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.train-hero-icon {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
  color: #b45309;
  background: #fde9d7;
}
.train-hero h2 { font-size: 17px; margin-bottom: 3px; }
.train-hero p { margin: 0; }
.train-hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.train-hero-actions { align-items: center; gap: 10px; }
.scope-pills {
  display: inline-flex; gap: 2px; padding: 3px;
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
}
.scope-pill {
  border: 0; background: none; cursor: pointer; font: inherit;
  padding: 5px 11px; border-radius: 999px;
  color: var(--muted); font-size: 12px; line-height: 1.4;
}
.scope-pill b { font-weight: 600; margin-left: 2px; }
.scope-pill:hover { color: var(--text); }
.scope-pill.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }

.btn.is-favorited { color: var(--amber); border-color: #f0d9a8; background: var(--amber-soft); }
a.card { color: inherit; }
a.card:hover { text-decoration: none; border-color: #b9c9ef; }

/* ---------------------------------------------------------------- Search */

.search-panel { padding: clamp(14px, 1.4vw, 22px); }
.search-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(140px, 190px) auto auto;
  gap: 10px;
  align-items: center;
}
.search-tabs { margin-top: 18px; }
.search-form .btn { height: 40px; }

/* ---------------------------------------------------------------- Exam */

.exam-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(230px, 18vw, 300px); gap: 18px; align-items: start; }
.exam-topbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.exam-progress { color: var(--muted); font-size: 13px; }
.exam-timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--primary-dark); font-size: 15px; white-space: nowrap; }
.exam-timer.warn { color: var(--red); }
.question-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; flex-wrap: wrap; }
.question-head .no { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.question-content { font-size: 16px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.option-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.option-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fff;
  min-width: 0;
}
.option-item:hover { border-color: #b9c9ef; background: #fbfcff; }
.option-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.option-item input { margin-top: 3px; accent-color: var(--primary); flex: 0 0 auto; }
.option-item .key {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border-radius: 50%;
  background: #eef1f7;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
}
.option-item.selected .key { background: var(--primary); color: #fff; }
body.question-detail:not(.show-answer) .option-item.selected {
  border-color: var(--border); background: #fff;
}
body.question-detail:not(.show-answer) .option-item.selected .key {
  background: #eef1f7; color: var(--muted);
}
body.question-detail:not(.show-answer) .option-item .badge-green,
body.question-detail:not(.show-answer) .result-detail { display: none; }
.option-item .text { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.exam-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; }
.answer-card { position: sticky; top: 18px; }
.answer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 7px; margin-top: 12px; }
.answer-grid button {
  position: relative;
  aspect-ratio: 1;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  min-height: 34px;
}
.answer-grid button.answered { background: var(--green-soft); border-color: #b7e4c8; color: var(--green); }
.answer-grid button.marked { background: var(--amber-soft); border-color: #f0d19a; color: var(--amber); }
.answer-grid button.answered.marked { background: linear-gradient(135deg, var(--green-soft) 55%, var(--amber-soft) 55%); }
.answer-grid button.current { outline: 2px solid var(--primary); outline-offset: 1px; }
.answer-grid button:hover { border-color: var(--primary); }
.answer-grid .mark-dot {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--amber);
}
.save-state { font-size: 12px; color: var(--muted); }
.save-state.error { color: var(--red); }
.save-state.ok { color: var(--green); }
.keyboard-hint { margin-top: 14px; }
.keyboard-hint b { color: var(--text); font-weight: 600; }
.exam-hint { margin-top: 16px; }
.exam-hint-toggle { color: var(--amber); border-color: var(--amber-soft); background: var(--amber-soft); }
.exam-hint-body {
    margin-top: 10px; padding: 12px 14px; border-radius: 10px;
    background: #fffaf0; border: 1px solid #f5e3bd;
}
.exam-hint-answer { font-size: 14px; color: var(--text); }
.exam-hint-answer b { color: var(--green); font-size: 15px; }
.exam-hint-parsing {
    margin-top: 8px; font-size: 14px; line-height: 1.75; color: var(--text);
    white-space: pre-wrap; overflow-wrap: anywhere;
}
.exam-note { margin-top: 22px; border-top: 1px dashed var(--border); padding-top: 14px; }
.exam-note-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.exam-note textarea { min-height: 80px; }

.review-section { margin-top: 12px; }
.review-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.review-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 7px; }
.review-jump {
  border: 1px solid #f0d19a;
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 7px;
  padding: 7px 0;
  font-size: 12px;
  cursor: pointer;
}
.review-jump:hover { border-color: var(--amber); }
.review-jump.flagged { background: #fff7e8; }

/* ---------------------------------------------------------------- Result */

.result-hero { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; }
.result-hero-main { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; flex: 1; min-width: 0; }
.result-score { font-size: clamp(36px, 3.2vw, 48px); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.result-score small { font-size: 20px; color: var(--muted); font-weight: 500; }
.result-stats { display: flex; gap: clamp(16px, 2vw, 30px); color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.result-stats b { display: block; font-size: 18px; color: var(--text); font-variant-numeric: tabular-nums; }
.result-tabs { margin-bottom: 0; }
.layout { transition: opacity 0.15s ease; }
body.result-pending .layout { opacity: 0; pointer-events: none; }

.self-check-bar {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.self-check-bar > div > b { font-size: 16px; }
body.self-check .result-hero-main { display: none; }
body.self-check.show-score .result-hero-main { display: flex; }
body.self-check .self-check-bar { display: flex; }
body.self-check .result-tabs { display: none; }
.self-check-box { display: none; }
body.self-check .self-check-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-top: 4px;
  border: 1px dashed var(--border);
  border-radius: 9px;
  background: #fafbfd;
}
body.self-check .self-check-box .btn-row { margin-left: auto; }
.self-check-box .btn[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}
body.self-check .result-item:not(.revealed) .result-detail,
body.self-check .result-item:not(.revealed) .actual-badge,
body.self-check .result-item:not(.revealed) .result-options .badge { display: none; }
body.self-check .result-item:not(.revealed) .result-option.correct,
body.self-check .result-item:not(.revealed) .result-option.wrong {
  border-color: var(--border);
  background: transparent;
}
body.self-check .result-item:not(.revealed) .result-option.correct .key,
body.self-check .result-item:not(.revealed) .result-option.wrong .key {
  background: #eef1f7;
  color: var(--muted);
}
body.self-check .result-item.revealed .actual-badge { display: inline-flex; }

.mode-choice { display: grid; gap: 10px; margin: 16px 0 12px; }
.mode-option {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.mode-option:hover, .mode-option:focus-visible {
  border-color: var(--primary);
  background: #f8faff;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.1);
  outline: none;
}
.mode-option b { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.mode-option > span { font-size: 13px; line-height: 1.6; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); user-select: none; }
.switch .track { width: 40px; height: 22px; border-radius: 999px; background: #d5dbe7; position: relative; transition: background 0.2s; }
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch.on .track { background: var(--primary); }
.switch.on .track::after { transform: translateX(18px); }

.result-card { padding: clamp(14px, 1.2vw, 20px); }
.result-card .head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.result-card .head .left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.result-card .content { font-size: 15px; line-height: 1.7; white-space: pre-wrap; margin-bottom: 12px; overflow-wrap: anywhere; }
.result-options { display: flex; flex-direction: column; gap: 8px; }
.result-option { border: 1px solid var(--border); border-radius: 9px; padding: 10px 13px; display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.result-option .key {
  width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%;
  background: #eef1f7; color: var(--muted); display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
}
.result-option .text { flex: 1; overflow-wrap: anywhere; }
.result-option.correct { border-color: #b7e4c8; background: var(--green-soft); }
.result-option.correct .key { background: var(--green); color: #fff; }
.result-option.wrong { border-color: #f3c2c2; background: var(--red-soft); }
.result-option.wrong .key { background: var(--red); color: #fff; }
.result-detail { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.result-detail .row { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.result-detail .row b { color: var(--text); font-weight: 500; }
.answer-box { display: flex; flex-wrap: wrap; gap: 10px; }
.answer-box > div { flex: 1; min-width: 160px; background: #fafbfd; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; font-size: 13px; }
.answer-box .label { color: var(--muted); font-size: 12px; }
.markdown { font-size: 14px; line-height: 1.75; color: var(--text); overflow-wrap: anywhere; }
.markdown h2 { font-size: 16px; margin: 16px 0 8px; color: var(--primary-dark); }
.markdown h2:first-child { margin-top: 0; }
.markdown h3 { font-size: 14px; margin: 12px 0 6px; }
.markdown p { margin: 6px 0; }
.markdown ul, .markdown ol { margin: 6px 0; padding-left: 22px; }
.markdown li { margin: 3px 0; }
.markdown strong { color: var(--text); }
.hidden-answer { display: none; }
body.show-answers .hidden-answer { display: flex; }
body.show-answers div.hidden-answer { display: flex; }
.hidden-block { display: none; }
body.show-answers .hidden-block { display: block; }

.evidence-list { display: flex; flex-direction: column; gap: 8px; }
.evidence-item { background: #fafbfd; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; font-size: 13px; }
.evidence-item .top { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.evidence-item .snippet { color: var(--text); line-height: 1.7; }
.evidence-item .full { display: none; white-space: pre-wrap; margin-top: 6px; color: var(--muted); }
.evidence-item.expanded .full { display: block; }

.ai-box { margin-top: 12px; background: #f8faff; border: 1px solid #dce5fb; border-radius: 10px; padding: 14px; }
.m-md-table-wrap { overflow-x: auto; margin: 10px 0; }
.m-md-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.m-md-table th, .m-md-table td {
    border: 1px solid #dce5fb; padding: 8px 10px;
    text-align: left; vertical-align: top; overflow-wrap: anywhere;
}
.m-md-table th { background: #eef3ff; font-weight: 700; }

/* ---------------------------------------------------------------- Modal / toast */

.modal-mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
[hidden] { display: none !important; }

.modal-mask {
  animation: modal-fade-in 0.16s ease-out;
}
.modal {
  position: relative;
  width: min(560px, 100%);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
  padding: 22px;
  max-height: 82vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  animation: modal-pop-in 0.18s ease-out;
}
.modal-md { width: min(640px, 100%); }
.modal-compact { width: min(440px, 100%); }
.modal h3 { font-size: 17px; margin-bottom: 4px; padding-right: 28px; }
.modal .sub { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.modal .folder-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 220px; overflow: auto; }
.folder-pick {
  display: flex; align-items: center; gap: 9px; border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; cursor: pointer; font-size: 13px;
}
.folder-pick:hover { border-color: #b9c9ef; }
.folder-pick.selected { border-color: var(--primary); background: var(--primary-soft); }
.folder-pick input { accent-color: var(--primary); }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.modal-close { position: relative; }
.modal-x {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font-size: 23px; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
}
.modal-x:hover { background: #eef1f7; color: var(--text); }
.dialog-head { display: flex; gap: 12px; align-items: flex-start; padding-right: 28px; }
.dialog-head h3 { padding-right: 0; }
.dialog-head .sub { margin-bottom: 0; }
.dialog-icon {
  flex: 0 0 36px; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-size: 18px; font-weight: 700;
  color: var(--primary-dark); background: var(--primary-soft);
}
.dialog-icon.danger { color: #b91c1c; background: var(--red-soft); }
.dialog-message {
  margin: 14px 0 2px; font-size: 13.5px; line-height: 1.7;
  color: var(--text); white-space: pre-line; overflow-wrap: anywhere;
}
.dialog-form .field { margin-bottom: 4px; }
.field-error { color: var(--red); font-size: 12px; line-height: 1.5; margin-top: 6px; }
.input-error { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.08); }
.paper-actions { margin-top: auto; padding-top: 4px; }

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: #1c2434;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: min(560px, 90vw);
  text-align: center;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.28);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

/* ---------------------------------------------------------------- Alert */

.alert { border-radius: 10px; padding: 11px 14px; font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); border-color: #d7e3ff; }
.alert-error { background: var(--red-soft); color: #991b1b; border-color: #f5cccc; }
.alert-success { background: var(--green-soft); color: #166534; border-color: #c4ecd4; }

/* ---------------------------------------------------------------- Misc */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.flex-wrap { flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 10%, #dbe6ff 0, transparent 45%),
              radial-gradient(circle at 85% 85%, #e4ecff 0, transparent 40%), var(--bg);
}
.login-card {
  width: min(410px, 100%);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(28, 36, 52, 0.14);
  padding: 34px 32px;
}
.login-card .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-card .logo-row .logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7aa2ff);
  color: #fff; display: grid; place-items: center; font-weight: 600;
}
.login-card h1 { font-size: 21px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 14px; margin-top: 6px; }
.login-foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 18px; }

.error-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; text-align: center; padding: 24px; }
.error-page .code { font-size: 74px; font-weight: 700; color: var(--primary); letter-spacing: -2px; }
.error-page h1 { margin: 8px 0; }

.hidden-file-input { display: none; }

.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-item {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; font-size: 13px; cursor: pointer; background: #fff;
}
.check-item:hover { border-color: #b9c9ef; background: #fbfcff; }
.check-item input { accent-color: var(--primary); }

.json-sample {
  background: #0f172a; color: #dbe6ff; border-radius: 10px;
  padding: 14px 16px; font-size: 12px; line-height: 1.6;
  overflow-x: auto; margin-top: 10px;
}
code {
  background: #eef1f7; border-radius: 5px; padding: 1px 5px;
  font-size: 12px; color: var(--primary-dark);
}

/* ---------------------------------------------------------------- Directory / import */

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.section-title h2 { font-size: 17px; }
.directory-list { display: flex; flex-direction: column; gap: 16px; }
.directory-card .dir-title h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.directory-card .dir-title p { margin-top: 4px; }
.dir-link { font-weight: 500; }
.dir-actions { justify-content: flex-end; flex-wrap: nowrap; }
.directory-table td, .directory-table th { white-space: nowrap; }
.directory-table td:nth-child(2) { white-space: normal; min-width: 180px; }
.child-empty {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  flex-wrap: wrap; padding: 18px 10px; color: var(--muted); font-size: 13px;
}

.step-card { padding: clamp(16px, 1.3vw, 24px); }
.step-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.step-head h2 { font-size: 16px; margin-bottom: 2px; }
.step-head p { line-height: 1.5; }
.step-no {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 999px;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
}
.subject-state { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }

.import-layout { grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); align-items: start; }
.import-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.import-main > .card + .card { margin-top: 0; }
.import-side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.import-side > .card + .card { margin-top: 0; }
.import-tabs { margin-bottom: 16px; }
.tab-panel { min-width: 0; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 28px 18px; border: 2px dashed var(--border); border-radius: 12px;
  background: #fafbfd; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-icon { font-size: 26px; color: var(--primary); line-height: 1; }
.dropzone-title { font-size: 14px; font-weight: 600; }

.file-chosen { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.file-chosen-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.file-chosen ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-chosen li { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.file-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-size-bad { color: var(--red); font-weight: 600; }

.code-input {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 13px; line-height: 1.6;
}
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.label-row label { margin-bottom: 0; }
.status-line { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.status-line.ok { color: var(--green); }
.status-line.bad { color: var(--red); }

.report-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); gap: 10px; }
.report-stat { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fafbfd; }
.report-stat span { display: block; color: var(--muted); font-size: 12px; }
.report-stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.warning-box {
  margin-top: 14px; border: 1px solid #f2dca6; background: var(--amber-soft);
  border-radius: 10px; padding: 12px 14px;
}
.warning-box h3 { font-size: 13px; color: var(--amber); margin-bottom: 6px; }
.warning-box ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.warning-box .warning-list {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 12px;
}
.type-counts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.type-counts .badge b { font-variant-numeric: tabular-nums; }

.step-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step-list li { display: flex; gap: 10px; font-size: 13px; line-height: 1.6; color: var(--text); }
.step-list .n {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-size: 11px; font-weight: 600; margin-top: 1px;
}
.tip-list { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.7; color: var(--muted); }
.import-details { margin-top: 12px; }
.import-details summary { cursor: pointer; font-size: 13px; color: var(--primary-dark); }
.import-details .json-sample { margin-top: 8px; }

body.modal-open { overflow: hidden; }
.modal-mask[hidden] { display: none; }

/* ---------------------------------------------------------------- Mobile shell */

.mobile-tabbar, .mobile-sheet-mask { display: none; }
.btn-block { width: 100%; }
.mobile-sheet-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mobile-sheet-links a {
  display: flex; align-items: center; gap: 10px; padding: 14px 12px;
  border: 1px solid var(--border); border-radius: 12px; color: var(--text);
  font-size: 14px; font-weight: 500;
}
.mobile-sheet-links a span {
  width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center;
  border-radius: 9px; background: var(--primary-soft); color: var(--primary-dark);
}
.mobile-sheet-user {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 16px 0 12px; padding-top: 14px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 13px;
}
.mobile-sheet-user form { margin: 0; }

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 1180px) {
  .grid.dashboard-analysis { grid-template-columns: 1fr; }
  .search-form { grid-template-columns: minmax(200px, 1fr) minmax(130px, 170px) auto auto; }
}

@media (max-width: 980px) {
  .grid.question-layout { grid-template-columns: 1fr; }
  .grid.import-layout { grid-template-columns: 1fr; }
  .import-side { position: static; }
}

@media (max-width: 980px) {
  .exam-layout { grid-template-columns: 1fr; }
  .answer-card { position: static; }
  .answer-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
  .topbar-tools { width: 100%; }
  .topbar-search { flex: 1; }
  .topbar-search input { width: 100%; }
}

@media (max-width: 760px) {
  body { font-size: 15px; }
  .layout { display: block; }
  .sidebar { display: none; }

  .main {
    padding: 12px 12px calc(92px + env(safe-area-inset-bottom));
  }
  .topbar { gap: 10px; margin-bottom: 14px; }
  .topbar h1 { font-size: 21px; }
  .topbar .sub { font-size: 12px; }
  .topbar-tools { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; }
  .topbar-search { width: 100%; }
  .topbar-search input { width: 100%; flex: 1; }
  .topbar-search .btn { min-height: 42px; }
  .topbar-user { justify-content: space-between; padding: 0 2px; }
  .topbar-user.global-user { display: none; }
  .breadcrumb {
    font-size: 12px; white-space: nowrap; overflow-x: auto;
    scrollbar-width: none; padding-bottom: 3px;
  }
  .breadcrumb::-webkit-scrollbar { display: none; }

  .card { padding: 14px; border-radius: 14px; box-shadow: 0 3px 14px rgba(28, 36, 52, 0.05); }
  .card + .card { margin-top: 12px; }
  .card-head { gap: 8px; margin-bottom: 12px; }
  .card-head h2 { font-size: 15px; }
  .grid { gap: 12px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4,
  .grid.dashboard-analysis, .grid.question-layout { grid-template-columns: 1fr; }
  .section-title { align-items: flex-start; }

  .home-actions { grid-template-columns: 1fr; gap: 10px; }
  .home-action { padding: 14px; }
  .home-action-ico { width: 42px; height: 42px; flex-basis: 42px; font-size: 19px; }
  .train-hero-side { width: 100%; align-items: stretch; }
  .scope-pills { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .scope-pill { padding: 7px 6px; }
  .train-hero-actions { justify-content: space-between; }
  .home-continue .flex-between { flex-direction: column; align-items: stretch; gap: 12px; }
  .home-continue .btn { width: 100%; }
  .card > .flex-between { flex-direction: column; align-items: stretch; gap: 12px; }
  .card > .flex-between .btn-row {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px; width: 100%;
  }
  .card > .flex-between .btn-row .btn { width: 100%; }
  .card > .flex-between .btn-row .btn-primary { grid-column: 1 / -1; }
  .subject-card > .flex-between { flex-direction: row; align-items: center; gap: 8px; }
  .subject-card > .flex-between .badge { width: auto; align-self: center; flex: 0 0 auto; }
  .grid.stats-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stats-overview .stat-card { padding: 12px 14px; }
  .stats-overview .stat-card .value { font-size: 24px; }
  .paper-primary-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .paper-primary-actions .btn { width: 100%; }
  .paper-primary-actions .btn-primary { grid-column: 1 / -1; }
  .paper-secondary-links { gap: 14px; }

  .form-row, .form-grid { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .form-row > .field, .form-grid > .field { min-width: 0; width: 100%; }
  .toolbar { display: grid; grid-template-columns: 1fr; gap: 10px; }
  .toolbar > .history-filter { max-width: none; }
  .toolbar-actions { grid-column: 1 / -1; justify-content: stretch; }
  .toolbar-actions .btn { flex: 1; }
  .search-form { grid-template-columns: 1fr; }
  .search-form .btn { height: 42px; }

  .papers-grid, .questions-grid { grid-template-columns: 1fr; gap: 12px; }
  .paper-card .foot { align-items: stretch; }
  .paper-card-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .paper-card-actions .btn { width: 100%; }
  .paper-card-links { gap: 16px; }
  .wrong-filter { width: 100%; }
  .wrong-filter select { width: 100%; }
  .paper-card .btn-row {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px; width: 100%;
  }
  .paper-card .btn-row .btn-primary { grid-column: 1 / -1; }
  .paper-card .btn-row form { display: block !important; margin: 0; }
  .paper-card .btn-row .btn { width: 100%; }
  .paper-card .btn-row .btn-ghost,
  .question-card-actions .btn-ghost { border-color: var(--border); }
  .question-card-actions {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  }
  .question-card-actions form { display: block !important; margin: 0; }
  .question-card-actions .btn { width: 100%; }

  .list-item { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 0; }
  .list-item .side { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .inline-form { width: 100%; }
  .inline-form input { flex: 1; width: auto; }
  .dir-actions { flex-wrap: wrap; justify-content: flex-start; }
  .directory-card .card-head { align-items: flex-start; }

  .tabs {
    overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a, .tabs button { white-space: nowrap; padding: 10px 14px; }

  .pager { justify-content: center; }
  .pager-info { width: 100%; text-align: center; }
  .pager-btns { justify-content: center; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; }
  .table { min-width: 680px; }
  .directory-table { min-width: 620px; }

  .exam-layout { grid-template-columns: 1fr; }
  .answer-card { position: static; }
  .answer-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .answer-grid button { min-height: 44px; }
  .option-list { gap: 9px; }
  .option-item { padding: 13px 14px; min-height: 52px; }
  .exam-nav { gap: 8px; }
  .question-head .btn-row { width: 100%; }
  .bar-chart { gap: 4px; }
  .trend-chart .bar:nth-child(even) span { visibility: hidden; }
  .trend-chart .bar span { font-size: 9px; }
  .keyboard-hint { display: none; }

  input[type="text"], input[type="password"], input[type="number"], input[type="search"],
  input[type="email"], input[type="url"], select, textarea {
    font-size: 16px; min-height: 44px;
  }
  textarea { min-height: 112px; }
  .btn { min-height: 42px; padding: 9px 14px; }
  .btn-sm { min-height: 36px; }
  .dropzone { padding: 24px 14px; }

  .modal-mask { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%; max-width: none; max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    padding: 20px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .modal-actions { display: flex; flex-direction: column; gap: 10px; }
  .modal-actions > span { display: none; }
  .modal-actions .btn-row { display: flex; gap: 8px; width: 100%; }
  .modal-actions .btn-row .btn { flex: 1; width: auto; }
  .toast {
    left: 14px; right: 14px; bottom: calc(84px + env(safe-area-inset-bottom));
    max-width: none; text-align: center; transform: translateY(20px);
  }
  .toast.show { transform: translateY(0); }

  .login-page { padding: 16px; }
  .login-card { padding: 26px 18px; border-radius: 16px; }
  .login-card .sub { margin-bottom: 20px; }

  .mobile-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 28px rgba(28, 36, 52, 0.08);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
  .mobile-tabbar a, .mobile-tabbar button {
    flex: 1; min-width: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    padding: 6px 2px; border: 0; border-radius: 10px; background: none;
    color: #7b8496; font: inherit; font-size: 11px; line-height: 1.2;
    text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .mobile-tabbar a.active, .mobile-tabbar button.active {
    color: var(--primary); background: var(--primary-soft);
  }
  .mobile-tabbar .tab-ico { font-size: 19px; line-height: 1; }

  .mobile-sheet-mask { display: flex; }
  .mobile-sheet { padding-top: 18px; }
  .mobile-sheet .mobile-sheet-links { margin-top: 4px; }
}

body:not(.show-history-scores) .history-score { display: none; }

@media (max-width: 480px) {
  .toolbar { grid-template-columns: 1fr; }
  .stat-card .value { font-size: 26px; }
  .result-score { font-size: 36px; }
  .exam-nav .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
