/* =========================================================
   研题 · 练习空间
   Lavender glass study workspace
   ========================================================= */

:root {
  --bg: #f4f0ff;
  --ink: #2c2842;
  --ink-soft: #575170;
  --muted: #8d87a5;
  --line: #e8e2f6;
  --line-strong: #dcd3f0;
  --card: rgba(255, 255, 255, 0.9);
  --white: #ffffff;
  --primary: #7a5cf0;
  --primary-2: #a183ff;
  --primary-soft: #f0ebff;
  --primary-line: #cfc2f7;
  --green: #2fae83;
  --green-soft: #e9f8f1;
  --red: #e26276;
  --red-soft: #fdeef1;
  --amber: #b8842d;
  --shadow: 0 14px 38px rgba(81, 61, 155, 0.10);
  --shadow-soft: 0 6px 18px rgba(81, 61, 155, 0.07);
  --radius: 20px;
  --sidebar-w: 258px;
  --topbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 620px at 6% -4%, #e3d8ff 0%, rgba(227, 216, 255, 0) 62%),
    radial-gradient(820px 620px at 102% 104%, #ddd2ff 0%, rgba(221, 210, 255, 0) 58%),
    radial-gradient(600px 420px at 72% 8%, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0) 70%),
    linear-gradient(135deg, #f7f3ff 0%, #efe9ff 52%, #f8f5ff 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

::selection { background: rgba(122, 92, 240, 0.2); }

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

.app-shell {
  position: relative;
  display: flex;
  height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(42, 32, 80, 0.32);
  backdrop-filter: blur(3px);
  animation: fade-in 0.2s ease both;
}
.drawer-mask[hidden] { display: none; }

/* ---------- sidebar ---------- */

.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  flex-direction: column;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100%;
  padding: 22px 15px 15px;
  background: rgba(255, 255, 255, 0.72);
  border-right: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 8px 0 32px rgba(81, 61, 155, 0.05);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 6px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, #7454e8 0%, #a98bff 100%);
  box-shadow: 0 8px 18px rgba(122, 92, 240, 0.34);
}

.brand-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand-copy strong { font-size: 19px; letter-spacing: 0.02em; }
.brand-copy span { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

.sidebar > .brand .icon-btn { margin-left: auto; }

.tabs {
  display: flex;
  gap: 4px;
  margin: 22px 4px 15px;
  padding: 4px;
  border-radius: 11px;
  background: rgba(122, 92, 240, 0.07);
}

.tab {
  flex: 1;
  padding: 8px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.tab.is-active {
  color: var(--primary);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(81, 61, 155, 0.09);
}

.side-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 9px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}
.library-count {
  min-width: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(122, 92, 240, 0.08);
  color: var(--primary);
  font-size: 10.5px;
  text-align: center;
}

.library-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 6px;
  scrollbar-width: thin;
  scrollbar-color: #d6ccef transparent;
}
.library-list::-webkit-scrollbar { width: 5px; }
.library-list::-webkit-scrollbar-thumb { background: #d6ccef; border-radius: 999px; }

.library-empty {
  padding: 26px 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  text-align: center;
}
.library-empty strong { display: block; color: var(--ink-soft); font-size: 13px; margin-bottom: 3px; }

.library-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  margin-bottom: 5px;
  padding: 10px 9px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease;
}
.library-item:hover { background: rgba(255, 255, 255, 0.62); }
.library-item.is-active {
  border-color: rgba(122, 92, 240, 0.18);
  background: rgba(122, 92, 240, 0.09);
}

.library-icon {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: var(--primary);
  background: rgba(122, 92, 240, 0.09);
}
.library-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.library-copy { flex: 1; min-width: 0; padding-top: 1px; }
.library-title {
  display: block;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-item.is-active .library-title { color: var(--ink); }
.library-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 10.5px; }

.item-more {
  flex: 0 0 auto;
  padding: 2px 3px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.library-item:hover .item-more,
.library-item.is-active .item-more { opacity: 1; }
.item-more:hover { background: rgba(122, 92, 240, 0.12); color: var(--primary); }

.item-menu {
  position: absolute;
  top: 34px;
  right: 6px;
  z-index: 20;
  min-width: 100px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(60, 45, 120, 0.16);
}
.item-menu button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  text-align: left;
}
.item-menu button:hover { background: var(--primary-soft); color: var(--primary); }
.item-menu button.danger:hover { background: var(--red-soft); color: var(--red); }

.upload-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed #cabdf0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.45);
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.upload-trigger:hover { border-color: var(--primary); background: rgba(255, 255, 255, 0.85); }
.upload-plus { font-size: 15px; line-height: 1; transform: translateY(-1px); }

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 13px 7px 2px;
  border-top: 1px solid rgba(122, 92, 240, 0.08);
}
.back-link { color: var(--ink-soft); font-size: 11.5px; transition: color 0.16s ease; }
.back-link:hover { color: var(--primary); }
.local-note { color: #a9a3bc; font-size: 10.5px; }

.more-card {
  margin: 2px 2px 10px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow-soft);
}
.more-card strong { display: block; margin-bottom: 5px; font-size: 13px; }
.more-card p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.8; }
.more-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 16px;
}
.more-card-ghost { background: rgba(255, 255, 255, 0.38); }

