/* 三流プラントエンジのへや - 共通スタイル（ブログ風・ライト／ダーク） */

/* ---------- 色（ライトモード） ---------- */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --surface-3: #eceef1;
  --text: #1f2328;
  --text-muted: #5c6670;
  --border: #e2e5e9;
  --accent: #1f5a6e;        /* 配管の深緑青 */
  --accent-ink: #ffffff;
  --accent-2: #e8730c;      /* 安全色オレンジ */
  --link: #1d6a85;
  --ok: #2e7d4f;
  --ng: #c0392b;
  --ai: #7a4fc4;            /* 生成AIが書いた記事の印 */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.05), 0 4px 16px rgba(16, 24, 32, 0.05);
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "BIZ UDPGothic", Meiryo, system-ui, sans-serif;
  color-scheme: light;
}

/* ---------- 色（ダークモード）：OS の設定に従う。ボタンで切り替えたときは data-theme が優先 ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b;
    --surface: #181d23;
    --surface-2: #1e252c;
    --surface-3: #262e36;
    --text: #e4e8ec;
    --text-muted: #9aa5af;
    --border: #2c353e;
    --accent: #5fa8c0;
    --accent-ink: #0d1316;
    --accent-2: #f39a4a;
    --link: #7cc0d8;
    --ok: #5cc28a;
    --ng: #ef7464;
    --ai: #b79cf0;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12161b;
  --surface: #181d23;
  --surface-2: #1e252c;
  --surface-3: #262e36;
  --text: #e4e8ec;
  --text-muted: #9aa5af;
  --border: #2c353e;
  --accent: #5fa8c0;
  --accent-ink: #0d1316;
  --accent-2: #f39a4a;
  --link: #7cc0d8;
  --ok: #5cc28a;
  --ng: #ef7464;
  --ai: #b79cf0;
  --shadow: none;
  color-scheme: dark;
}

/* ---------- 基本 ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

a { color: var(--link); }
a:hover { color: var(--accent-2); }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { line-height: 1.45; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 4px; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

/* ---------- ヘッダー ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 8px 24px;
  min-height: 64px;
  flex-wrap: wrap;
}

.site-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.03em;
  margin-right: auto;
}
.site-title:hover { color: var(--text); }
.site-title svg { color: var(--accent); flex: none; }

.header-tools { display: flex; gap: 4px; order: 2; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }

/* 今の表示モードのアイコンだけ出す */
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

.menu-btn { display: none; }

.site-nav { order: 1; }
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 2px; }
.site-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}
.site-nav a:hover { background: var(--surface-2); color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--accent); font-weight: 700; box-shadow: inset 0 -2px 0 var(--accent-2); border-radius: 8px 8px 0 0; }

@media (max-width: 820px) {
  .header-inner { gap: 0 8px; min-height: 56px; }
  .site-title { font-size: 1.02rem; gap: 8px; }
  .site-title svg { width: 26px; height: 26px; }
  .menu-btn { display: inline-grid; }
  .site-nav { order: 3; width: 100%; display: none; padding-bottom: 12px; }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; }
  .site-nav a { padding: 10px 12px; }
  .site-nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent-2); border-radius: 0 8px 8px 0; background: var(--surface-2); }
}

/* ---------- 本文のレイアウト ---------- */
main { padding: 32px 0 64px; }

.with-sidebar { display: grid; gap: 40px; }
@media (min-width: 960px) {
  .with-sidebar { grid-template-columns: minmax(0, 1fr) 300px; }
}

.content { min-width: 0; }
.content.narrow { max-width: 860px; margin: 0 auto; }

