/*
 * Exam Hub · 个人学习图书馆共享样式（书架、实体书本、多层级折叠动画、弹窗与移动端适配）
 * 设计纪律：米白护眼底色、零蓝紫渐变、零卡片套娃、手机端优先防溢出/防拥挤。
 */

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-size-base);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

/* ==================== 统一顶部导航栏 ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  min-height: 52px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-title-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: var(--text);
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.01em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark {
  display: inline-block;
  width: 9px;
  height: 18px;
  border-radius: 2px 3px 3px 2px;
  background: var(--accent);
  box-shadow: inset 2px 0 0 rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* 统一按钮 */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  line-height: 1.3;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

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

.btn-accent {
  background: var(--accent-soft);
  border-color: var(--amber-border);
  color: var(--accent);
}

.btn-accent:hover:not(:disabled) {
  background: var(--amber-border);
  color: var(--text);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 7px;
}

.btn-danger {
  color: var(--red);
  border-color: var(--red-border);
  background: var(--red-soft);
}

.btn-compact {
  max-width: 108px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill-badge {
  background: var(--red-soft);
  color: var(--red);
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.page-container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 22px 16px calc(68px + env(safe-area-inset-bottom));
}

/* ==================== 继续上次复习快捷条（单层轻量条） ==================== */
.resume-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  margin-bottom: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3.5px solid var(--accent);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, background 0.14s ease;
}

.resume-strip:hover {
  border-color: var(--border-strong);
  border-left-color: var(--accent);
  background: var(--surface-2);
}

.resume-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.resume-kicker {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.resume-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-cta {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ==================== 实体书架与精装书本 ==================== */
.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.shelf-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.shelf-title {
  margin: 0;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.shelf-sub {
  font-size: 12.5px;
  color: var(--text-3);
}

.shelf-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 书架分区（无外层大框，仅以底部分隔木条承载书本） */
.shelf-group {
  margin-bottom: 28px;
}

.shelf-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}

.shelf-group-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text-2);
  background: none;
  border: none;
  padding: 2px 0;
}

.shelf-group-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 响应式书本网格：手机端 2 列、平板 3-4 列、桌面 4-5 列 */
.bookshelf-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px 20px;
  padding: 6px 4px 18px;
  border-bottom: 5px solid var(--shelf-wood);
  box-shadow: 0 5px 10px -8px var(--shelf-shadow);
}

@media (max-width: 960px) {
  .bookshelf-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px 16px;
  }
}

@media (max-width: 560px) {
  .bookshelf-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 14px;
    padding: 4px 2px 16px;
  }
}

