/*
Theme Name: 书阁 ShuGe
Theme URI: https://example.com/shuge
Author: Kimi
Author URI: https://example.com
Description: 参考 Scribd 版面的个人图书站主题：顶栏大搜索框、分类标签、封面卡片网格首页，点击封面进入书评文章页。适合个人书评、读书笔记、电子书推荐站点。
Version: 1.2.2
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 7.4
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: shuge
Tags: blog, grid-layout, custom-logo, featured-images, one-column, two-columns, threaded-comments, translation-ready
*/

/* ============ 基础变量与重置 ============ */
:root {
  --sg-primary: #1e3a8a;          /* 主色：深蓝，可在自定义器中修改 */
  --sg-primary-dark: #162c6b;
  --sg-bg: #f6f7f9;
  --sg-card-bg: #ffffff;
  --sg-text: #1f2937;
  --sg-text-secondary: #6b7280;
  --sg-border: #e5e7eb;
  --sg-radius: 10px;
  --sg-shadow: 0 1px 3px rgba(0,0,0,.08);
  --sg-shadow-hover: 0 10px 28px rgba(15,23,42,.16);
  --sg-header-height: 64px;
  --sg-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sg-font);
  font-size: 16px;
  line-height: 1.7;
  color: var(--sg-text);
  background: var(--sg-bg);
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--sg-primary); text-decoration: none; }
a:hover { color: var(--sg-primary-dark); }

.sg-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.screen-reader-text {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ============ 顶栏（Scribd 风格） ============ */
.sg-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--sg-border);
}

.sg-header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--sg-header-height);
}

.sg-branding { flex-shrink: 0; }
.sg-branding .custom-logo { max-height: 36px; width: auto; }
.sg-site-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .5px;
}
.sg-site-title a { color: var(--sg-primary); }

/* 居中大搜索框 */
.sg-header-search { flex: 1; max-width: 560px; }
.sg-searchform { position: relative; display: flex; }
.sg-searchform .search-field {
  width: 100%;
  height: 42px;
  padding: 0 46px 0 18px;
  border: 1px solid var(--sg-border);
  border-radius: 21px;
  background: var(--sg-bg);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.sg-searchform .search-field:focus {
  background: #fff;
  border-color: var(--sg-primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,.12);
}
.sg-searchform .search-submit {
  position: absolute;
  right: 4px; top: 4px;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 0;
}
.sg-searchform .search-submit::before {
  content: "";
  position: absolute;
  left: 10px; top: 9px;
  width: 12px; height: 12px;
  border: 2px solid var(--sg-text-secondary);
  border-radius: 50%;
}
.sg-searchform .search-submit::after {
  content: "";
  position: absolute;
  left: 23px; top: 22px;
  width: 8px; height: 2px;
  background: var(--sg-text-secondary);
  transform: rotate(45deg);
}
.sg-searchform .search-submit:hover::before { border-color: var(--sg-primary); }
.sg-searchform .search-submit:hover::after { background: var(--sg-primary); }

/* 顶部菜单 */
.sg-nav { flex-shrink: 0; margin-left: auto; }
.sg-nav ul { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.sg-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--sg-text);
  font-size: 15px;
  font-weight: 500;
}
.sg-nav a:hover { background: var(--sg-bg); color: var(--sg-primary); }
.sg-nav .current-menu-item > a { color: var(--sg-primary); }

/* 移动端汉堡按钮 */
.sg-nav-toggle {
  display: none;
  margin-left: auto;
  width: 42px; height: 42px;
  border: 0; background: transparent;
  cursor: pointer;
  position: relative;
}
.sg-nav-toggle span,
.sg-nav-toggle span::before,
.sg-nav-toggle span::after {
  content: "";
  position: absolute;
  left: 9px;
  width: 24px; height: 2px;
  background: var(--sg-text);
  transition: .2s;
}
.sg-nav-toggle span { top: 20px; }
.sg-nav-toggle span::before { left: 0; top: -7px; }
.sg-nav-toggle span::after { left: 0; top: 7px; }

/* ============ 首页 Hero 搜索区 ============ */
.sg-hero {
  background: linear-gradient(135deg, var(--sg-primary) 0%, var(--sg-primary-dark) 100%);
  color: #fff;
  padding: 64px 0 72px;
  text-align: center;
}
.sg-hero-title { margin: 0 0 8px; font-size: 34px; font-weight: 800; }
.sg-hero-subtitle { margin: 0 0 28px; font-size: 16px; opacity: .85; }
.sg-hero .sg-searchform { max-width: 620px; margin: 0 auto; }
.sg-hero .sg-searchform .search-field {
  height: 52px;
  border-radius: 26px;
  border: 0;
  background: #fff;
  padding-right: 56px;
  font-size: 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.sg-hero .sg-searchform .search-submit { right: 8px; top: 8px; }

/* ============ 分类标签（Pills） ============ */
.sg-cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 28px 0 4px;
}
.sg-cat-pills a {
  display: inline-block;
  padding: 7px 18px;
  border: 1px solid var(--sg-border);
  border-radius: 999px;
  background: #fff;
  color: var(--sg-text);
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
}
.sg-cat-pills a:hover,
.sg-cat-pills a.is-active {
  background: var(--sg-primary);
  border-color: var(--sg-primary);
  color: #fff;
}

/* ============ 封面卡片网格（核心） ============ */
.sg-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 28px 0 18px;
}
.sg-section-title { margin: 0; font-size: 22px; font-weight: 700; }

.sg-book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 28px 22px;
  padding-bottom: 48px;
}