.breadcrumbs { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.breadcrumbs a { color: var(--text-muted); }

.page-header { margin-bottom: 28px; }
.page-title { font-size: 1.85rem; margin: 0 0 8px; }
.lead { color: var(--text-muted); margin: 0; font-size: 1.02rem; }

.section { margin-top: 44px; }
.section:first-child { margin-top: 0; }
.section-title {
  font-size: 1.3rem;
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.section-title .more-link { font-size: 0.875rem; font-weight: 400; }
section + section { margin-top: 44px; }

/* ---------- ホームの見出し ---------- */
.hero {
  padding: 40px 0 8px;
}
.hero h1 { font-size: 2rem; margin: 0 0 12px; }
.hero p { margin: 0; color: var(--text-muted); max-width: 720px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

/* ---------- 記事一覧 ---------- */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-item { padding: 18px 0; border-bottom: 1px solid var(--border); }
.post-item:first-child { padding-top: 4px; }
.post-link { display: block; text-decoration: none; color: var(--text); }
.post-link:hover { color: var(--text); }
.post-link:hover .post-title { color: var(--link); }
.post-title { display: block; font-size: 1.15rem; font-weight: 700; line-height: 1.5; }
.post-excerpt { display: block; color: var(--text-muted); font-size: 0.93rem; margin-top: 4px; }
.post-meta { margin: 8px 0 0; font-size: 0.85rem; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }

/* ---------- 記事本文 ---------- */
.post-header { margin-bottom: 28px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.prose { font-size: 1.02rem; line-height: 1.95; }
.prose h2 { font-size: 1.4rem; margin: 2em 0 0.8em; padding-left: 12px; border-left: 4px solid var(--accent-2); }
.prose h3 { font-size: 1.15rem; margin: 1.8em 0 0.6em; }
.prose p { margin: 0 0 1.2em; }
.prose blockquote { margin: 1.2em 0; padding: 4px 16px; border-left: 4px solid var(--border); color: var(--text-muted); }
.prose code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em; }
.prose pre { background: var(--surface-2); padding: 14px 16px; border-radius: 8px; overflow-x: auto; line-height: 1.6; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 12px; }
.prose th { background: var(--surface-2); }
.prose img { border-radius: 8px; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

.post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; }
.post-nav a { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.post-nav a:hover { border-color: var(--accent); }
.post-nav span { display: block; }
.post-nav .next { text-align: right; grid-column: 2; }
@media (max-width: 600px) { .post-nav { grid-template-columns: 1fr; } .post-nav .next { grid-column: 1; } }

/* ---------- サイドバー ---------- */
.sidebar { display: grid; gap: 20px; align-content: start; }
.sidebar section + section { margin-top: 0; }
.side-box { background: var(--surface-2); border-radius: var(--radius); padding: 18px 20px; }
.side-title { font-size: 0.95rem; margin: 0 0 10px; }
.profile-box { text-align: center; }
.profile-box p { margin: 6px 0; }
.avatar { display: inline-block; }
.profile-name { font-weight: 700; }
.side-tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.side-tags a { display: inline-flex; gap: 6px; align-items: center; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 0.85rem; }
.side-tags a:hover { border-color: var(--accent); }
.side-tags .count { color: var(--text-muted); font-size: 0.75rem; }
.side-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 0.92rem; }
.side-list li { display: flex; flex-direction: column; }

/* ---------- カード ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.cards-fit { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card h3 { margin: 6px 0 6px; font-size: 1.1rem; }
.card p { margin: 0 0 12px; color: var(--text-muted); flex: 1; }

.card-link { text-decoration: none; color: inherit; transition: border-color 0.15s, transform 0.15s; }
.card-link:hover { color: inherit; border-color: var(--accent); transform: translateY(-2px); }
.card-link .more { color: var(--link); font-weight: 700; font-size: 0.92rem; }
.card-icon { font-size: 1.6rem; line-height: 1; }

.tag {
  display: inline-block;
  font-size: 0.75rem;
  line-height: 1.6;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-right: 4px;
  text-decoration: none;
}
a.tag:hover { border-color: var(--accent); color: var(--text); }
.tag-license { background: transparent; color: var(--accent); border-color: var(--accent); }
.tag-latest { background: transparent; color: var(--ok); border-color: var(--ok); }

/* ---------- 経歴（筆者について） ---------- */
.career { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0 0 1.2em; padding-left: 14px; border-left: 3px solid var(--border); }
.career dt { font-weight: 700; color: var(--accent); white-space: nowrap; }
.career dd { margin: 0; }
@media (max-width: 480px) {
  .career { grid-template-columns: 1fr; gap: 0; }
  .career dd { margin-bottom: 10px; }
}

/* ---------- 記事を書いたのがだれか（筆者／生成AI） ---------- */
.writer {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.75rem; line-height: 1.6; padding: 1px 9px; border-radius: 999px;
  border: 1px solid currentColor; font-weight: 700; white-space: nowrap;
}
.writer-me { color: var(--accent); }
.writer-ai { color: var(--ai); }
.writer-mixed { color: var(--ai); border-style: dashed; }
.writer-note {
  margin: 0 0 1.4em; padding: 10px 14px; border-radius: 8px; font-size: 0.9rem;
  border-left: 4px solid var(--ai); background: var(--surface-2); color: var(--text-muted);
}
.writer-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.writer-filter[hidden] { display: none; }
.writer-filter button {
  font: inherit; font-size: 0.85rem; padding: 4px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
}
.writer-filter button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--surface-2); font-weight: 700; }

/* ---------- ゲーム ---------- */
.game-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.game-chips a {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 999px; text-decoration: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.92rem;
}
.game-chips a:hover { border-color: var(--accent); }
.game-chips span { color: var(--accent); font-weight: 700; font-variant-emoji: text; }
.game-chips .chip-icon {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; margin-left: -6px;
  background: var(--game); color: #fff;
}
.game-chips .chip-icon svg { width: 17px; height: 17px; }

/* ゲーム一覧：説明あり（カード）とアイコンだけ（タイル） */
.games-filters { margin-bottom: 18px; }
.game-list { display: grid; gap: 14px; }
.game-list.is-detail { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.game-list.is-simple { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px; }
.game-item { position: relative; display: flex; gap: 14px; text-decoration: none; color: var(--text); border-radius: var(--radius); }
.game-item:hover { color: var(--text); }
.game-tile {
  position: relative; flex: none; display: grid; place-items: center; width: 64px; height: 64px; border-radius: 16px;
  background: var(--game); color: #fff; box-shadow: var(--shadow); transition: transform 0.15s;
}
.game-tile svg { width: 60%; height: 60%; }
.game-item:hover .game-tile { transform: translateY(-2px); }
.game-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.game-title { font-weight: 700; font-size: 1.08rem; line-height: 1.4; }
.game-summary { color: var(--text-muted); font-size: 0.92rem; line-height: 1.7; }
.game-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin-top: 2px; }
.game-state { font-size: 0.8rem; font-weight: 700; color: var(--ok); }
.game-dot {
  position: absolute; right: -6px; top: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; font-size: 0.68rem; font-weight: 700; line-height: 1;
  background: var(--accent-2); color: #fff; box-shadow: 0 0 0 2px var(--bg);
}
.is-detail .game-item { padding: 16px; border: 1px solid var(--border); background: var(--surface); }
.is-detail .game-item:hover { border-color: var(--accent); }
.is-detail .game-dot { display: none; }
.is-simple .game-item { flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 4px 0; }
.is-simple .game-tile { width: 100%; height: auto; aspect-ratio: 1; max-width: 120px; border-radius: 22px; }
.is-simple .game-title { font-size: 0.88rem; line-height: 1.35; }
.is-simple .game-summary, .is-simple .game-meta { display: none; }
@media (max-width: 599px) {
  .game-list.is-detail { grid-template-columns: 1fr; }
  .game-list.is-simple { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .is-detail .game-item { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) { .game-tile { transition: none; } }

/* ---------- お知らせ枠 ---------- */
.notice {
  background: var(--surface-2);
  border-left: 4px solid var(--accent-2);
  border-radius: 8px;
  padding: 14px 18px;
}
.notice p:first-child { margin-top: 0; }
.notice p:last-child, .notice ul:last-child { margin-bottom: 0; }
.notice ul { padding-left: 1.2em; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  min-height: 42px;
}
.btn:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn-outline { background: transparent; color: var(--accent); }
.btn-outline:hover { color: var(--accent); background: var(--surface-2); }
.btn-accent { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-accent:hover { color: #fff; }

/* ---------- 表 ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
.table-wrap table { min-width: 560px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-size: 0.88rem; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.nowrap-3 td:nth-child(-n+3) { white-space: nowrap; }

/* ---------- 絞り込みフォーム ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 16px; }
.filters label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--text-muted); gap: 4px; max-width: 100%; }
.filters .check-inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 0.95rem; min-height: 42px; }
.check-inline input { width: 18px; height: 18px; }

select, input[type="search"], input[type="text"] {
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
  max-width: 100%;
}

/* ---------- 定義リスト（資格の概要など） ---------- */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; }
@media (max-width: 600px) { .facts { grid-template-columns: 1fr; gap: 2px; } .facts dd { margin-bottom: 8px; } }

/* ---------- 規約の確認ダイアログ ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog-body { padding: 20px 24px; overflow-y: auto; max-height: calc(100vh - 170px); }
.dialog-body h2 { margin-top: 0; font-size: 1.25rem; }
.dialog-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.dl-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.license-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; font-size: 0.92rem; }
.license-box dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.license-box dt { font-weight: 700; }
.license-box dd { margin: 0; word-break: break-all; }

.terms-box {
  max-height: 40vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 16px 12px;
  background: var(--surface);
  font-size: 0.88rem;
}

.agree { display: flex; gap: 8px; align-items: flex-start; margin-top: 16px; font-weight: 700; }
.agree input { width: 20px; height: 20px; margin-top: 4px; flex: none; }

/* ---------- 教科書：過去のバージョン ---------- */
.history { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); flex: none; }
.history p { margin: 0 0 6px; flex: none; }
.history ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- 利用規約の全文 ---------- */
.terms h2 { font-size: 1.3rem; }
.terms h3 { font-size: 1rem; margin: 20px 0 6px; }
.terms p { margin: 0 0 6px; }
.terms-version { color: var(--text-muted); font-size: 0.9rem; }
.terms-items { margin: 0; padding-left: 1.6em; }
.terms-items > li { margin-bottom: 6px; }
.terms-sub { list-style: none; counter-reset: go; padding-left: 0.5em; margin: 4px 0 8px; }
.terms-sub > li { counter-increment: go; padding-left: 2.4em; text-indent: -2.4em; margin-bottom: 2px; }
.terms-sub > li::before { content: "（" counter(go, cjk-ideographic) "）"; }
.terms-closing { margin-top: 20px; }

/* ---------- 教科書の巻一覧 ---------- */
.vol-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.vol-item { display: grid; grid-template-columns: 48px 1fr; gap: 14px; align-items: start; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.vol-no { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff; }
.vol-item h3 { margin: 0; font-size: 1.05rem; }
.vol-item p { margin: 4px 0 0; font-size: 0.9rem; color: var(--text-muted); }

/* ---------- フッター ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface-2); padding: 40px 0 16px; font-size: 0.92rem; }
.footer-grid { display: grid; gap: 24px; grid-template-columns: 2fr 1fr 1fr 1fr; }
@media (max-width: 820px) { .footer-grid { grid-template-columns: 1fr 1fr; } .footer-grid > div:first-child { grid-column: 1 / -1; } }
.footer-title { font-weight: 700; margin: 0 0 6px; }
.footer-head { font-weight: 700; margin: 0 0 8px; font-size: 0.9rem; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent-2); }
.copyright { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.85rem; }
.copyright p { margin: 0; }

@media (max-width: 600px) {
  main { padding-top: 20px; }
  .page-title { font-size: 1.5rem; }
  .hero { padding-top: 16px; }
  .hero h1 { font-size: 1.55rem; }
  .dialog-body, .dialog-footer { padding-left: 16px; padding-right: 16px; }
}

/* ---------- 教科書：巻のアイコン・簡易表示 ---------- */
.card-head { display: flex; align-items: center; gap: 12px; }
.vol-icon {
  position: relative;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--vol);
  color: #fff;
  display: grid;
  place-items: center;
}
.vol-icon svg { width: 28px; height: 28px; }
.vol-icon .vol-num { position: absolute; top: 2px; left: 5px; font-size: 0.68rem; font-weight: 700; line-height: 1.2; }
.vol-icon .kind-badge { position: absolute; right: -6px; bottom: -6px; font-size: 0.6rem; }

.vol-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile, 104px), 1fr));
  gap: 14px;
}
.vol-tile {
  position: relative;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 18px;
  aspect-ratio: 1;
  transition: transform 0.15s;
}
.vol-tile:hover { transform: translateY(-3px); }
.vol-tile:focus-visible { outline-offset: 3px; }
.vol-tile-face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: var(--vol);
  color: #fff;
  box-shadow: var(--shadow);
}
.vol-tile-face svg { width: 52%; height: 52%; }
.vol-tile-face .vol-num { position: absolute; top: 8px; left: 11px; font-weight: 700; font-size: 0.95rem; }
.vol-tile.is-old .vol-tile-face { opacity: 0.6; }

