/*
Theme Name: Chapter Theme
Theme URI: https://gorosuke.net/
Author: Gorosuke
Description: チャプターとページを管理する学習サイト用テーマ。xwrite テーマの配色とレイアウトに調和。Verse 用 Prism.js シンタックスハイライト同梱。
Version: 1.1.0
Requires at least: 6.0
Requires PHP: 7.4
License: GPL v2 or later
Text Domain: chapter-theme
*/

/* ===== Design tokens (xwrite準拠) ===== */
:root {
  --ct-bg:              #222222;
  --ct-headbg:          #565656;
  --ct-headtxt:         #ffffff;
  --ct-card-bg:         #ffffff;
  --ct-card-shadow:     0 1px 10px rgba(0, 0, 0, 0.03);
  --ct-txt:             #333333;
  --ct-txt-muted:       #888888;
  --ct-key:             #1e73be;     /* primary accent (xwrite --key-color) */
  --ct-key-soft:        rgba(30,115,190,0.13);
  --ct-link:            #b75e37;     /* xwrite --link-color */
  --ct-border:          #eeeeee;
  --ct-radius:          10px;
  --ct-radius-sm:       4px;
  --ct-block-pad:       2rem;
  --ct-container:       1260px;
  --ct-main:            830px;
  --ct-sidebar:         320px;
  --ct-gutter:          30px;
}

/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 62.5%; }
body {
  margin: 0;
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 1.6rem;
  line-height: 1.85;
  letter-spacing: 0.02em;
  color: var(--ct-txt-muted);
  background: var(--ct-bg);
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--ct-link); text-decoration: none; transition: opacity .15s; }
a:hover { opacity: 0.75; }

