/* ==========================================================================
   每日导航 - 大容量书签工作台
   双模式配色：
     - 日间：澄怀素笺（清润温和宣纸白，去除沉闷偏黄，久看舒适）
     - 夜间：深夜墨香书房（深碳墨底 ＋ 暖骨白字 ＋ 琥珀温光）
   ========================================================================== */

:root {
  /* 日间模式：澄怀素笺 */
  --ink: #272422;
  --muted: #736b62;
  --ochre: #9e472a;
  --green: #264637;
  --paper: #f8f5ee;
  --card: #ffffff;
  --card-hover: #ffffff;
  --box-bg: #ffffff;
  --card-shadow: rgba(39, 36, 34, 0.88);
  --border-line: rgba(39, 36, 34, 0.16);
  --pattern-dot: rgba(43, 39, 36, 0.04);
  --quick-bg: rgba(255, 255, 255, 0.82);
  --pinned-bg: rgba(255, 255, 255, 0.65);
  --icon-bg: #ffffff;
  --modal-overlay: rgba(39, 36, 34, 0.52);

  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", "STSong", "Hiragino Mincho ProN", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* 夜间模式：深夜古籍墨香书房 */
html.dark-theme,
body.dark-theme {
  --ink: #e6dfd3;
  --muted: #9c9487;
  --ochre: #c9603e;
  --green: #37654f;
  --paper: #161514;
  --card: #201e1c;
  --card-hover: #272421;
  --box-bg: #201e1c;
  --card-shadow: #0a0909;
  --border-line: rgba(230, 223, 211, 0.16);
  --pattern-dot: rgba(230, 223, 211, 0.035);
  --quick-bg: rgba(32, 30, 28, 0.85);
  --pinned-bg: rgba(32, 30, 28, 0.7);
  --icon-bg: #ffffff;
  --modal-overlay: rgba(0, 0, 0, 0.72);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--paper);
  background-image:
    radial-gradient(var(--pattern-dot) 1px, transparent 0),
    radial-gradient(rgba(158, 71, 42, 0.02) 1px, transparent 0);
  background-size: 26px 26px, 40px 40px;
  background-position: 0 0, 13px 13px;
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

/* 页面主容器 */
.page {
  max-width: 1360px;
  margin: 0 auto;
  padding: 40px 32px 50px;
}

/* ---------- 1. 大报头 (Masthead) ---------- */
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 32px;
  flex-wrap: wrap;
}

.eyebrow-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.eyebrow {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 5px;
  color: var(--ochre);
}

.mast-stamp {
  font-family: var(--serif);
  font-size: 11px;
  font-weight: 800;
  color: var(--ochre);
  border: 1.2px solid var(--ochre);
  padding: 1px 4px;
  border-radius: 3px;
  transform: rotate(-3deg);
  user-select: none;
}

.mast-title {
  font-family: var(--serif);
  font-size: 80px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 4px;
  color: var(--ink);
  display: inline-flex;
  align-items: baseline;
}

.mast-dot {
  color: var(--ochre);
}

.mast-seal {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 900;
  color: #fff;
  background: var(--ochre);
  border: 1.5px solid var(--ochre);
  padding: 1px 5px;
  line-height: 1.1;
  letter-spacing: 2px;
  transform: rotate(-3deg) translateY(-30px);
  margin-left: 10px;
  box-shadow: 2px 2px 0 rgba(39, 36, 34, 0.4);
  user-select: none;
  border-radius: 3px;
}

.masthead-side {
  border-left: 3px solid var(--ink);
  padding-left: 22px;
  padding-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 350px;
}

.masthead-side-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.date-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mast-solar-date {
  font-family: var(--serif);
  font-size: 24.5px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.2;
  letter-spacing: 0.5px;
}

.almanac-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--serif);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ochre);
  background: rgba(158, 71, 42, 0.08);
  border: 1.2px solid rgba(158, 71, 42, 0.3);
  padding: 3.5px 10px;
  border-radius: 4px;
  letter-spacing: 0.8px;
  width: fit-content;
  user-select: none;
}

/* 阴阳日夜切换印钮 (Yin-Yang Button) */
.yinyang-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2.2px solid var(--ink);
  background: var(--box-bg);
  box-shadow: 2.5px 2.5px 0 var(--ochre);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  padding: 0;
  transition: transform .2s ease, box-shadow .2s ease, background-color .2s ease;
  user-select: none;
  margin-top: 2px;
}