.kind-badge, .old-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.6;
}
.old-badge { top: 6px; bottom: auto; }

.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.view-switch .seg {
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 14px;
  min-height: 42px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.view-switch .seg + .seg { border-left: 1px solid var(--border); }
.view-switch .seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ============================================================
   端末・画面の比率に合わせた表示の最適化
   幅だけでなく、縦横の比率（aspect-ratio / orientation）と
   操作方法（タッチかマウスか）を読み取って調整します。
   ============================================================ */

/* 大きな画面（PC）：本文を少し大きく、横幅を広く */
@media (min-width: 1440px) {
  html { font-size: 17px; }
  .container { max-width: 1240px; }
  .with-sidebar { grid-template-columns: minmax(0, 1fr) 320px; }
}

/* 横に極端に長い画面（ウルトラワイド）：読みやすい幅に抑えて中央に */
@media (min-width: 1440px) and (min-aspect-ratio: 21/9) {
  .container { max-width: 1320px; }
}

/* ノート PC・横向きタブレット：サイドバーを少し細く */
@media (min-width: 960px) and (max-width: 1199px) {
  .with-sidebar { grid-template-columns: minmax(0, 1fr) 260px; gap: 28px; }
}

/* 縦向きタブレット：サイドバーは本文の下に2列で並べる */
@media (min-width: 600px) and (max-width: 959px) and (orientation: portrait) {
  .sidebar { grid-template-columns: 1fr 1fr; }
  .sidebar .profile-box { grid-column: 1 / -1; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vol-tiles { --tile: 120px; }
}

/* 横向きタブレット（幅は狭めだが横長）：カードを3列に */
@media (min-width: 820px) and (max-width: 1199px) and (orientation: landscape) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* スマートフォン（縦向き） */
@media (max-width: 599px) {
  .cards { grid-template-columns: 1fr; }
  .vol-tiles { --tile: 88px; gap: 10px; }
  .filters > label, .filters select, .filters input[type="search"] { width: 100%; }
  .view-switch { width: 100%; }
  .view-switch .seg { flex: 1; }
  .footer-grid { gap: 20px; }
}

/* スマートフォンを横向きにしたとき（高さが低い）：ヘッダーを固定せず、余白を詰めて縦の表示領域を確保 */
@media (orientation: landscape) and (max-height: 500px) {
  .site-header { position: static; }
  main { padding: 16px 0 32px; }
  .hero { padding-top: 8px; }
  .page-title, .hero h1 { font-size: 1.4rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .vol-tiles { --tile: 80px; }
  dialog { max-height: calc(100vh - 16px); }
  .dialog-body { max-height: calc(100vh - 120px); }
  .terms-box { max-height: 30vh; }
}

/* タッチ操作の端末：押しやすいように、リンクやボタンの当たり判定を広げる */
@media (pointer: coarse) {
  .site-nav a { padding: 12px 14px; }
  .side-list a, .site-footer a { display: inline-block; padding: 4px 0; }
  .tag { padding: 3px 10px; }
  .agree input, .check-inline input { width: 22px; height: 22px; }
}

/* 動きを減らす設定の端末：アニメーションを止める */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================
   教科書ビューア
   ============================================================ */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

main:has(.viewer) { padding: 0; }
main:has(.viewer) ~ .site-footer { display: none; }   /* ビューアは画面いっぱいに使う */
.viewer {
  --hdr: 65px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--hdr));
  height: calc(100dvh - var(--hdr));
  background: var(--surface-3);
}
@media (max-width: 820px) { .viewer { --hdr: 57px; } }
@media (orientation: landscape) and (max-height: 500px) { .viewer { --hdr: 0px; } }

.viewer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.vb-group { display: flex; align-items: center; gap: 4px; }
.vb-title { flex: 1 1 260px; min-width: 0; }
.vb-book { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.vb-book-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vb-book-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vb-page input { width: 4.2em; text-align: center; }
.vb-actions .btn { min-height: 40px; padding: 6px 14px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

.shot-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--accent-2) 16%, var(--bg));
  border-bottom: 1px solid var(--accent-2);
  font-size: 0.92rem;
  font-weight: 700;
}
.shot-banner[hidden] { display: none; }
.shot-banner-actions { display: flex; gap: 8px; }
.shot-banner .btn { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; }