/* ---------- main ---------- */

.main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  flex: 0 0 var(--topbar-h);
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 26px;
  border-bottom: 1px solid rgba(122, 92, 240, 0.08);
  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.crumb strong { overflow: hidden; color: var(--ink); font-size: 12.5px; font-weight: 600; text-overflow: ellipsis; }
.crumb-sep { color: #c5bdd8; }

.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.status-pill {
  padding: 5px 10px;
  border: 1px solid rgba(122, 92, 240, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.status-pill.is-running { color: var(--primary); border-color: rgba(122, 92, 240, 0.22); background: var(--primary-soft); }
.status-pill.is-submitted { color: var(--green); border-color: rgba(47, 174, 131, 0.2); background: var(--green-soft); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 236px;
  align-items: start;
  gap: 22px;
  flex: 1;
  min-height: 0;
  padding: 24px 26px 40px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d6ccef transparent;
}
.workspace::-webkit-scrollbar { width: 6px; }
.workspace::-webkit-scrollbar-thumb { background: #d6ccef; border-radius: 999px; }

/* ---------- paper ---------- */

.paper {
  width: 100%;
  max-width: 900px;
  min-width: 0;
  margin: 0 auto;
}

.paper-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 3px 16px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.paper-title-block h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

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

.paper-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; padding-top: 4px; }

.chip {
  display: inline-flex;
  align-items: center;
  height: 23px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 10.5px;
  white-space: nowrap;
}
.chip-saved { color: var(--green); background: var(--green-soft); border-color: rgba(47, 174, 131, 0.14); }
.chip-draft { color: #9b7a2e; background: #fbf4e3; border-color: rgba(184, 132, 45, 0.13); }
.chip-submitted { color: var(--primary); background: var(--primary-soft); border-color: rgba(122, 92, 240, 0.16); }

.paper-toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 11px;
  padding: 0 3px;
}
.type-badge {
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
}
.score-badge {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  font-size: 10.5px;
}
.toolbar-spacer { flex: 1; }

.tool-btn {
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  transition: color 0.16s ease, background 0.16s ease;
}
.tool-btn:hover { color: var(--primary); background: rgba(255, 255, 255, 0.6); }
.tool-btn.is-on { color: var(--primary); background: var(--primary-soft); }

.question-card {
  padding: 26px 30px 24px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.question-topline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 17px;
  color: var(--muted);
  font-size: 10.5px;
}
.question-topline .dot { width: 3px; height: 3px; border-radius: 50%; background: #c8c0dc; }

.stem {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.95;
  overflow-wrap: anywhere;
}
.stem .katex-display { margin: 0.55em 0; }
.stem p { margin: 0 0 8px; }
.stem p:last-child { margin-bottom: 0; }

.options { display: grid; gap: 9px; margin-top: 21px; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
.option:hover:not(:disabled) { border-color: var(--primary-line); background: #fff; }
.option:disabled { cursor: default; }
.option.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(122, 92, 240, 0.06);
}
.option.is-correct {
  border-color: rgba(47, 174, 131, 0.5);
  background: var(--green-soft);
}
.option.is-wrong {
  border-color: rgba(226, 98, 118, 0.45);
  background: var(--red-soft);
}

.option-letter {
  display: grid;
  place-items: center;
  flex: 0 0 25px;
  width: 25px;
  height: 25px;
  margin-top: 1px;
  border: 1px solid #dcd4ee;
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.option.is-selected .option-letter { border-color: var(--primary); background: var(--primary); color: #fff; }
.option.is-correct .option-letter { border-color: var(--green); background: var(--green); color: #fff; }
.option.is-wrong .option-letter { border-color: var(--red); background: var(--red); color: #fff; }

.option-text { flex: 1; min-width: 0; padding-top: 2px; font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; }

.answer-box { margin-top: 21px; }

.answer-input,
.answer-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.answer-input::placeholder,
.answer-textarea::placeholder { color: #b4aec5; }
.answer-input:focus,
.answer-textarea:focus { border-color: var(--primary-line); box-shadow: 0 0 0 3px rgba(122, 92, 240, 0.08); }
.answer-textarea { min-height: 112px; resize: vertical; }
.answer-input:disabled,
.answer-textarea:disabled { color: var(--ink-soft); background: rgba(246, 243, 253, 0.72); }

.question-hint {
  margin-top: 16px;
  padding: 10px 13px;
  border-radius: 10px;
  background: rgba(122, 92, 240, 0.05);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

.analysis {
  margin-top: 22px;
  padding-top: 17px;
  border-top: 1px dashed var(--line-strong);
}
.analysis-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}
.analysis-head::before {
  content: "";
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--primary);
}
.analysis-correct { color: var(--green); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.analysis-body {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.question-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding-top: 15px;
  border-top: 1px solid rgba(122, 92, 240, 0.07);
}
.question-actions .spacer { flex: 1; }

.question-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding: 0 3px;
}
.question-index { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* ---------- result ---------- */

.result-card {
  margin-top: 18px;
  padding: 24px 26px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(244, 239, 255, 0.92));
  box-shadow: var(--shadow);
}
.result-top { display: flex; align-items: center; gap: 14px; }
.result-score {
  display: flex;
  align-items: baseline;
  gap: 2px;
  color: var(--primary);
  font-weight: 700;
}
.result-score b { font-size: 34px; line-height: 1; letter-spacing: -0.03em; }
.result-score small { font-size: 12px; color: var(--muted); font-weight: 500; }
.result-copy strong { display: block; font-size: 14px; }
.result-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.result-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- outline ---------- */

.outline-panel {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--topbar-h) - 48px);
  padding: 15px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.outline-head { display: flex; align-items: center; justify-content: space-between; padding: 1px 2px 11px; }
.outline-head strong { font-size: 12.5px; }
.outline-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 10px;
  scrollbar-width: thin;
  scrollbar-color: #d6ccef transparent;
}
.outline-body::-webkit-scrollbar { width: 5px; }
.outline-body::-webkit-scrollbar-thumb { background: #d6ccef; border-radius: 999px; }

.outline-group { margin-bottom: 12px; }
.outline-group-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10.5px;
}
.outline-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }

.outline-num {
  display: grid;
  place-items: center;
  aspect-ratio: 1.25;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}
.outline-num:hover { border-color: var(--primary-line); color: var(--primary); }
.outline-num.is-answered { border-color: rgba(47, 174, 131, 0.32); background: var(--green-soft); color: var(--green); }
.outline-num.is-current { border-color: var(--primary); background: var(--primary); color: #fff; box-shadow: 0 4px 10px rgba(122, 92, 240, 0.28); }
.outline-num.is-correct { border-color: rgba(47, 174, 131, 0.5); background: var(--green); color: #fff; }
.outline-num.is-wrong { border-color: rgba(226, 98, 118, 0.4); background: var(--red-soft); color: var(--red); }

.outline-foot { padding-top: 9px; border-top: 1px solid rgba(122, 92, 240, 0.08); }
.progress-track { height: 5px; border-radius: 999px; background: rgba(122, 92, 240, 0.1); overflow: hidden; }
.progress-fill { width: 0; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #8a6df2, #b49aff); transition: width 0.25s ease; }
.outline-stats { display: flex; justify-content: space-between; gap: 8px; margin: 8px 0 10px; color: var(--muted); font-size: 10.5px; }
.outline-stats b { color: var(--ink-soft); font-weight: 600; }
.outline-submit { width: 100%; }
.outline-reset { width: 100%; margin-top: 6px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 33px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  transition: background 0.17s ease, border-color 0.17s ease, color 0.17s ease, box-shadow 0.17s ease, transform 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #7a5cf0, #9678ff);
  box-shadow: 0 6px 14px rgba(122, 92, 240, 0.25);
}
.btn-primary:hover { box-shadow: 0 8px 18px rgba(122, 92, 240, 0.32); }
.btn-primary:disabled { opacity: 0.45; box-shadow: none; cursor: default; }
.btn-ghost { color: var(--ink-soft); background: rgba(255, 255, 255, 0.55); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--primary-line); color: var(--primary); background: #fff; }
.btn-ghost:disabled { opacity: 0.45; cursor: default; }

.text-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: inherit;
  font-weight: 600;
}
.text-btn:hover { text-decoration: underline; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.7); color: var(--primary); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- empty ---------- */

.paper.is-empty .paper-head,
.paper.is-empty .paper-toolbar,
.paper.is-empty .question-nav,
.paper.is-empty .result-card { display: none; }

.question-card.is-empty {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.workspace.is-empty { grid-template-columns: minmax(0, 1fr); }
.workspace.is-empty .paper { max-width: 760px; }

.empty-paper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 340px;
  padding: 40px 22px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  text-align: center;
}
.empty-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 15px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 23px;
}
.empty-paper h2 { margin: 0 0 6px; font-size: 17px; }
.empty-paper p { max-width: 300px; margin: 0 0 17px; color: var(--muted); font-size: 12px; line-height: 1.8; }

/* ---------- modal ---------- */

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(42, 32, 80, 0.36);
  backdrop-filter: blur(5px);
  animation: fade-in 0.18s ease both;
}
.modal-card {
  width: min(500px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 26px 70px rgba(48, 34, 100, 0.28);
  animation: pop-in 0.2s ease both;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-head .eyebrow { margin-bottom: 3px; }

.dropzone {
  padding: 28px 20px;
  border: 1.5px dashed #cec1f1;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(248, 245, 255, 0.75), rgba(255, 255, 255, 0.7));
  text-align: center;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone p { margin: 5px 0; color: var(--ink-soft); font-size: 12.5px; }
.drop-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 20px;
}
.hint { color: var(--muted); font-size: 10.5px; line-height: 1.7; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; }

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

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  z-index: 200;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(42, 32, 80, 0.9);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 12px 30px rgba(30, 22, 60, 0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- utilities ---------- */

.is-hidden { display: none !important; }

.mobile-only { display: none !important; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.97) translateY(6px); } to { opacity: 1; transform: none; } }

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(122, 92, 240, 0.45);
  outline-offset: 2px;
}

.katex { font-size: 1.02em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 1px 0; }
.katex-display > .katex { white-space: normal; }

/* ---------- public wrong book ---------- */

.wrongs-side-card {
  margin: 2px 2px 10px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow-soft);
}
.wrongs-side-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 15px;
}
.wrongs-side-card strong { display: block; margin-bottom: 5px; font-size: 13px; }
.wrongs-side-card p { margin: 0 0 10px; color: var(--muted); font-size: 11.5px; line-height: 1.8; }
.wrongs-side-stats { margin-bottom: 10px; color: var(--ink-soft); font-size: 12px; }
.wrongs-side-stats b { color: var(--red); }
.wrongs-side-card .btn { width: 100%; margin-top: 5px; }

.wrongs-view {
  flex: 1;
  min-height: 0;
  padding: 26px 26px 48px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d6ccef transparent;
}
.wrongs-view::-webkit-scrollbar { width: 6px; }
.wrongs-view::-webkit-scrollbar-thumb { background: #d6ccef; border-radius: 999px; }

.wrongs-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  max-width: 980px;
  margin: 0 auto 20px;
}
.wrongs-title h1 { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.wrongs-title p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.wrongs-actions { display: flex; align-items: center; gap: 8px; }
.wrongs-select {
  min-width: 140px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink-soft);
  font-size: 12px;
  outline: none;
}
.wrongs-select:focus { border-color: var(--primary-line); }

.wrongs-list {
  display: grid;
  gap: 14px;
  max-width: 980px;
  margin: 0 auto;
}

.wrong-card {
  padding: 20px 22px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.wrong-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrong-card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-width: 0; }
.wrong-bank { color: var(--primary); font-size: 12px; font-weight: 600; }
.wrong-type {
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 10px;
}
.wrong-count {
  flex: 0 0 auto;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 10.5px;
  white-space: nowrap;
}
.wrong-index { margin-top: 7px; color: var(--muted); font-size: 10.5px; }
.wrong-stem {
  margin-top: 11px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.9;
  overflow-wrap: anywhere;
}
.wrong-options { display: grid; gap: 7px; margin-top: 13px; }
.wrong-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.65;
}
.wrong-option.is-correct { border-color: rgba(47, 174, 131, 0.35); background: var(--green-soft); }
.wrong-option-letter {
  display: grid;
  place-items: center;
  flex: 0 0 21px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #ddd5ee;
  color: var(--muted);
  font-size: 10px;
}
.wrong-option.is-correct .wrong-option-letter { background: var(--green); border-color: var(--green); color: #fff; }
.wrong-answer {
  margin-top: 13px;
  padding: 9px 12px;
  border-left: 3px solid var(--green);
  border-radius: 0 8px 8px 0;
  background: var(--green-soft);
  color: #1f6e54;
  font-size: 12.5px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.wrong-answer b { font-weight: 600; }
.wrong-top {
  margin-top: 8px;
  color: var(--red);
  font-size: 11.5px;
}
.wrong-analysis {
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.85;
  overflow-wrap: anywhere;
}
.wrong-analysis-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10.5px; letter-spacing: 0.04em; }
.wrong-actions { display: flex; justify-content: flex-end; margin-top: 13px; }

.wrongs-empty {
  max-width: 980px;
  margin: 0 auto;
  padding: 46px 22px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-soft);
  text-align: center;
}
.wrongs-empty h2 { margin: 0 0 6px; font-size: 17px; }
.wrongs-empty p { max-width: 380px; margin: 0 auto 16px; color: var(--muted); font-size: 12px; line-height: 1.8; }
.wrongs-loading { padding: 40px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- per-question comments ---------- */

.comments {
  margin-top: 20px;
  padding-top: 17px;
  border-top: 1px dashed var(--line-strong);
}
.comments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}
.comments-count { color: var(--primary); font-weight: 700; }
.comments-hint { color: var(--muted); font-size: 10px; font-weight: 400; }
.comments-empty { padding: 8px 0; color: var(--muted); font-size: 11.5px; }
.comment-list { display: grid; gap: 7px; }
.comment-item {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.48);
}
.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
}
.comment-meta strong { color: var(--ink-soft); font-weight: 600; }
.comment-text {
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.comment-form { display: grid; gap: 7px; margin-top: 10px; }
.comment-name,
.comment-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink);
  font-size: 12px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.comment-name::placeholder,
.comment-input::placeholder { color: #b4aec5; }
.comment-name:focus,
.comment-input:focus { border-color: var(--primary-line); box-shadow: 0 0 0 3px rgba(122, 92, 240, 0.07); }
.comment-input { min-height: 58px; resize: vertical; line-height: 1.7; }
.comment-submit { justify-self: end; min-width: 88px; }

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .outline-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    width: 284px;
    max-height: none;
    border-radius: 20px 0 0 20px;
    transform: translateX(108%);
    transition: transform 0.24s cubic-bezier(0.22, 0.8, 0.3, 1);
    background: rgba(255, 255, 255, 0.94);
  }
  .outline-panel.is-open { transform: translateX(0); }
  .outline-panel .mobile-only { display: inline-grid !important; }
  .outline-body { max-height: none; }
}