/* 单本书容器（无边框外框，书本本身即主体） */
.book-slot {
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* 实体精装书本视觉：左侧书脊 + 封面 + 右侧纸页厚度 + 克制阴影 */
.book-cover {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  aspect-ratio: 3 / 3.85;
  min-height: 158px;
  padding: 18px 14px 18px 26px;
  border-radius: 3px 8px 8px 3px;
  text-decoration: none;
  background-color: var(--b-cover, var(--book-ochre-cover));
  color: var(--b-ink, var(--book-ochre-ink));
  border: 1px solid rgba(30, 24, 16, 0.1);
  border-right: 4px solid var(--page-edge);
  box-shadow:
    inset 14px 0 0 var(--b-spine, var(--book-ochre-spine)),
    inset 16px 0 0 rgba(0, 0, 0, 0.14),
    inset 17px 0 0 rgba(255, 255, 255, 0.22),
    inset -1px 0 0 var(--page-edge-line),
    var(--shadow-book);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  overflow: hidden;
}

.book-cover::after {
  /* 底部纸页微边 */
  content: "";
  position: absolute;
  left: 14px;
  right: 0;
  bottom: 0;
  height: 4px;
  background: var(--page-edge);
  border-top: 1px solid var(--page-edge-line);
  pointer-events: none;
}

.book-cover:hover {
  transform: translateY(-3px);
  box-shadow:
    inset 14px 0 0 var(--b-spine, var(--book-ochre-spine)),
    inset 16px 0 0 rgba(0, 0, 0, 0.14),
    inset 17px 0 0 rgba(255, 255, 255, 0.22),
    inset -1px 0 0 var(--page-edge-line),
    var(--shadow-book-hover);
}

.book-cover:active {
  transform: translateY(-1px);
}

/* 8 色书本主题映射 */
.book-c-ochre      { --b-cover: var(--book-ochre-cover);      --b-spine: var(--book-ochre-spine);      --b-ink: var(--book-ochre-ink); }
.book-c-sage       { --b-cover: var(--book-sage-cover);       --b-spine: var(--book-sage-spine);       --b-ink: var(--book-sage-ink); }
.book-c-slate      { --b-cover: var(--book-slate-cover);      --b-spine: var(--book-slate-spine);      --b-ink: var(--book-slate-ink); }
.book-c-terracotta { --b-cover: var(--book-terracotta-cover); --b-spine: var(--book-terracotta-spine); --b-ink: var(--book-terracotta-ink); }
.book-c-teal       { --b-cover: var(--book-teal-cover);       --b-spine: var(--book-teal-spine);       --b-ink: var(--book-teal-ink); }
.book-c-olive      { --b-cover: var(--book-olive-cover);      --b-spine: var(--book-olive-spine);      --b-ink: var(--book-olive-ink); }
.book-c-walnut     { --b-cover: var(--book-walnut-cover);     --b-spine: var(--book-walnut-spine);     --b-ink: var(--book-walnut-ink); }
.book-c-plum       { --b-cover: var(--book-plum-cover);       --b-spine: var(--book-plum-spine);       --b-ink: var(--book-plum-ink); }

/* 书本封面文字：极简克制，防异常换行与溢出 */
.book-cover-title {
  font-family: var(--font-serif);
  font-size: 16.5px;
  font-weight: 800;
  line-height: 1.45;
  letter-spacing: 0.01em;
  color: inherit;
  word-break: normal;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 100%;
}

/* 仅用于首选模拟卷的细小书签缎带 */
.book-ribbon {
  position: absolute;
  top: 0;
  right: 12px;
  background: var(--b-spine, var(--accent));
  color: #fffdf8;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 6px 5px;
  border-radius: 0 0 4px 4px;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

/* 每本书下方的独立学习进度条与百分比 */
.book-prog {
  margin-top: 9px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.book-prog-track {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.book-prog-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--b-spine, var(--accent));
  transition: width 0.28s ease;
}

.book-prog-pct {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: right;
  flex-shrink: 0;
}

/* 科目内部书本下方的轻量模式入口（如 做题/背题/刷题，仅一行不拥挤） */
.book-quick-modes {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.book-mode-link {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.book-mode-link:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-2);
}

/* 整理书架模式下的操控条（常规浏览隐藏，零视觉干扰） */
.book-manage-bar {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  flex-wrap: wrap;
}

.book-manage-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}

.book-manage-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* 收纳后的书本 / 科目条 */
.folded-shelf-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.folded-book-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--b-spine, var(--accent));
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s ease;
}

.folded-book-strip:hover {
  background: var(--surface-2);
}

.folded-strip-main {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.folded-strip-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
}

.folded-strip-summary {
  font-size: 12.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.folded-strip-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* 色板选择器 */
.swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
}

.swatch-dot.active {
  border-color: var(--text);
  transform: scale(1.08);
}

/* ==================== 统一多层级折叠收纳组件 ==================== */
.eh-fold {
  position: relative;
}

.eh-fold-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.eh-fold-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 11px;
  flex-shrink: 0;
  transition: transform var(--fold-dur) var(--fold-ease), background 0.14s ease;
}

.eh-fold-toggle-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.eh-fold.is-collapsed > .eh-fold-head .eh-fold-toggle-btn,
.eh-fold.is-collapsed .eh-fold-chevron {
  transform: rotate(-90deg);
}

.eh-fold-chevron {
  display: inline-block;
  font-size: 11px;
  color: var(--text-3);
  transition: transform var(--fold-dur) var(--fold-ease);
  flex-shrink: 0;
}

.eh-fold-cue {
  display: none;
  margin-top: 5px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.55;
}

.eh-fold.is-collapsed > .eh-fold-cue,
.eh-fold.is-collapsed > .eh-fold-head .eh-fold-cue {
  display: block;
}

