:root {
  --bg: #fff8f2;
  --ink: #2b2320;
  --muted: #7a6a62;
  --accent: #e8743a;
  --accent-dark: #b5451b;
  --line: #e9d9cd;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14100f; --ink: #f3e9e2; --muted: #a8968c; --line: #3a2d28; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  line-height: 1.7; color: var(--ink); background: var(--bg);
}
a { color: var(--accent-dark); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.site-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--ink); }
.site-header nav a { margin-left: 14px; font-size: .9rem; text-decoration: none; }
.site-footer { padding: 24px 16px; color: var(--muted); font-size: .85rem; text-align: center; }

.home { max-width: 52rem; margin: 0 auto; padding: 0 16px; }
.hero { padding: 32px 0 8px; }
.hero h1 { font-size: 1.6rem; line-height: 1.4; margin: 0 0 8px; }
.hero p { margin: 0; color: var(--muted); }
.search form { display: flex; gap: 8px; margin: 16px 0 8px; flex-wrap: wrap; }
.search input[type=search] { flex: 1 1 14rem; padding: 10px 12px; font-size: 1rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--ink); }
.search select, .search button { padding: 10px 12px; font-size: 1rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--ink); }
.search button { background: var(--accent); color: #fff; border-color: var(--accent); }
.status { color: var(--muted); font-size: .9rem; min-height: 1.5em; }
.works { list-style: none; padding: 0; margin: 0 0 32px; display: grid; gap: 12px; }
.works a { display: flex; gap: 12px; text-decoration: none; color: var(--ink); padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
/* 1 コマ目は見開きのスキャンが多い。中央で切り抜くと背と色票しか見えないので、全体を枠に収める */
.works img { flex: 0 0 auto; width: 96px; height: 128px; object-fit: contain; border-radius: 4px; background: var(--line); }
.works div { display: flex; flex-direction: column; gap: 2px; }
/* テキストの作品の表紙。題名を縦に置く(iOS・Android と同じ見た目) */
.works .cover { flex: 0 0 auto; width: 96px; height: 128px; border-radius: 4px; background: #5c3326; color: #f6e7d8; writing-mode: vertical-rl;
  font-family: "Hiragino Mincho ProN", "Noto Serif JP", serif; font-size: 1rem; font-weight: 600; letter-spacing: .1em; display: flex; align-items: center; justify-content: center; padding: 10px 6px; overflow: hidden; }
.works strong { font-size: 1.05rem; }
.works span { color: var(--muted); font-size: .85rem; }
.search .more { display: block; width: 100%; margin: -16px 0 32px; padding: 12px; border-radius: 10px; cursor: pointer; }
.search .more:disabled { opacity: .6; cursor: default; }
.more[hidden], .status[hidden] { display: none; }
.attribution { border-top: 1px solid var(--line); padding: 16px 0 24px; color: var(--muted); font-size: .9rem; }
.attribution h2 { font-size: 1rem; margin: 0 0 4px; color: var(--ink); }

/* ビューア */
/* ヘッダーとフッターはページの上に重ねる。隠したときにページ画像が画面いっぱいに広がるように */
.reader-body { height: 100dvh; background: #111; color: #eee; overflow: hidden; }
.reader-header, .reader-footer { position: fixed; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: rgba(0,0,0,.75); transition: opacity .2s, visibility .2s; z-index: 2; }
.reader-header { top: 0; padding-top: max(8px, env(safe-area-inset-top)); }
.reader-footer { bottom: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.reader-header.hidden, .reader-footer.hidden { opacity: 0; visibility: hidden; }
.reader-header .back, .reader-footer .nav { font-size: 1.6rem; line-height: 1; color: #eee; background: none; border: 0; text-decoration: none; padding: 4px 10px; cursor: pointer; }
.reader-footer .nav:disabled { opacity: .3; }
/* 狭い画面では題名・著者・出典を 3 行に積む。広い画面では出典を右に置く */
.reader-title { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.reader-title h1 { font-size: 1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-title .meta { margin: 0; font-size: .75rem; color: #bbb; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-link { font-size: .75rem; color: #f3b48c; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 640px) {
  .reader-title { grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px; }
  .reader-title .source-link { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
}
/* direction はスクロールする要素に付ける。中身にだけ付けると rtl のページが左へはみ出し、スクロールできない */
.reader { height: 100%; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.track { display: flex; height: 100%; }
.slide { flex: 0 0 100%; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; display: flex; align-items: center; justify-content: center; }
.slide img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; background: #222; }
/* 上から下へ続けて並べる(横長のページ)。綴じの向きは関係ないので direction は戻す */
.reader.scroll { overflow-x: hidden; overflow-y: auto; scroll-snap-type: none; direction: ltr !important; }
.reader.scroll .track { flex-direction: column; height: auto; gap: 6px; }
.reader.scroll .slide { flex: none; height: auto; width: 100%; }
.reader.scroll .slide img { width: 100%; max-height: none; }
.reader-header .tool { color: #eee; background: none; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: 4px 8px; font-size: .8rem; cursor: pointer; white-space: nowrap; }
/* フッターの並びは綴じの向きに合わせる(rtl なら次へが左)。ページ番号の「3 / 36」だけは左から右に書く */
.reader-footer input[type=range] { flex: 1; min-width: 0; }
.page-label { font-variant-numeric: tabular-nums; font-size: .85rem; min-width: 4.5em; text-align: center; direction: ltr; unicode-bidi: isolate; }
.notice { border: 0; border-radius: 12px; max-width: min(28rem, calc(100% - 32px)); padding: 20px 24px; background: var(--bg); color: var(--ink); }
.notice::backdrop { background: rgba(0,0,0,.6); }
.notice h2 { margin: 0 0 8px; font-size: 1.1rem; }
.notice button { margin-top: 12px; padding: 10px 20px; font-size: 1rem; background: var(--accent); color: #fff; border: 0; border-radius: 8px; }

/* テキストのリーダー */
.text-body { height: 100dvh; overflow: hidden; background: #f8f3ea; color: #2b2320; }
@media (prefers-color-scheme: dark) { .text-body { background: #1a1614; color: #e9e0d6; } }
.text-header { background: rgba(40, 30, 26, .88); color: #eee; }
.text-header .tool { color: #eee; background: none; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: 4px 8px; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.text-reader { height: 100%; font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; font-size: var(--text-size, 18px); line-height: 1.8; }
/* 縦書きの要素は横幅が中身に合わせて伸びる(直交するフロー)ので、画面の幅に止めて横にスクロールさせる */
.text-reader.vertical { width: 100%; writing-mode: vertical-rl; overflow-x: auto; overflow-y: hidden; padding: calc(64px + env(safe-area-inset-top)) 24px 32px; }
.text-reader.horizontal { overflow-y: auto; padding: calc(72px + env(safe-area-inset-top)) max(20px, calc((100% - 40rem) / 2)) 48px; }
.text { text-align: justify; line-break: strict; hanging-punctuation: allow-end; }
.text p { margin: 0; }
.text .blank { height: 1em; width: 1em; }
.text-title { font-size: 1.6em; margin: 0 0 1em; }
.text h2 { font-size: 1.3em; margin: 1.5em 0 .8em; }
.text h3 { font-size: 1.15em; margin: 1.2em 0 .6em; }
.text h4 { font-size: 1.05em; margin: 1em 0 .5em; }
.text-reader.vertical .text-title, .text-reader.vertical h2, .text-reader.vertical h3, .text-reader.vertical h4 { margin: 0 0 0 1em; }
.text ruby rt { font-size: .5em; }
.text .tcy { text-combine-upright: all; }
.source-dialog .source-name { font-weight: 700; margin: 0; }
.source-dialog .source-links { padding-left: 1.2em; margin: 8px 0 0; max-height: 40dvh; overflow-y: auto; }
