/* よくよむ。インラインの style は使わない（CSP）。値の変化は CSS 変数を CSSOM で入れる。 */
:root {
  --bg: #f5f4f1; --surface: #fff; --ink: #1f1f1f; --muted: #6b6b6b; --line: #e3e0da; --accent: #2b4a6f; --accent-ink: #fff;
  --badge: #c0392b; --chip: #ecebe7; --ok: #2f7d4f; --error: #b3261e; --paper: #f9f8f5; --paper-ink: #1d1d1d;
  --tab-h: 58px; --top-h: 52px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --surface: #1e1e1e; --ink: #e9e7e3; --muted: #a09d97; --line: #2f2f2f; --accent: #8fb3dc; --accent-ink: #0d1b2b;
    --badge: #e06456; --chip: #2a2a2a; --ok: #6fcf97; --error: #f2b8b5; --paper: #161616; --paper-ink: #dedad3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141414; --surface: #1e1e1e; --ink: #e9e7e3; --muted: #a09d97; --line: #2f2f2f; --accent: #8fb3dc; --accent-ink: #0d1b2b;
  --badge: #e06456; --chip: #2a2a2a; --ok: #6fcf97; --error: #f2b8b5; --paper: #161616; --paper-ink: #dedad3;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif; font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden, [hidden] { display: none !important; }
.icon { width: 22px; height: 22px; fill: currentColor; flex: none; }

/* 枠 */
.app { display: flex; flex-direction: column; height: 100dvh; }
.top { height: calc(var(--top-h) + var(--safe-t)); padding-top: var(--safe-t); display: grid; grid-template-columns: 88px 1fr 88px; align-items: center; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.top-title { margin: 0; text-align: center; font-size: 17px; font-weight: 700; }
.top-side { display: flex; gap: 4px; padding: 0 8px; }
.top-side.right { justify-content: flex-end; }
.view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px; max-width: 760px; width: 100%; margin: 0 auto; outline: none; }
.tabbar { flex: none; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tab-h); color: var(--muted); text-decoration: none; font-size: 11px; }
.tab.on { color: var(--accent); }
.tab.on::before { content: ""; position: absolute; inset: 6px 10px; border-radius: 10px; background: var(--chip); z-index: -1; }
.tab-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--badge); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
@media (display-mode: standalone) { html, body { overscroll-behavior-x: none; overflow-x: clip; } }

/* 部品 */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; border: 0; background: none; border-radius: 10px; cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: var(--chip); }
.icon-btn.txt { font-size: 14px; font-weight: 700; padding: 0 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); font-size: 15px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.btn.file { position: relative; }
.input, .select { min-height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 0 12px; font-size: 16px; min-width: 0; }
.input { flex: 1; width: 100%; }
.toolbar { display: flex; gap: 8px; align-items: center; margin: 4px 0 10px; }
.toolbar.small .select { flex: 1; }
.chips, .pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 18px; background: var(--chip); border: 1px solid transparent; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.segmented { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; margin: 4px 0 10px; }
.seg { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 9px; cursor: pointer; font-size: 14px; }
.seg.on { background: var(--surface); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.pill { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--accent); font-size: 14px; cursor: pointer; }
.pill .icon { width: 14px; height: 14px; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 13px; }
.error { color: var(--error); }
.status { margin: 0 0 6px; font-size: 13px; min-height: 1em; }
.label { color: var(--muted); font-size: 12px; margin: 8px 0 2px; }
.section-title { font-size: 15px; margin: 18px 0 6px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px 12px; margin-bottom: 14px; }
.link { border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; }

/* 一覧 */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 10px; padding: 12px 2px; border: 0; background: none; text-align: left; cursor: pointer; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 700; font-size: 16px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { color: var(--muted); font-size: 13px; }
.row-syn { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; font-size: 12px; color: var(--muted); }
.rank { flex: none; min-width: 30px; font-weight: 800; color: var(--accent); font-size: 17px; text-align: right; }
.badge { background: var(--badge); color: #fff; border-radius: 10px; padding: 0 8px; font-weight: 700; font-size: 12px; line-height: 20px; }
.shelf-row.has-update .row-title::before { content: "● "; color: var(--badge); }
.icon-btn.add { color: var(--accent); }
.icon-btn.add.done { color: var(--ok); }
.empty { padding: 24px 4px; border: 0; }
.empty-actions { display: flex; gap: 8px; margin-top: 10px; }
.more { margin: 10px 0; width: 100%; }

/* 文庫 */
.site-list { list-style: none; padding: 0; margin: 0; }
.site-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 6px; margin-bottom: 10px; }
.site-head { display: flex; justify-content: space-between; align-items: center; }
.site-name { font-weight: 800; font-size: 18px; }
.site-desc { margin: 2px 0 6px; color: var(--muted); font-size: 13px; }
.tag { font-size: 11px; border-radius: 8px; padding: 2px 8px; background: var(--chip); color: var(--muted); }
.tag.in-app { background: var(--accent); color: var(--accent-ink); }

