/* bookshelf の画面スタイル。外部フォントは読み込まない（NFR-50）。 */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #666;
  --border: #ddd;
  --accent: #2b6cb0;
  --accent-text: #fff;
  --danger: #c53030;
  --warning-bg: #fff6d6;
  --notice-bg: #e6f4ea;
  --radius: 8px;
  --shadow: 0 1px 3px rgb(0 0 0 / 12%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #222226;
    --text: #e6e6e6;
    --muted: #9a9aa0;
    --border: #3a3a40;
    --accent: #6ea8fe;
    --accent-text: #0b1b33;
    --danger: #f87171;
    --warning-bg: #3d3416;
    --notice-bg: #1d3524;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.6;
}

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; overflow-x: auto; }

.container { max-width: 1200px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-left)) 3rem; }
.narrow { max-width: 520px; }
.center { text-align: center; }
.small { font-size: 0.85rem; color: var(--muted); }
.break { overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

/* ---- ヘッダー ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.5rem max(1rem, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.brand-large { font-size: 2rem; margin: 3rem 0 2rem; }
.topbar nav { display: flex; align-items: center; gap: 0.25rem; }
.topbar nav > a { padding: 0.4rem 0.6rem; border-radius: var(--radius); text-decoration: none; color: var(--text); }
.topbar nav > a[aria-current="page"] { background: var(--bg); font-weight: 600; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 0.4rem 0.7rem; border-radius: var(--radius); }
.menu summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: 2.4rem; min-width: 11rem;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu-body > a, .menu-body button { padding: 0.6rem 1rem; text-align: left; text-decoration: none; color: var(--text); }

/* ---- フォーム部品 ---- */
input, select, textarea, button, .button {
  font: inherit; color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  min-height: 2.5rem;
}
input, textarea { width: 100%; }
textarea { resize: vertical; }
button, .button { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; gap: 0.3rem; }
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.large { font-size: 1.1rem; padding: 0.75rem 1.5rem; }
button.link { border: 0; background: none; min-height: 0; width: 100%; justify-content: flex-start; }
label { display: block; font-size: 0.9rem; }
label > input, label > select, label > textarea { margin-top: 0.25rem; }
.stack > * + * { margin-top: 0.75rem; }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 0.75rem; }
form.inline { display: inline-flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
form.inline input { width: auto; flex: 1 1 10rem; }

.notice, .warning, .error { padding: 0.6rem 0.9rem; border-radius: var(--radius); }
.notice { background: var(--notice-bg); }
.warning { background: var(--warning-bg); }
.error { color: var(--danger); border: 1px solid var(--danger); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; margin: 1rem 0; }
.panel > summary { cursor: pointer; font-weight: 600; }
.panel[open] > summary { margin-bottom: 0.75rem; }
.panel.danger { border-color: var(--border); }
.badge { display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }

/* ---- 本棚 ---- */
.search { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.filters select { flex: 1 1 9rem; }
.active-filters { font-size: 0.9rem; }
.count { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.5rem; }
.welcome { text-align: center; padding: 3rem 0; }

.book-grid {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 1.25rem 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(130px, 42%), 1fr));
}
.card a { display: flex; flex-direction: column; gap: 0.25rem; text-decoration: none; color: inherit; position: relative; }
.cover { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; box-shadow: var(--shadow); background: var(--surface); display: block; }
.cover.placeholder {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 0.5rem;
  padding: 0.75rem; text-align: center; overflow: hidden;
  border: 1px solid var(--border); font-size: 0.85rem; color: var(--muted);
  overflow-wrap: anywhere;
}
.cover.placeholder span { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.card-title { font-size: 0.9rem; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-author { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .badge { position: absolute; top: 0.4rem; right: 0.4rem; background: var(--surface); }
progress { width: 100%; height: 4px; appearance: none; border: 0; border-radius: 2px; background: var(--border); }
progress::-webkit-progress-bar { background: var(--border); border-radius: 2px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 2px; }

.book-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.book-list .row + .row { border-top: 1px solid var(--border); }
.row a { display: flex; flex-direction: column; padding: 0.6rem 0.9rem; text-decoration: none; color: inherit; }
.row-title { font-weight: 600; }
.row-meta { font-size: 0.8rem; color: var(--muted); }
.more { grid-column: 1 / -1; text-align: center; padding: 1rem; list-style: none; }

/* ---- 詳細 ---- */
.book-detail { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 1.5rem; align-items: start; }
.book-detail h1 { margin-top: 0; }
.authors a { color: inherit; }
.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag { font-size: 0.8rem; padding: 0.1rem 0.6rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 1rem; font-size: 0.9rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.notes { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; }
@media (max-width: 600px) {
  .book-detail { grid-template-columns: 1fr; }
  .book-cover { max-width: 180px; margin: 0 auto; }
  .two { grid-template-columns: 1fr; }
}

/* ---- アップロード ---- */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; background: var(--surface); }
.dropzone.over { border-color: var(--accent); }
.upload-list { list-style: none; padding: 0; }
.upload-list li { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.upload-list progress { grid-column: 1 / -1; }
.upload-list .name { overflow-wrap: anywhere; }
.upload-list .status { font-size: 0.85rem; color: var(--muted); }
.upload-list .failed .status { color: var(--danger); }

/* ---- セキュリティ・管理 ---- */
.passkeys, .sessions, .series-list { list-style: none; padding: 0; }
.passkeys li, .sessions li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 0.5rem; }
.passkey-head { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.passkey-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.series-list li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.table-wrap { overflow-x: auto; }
.events { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.events th, .events td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.events tr.failure td { color: var(--danger); }
.stats { list-style: none; padding: 0; display: flex; gap: 1.5rem; flex-wrap: wrap; }
.commands dd { margin: 0.25rem 0 1rem; }

/* ---- 閲覧画面 ---- */
.reader-main { padding: 0; }
.page-reader { overflow: hidden; height: 100dvh; }
.reader {
  --r-bg: var(--bg); --r-fg: var(--text);
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: var(--r-bg); color: var(--r-fg);
  padding-bottom: env(safe-area-inset-bottom);
}
.reader[data-theme="light"] { --r-bg: #fff; --r-fg: #1f1f1f; }
.reader[data-theme="dark"] { --r-bg: #1b1b1d; --r-fg: #ddd; }
.reader[data-theme="sepia"] { --r-bg: #f4ecd8; --r-fg: #3b2f22; }
.reader-bar {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.25rem max(0.5rem, env(safe-area-inset-left));
  padding-top: max(0.25rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--r-bg);
  z-index: 3; transition: transform 0.2s;
}
.bar-hidden .reader-bar { position: absolute; left: 0; right: 0; transform: translateY(-110%); }
.reader-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }
.reader-pos { font-size: 0.8rem; color: var(--muted); }
.icon-button { border: 0; background: none; min-width: 2.5rem; text-decoration: none; color: inherit; }
.reader-stage { flex: 1; position: relative; overflow: hidden; display: flex; justify-content: center; align-items: center; }
.reader-stage.scroll { overflow-y: auto; align-items: flex-start; }
.reader-stage foliate-view { display: block; width: 100%; height: 100%; }
.reader-loading { color: var(--muted); }
.reader-loading.error { color: var(--danger); padding: 1rem; }
.pdf-page { display: block; box-shadow: var(--shadow); background: #fff; }
.tap-zone { position: absolute; top: 3rem; bottom: 0; border: 0; background: transparent; padding: 0; min-height: 0; border-radius: 0; z-index: 2; }
.tap-zone.left { left: 0; width: 18%; }
.tap-zone.right { right: 0; width: 18%; }
.tap-zone.center { left: 35%; width: 30%; top: 30%; bottom: 30%; }
.tap-zone:focus-visible { outline: 2px solid var(--accent); }
.sheet { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(32rem, 92vw); max-height: 80dvh; padding: 1rem 1.25rem; }
.sheet::backdrop { background: rgb(0 0 0 / 40%); }
.sheet .close { float: right; border: 0; background: none; font-size: 1.4rem; min-height: 0; }
.sheet h2 { margin-top: 0; }
#toc ul { list-style: none; padding-left: 1rem; margin: 0; }
#toc > ul { padding-left: 0; }
#toc a { display: block; padding: 0.3rem 0; text-decoration: none; color: inherit; }