.yinyang-btn:hover {
  transform: translate(-1.5px, -1.5px);
  box-shadow: 4px 4px 0 var(--ochre);
  background: var(--card-hover);
}

.yinyang-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ochre);
}

.yinyang-icon {
  width: 28px;
  height: 28px;
  transition: transform .45s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: block;
}

.yinyang-btn:hover .yinyang-icon {
  transform: rotate(90deg);
}

html.dark-theme .yinyang-icon {
  transform: rotate(180deg);
}

html.dark-theme .yinyang-btn:hover .yinyang-icon {
  transform: rotate(270deg);
}

.masthead-side-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14.5px;
  color: var(--muted);
  flex-wrap: wrap;
}

.mast-stats b {
  color: var(--ochre);
  font-size: 17px;
}

.mast-divider {
  opacity: 0.5;
  font-size: 14px;
}

.mast-note {
  letter-spacing: 0.8px;
  font-size: 14px;
}

/* 报刊经典双墨线 */
.rule-double {
  border-top: 3.5px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 5px;
  margin: 24px 0 26px;
}

/* ---------- 2. 搜索与控制工具栏 ---------- */
.toolbar {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--box-bg);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ochre);
  transition: transform .18s ease, box-shadow .18s ease;
}

.search-box:hover,
.search-box:focus-within {
  transform: translate(-2px, -2px);
  box-shadow: 8px 8px 0 var(--ochre);
  background: var(--card-hover);
}

.search-icon {
  width: 20px;
  height: 20px;
  margin-left: 16px;
  color: var(--ink);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  height: 56px;
  border: none;
  outline: none;
  background: transparent;
  padding: 0 40px 0 12px;
  font-size: 16px;
  font-family: var(--sans);
  color: var(--ink);
}

.search-input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.search-kbd-hint {
  position: absolute;
  right: 36px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-kbd-hint kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  background: rgba(39, 36, 34, 0.08);
  border: 1px solid rgba(39, 36, 34, 0.2);
  border-radius: 4px;
  color: var(--muted);
}

.clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}

.clear-btn:hover {
  color: var(--ochre);
}

/* 密度与主题视图切换按钮 */
.toggle-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  min-height: 56px;
  background: var(--box-bg);
  color: var(--ink);
  border: 3px solid var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--ink);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
  user-select: none;
  white-space: nowrap;
}

.toggle-view-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 7px 7px 0 var(--ink);
  background: var(--card-hover);
}

.toggle-view-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

/* 工具按钮（导入书签 / 私密切换）：与视图切换同款描边按压 */
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  min-height: 56px;
  background: var(--box-bg);
  color: var(--ink);
  border: 3px solid var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--ink);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
  user-select: none;
  white-space: nowrap;
}

.tool-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 7px 7px 0 var(--ink);
  background: var(--card-hover);
}

.tool-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

/* 主操作按钮：添加网站 (朱砂印鉴古风) */
.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 22px;
  min-height: 56px;
  background: var(--ochre);
  color: #ffffff;
  border: 3px solid var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--ink);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
  user-select: none;
  white-space: nowrap;
}

.add-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 7px 7px 0 var(--ink);
  background: #883920;
}

html.dark-theme .add-btn:hover {
  background: #b55333;
}

.add-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.add-plus {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

/* ---------- 2.1 A-Z 快速字母条与定位说明 ---------- */
.quick-loc-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 8px 16px;
  background: var(--quick-bg);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--card-shadow);
  font-size: 12.5px;
  color: var(--muted);
  box-sizing: border-box;
  max-width: 100%;
}

.az-strip-wrap {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.az-strip {
  display: flex;
  gap: 3px;
  align-items: center;
  flex-wrap: wrap;
}

.quick-loc-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}

.hint-dot {
  color: var(--ochre);
  font-size: 13px;
  line-height: 1;
}

.quick-loc-hint strong {
  color: var(--ochre);
}

.quick-loc-hint kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  background: rgba(39, 36, 34, 0.08);
  border: 1px solid rgba(39, 36, 34, 0.25);
  border-radius: 3px;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.desktop-hint-span { display: inline; }
.mobile-hint-span { display: none; }

.az-btn {
  background: transparent;
  border: 1.5px solid transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 5px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1;
  transition: all .12s ease;
}