/* 小窓 */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, 0); display: flex; align-items: flex-end; justify-content: center; z-index: 50; transition: background .2s; }
.sheet-wrap.open { background: rgba(0, 0, 0, .35); }
.sheet { width: 100%; max-width: 640px; max-height: 88dvh; display: flex; flex-direction: column; background: var(--surface); border-radius: 18px 18px 0 0; transform: translateY(100%); transition: transform .2s; padding-bottom: var(--safe-b); }
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 10px 6px 16px; }
.sheet-title { flex: 1; margin: 0; font-size: 18px; line-height: 1.4; }
.sheet-body { overflow-y: auto; padding: 0 16px 16px; }
.work-meta { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.work-facts { margin: 0 0 8px; font-size: 14px; }
.work-synopsis { font-size: 14px; background: var(--chip); border-radius: 10px; padding: 8px 10px; }
.work-synopsis .label { display: inline; margin: 0; }
.work-actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.toc-head { font-size: 14px; margin: 14px 0 4px; }
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list li { border-bottom: 1px solid var(--line); }
.toc-list li.current .toc-item { font-weight: 700; color: var(--accent); }
.toc-item { width: 100%; text-align: left; padding: 10px 4px; border: 0; background: none; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 80; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.ptr { position: fixed; top: calc(var(--top-h) + var(--safe-t)); left: 50%; transform: translate(-50%, -40px); width: 36px; height: 36px; border-radius: 18px; background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .2); display: flex; align-items: center; justify-content: center; z-index: 40; color: var(--muted); }
.ptr.ready { color: var(--accent); }

/* 読む画面（青空文庫） */
body.reading { overflow: hidden; }
.reader { --fs: 18px; position: fixed; inset: 0; z-index: 60; background: var(--paper); color: var(--paper-ink); display: flex; flex-direction: column; padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
.rd-bar { position: absolute; top: var(--safe-t); left: 0; right: 0; display: flex; align-items: center; gap: 2px; padding: 4px 6px; background: var(--surface); border-bottom: 1px solid var(--line); transform: translateY(-120%); transition: transform .2s; z-index: 2; }
.reader.ui .rd-bar { transform: none; }
.rd-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.rd-page { flex: 1; min-height: 0; margin: 0 auto; font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif; font-size: var(--fs); }
.reader.vertical .rd-page { writing-mode: vertical-rl; overflow-x: auto; overflow-y: hidden; line-height: 2; padding: 28px 0 8px; scrollbar-width: none; }
.reader.vertical .rd-page::-webkit-scrollbar { display: none; }
.reader.horizontal .rd-page { overflow-y: auto; line-height: 1.9; padding: 24px 18px 40px; width: 100%; max-width: 40em; }
.rd-page p, .rd-page h2, .rd-page h3, .rd-page h4 { margin: 0; font-size: 1em; padding-inline-start: calc(var(--indent, 0) * 1em); }
.rd-page .rd-h { font-weight: 700; }
.rd-page .end { text-align: end; padding-inline-end: calc(var(--raise, 0) * 1em); }
.rd-page .brk { text-align: center; color: var(--muted); }
.rd-h1 { font-size: 1em; font-weight: 700; margin: 0; }
.rd-author { margin: 0; text-align: end; }
.rd-page rt { font-size: .5em; }
.rd-page .bouten { font-style: normal; text-emphasis: filled sesame; -webkit-text-emphasis: filled sesame; }
.reader.vertical .rd-page .bousen { text-decoration: overline; }
.reader.horizontal .rd-page .bousen { text-decoration: underline; }
.rd-page .gaiji { color: var(--muted); }
.colophon { font-size: .8em; color: var(--muted); }
.reader.vertical .colophon p { line-height: 2.5; }
.rd-foot { flex: none; display: flex; justify-content: space-between; padding: 6px 22px 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; font-family: Georgia, serif; }
.rd-msg { position: absolute; top: 40%; left: 0; right: 0; text-align: center; padding: 0 24px; }

/* 法務ページなど */
body.plain { overflow: auto; }
.plain-main { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }
.plain-main h1 { font-size: 22px; }
.plain-main h2 { font-size: 17px; margin-top: 28px; }
.plain-main table { border-collapse: collapse; width: 100%; font-size: 14px; }
.plain-main th, .plain-main td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.noscript { padding: 24px; }

@media (max-width: 768px) { input, select, textarea { font-size: 16px; } }