.sg-book-card { display: block; color: inherit; }
.sg-book-cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--sg-radius);
  overflow: hidden;
  background: #e5e7eb;
  box-shadow: var(--sg-shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.sg-book-cover img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.sg-book-card:hover .sg-book-cover {
  transform: translateY(-5px);
  box-shadow: var(--sg-shadow-hover);
}
/* 无封面时的占位 */
.sg-book-cover-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%; height: 100%;
  padding: 16px;
  background: linear-gradient(150deg, #dbe4f5, #c3d0ea);
  color: var(--sg-primary-dark);
  font-size: 17px;
  font-weight: 700;
  text-align: center;
}
.sg-book-badge {
  position: absolute;
  top: 10px; left: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(30,58,138,.92);
  color: #fff;
  font-size: 12px;
}
.sg-book-title {
  margin: 12px 0 4px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sg-book-card:hover .sg-book-title { color: var(--sg-primary); }
.sg-book-meta {
  font-size: 13px;
  color: var(--sg-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 分页 */
.sg-pagination { padding: 8px 0 56px; text-align: center; }
.sg-pagination .page-numbers {
  display: inline-block;
  min-width: 38px;
  padding: 7px 12px;
  margin: 0 3px;
  border: 1px solid var(--sg-border);
  border-radius: 8px;
  background: #fff;
  color: var(--sg-text);
}
.sg-pagination .page-numbers.current,
.sg-pagination .page-numbers:hover {
  background: var(--sg-primary);
  border-color: var(--sg-primary);
  color: #fff;
}

/* ============ 书评文章页 ============ */
.sg-single-wrap { padding: 40px 0 64px; }
.sg-single-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 48px;
  align-items: start;
}
.sg-single-cover { position: sticky; top: calc(var(--sg-header-height) + 24px); }
.sg-single-cover .sg-book-cover { box-shadow: var(--sg-shadow-hover); }
.sg-breadcrumb {
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--sg-text-secondary);
}
.sg-breadcrumb a { color: var(--sg-text-secondary); }
.sg-breadcrumb a:hover { color: var(--sg-primary); }
.sg-single-title {
  margin: 0 0 10px;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.3;
}
.sg-single-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 26px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--sg-border);
  font-size: 14px;
  color: var(--sg-text-secondary);
}
.sg-entry-content { font-size: 17px; }
.sg-entry-content h2 { font-size: 24px; margin: 1.6em 0 .6em; }
.sg-entry-content h3 { font-size: 20px; margin: 1.5em 0 .5em; }
.sg-entry-content blockquote {
  margin: 1.4em 0;
  padding: 4px 0 4px 20px;
  border-left: 4px solid var(--sg-primary);
  color: var(--sg-text-secondary);
}
.sg-entry-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
}
.sg-entry-content th, .sg-entry-content td {
  padding: 10px 14px;
  border: 1px solid var(--sg-border);
  text-align: left;
}
.sg-entry-content th { background: var(--sg-bg); }
.sg-entry-content img { border-radius: 8px; margin: 1em 0; }
.sg-entry-content .wp-block-button__link { border-radius: 999px; }

/* 相关推荐 */
.sg-related { margin-top: 56px; }
.sg-related .sg-book-grid { padding-bottom: 0; }

/* 评论区 */
.sg-comments {
  max-width: 760px;
  margin: 48px auto 0;
  padding-top: 32px;
  border-top: 1px solid var(--sg-border);
}
.sg-comments .comment-list { padding-left: 0; list-style: none; }
.sg-comments .comment-body {
  padding: 18px;
  margin-bottom: 14px;
  background: #fff;
  border: 1px solid var(--sg-border);
  border-radius: var(--sg-radius);
}
.sg-comments input[type="text"],
.sg-comments input[type="email"],
.sg-comments input[type="url"],
.sg-comments textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--sg-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
}
.sg-comments .submit {
  padding: 10px 28px;
  border: 0; border-radius: 999px;
  background: var(--sg-primary);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}
.sg-comments .submit:hover { background: var(--sg-primary-dark); }

/* ============ 通用文章列表（归档/搜索/普通页） ============ */
.sg-list-wrap { padding: 40px 0 56px; }
.sg-page-title { margin: 0 0 6px; font-size: 28px; font-weight: 800; }
.sg-page-desc { margin: 0 0 28px; color: var(--sg-text-secondary); }

/* ============ 页脚 ============ */
.sg-footer {
  margin-top: 40px;
  background: #111827;
  color: #9ca3af;
  padding: 40px 0 24px;
  font-size: 14px;
}
.sg-footer a { color: #d1d5db; }
.sg-footer a:hover { color: #fff; }
.sg-footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: space-between;
  align-items: center;
}
.sg-footer-nav ul { display: flex; gap: 16px; margin: 0; padding: 0; list-style: none; }
.sg-footer-bottom {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid #1f2937;
  text-align: center;
  font-size: 13px;
  color: #6b7280;
}

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .sg-single-layout { grid-template-columns: 1fr; gap: 28px; }
  .sg-single-cover { position: static; max-width: 260px; }
  .sg-single-title { font-size: 26px; }
}

@media (max-width: 768px) {
  .sg-header-inner { gap: 12px; height: auto; flex-wrap: wrap; padding: 10px 0; }
  .sg-header-search { order: 3; flex-basis: 100%; max-width: none; }
  .sg-nav-toggle { display: block; }
  .sg-nav { display: none; flex-basis: 100%; order: 4; margin-left: 0; }
  .sg-nav.is-open { display: block; }
  .sg-nav ul { flex-direction: column; gap: 2px; padding-bottom: 8px; }
  .sg-hero { padding: 44px 0 48px; }
  .sg-hero-title { font-size: 26px; }
  .sg-book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 14px; }
}