.az-btn:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.az-btn.active {
  background: var(--ochre);
  color: #fff;
  border-color: var(--ochre);
}

.az-btn.disabled,
.az-btn.no-sites {
  opacity: 0.38;
  cursor: pointer;
}

.az-btn:active {
  transform: scale(0.92);
  background: var(--ochre);
  color: #fff;
}

/* 移动端吸顶横向滑动标签栏 (在小屏显示) */
.mobile-chips-bar {
  display: none;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 2px;
  margin-top: 14px;
  -webkit-overflow-scrolling: touch;
}

.mobile-chips-bar::-webkit-scrollbar {
  display: none;
}

/* ---------- 3. 主体工作区 (两栏字典索引布局) ---------- */
.workspace-layout {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  margin-top: 32px;
}

/* 左侧吸顶分类索引导航 (Sidebar Index) */
.sidebar-index {
  width: 230px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  z-index: 20;
}

.sidebar-sticky-box {
  background: var(--card);
  border: 2.5px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
}

.sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 6px 12px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 10px;
}

.sidebar-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
}

.sidebar-subtitle {
  font-size: 11px;
  color: var(--ochre);
  font-weight: 800;
  letter-spacing: 1px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  padding-right: 2px;
  flex: 1;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(39, 36, 34, 0.2);
  border-radius: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  text-decoration: none;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 6px;
  border: 1.5px solid transparent;
  transition: all .15s ease;
  user-select: none;
}

.sidebar-link:hover {
  background: var(--card-hover);
  border-color: var(--ink);
  transform: translateX(2px);
}

.sidebar-link.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--ochre);
}

.sidebar-link-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sidebar-num {
  font-family: var(--serif);
  font-size: 12px;
  opacity: 0.8;
}

.sidebar-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--border-line);
  color: var(--muted);
  font-family: var(--sans);
}

.sidebar-link.active .sidebar-badge {
  background: var(--ochre);
  color: #ffffff;
}

.back-to-top-btn {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-line);
  background: none;
  border-left: none;
  border-right: none;
  border-bottom: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: color .15s;
}

.back-to-top-btn:hover {
  color: var(--ochre);
}

/* 右侧内容主画卷 */
.main-sections-content {
  flex: 1;
  min-width: 0;
  min-height: 50vh;
  padding-bottom: 25vh;
}

/* 分区容器 */
.section {
  margin-bottom: 40px;
  scroll-margin-top: 24px;
}

/* 常用常顾 (Pinned) 专区样式 */
.pinned-section {
  background: var(--pinned-bg);
  border: 2px dashed rgba(158, 71, 42, 0.4);
  padding: 18px 20px 22px;
  margin-bottom: 44px;
}

.section-star {
  color: var(--ochre);
  font-size: 22px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
}

.section-num {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 900;
}

.accent-ochre { color: var(--ochre); }
.accent-green { color: var(--ochre); }
.accent-dark { color: var(--ink); }

.section-title {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 1.5px;
  white-space: nowrap;
}

.section-sub {
  font-family: var(--serif);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
  font-weight: 700;
  opacity: 0.75;
  white-space: nowrap;
}

.section-line {
  flex: 1;
  border-top: 2px solid var(--ink);
  transform: translateY(-5px);
  opacity: .9;
}

.section-count {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ---------- 4. 站点卡片网格 (详细 vs 紧凑模式) ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* 默认舒适模式卡片 */
.card {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(39, 36, 34, .92);
  padding: 14px 14px 13px;
  text-decoration: none;
  color: var(--ink);
  height: 100%;
}

.card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ochre);
  background: var(--card-hover);
  border-color: var(--ochre);
}

/* 键盘与字母定位选定态：原地变色高亮与柔光呼吸提示，确保同行所有卡片严格对齐 */
.card.keyboard-selected {
  border-color: var(--ochre) !important;
  box-shadow: 4px 4px 0 var(--ochre) !important;
  background: var(--card-hover) !important;
  transform: none !important;
  animation: cardLocPulse 1.2s ease-out;
}

@keyframes cardLocPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(166, 75, 42, 0.6), 4px 4px 0 var(--ochre);
  }
  60% {
    box-shadow: 0 0 0 10px rgba(166, 75, 42, 0), 4px 4px 0 var(--ochre);
  }
  100% {
    box-shadow: 4px 4px 0 var(--ochre);
  }
}

