:root {
  --bg: #f4ede1;
  --bg-soft: #fbf6ee;
  --ink: #2b2620;
  --ink-soft: #8a7f70;
  --shelf: #d9c7a8;
  --shelf-edge: #c2a878;
  --card: #ffffff;
  --accent: #c0392b;
  --shadow: 0 6px 18px rgba(80, 60, 30, .14);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- 顶部 ---------- */
.app-header {
  flex: 0 0 auto;
  background: linear-gradient(180deg, #fbf6ee 0%, #f4ede1 100%);
  padding: max(16px, env(safe-area-inset-top)) 16px 10px;
  box-shadow: 0 2px 10px rgba(80, 60, 30, .06);
}
.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 1px;
}
.app-header .subtitle {
  margin: 2px 0 12px;
  color: var(--ink-soft);
  font-size: 13px;
}
.search-box input {
  width: 100%;
  border: 1px solid var(--shelf-edge);
  background: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  color: var(--ink);
}
.search-box input:focus { border-color: var(--accent); }

/* ---------- 维度切换（按分类 / 按期刊名） ---------- */
.dim-toggle {
  display: flex;
  gap: 6px;
  margin: 0 0 4px;
  flex: 0 0 auto;
}
.dim-toggle button {
  flex: 1;
  border: 1px solid var(--shelf-edge);
  background: var(--bg-soft);
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 7px 0;
  font-size: 13px;
  cursor: pointer;
  transition: .2s;
}
.dim-toggle button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- 分类标签（左侧竖排） ---------- */
.tabs {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tab {
  border: 1px solid var(--shelf-edge);
  background: var(--bg-soft);
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 13px;
  text-align: center;
  line-height: 1.25;
  cursor: pointer;
  transition: .2s;
}
.tab.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ---------- 左右布局（左：标签栏 / 右：书架） ---------- */
.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  flex: 0 0 28%;
  max-width: 112px;
  min-width: 92px;
  background: var(--bg-soft);
  border-right: 1px solid var(--shelf-edge);
  padding: 12px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
main {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- 书架网格 ---------- */
.bookshelf {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.card {
  position: relative;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s ease;
}
.card:active { transform: scale(.97); }
.cover {
  position: relative;
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  color: #fff;
  background: #999;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover.has-img { padding: 0; }
.cover .cover-title {
  position: relative;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  text-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.cover .cover-cat {
  position: relative;
  margin-top: 6px;
  align-self: flex-start;
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
}
.fav {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0,0,0,.32);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  z-index: 2;
}
.fav.on { background: var(--accent); }
.card-meta { padding: 9px 11px 11px; }
.card-meta .m-title { font-size: 13px; font-weight: 600; line-height: 1.3; }
.card-meta .m-issue { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.empty { text-align: center; color: var(--ink-soft); padding: 40px 0; }

/* ---------- 满屏阅读页（替代底部弹窗） ---------- */
.sheet-mask { display: none; }   /* 满屏模式下无需遮罩 */
/* hidden 属性默认被 .sheet 的 display:flex 覆盖，必须显式兜底，否则页面关不掉 */
.sheet[hidden], .sheet-mask[hidden] { display: none; }
.sheet {
  position: fixed;
  inset: 0;
  background: var(--bg-soft);
  z-index: 31;
  display: flex;
  flex-direction: column;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sheet-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 18px 16px;
}
.sheet-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--shelf-edge);
  background: var(--bg-soft);
  padding: 5px 12px calc(5px + env(safe-area-inset-bottom));
}
.sheet-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--shelf-edge);
}
.sheet-bar .bar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-close {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border: none; border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 19px; line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, box-shadow .08s ease;
}
.sheet-close:active { transform: scale(.9); box-shadow: 0 1px 4px rgba(0,0,0,.26); }
.sheet-head { display: flex; gap: 12px; }
.sheet-head .mini-cover {
  position: relative;
  width: 72px; height: 96px; flex: 0 0 auto;
  border-radius: 8px; overflow: hidden; color: #fff;
  display: flex; align-items: flex-end; padding: 8px; font-weight: 700; font-size: 13px;
}
.sheet-head .mini-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sheet-head .sh-info { flex: 1; min-width: 0; }
.sheet-head .sh-title { font-size: 16px; font-weight: 700; }
.sheet-head .sh-issue { font-size: 13px; color: var(--ink-soft); margin-top: 3px; }
.sheet-head .sh-name { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.sheet-head .sh-cat {
  display: inline-block; margin-top: 8px;
  background: var(--ink); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 12px;
}
.sheet-desc { margin: 14px 0; font-size: 14px; color: #4a4239; }
.sheet-article { margin: 6px 0 4px; font-size: 15.5px; color: #3a342c; line-height: 1.85; }
.sheet-article .lead { font-size: 16px; line-height: 1.8; color: #4a4239; margin: 6px 0 14px; }
.sheet-article h2 {
  font-size: 18px; line-height: 1.4; margin: 24px 0 12px;
  color: var(--accent); font-weight: 800;
  border-left: 5px solid var(--accent); padding-left: 11px;
}
.sheet-article h3 {
  font-size: 16px; margin: 18px 0 8px; color: var(--ink);
  font-weight: 700;
}
.sheet-article p { margin: 10px 0; }
.sheet-article ul { margin: 10px 0; padding-left: 20px; }
.sheet-article li { margin: 7px 0; }
.sheet-article .point {
  background: #fff; border: 1px solid var(--shelf-edge);
  border-radius: 12px; padding: 13px 15px; margin: 14px 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.sheet-article .point h3 { margin-top: 0; }
.sheet-article blockquote {
  margin: 14px 0; padding: 12px 16px;
  background: #fff; border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0; color: #5a5048; font-style: italic;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.sheet-article img {
  width: 100%; height: auto; border-radius: 12px; margin: 12px 0;
  display: block; background: #f0ece4;
  border: 1px solid #ece6dc; box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.sheet-article .cap { font-size: 11px; color: #8a8073; text-align: center; margin: -6px 0 16px; line-height: 1.5; }
.sheet-article .tip { color: var(--accent); font-weight: 600; }
.sheet-article .more {
  margin: 18px 0 6px; padding: 13px 15px;
  background: linear-gradient(135deg, #fff7f3, #fff);
  border: 1px solid #f3d9cd; border-radius: 12px;
  font-size: 14.5px; color: #8a3b22; text-align: center; font-weight: 600;
}
.code-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px dashed var(--shelf-edge);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px;
}
.code-row .code-label { font-size: 12px; color: var(--ink-soft); }
.code-row .code-val { font-size: 18px; font-weight: 700; letter-spacing: 2px; flex: 1; }
.code-row .code-val.none { font-size: 13px; font-weight: 400; letter-spacing: 0; color: var(--ink-soft); }
.btn {
  display: block; width: 100%; text-align: center;
  border: none; border-radius: 9px; padding: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer; margin-bottom: 5px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--shelf-edge); }
.foot-row {
  display: flex; gap: 8px; margin-bottom: 5px;
}
.foot-row .btn {
  flex: 1 1 0; margin-bottom: 0; padding: 7px; font-size: 11px;
}
.sheet-hint { font-size: 11px; color: var(--ink-soft); text-align: center; margin: 2px 0 6px; }
.disclaimer { font-size: 10px; color: var(--ink-soft); opacity: .7; text-align: center; line-height: 1.45; margin-top: 4px; padding: 0 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: rgba(0,0,0,.82); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 50; max-width: 80vw; text-align: center;
}

/* ---------- 桌面端增强 ---------- */
@media (min-width: 768px) {
  .sidebar { flex-basis: 160px; max-width: 160px; }
  .bookshelf { grid-template-columns: repeat(3, 1fr); }
}