.viewer-body { flex: 1; min-height: 0; display: flex; position: relative; }

/* ページを表示する場所。ページ全体が収まるときは中央に置く */
.viewer-stage {
  flex: 1;
  min-width: 0;
  overflow: auto;
  position: relative;
  display: flex;
  outline: none;
  touch-action: pan-y pinch-zoom;       /* 横のスワイプはページめくりに使う */
  -webkit-overflow-scrolling: touch;
}
.viewer-stage.is-zoomed { touch-action: auto; }
.spread { margin: auto; display: flex; gap: 4px; padding: 16px; }
.spread[hidden] { display: none; }
.page-wrap { position: relative; flex: none; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25); background: #fff; }
.spread.is-spread .page-wrap:first-child { box-shadow: -2px 2px 12px rgba(0, 0, 0, 0.25), inset -12px 0 16px -12px rgba(0, 0, 0, 0.25); }
.spread.is-spread .page-wrap:last-child { box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.25); }
.page-wrap canvas { display: block; }
.viewer-msg { max-width: 560px; margin: 40px auto; text-align: center; color: var(--text-muted); }

/* 画面の端（左右）：マウスを乗せると矢印を出し、押すとページをめくる */
.edge-hint {
  position: sticky;
  top: 0;
  flex: none;
  width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--text);
}
.edge-hint svg { padding: 10px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 85%, transparent); box-shadow: var(--shadow); width: 48px; height: 48px; flex: none; }
.edge-prev { order: -1; left: 0; justify-content: flex-start; }
.edge-prev svg { margin-left: 12px; }
.edge-next { right: 0; justify-content: flex-end; }
.edge-next svg { margin-right: 12px; }
.viewer-stage.hover-prev, .viewer-stage.hover-next { cursor: pointer; }
.viewer-stage.hover-prev .edge-prev, .viewer-stage.hover-next .edge-next { opacity: 1; }