.reset-filter-btn {
  background: none;
  border: none;
  color: var(--ochre);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 0 4px;
  font-family: inherit;
  font-size: inherit;
  transition: color .15s ease;
}

.reset-filter-btn:hover {
  color: var(--ink);
}

.card:active {
  transform: translate(1px, 1px);
  box-shadow: 1.5px 1.5px 0 var(--ochre);
}

.card-pinyin-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ochre);
  background: rgba(145, 67, 40, 0.08);
  border: 1px solid rgba(145, 67, 40, 0.25);
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 6px;
  letter-spacing: 0.5px;
}

.icon-box {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border: 1.5px solid var(--ink);
  border-radius: 9px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 1px 1px 0 rgba(39, 36, 34, 0.1);
  flex-shrink: 0;
}

.icon-box img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}

.icon-fallback {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
}

.card-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.card-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .2px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-arrow {
  display: inline-block;
  color: var(--muted);
  font-size: 13px;
  margin-left: 4px;
  transition: transform .22s cubic-bezier(0.34, 1.56, 0.64, 1), color .18s ease;
}

.card:hover .card-arrow,
.card.keyboard-selected .card-arrow {
  color: var(--ochre);
  transform: translate(3px, -3px);
}

.card-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-host {
  font-size: 11px;
  color: #a1988b;
  margin-top: 4px;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-del {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  color: #b3aa9d;
  font-size: 12px;
  cursor: pointer;
  padding: 3px;
  line-height: 1;
}

.card-del:hover {
  color: var(--ochre);
}

/* ---------- 紧凑模式 (Compact View) ---------- */
/* 当启用紧凑模式时：列数增加至 5 列，高度缩减至 ~46px，一屏尽收 50+ 书签！ */
.compact-view .grid {
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.compact-view .card {
  padding: 8px 10px;
  gap: 8px;
  align-items: center;
}

.compact-view .icon-box {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 6px;
}

.compact-view .icon-box img {
  width: 16px;
  height: 16px;
}

.compact-view .icon-fallback {
  font-size: 13px;
}

.compact-view .card-desc,
.compact-view .card-host {
  display: none !important;
}

.compact-view .card-name {
  font-size: 13.5px;
}

/* 搜索无结果提示 */
.no-results {
  display: none;
  text-align: center;
  padding: 56px 0 30px;
  font-family: var(--serif);
  font-size: 16.5px;
  color: var(--muted);
  line-height: 1.9;
}

.no-results span {
  font-size: 13px;
  color: var(--ochre);
  font-family: var(--sans);
}

/* ---------- 5. 页脚 ---------- */
.footer {
  margin-top: 50px;
  padding-top: 18px;
  border-top: 2px solid var(--ink);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
}

.footer-right {
  letter-spacing: 2px;
}

/* ---------- 6. 添加网站弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ochre);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 18px;
  border-bottom: 3px solid var(--ink);
  background: var(--box-bg);
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
}

.modal-close:hover {
  color: var(--ochre);
}

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
}

.modal-input {
  padding: 9px 12px;
  border: 2px solid var(--ink);
  background: var(--box-bg);
  font-size: 14px;
  font-family: var(--sans);
  color: var(--ink);
  outline: none;
}

.modal-input:focus {
  border-color: var(--ochre);
  box-shadow: 2px 2px 0 var(--ochre);
}

.modal-submit {
  min-height: 44px;
  justify-content: center;
  margin-top: 4px;
}

.modal-tip {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

/* ---------- 7. 移动端浮动回到顶部按钮 ---------- */
.float-top-btn {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 44px;
  height: 44px;
  background: var(--paper);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ochre);
  border-radius: 50%;
  font-size: 19px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 85;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease, box-shadow .15s ease;
  user-select: none;
}

.float-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.float-top-btn:hover {
  background: #ffffff;
  box-shadow: 4px 4px 0 var(--ink);
}

.float-top-btn:active {
  transform: scale(0.92);
  box-shadow: 1px 1px 0 var(--ochre);
}

/* ---------- 8. 响应式与手机端深度适配 ---------- */
@media (max-width: 1200px) {
  .compact-view .grid { grid-template-columns: repeat(4, 1fr); }
  .grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 960px) {
  .page {
    padding: 22px 16px 40px;
    padding-bottom: max(40px, env(safe-area-inset-bottom, 20px));
  }
  
  .mast-title { font-size: 56px; letter-spacing: 3px; }
  .masthead-side { border-left: none; padding-left: 0; }
  
  /* 平板/横屏手机：两栏转为单栏，左侧索引转为顶部横向吸顶滑动条 */
  .workspace-layout { flex-direction: column; gap: 20px; margin-top: 20px; }
  
  .sidebar-index {
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--paper);
    padding: 6px 0;
  }
  
  .sidebar-sticky-box {
    max-height: none;
    box-shadow: 3px 3px 0 var(--ink);
    padding: 8px 10px;
    background: var(--card);
  }
  
  .sidebar-head, .back-to-top-btn { display: none; }
  
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  
  .sidebar-link {
    white-space: nowrap;
    padding: 6px 13px;
    border: 1.5px solid var(--ink);
    border-radius: 999px;
    font-size: 13.5px;
    flex-shrink: 0;
  }
  .sidebar-num { display: none; }
  
  .toolbar { flex-wrap: wrap; }
  .search-box { min-width: 100%; order: 1; }
  .add-btn { flex: 1; order: 2; justify-content: center; }
  .toggle-view-btn { flex: 1; order: 3; justify-content: center; }
  .tool-btn { flex: 1; order: 3; justify-content: center; }
  
  /* 移动端主内容区：提供充足的底部余白，确保无论筛选出多少卡片都能畅快平滑滚动置顶 */
  .main-sections-content {
    min-height: 80vh !important;
    padding-bottom: 75vh !important;
  }

  /* 快速定位栏移动端：上层提示文字折行，下层 A-Z 字母条升级为打字机按键横向滑轨，并支持吸顶随时点按 */
  .desktop-hint-span { display: none !important; }
  .mobile-hint-span { display: inline !important; }
  .search-kbd-hint { display: none !important; }
  
  .quick-loc-bar {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    padding: 8px 12px 9px !important;
    gap: 7px !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: calc(100% + 24px) !important;
    margin-left: -12px !important;
    margin-right: -12px !important;
    margin-top: 10px !important;
    border-left: none !important;
    border-right: none !important;
    box-sizing: border-box !important;
    touch-action: pan-y !important;
    background: var(--quick-bg) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2.5px 0 var(--border-line) !important;
  }

  .quick-loc-hint {
    font-size: 11.5px !important;
    line-height: 1.4 !important;
    white-space: normal !important;
    word-break: break-word !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    color: var(--muted) !important;
    padding: 0 2px !important;
  }

  /* A–Z 字母条专属横向滑轨容器（带右侧微渐变与内嵌导轨） */
  .az-strip-wrap {
    position: relative !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    touch-action: pan-x pan-y !important;
    background: rgba(39, 36, 34, 0.04);
    border: 1px solid var(--border-line);
    border-radius: 6px;
    padding: 4px 6px;
    box-sizing: border-box;
  }
  html.dark-theme .az-strip-wrap {
    background: rgba(230, 223, 211, 0.04);
  }
  .az-strip-wrap::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 32px;
    background: linear-gradient(to right, transparent, var(--box-bg));
    pointer-events: none;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
    z-index: 2;
    opacity: 0.85;
  }

  .az-strip {
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    touch-action: pan-x pan-y !important;
    -webkit-overflow-scrolling: touch;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding: 2px 24px 4px 2px !important;
    gap: 6px !important;
    scrollbar-width: thin;
    scrollbar-color: var(--ochre) transparent;
  }
  .az-strip::-webkit-scrollbar {
    height: 3px !important;
    display: block !important;
  }
  .az-strip::-webkit-scrollbar-thumb {
    background: var(--ochre) !important;
    border-radius: 999px !important;
  }
  .az-strip::-webkit-scrollbar-track {
    background: rgba(39, 36, 34, 0.08) !important;
    border-radius: 999px !important;
  }

  .az-btn {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    min-width: 32px !important;
    height: 30px !important;
    padding: 0 9px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-family: var(--mono);
    font-size: 13.5px !important;
    font-weight: 800 !important;
    background: var(--box-bg) !important;
    border: 1.5px solid var(--ink) !important;
    box-shadow: 2px 2px 0 var(--border-line) !important;
    border-radius: 4px !important;
    color: var(--ink) !important;
    cursor: pointer;
    user-select: none;
    transition: all .12s ease;
  }

  .az-btn.active {
    background: var(--ochre) !important;
    color: #ffffff !important;
    border-color: var(--ink) !important;
    box-shadow: 2px 2px 0 var(--ink) !important;
  }

  .az-btn.disabled,
  .az-btn.no-sites {
    opacity: 0.42 !important;
    background: transparent !important;
    border: 1px dashed var(--border-line) !important;
    box-shadow: none !important;
    color: var(--muted) !important;
    cursor: pointer !important;
  }

  .az-btn:active {
    transform: scale(0.9) !important;
    background: var(--ochre) !important;
    color: #ffffff !important;
  }

  /* 置顶区标题的英文副标题在手机上隐藏 */
  .pinned-section .section-sub {
    display: none !important;
  }
}