@media (max-width: 880px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 70;
    transform: translateX(-108%);
    transition: transform 0.24s cubic-bezier(0.22, 0.8, 0.3, 1);
    box-shadow: 18px 0 44px rgba(48, 34, 100, 0.18);
    background: rgba(255, 255, 255, 0.9);
  }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-only { display: inline-grid !important; }
  .topbar { padding: 0 14px; }
  .top-actions { gap: 6px; }
  .status-pill { display: none; }
  .workspace { padding: 16px 14px 34px; }
  .paper-title-block h1 { font-size: 20px; }
  .question-card { padding: 22px 20px 20px; border-radius: 18px; }
  .result-card { padding: 20px; }
  .paper-head { flex-direction: column; gap: 8px; }
  .paper-chips { justify-content: flex-start; padding-top: 0; }
}

@media (max-width: 560px) {
  .crumb { gap: 6px; font-size: 11.5px; }
  .crumb strong { font-size: 11.5px; max-width: 34vw; }
  .top-actions .btn-primary { padding: 7px 10px; font-size: 11.5px; }
  .top-actions .icon-btn { width: 29px; height: 29px; }
  .paper-title-block h1 { font-size: 18px; }
  .paper-meta { font-size: 10.5px; }
  .stem { font-size: 14px; line-height: 1.9; }
  .option { padding: 11px 12px; gap: 9px; }
  .option-text { font-size: 13px; }
  .option-letter { flex-basis: 23px; width: 23px; height: 23px; font-size: 10.5px; }
  .question-nav .btn { padding: 7px 10px; font-size: 11.5px; }
  .question-index { font-size: 10.5px; }
  .modal-card { padding: 18px; border-radius: 17px; }
  .modal-foot { flex-direction: column; align-items: flex-start; gap: 7px; }
  .result-top { flex-wrap: wrap; }
  .result-actions { width: 100%; margin-left: 0; }
  .result-actions .btn { flex: 1; }
}

@media (max-width: 880px) {
  .wrongs-view { padding: 16px 14px 34px; }
  .wrongs-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .wrongs-actions { width: 100%; }
  .wrongs-select { flex: 1; min-width: 0; }
  .wrong-card { padding: 16px; }
}

@media (max-width: 560px) {
  .wrongs-title h1 { font-size: 20px; }
  .wrongs-title p { font-size: 11px; }
  .wrong-card-head { align-items: flex-start; }
  .wrong-count { font-size: 10px; padding: 3px 7px; }
  .wrong-option { font-size: 12px; }
}