.shot-layer { position: absolute; inset: 0; cursor: crosshair; touch-action: none; background: rgba(0, 0, 0, 0.12); }
.shot-rect { position: absolute; border: 2px solid var(--accent-2); background: rgba(232, 115, 12, 0.15); box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25); }

/* しおり（目次） */
.viewer-toc {
  flex: none;
  width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.viewer-toc[hidden] { display: none; }
.toc-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border); }
.toc-list { list-style: none; margin: 0; padding: 6px 0 16px; overflow-y: auto; flex: 1; }
.toc-list button {
  display: flex;
  width: 100%;
  gap: 8px;
  justify-content: space-between;
  align-items: baseline;
  text-align: left;
  padding: 7px 14px 7px 16px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.toc-list button:hover { background: var(--surface-2); }
.toc-list .toc-l1 button { font-weight: 700; margin-top: 4px; }
.toc-list .toc-l2 button { padding-left: 30px; }
.toc-list .toc-l3 button { padding-left: 44px; font-size: 0.85rem; }
.toc-list button[aria-current="true"] { border-left-color: var(--accent-2); background: var(--surface-2); color: var(--accent); }
.toc-p { color: var(--text-muted); font-size: 0.8rem; font-weight: 400; flex: none; }
.toc-backdrop { display: none; }

/* 画面が狭いときは、しおりを左から重ねて出す */
@media (max-width: 1023px) {
  .viewer-toc { position: absolute; z-index: 5; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25); }
  .toc-backdrop { display: block; position: absolute; inset: 0; z-index: 4; background: rgba(0, 0, 0, 0.35); }
  .toc-backdrop[hidden] { display: none; }
}