@media (max-width: 540px) {
  /* 手机端精细化排版 */
  .page {
    padding: 16px 12px 50px;
    padding-bottom: max(50px, env(safe-area-inset-bottom, 20px));
  }
  
  .masthead { gap: 12px; }
  .mast-title {
    font-size: 40px;
    letter-spacing: 2px;
  }
  .mast-seal {
    font-size: 11px;
    padding: 1px 3px;
    transform: rotate(-3deg) translateY(-14px);
    margin-left: 6px;
  }
  .masthead-side {
    width: 100%;
    border-left: none;
    border-top: 1.5px dashed var(--border-line);
    padding-left: 0;
    padding-top: 10px;
    min-width: 0;
  }
  .mast-solar-date {
    font-size: 16px;
  }
  .almanac-badge {
    font-size: 11px;
    padding: 1px 6px;
  }
  .yinyang-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
  .yinyang-icon {
    width: 22px;
    height: 22px;
  }
  .mast-stats {
    font-size: 12px;
  }
  
  .rule-double {
    margin: 16px 0 18px;
  }
  
  /* 工具栏手机端高度自适应，防止 iOS 弹出自动缩放 */
  .search-input {
    height: 48px;
    font-size: 16px;
    padding-right: 32px;
  }
  .toggle-view-btn, .add-btn {
    min-height: 46px;
    font-size: 13.5px;
    padding: 0 10px;
  }
  
  /* 手机端网格：详细模式单列自适应，紧凑模式双列并排（一屏可容纳 12+ 站点！） */
  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .compact-view .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .compact-view .card {
    padding: 7px 8px;
    gap: 6px;
  }
  .compact-view .card-name {
    font-size: 12.5px;
  }
  .compact-view .card-pinyin-tag {
    display: none; /* 紧凑模式在窄屏下隐藏首字母标签，避免文字折行 */
  }
  
  /* 分区与常用专区 */
  .section {
    margin-bottom: 26px;
    scroll-margin-top: 56px; /* 避让吸顶导航条 */
  }
  .section-head {
    gap: 6px;
    margin-bottom: 10px;
  }
  .section-num { font-size: 20px; }
  .section-title { font-size: 19px; }
  .section-sub {
    display: none;
  }
  .section-count { font-size: 11px; }

  .pinned-section {
    padding: 10px 10px 12px;
    margin-bottom: 24px;
    scroll-margin-top: 56px;
  }
  .pinned-section .section-sub {
    display: none;
  }
  
  /* 手机端触屏按压反馈 */
  .card:active {
    transform: scale(0.98);
    box-shadow: 1.5px 1.5px 0 var(--ochre);
  }
  
  /* 弹窗在手机软键盘弹出时的保护 */
  .modal {
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  }
  .modal-head {
    padding: 11px 14px;
    font-size: 16px;
  }
  .modal-body {
    padding: 14px;
    gap: 11px;
  }
}

/* 二级分类：子分区小一号、带「隶属」标；侧栏子项缩进 */
.section--sub { margin-top: -6px; }
.section--sub .section-num { font-size: 20px; }
.section--sub .section-title { font-size: 20px; }
.section--sub .section-head { margin-bottom: 12px; }
.section-parent {
  font-family: var(--serif);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--ochre);
  border: 1.5px solid var(--ochre);
  padding: 2px 8px;
  white-space: nowrap;
  transform: translateY(-2px);
}
.sidebar-link--sub { padding-left: 30px; }
.sidebar-link--sub .sidebar-name { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sidebar-link--sub.active .sidebar-name { color: var(--paper); }