/* ===== Header ===== */
.site-header {
  background: var(--ct-headbg);
  color: var(--ct-headtxt);
}
.site-header__inner {
  max-width: var(--ct-container);
  margin: 0 auto;
  padding: 18px var(--ct-gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.site-title {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.site-title a { color: var(--ct-headtxt); }
.site-description {
  margin: 0;
  font-size: 1.2rem;
  color: rgba(255,255,255,0.75);
}

/* ===== Layout ===== */
.site-main {
  max-width: var(--ct-container);
  margin: 0 auto;
  padding: 40px var(--ct-gutter) 80px;
}
.layout {
  display: grid;
  grid-template-columns: var(--ct-sidebar) 1fr;
  gap: 40px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ===== Sidebar (xwrite widget style) ===== */
.chapter-sidebar {
  position: sticky;
  top: 24px;
  background: var(--ct-card-bg);
  border-radius: var(--ct-radius);
  box-shadow: var(--ct-card-shadow);
  overflow: hidden;
}
.chapter-sidebar__head {
  background: var(--ct-key-soft);
  color: var(--ct-key);
  padding: 14px 20px;
  border-radius: var(--ct-radius) var(--ct-radius) 0 0;
}
.chapter-sidebar__label {
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0;
  opacity: 0.8;
  font-weight: 700;
}
.chapter-sidebar__title {
  margin: 4px 0 0;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--ct-key);
  line-height: 1.4;
}
.chapter-sidebar__title a { color: inherit; }

.chapter-pages {
  list-style: none;
  margin: 0;
  padding: 8px 0;
}
.chapter-pages__item + .chapter-pages__item {
  border-top: 1px solid var(--ct-border);
}
.chapter-pages__link {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 12px 20px;
  color: var(--ct-txt);
  font-size: 1.4rem;
  line-height: 1.55;
}
.chapter-pages__link:hover { background: #f7f9fc; opacity: 1; }
.chapter-pages__index {
  flex: 0 0 auto;
  min-width: 24px;
  font-variant-numeric: tabular-nums;
  color: var(--ct-txt-muted);
  font-size: 1.2rem;
  font-weight: 600;
}
.chapter-pages__item.is-current .chapter-pages__link {
  background: var(--ct-key-soft);
  color: var(--ct-key);
  border-left: 3px solid var(--ct-key);
  padding-left: 17px;
  font-weight: 600;
}
.chapter-pages__item.is-current .chapter-pages__index { color: var(--ct-key); }
.chapter-sidebar__back {
  display: block;
  padding: 12px 20px;
  font-size: 1.3rem;
  color: var(--ct-txt-muted);
  border-top: 1px solid var(--ct-border);
}

/* ===== Content card ===== */
.content-card {
  background: var(--ct-card-bg);
  color: var(--ct-txt);
  border-radius: var(--ct-radius);
  box-shadow: var(--ct-card-shadow);
  padding: var(--ct-block-pad) calc(var(--ct-block-pad) * 1.25);
}
@media (max-width: 600px) {
  .content-card { padding: 1.5rem; }
}
.content-card h1, .content-card h2, .content-card h3, .content-card h4 {
  color: #1f1e1e;
  line-height: 1.5;
}
.content-card h1 {
  font-size: 2.8rem;
  margin: 0 0 24px;
  padding-bottom: 14px;
  border-bottom: 3px solid var(--ct-key);
}
.content-card h2 {
  font-size: 2.0rem;
  margin: 40px 0 16px;
  padding: 8px 0 8px 14px;
  border-left: 4px solid var(--ct-key);
  background: linear-gradient(90deg, var(--ct-key-soft), transparent 70%);
}
.content-card h3 {
  font-size: 1.7rem;
  margin: 28px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px dashed #d6d6d6;
}
.content-card p { margin: 0 0 16px; }
.content-card a { color: var(--ct-link); text-decoration: underline; text-underline-offset: 3px; }
.content-card code:not([class*="language-"]) {
  background: #f8f6f6;
  color: #c7254e;
  padding: 2px 8px;
  border-radius: 3px;
  font-family: Menlo, Consolas, "Hiragino Kaku Gothic Pro", monospace;
  font-size: 1.4rem;
}
.content-card blockquote {
  border-left: 4px solid var(--ct-key);
  background: #f7f9fc;
  margin: 16px 0;
  padding: 14px 18px;
  color: #555;
  border-radius: 0 var(--ct-radius-sm) var(--ct-radius-sm) 0;
}

/* ===== Top page: chapter list ===== */
.page-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
  margin: 0 0 28px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ct-key);
  letter-spacing: 0.05em;
}
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}
.chapter-card {
  background: var(--ct-card-bg);
  color: var(--ct-txt);
  border-radius: var(--ct-radius);
  overflow: hidden;
  box-shadow: var(--ct-card-shadow);
  transition: transform .18s ease, box-shadow .18s ease;
  display: flex;
  flex-direction: column;
}
.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.chapter-card__thumb {
  aspect-ratio: 1.618 / 1;     /* xwrite --posts--thumb--ratio--card: 61.8% */
  background: linear-gradient(135deg, var(--ct-key) 0%, var(--ct-headbg) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  overflow: hidden;
}
.chapter-card__thumb img { width: 100%; height: 100%; object-fit: cover; }
.chapter-card__body {
  padding: 18px 22px 22px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.chapter-card__title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 700;
  color: #1f1e1e;
  line-height: 1.5;
}
.chapter-card__title a { color: inherit; text-decoration: none; }
.chapter-card__title a:hover { color: var(--ct-key); opacity: 1; }
.chapter-card__excerpt {
  margin: 0 0 12px;
  font-size: 1.3rem;
  color: var(--ct-txt-muted);
  flex: 1;
  line-height: 1.7;
}
.chapter-card__meta { font-size: 1.2rem; color: var(--ct-txt-muted); }
.chapter-card__meta strong { color: var(--ct-key); font-weight: 700; }

/* ===== Chapter page list ===== */
.page-list {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
}
.page-list__item {
  border-bottom: 1px solid var(--ct-border);
  padding: 14px 4px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.page-list__index {
  flex: 0 0 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ct-key);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
}
.page-list__title { font-size: 1.5rem; font-weight: 600; }
.page-list__title a { color: #1f1e1e; }
.page-list__title a:hover { color: var(--ct-key); opacity: 1; }

/* ===== Article nav (prev / next) ===== */
.article-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 40px;
}
.article-nav__item {
  background: #f7f9fc;
  border-radius: var(--ct-radius-sm);
  padding: 14px 18px;
  text-decoration: none;
  color: var(--ct-txt);
  transition: background .15s;
}
.article-nav__item:hover { background: var(--ct-key-soft); opacity: 1; }
.article-nav__label { font-size: 1.1rem; color: var(--ct-txt-muted); letter-spacing: 0.05em; }
.article-nav__title { display: block; font-size: 1.4rem; font-weight: 700; color: #1f1e1e; margin-top: 4px; }
.article-nav__item--next { text-align: right; }

/* ===== Footer ===== */
.site-footer {
  background: #ffffff;
  color: #64625f;
  text-align: center;
  padding: 24px;
  font-size: 1.3rem;
}
