:root {
  --bg: #fafaf9; --fg: #1f2937; --muted: #6b7280; --line: #e5e7eb; --accent: #0f766e; --accent-2: #e0f2f1;
  --rec: #b45309; --rec-bg: #fff7ed; --err: #b91c1c; --err-bg: #fef2f2; --card: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111827; --fg: #e5e7eb; --muted: #9ca3af; --line: #374151; --accent: #2dd4bf; --accent-2: #134e4a;
          --rec-bg: #3b2a12; --err-bg: #3b1515; --card: #1f2937; }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
       background: var(--bg); color: var(--fg); line-height: 1.55; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.top { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--fg); }
.brand span { color: var(--accent); margin-left: .15rem; }
header nav a { margin-right: .75rem; color: var(--muted); }
header nav a.on { color: var(--fg); font-weight: 600; }
.ver { margin-left: auto; color: var(--muted); font-size: .8rem; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
input[type=search], input[type=number], input[type=text], select { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); }
input[type=search] { flex: 1; min-width: 240px; font-size: 1.05rem; }
button, .btn { font: inherit; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; display: inline-block; }
button.secondary, .btn.secondary { background: var(--card); color: var(--accent); }
button.link { background: none; border: none; color: var(--muted); padding: 0 .3rem; }
.filters { margin-top: .5rem; }
.filters summary { cursor: pointer; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .5rem .8rem; margin-top: .5rem; }
.grid label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); gap: .2rem; }
.grid label.chk { flex-direction: row; align-items: center; gap: .4rem; align-self: end; }
.grid select, .grid input { width: 100%; }
.meta, .dim { color: var(--muted); font-size: .85rem; }
.small { font-size: .8rem; }
code { background: var(--accent-2); padding: .05rem .3rem; border-radius: 4px; }
.hit { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .75rem .9rem; margin: .6rem 0; }
.hit-head { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.hit .title { font-weight: 600; }
.hit .page { color: var(--muted); }
.section { color: var(--muted); font-size: .8rem; margin: .15rem 0; }
.snippet { margin: .3rem 0; white-space: pre-wrap; }
.hit-foot { font-size: .8rem; color: var(--muted); }
.tag { font-size: .72rem; padding: .05rem .4rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.rec { color: var(--rec); background: var(--rec-bg); border-color: transparent; }
.tag.err { color: var(--err); background: var(--err-bg); border-color: transparent; }
mark { background: #fde68a; color: #111; padding: 0 .1rem; border-radius: 2px; }
.answer { background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: .8rem 1rem; margin: .8rem 0; }
.answer-head { display: flex; gap: .6rem; align-items: baseline; }
.answer-head .link { margin-left: auto; }
.answer-body { white-space: pre-wrap; margin-top: .5rem; }
.answer-body.loading::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.sources { margin-top: .6rem; border-top: 1px dashed var(--line); padding-top: .5rem; font-size: .85rem; }
.sources ol { padding-left: 1.4rem; margin: .2rem 0; }
table.list, table.recs { width: 100%; border-collapse: collapse; background: var(--card); font-size: .92rem; }
table th, table td { border-bottom: 1px solid var(--line); padding: .4rem .5rem; text-align: left; vertical-align: top; }
table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.cls { font-weight: 700; white-space: nowrap; }
.cls-I { color: #15803d; } .cls-IIa { color: #0e7490; } .cls-IIb { color: #b45309; } .cls-III, .cls-III-Harm, .cls-III-No-benefit { color: #b91c1c; }
.gl-head h1 { font-size: 1.25rem; margin: .2rem 0; }
.viewer-head { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.viewer-head .pager { display: inline-flex; gap: .4rem; align-items: center; }
.viewer-head form.inline { display: inline-flex; gap: .3rem; }
.viewer-body { display: grid; grid-template-columns: 3fr 2fr; gap: .8rem; height: calc(100vh - 140px); }
.viewer-body .pdf { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: flex; flex-direction: column; }
.viewer-body .pdf .pdf-tools { padding: .3rem .6rem; border-bottom: 1px solid var(--line); background: var(--card); font-size: .85rem; }
.viewer-body .pdf img { width: 100%; height: auto; display: block; }
.viewer-body .pdf iframe { width: 100%; flex: 1; min-height: 70vh; border: 0; background: #fff; }
.viewer-body .text { overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem; background: var(--card); }
.viewer-body .text pre { white-space: pre-wrap; font: inherit; margin: 0; }
.hint { color: var(--muted); }
@media (max-width: 800px) {
  .viewer-body { grid-template-columns: 1fr; height: auto; }
  .viewer-body .pdf iframe { height: 70vh; }
  main { padding: .6rem; }
}

/* ============================================================ 共通追加 */
.btn.small, button.small { padding: .3rem .6rem; font-size: .85rem; }
.engine { margin-top: .4rem; }
.inline-label { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.inline-label select { max-width: 100%; }
.layout-toggle { font-size: .8rem; }
.tabbar { display: none; }

/* ============================================================ 閲覧（領域別） */
.browse-head h1 { font-size: 1.3rem; margin: .2rem 0; }
.cats { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 1rem; }
.cat { display: inline-flex; align-items: center; gap: .3rem; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg); font-size: .9rem; }
.cat .n { color: var(--muted); font-size: .78rem; }
.cat.on { border-color: var(--accent); background: var(--accent-2); color: var(--fg); font-weight: 600; }
.cat-body h2 { font-size: 1.1rem; margin: .6rem 0 .3rem; }
details.soc { margin: .6rem 0; }
details.soc summary { cursor: pointer; padding: .3rem 0; }
.cards { list-style: none; margin: .3rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .6rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; display: flex; flex-direction: column; gap: .35rem; }
.card.old { opacity: .75; }
.card-title { font-weight: 600; line-height: 1.35; }
.card-meta { display: flex; flex-wrap: wrap; gap: .5rem; color: var(--muted); font-size: .8rem; align-items: center; }
.card-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: auto; }
.cards.overview .card-title { font-size: 1.02rem; }

/* ============================================================ リーダー */
.reader-head { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; position: sticky; top: 46px; background: var(--bg); padding: .4rem 0; z-index: 4; border-bottom: 1px solid var(--line); }
.reader-title { flex: 1; min-width: 200px; display: flex; flex-direction: column; line-height: 1.3; }
.reader-tools { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.reader-tools .pager { display: inline-flex; align-items: center; gap: .2rem; }
.reader-tools .pager input { width: 4.2em; padding: .25rem .3rem; text-align: center; }
.toc-btn { display: none; }
.reader-body { display: grid; grid-template-columns: 280px 1fr; gap: .8rem; margin-top: .6rem; }
.toc { position: sticky; top: 104px; align-self: start; max-height: calc(100vh - 120px); overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: .5rem .6rem; font-size: .86rem; }
.toc-head { display: flex; justify-content: space-between; align-items: center; }
.toc-head .link { display: none; }
.toc input[type=search] { width: 100%; min-width: 0; font-size: .85rem; padding: .3rem .5rem; margin: .3rem 0; }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li a { display: flex; justify-content: space-between; gap: .4rem; padding: .18rem .3rem; border-radius: 6px; color: var(--fg); }
.toc-list li a .pg { color: var(--muted); font-size: .75rem; flex: none; }
.toc-list li a.on { background: var(--accent-2); font-weight: 600; }
.toc-list li.lv1 a { font-weight: 600; margin-top: .3rem; }
.toc-list li.lv2 a { padding-left: .8rem; }
.toc-list li.lv3 a { padding-left: 1.6rem; color: var(--muted); }
.pages { min-width: 0; }
.page-img { margin: 0 0 .8rem; background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.page-img img { width: 100%; height: auto; display: block; aspect-ratio: 1240 / 1754; background: #f3f4f6; }
.page-no { font-size: .75rem; color: var(--muted); text-align: right; padding: .15rem .5rem; }
.page-text { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; margin-bottom: .8rem; }
.page-text pre { white-space: pre-wrap; font: inherit; margin: 0; }

/* ============================================================ スマホ表示（html.layout-mobile） */
html.layout-mobile body { font-size: 16px; }
html.layout-mobile header.top { padding: .4rem .6rem; gap: .5rem; }
html.layout-mobile header.top nav { display: none; }
html.layout-mobile header.top .ver { display: none; }
html.layout-mobile main { padding: .6rem .6rem 4.5rem; }
html.layout-mobile .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); z-index: 6; padding-bottom: env(safe-area-inset-bottom); }
html.layout-mobile .tabbar a { flex: 1; text-align: center; padding: .4rem 0 .3rem; color: var(--muted); font-size: .72rem; display: flex; flex-direction: column; gap: .05rem; }
html.layout-mobile .tabbar a .ic { font-size: 1.25rem; }
html.layout-mobile .tabbar a.on { color: var(--accent); font-weight: 600; }
html.layout-mobile input[type=search] { min-width: 0; width: 100%; font-size: 1rem; }
html.layout-mobile .search .row button { flex: 1; padding: .6rem .6rem; }
html.layout-mobile .search .row input[type=search] { flex: 1 1 100%; }
html.layout-mobile .grid { grid-template-columns: 1fr 1fr; }
html.layout-mobile .hit { padding: .6rem .7rem; }
html.layout-mobile .hit-foot a { display: inline-block; padding: .3rem 0; }
html.layout-mobile .cards { grid-template-columns: 1fr; }
html.layout-mobile .card-actions .btn { flex: 1; text-align: center; }
html.layout-mobile .cats { gap: .35rem; }
html.layout-mobile .cat { font-size: .85rem; padding: .35rem .6rem; }
html.layout-mobile .reader-head { top: 42px; }
html.layout-mobile .reader-title { flex-basis: 100%; }
html.layout-mobile .reader-title strong { font-size: .95rem; }
html.layout-mobile .toc-btn { display: inline-block; }
html.layout-mobile .reader-body { grid-template-columns: 1fr; }
html.layout-mobile .toc { display: none; position: fixed; inset: 42px 0 0 0; max-height: none; border-radius: 0; z-index: 7; }
html.layout-mobile .toc.open { display: block; }
html.layout-mobile .toc-head .link { display: inline; }
html.layout-mobile .page-img { border-left: 0; border-right: 0; border-radius: 0; margin: 0 -.6rem .6rem; }
html.layout-mobile .viewer-body { grid-template-columns: 1fr; height: auto; }
html.layout-mobile table.list { font-size: .85rem; }
html.layout-mobile table.list th:nth-child(4), html.layout-mobile table.list td:nth-child(4),
html.layout-mobile table.list th:nth-child(6), html.layout-mobile table.list td:nth-child(6) { display: none; }
html.layout-mobile table.recs th:nth-child(5), html.layout-mobile table.recs td:nth-child(5) { display: none; }

/* ============================================================ AI モード（チャット） */
.chat { display: flex; flex-direction: column; height: calc(100vh - 80px); }
.chat-head { display: flex; justify-content: space-between; gap: .8rem; flex-wrap: wrap; align-items: flex-start; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.chat-tools { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.chat-log { flex: 1; overflow: auto; padding: .6rem 0; }
.chat-empty { color: var(--muted); padding: 1rem; }
.msg { display: flex; margin: .5rem 0; }
.msg.me { justify-content: flex-end; }
.msg .bubble { max-width: 85%; border-radius: 14px; padding: .6rem .9rem; border: 1px solid var(--line); background: var(--card); }
.msg.me .bubble { background: var(--accent-2); border-color: transparent; white-space: pre-wrap; }
.msg.ai .bubble { width: 100%; max-width: 100%; }
.msg.ai .body { white-space: pre-wrap; }
.msg.ai .body.loading::after { content: "▍"; animation: blink 1s steps(2) infinite; }
.chat-sources { margin-top: .5rem; border-top: 1px dashed var(--line); padding-top: .4rem; font-size: .85rem; }
.chat-sources summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.chat-sources ol { padding-left: 1.4rem; margin: .3rem 0; }
.chat-sources li { margin: .15rem 0; }
.chat-meta { margin-top: .3rem; }
.chat-input { display: flex; gap: .5rem; padding-top: .5rem; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input textarea { flex: 1; font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); resize: vertical; min-height: 2.6rem; }
.chat-input button { padding: .6rem 1rem; }
html.layout-mobile .chat { height: calc(100vh - 110px); }
html.layout-mobile .chat-head .small { display: none; }
html.layout-mobile .msg .bubble { max-width: 95%; }
html.layout-mobile .chat-input { position: sticky; bottom: 3.6rem; background: var(--bg); }
/* 新版あり・更新チェック */
.newer-banner { background:#fef3c7; color:#78350f; border:1px solid #f59e0b; border-radius:8px; padding:.5rem .8rem; margin:.5rem 0 .8rem; }
.newer-banner a { color:#78350f; }
.newer-banner a.btn { color:#fff; }
a.tag.newer { background:#fef3c7; color:#78350f; border-color:#f59e0b; text-decoration:none; }
.badge { display:inline-block; min-width:1.2em; padding:0 .35em; border-radius:999px; background:#dc2626; color:#fff; font-size:.72rem; line-height:1.4; text-align:center; font-weight:600; }
.tabbar .badge { position:relative; top:-.1rem; margin-left:.15rem; }
.updates ul.upd > li { margin:.45rem 0; }
.updates h2 { font-size:1.05rem; margin-top:1.2rem; }
/* 出典照合 */
mark.v-warn { background:#fef3c7; color:inherit; border-bottom:2px solid #f59e0b; }
mark.v-ng { background:#fee2e2; color:inherit; border-bottom:2px solid #dc2626; }
mark.v-uncited { background:transparent; color:inherit; border-bottom:2px dotted #9ca3af; }
.verify { margin:.5rem 0; padding:.4rem .6rem; border:1px solid var(--line); border-radius:8px; background:var(--card); }
.verify.ok { border-color:#86efac; }
.verify summary { cursor:pointer; }
.verify ol { margin:.4rem 0 .2rem 1.2rem; padding:0; } .verify li { margin:.25rem 0; }
.v-warn-t { color:#b45309; font-weight:600; } .v-ng-t { color:#b91c1c; font-weight:600; } .v-uncited-t { color:var(--muted); font-weight:600; }
@media (prefers-color-scheme: dark) { mark.v-warn { background:#78350f55; } mark.v-ng { background:#7f1d1d66; } }