.eh-fold-summary {
  display: inline;
  color: var(--text-2);
}

.eh-fold-kws {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.eh-kw-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.eh-edit-summary-btn {
  border: none;
  background: transparent;
  color: var(--text-3);
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1;
}

.eh-edit-summary-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* 零卡顿 Grid 折叠动画容器（smooth / book / folder / fade / none） */
.eh-fold-body {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transform: none;
  transform-origin: top center;
  transition:
    grid-template-rows var(--fold-dur) var(--fold-ease),
    opacity var(--fold-dur) var(--fold-ease),
    transform var(--fold-dur) var(--fold-ease);
}

.eh-fold-inner {
  overflow: hidden;
  min-height: 0;
}

.eh-fold.is-collapsed > .eh-fold-body {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
}

/* 书本合拢动画 */
[data-collapse-anim="book"] .eh-fold.is-collapsed > .eh-fold-body {
  transform: perspective(900px) rotateX(-14deg) scaleY(0.95);
}

/* 文件夹收纳动画 */
[data-collapse-anim="folder"] .eh-fold.is-collapsed > .eh-fold-body {
  transform: translateY(-8px) scale(0.985);
}

/* 淡入淡出动画 */
[data-collapse-anim="fade"] .eh-fold-body {
  transition: opacity var(--fold-dur) ease, grid-template-rows var(--fold-dur) ease;
}

/* 无动画模式 */
[data-collapse-anim="none"] .eh-fold-body,
[data-collapse-anim="none"] .eh-fold-toggle-btn,
[data-collapse-anim="none"] .eh-fold-chevron {
  transition: none !important;
  transform: none !important;
}

/* ==================== 显式复习确认按钮（独立于折叠/掌握） ==================== */
.review-check-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.review-check-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.review-check-btn.done {
  background: var(--green-soft);
  border-color: var(--green-border);
  color: var(--green);
}

/* ==================== 原位返回高亮提示 ==================== */
@keyframes ehReturnPulse {
  0% {
    box-shadow: 0 0 0 2px var(--accent), 0 0 0 6px var(--accent-soft);
  }
  70% {
    box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px transparent;
  }
  100% {
    box-shadow: none;
  }
}

.eh-return-highlight {
  animation: ehReturnPulse 1.75s ease-out;
  border-color: var(--accent) !important;
}

/* ==================== 通用轻量弹窗 ==================== */
.eh-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 18, 0.48);
  z-index: 95;
  place-items: center;
  padding: 16px;
}

.eh-modal-backdrop.open {
  display: grid;
}

.eh-modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow-md);
}

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

.eh-modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.eh-modal-field {
  margin-bottom: 14px;
}

.eh-modal-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 6px;
}

.eh-input {
  width: 100%;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.eh-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.eh-seg-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.eh-seg-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

.eh-seg-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.eh-modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* Toast 提示 */
.eh-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(14px);
  background: var(--primary);
  color: var(--on-primary);
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 105;
  white-space: nowrap;
}

.eh-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== 手机端精细适配（防挤占、防异常换行、防横向溢出） ==================== */
@media (max-width: 640px) {
  .topbar-inner {
    padding: 7px 12px;
    gap: 6px;
  }
  .brand-title-link {
    font-size: 14.5px;
  }
  .btn {
    padding: 5px 8px;
    font-size: 12px;
  }
  .btn-compact {
    max-width: 82px;
  }
  .page-container {
    padding: 16px 12px calc(60px + env(safe-area-inset-bottom));
  }
  .shelf-title {
    font-size: 18.5px;
  }
  .book-cover {
    min-height: 144px;
    padding: 14px 11px 14px 22px;
    box-shadow:
      inset 11px 0 0 var(--b-spine, var(--book-ochre-spine)),
      inset 13px 0 0 rgba(0, 0, 0, 0.14),
      inset 14px 0 0 rgba(255, 255, 255, 0.22),
      inset -1px 0 0 var(--page-edge-line),
      var(--shadow-book);
  }
  .book-cover::after {
    left: 11px;
  }
  .book-cover-title {
    font-size: 15px;
    line-height: 1.42;
  }
  .hide-xs {
    display: none !important;
  }
}