.vb-view select, .vb-page input {
  min-height: 38px;
  padding: 4px 6px;
  font: inherit;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

/* 意見の入力 */
.fb-shot { display: block; max-width: 100%; max-height: 260px; margin: 0 auto 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.fb-auto { margin-bottom: 12px; }
.fb-auto summary { cursor: pointer; color: var(--text-muted); }
.fb-auto .facts { margin-top: 8px; }
.fb-kinds { border: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.fb-kinds legend { font-weight: 700; margin-bottom: 6px; }
.fb-kinds label { display: flex; gap: 8px; align-items: center; }
.fb-kinds input { width: 18px; height: 18px; }
.fb-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 700; font-size: 0.92rem; }
.fb-field textarea, .fb-field select { font: inherit; font-weight: 400; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.fb-hp { position: absolute; left: -9999px; }
.fb-status { min-height: 1.5em; margin: 8px 0 0; }
.fb-status.is-error { color: var(--ng); }
.fb-status.is-ok { color: var(--ok); font-weight: 700; }

@media (max-width: 599px) {
  /* スマホ：1段目に書名と操作ボタン、2段目にページ移動と表示の切り替え（読む場所を広く取る） */
  .viewer-bar { gap: 4px 6px; padding: 6px 8px; justify-content: space-between; }
  .viewer-bar .icon-btn { width: 36px; height: 36px; }
  .vb-title { order: 1; flex: 1 1 calc(100% - 100px); }
  .vb-actions { order: 2; }
  .vb-nav, .vb-view { order: 3; }
  .vb-actions .btn { width: 44px; padding: 0; }
  .vb-actions .btn span { display: none; }      /* スマホではカメラのアイコンだけ */
  .vb-page input { width: 3.6em; }
  #vw-layout { display: none; }                  /* スマホの縦向きは1ページ（自動）で読む */
  #vw-zoom-in, #vw-zoom-out { display: none; }   /* スマホの拡大縮小は指でのピンチ操作で */
  .spread { padding: 8px; }
}

/* とても幅の狭いスマホ（360px 前後） */
@media (max-width: 380px) {
  .site-title { font-size: 0.92rem; letter-spacing: 0; gap: 6px; }
  .header-tools { gap: 0; }
  .header-tools .icon-btn { width: 36px; height: 36px; }
  .site-title svg { width: 22px; height: 22px; }
  .vb-title .icon-btn:first-child { display: none; } /* 一覧へ戻るはブラウザの「戻る」で */
}

/* ---------- ビューア：読者の声の機能 ---------- */
.rev-banner { position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 3; max-width: min(720px, 92%); margin-top: 8px; padding: 8px 14px; border-radius: 10px; background: color-mix(in srgb, var(--ok) 14%, var(--bg)); border: 1px solid var(--ok); font-size: 0.88rem; box-shadow: var(--shadow); }
.rev-banner p { margin: 0; }
.rev-banner { cursor: pointer; }
.rev-banner[hidden] { display: none; }

.page-signal {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  white-space: nowrap;
}
.page-signal[hidden] { display: none; }
.page-signal button { font: inherit; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.page-signal button:hover { border-color: var(--accent); }
.page-signal button[data-signal="hard"] { color: var(--ng); }
.page-signal.is-voted button, .page-signal.is-voted .ps-q { display: none; }
.ps-stats { color: var(--text-muted); }
.ps-stats:empty { display: none; }
.page-signal.is-voted .ps-stats:empty::after { content: "ありがとうございました"; }
.page-signal.is-voted .ps-stats:empty { display: inline; }

.toast { position: absolute; z-index: 6; top: 12px; right: 12px; max-width: min(360px, 90%); padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.88rem; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }
.toast[hidden] { display: none; }

.mark { position: absolute; pointer-events: none; border-radius: 3px; border: 2px solid rgba(232, 115, 12, 0.85); background: rgba(232, 115, 12, 0.12); }
.mark-question { border-color: rgba(47, 127, 193, 0.85); background: rgba(47, 127, 193, 0.12); }
.mark-error { border-color: rgba(192, 57, 43, 0.85); background: rgba(192, 57, 43, 0.1); }
#vw-marks[aria-pressed="true"] { background: color-mix(in srgb, var(--accent-2) 20%, transparent); color: var(--accent-2); }

.toc-heat { flex: none; min-width: 1.8em; padding: 0 6px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-align: center; line-height: 1.6; color: #fff; }
.toc-heat.heat-1 { background: #e9b949; }
.toc-heat.heat-2 { background: #e8730c; }
.toc-heat.heat-3 { background: #c0392b; }
.toc-foot { padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.toc-foot .btn { width: 100%; min-height: 38px; font-size: 0.88rem; }

.fb-tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 12px; }
.fb-tabs button { flex: 1; font: inherit; font-weight: 700; padding: 10px 8px; border: none; background: none; color: var(--text-muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.fb-tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent-2); }
.fb-shot-wrap { margin-bottom: 8px; }
canvas.fb-shot { display: block; max-width: 100%; max-height: 260px; margin: 0 auto 6px; border: 1px solid var(--border); border-radius: 8px; background: #fff; touch-action: auto; }
canvas.fb-shot.is-pen { cursor: crosshair; touch-action: none; outline: 2px solid var(--accent-2); }
.fb-pen-tools { display: flex; gap: 8px; justify-content: center; }
.fb-pen-tools .btn { min-height: 34px; padding: 2px 12px; font-size: 0.82rem; }
#vw-pen[aria-pressed="true"] { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.fb-reader { margin-top: 8px; }
form[hidden], .fb-ask[hidden] { display: none; }

.chat { display: grid; gap: 8px; margin-bottom: 10px; }
.chat:empty { display: none; }
.bubble { padding: 10px 12px; border-radius: 12px; font-size: 0.92rem; line-height: 1.75; white-space: pre-wrap; max-width: 92%; }
.bubble-me { justify-self: end; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.bubble-ai { justify-self: start; background: var(--surface-2); border: 1px solid var(--border); }
.bubble.is-wait { color: var(--text-muted); font-style: italic; }
.rate { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; white-space: normal; }
.rate button { font: inherit; font-size: 0.8rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.linklike { font: inherit; border: none; background: none; padding: 0; color: var(--link); text-decoration: underline; cursor: pointer; }
.fb-ask-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

.mine-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.mine-list li { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.tag.st-done { color: var(--ok); border-color: var(--ok); background: transparent; }
.tag.st-in_progress { color: var(--accent-2); border-color: var(--accent-2); background: transparent; }

@media (max-width: 599px) {
  .page-signal { bottom: 8px; font-size: 0.75rem; }
  .ps-q { display: none; }
}
