:root {
  --bg: #23201d;
  --bg2: #38322c;
  --panel: rgba(28, 25, 22, .92);
  --line: rgba(255, 255, 255, .12);
  --text: #f4efe8;
  --muted: #b9afa2;
  --accent: #f08a00;
  --bar-h: 52px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: var(--bar-h) 1fr auto;
  background: radial-gradient(ellipse at 50% 40%, var(--bg2), var(--bg) 75%);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- 上下のバー ---- */
.bar { display: flex; align-items: center; gap: 8px; padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
.bar.top { justify-content: space-between; }
.bar.bottom { justify-content: space-between; min-height: var(--bar-h); padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line); }
h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h1 .brand { color: var(--accent); font-weight: 800; margin-right: 4px; letter-spacing: .02em; }
h1 small { margin-left: 10px; font-size: 12px; font-weight: 400; color: var(--muted); }
nav { display: flex; gap: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255, 255, 255, .06); color: var(--text);
  font: inherit; font-size: 13px; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn:focus-visible, .edge:focus-visible, .thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255, 255, 255, .08); }
.btn.icon { width: 38px; padding: 0; justify-content: center; }

.pager { display: flex; align-items: center; gap: 6px; flex: 1; max-width: 640px; min-width: 0; }
#pageNo { min-width: 84px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
#slider { flex: 1; min-width: 40px; accent-color: var(--accent); cursor: pointer; }

/* ---- 本 ---- */
#stage { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; }
#holder { position: relative; filter: drop-shadow(0 18px 28px rgba(0, 0, 0, .55)); transition: transform .6s ease; }
/* 表紙・裏表紙だけのときは中央に寄せる */
body.spread.at-cover #holder { transform: translateX(-25%); }
body.spread.at-back #holder { transform: translateX(25%); }

.page { background: #fff; overflow: hidden; }
.page img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
/* のど（綴じ側）の影 */
body.spread .page::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
body.spread .page.left::after { background: linear-gradient(to left, rgba(0, 0, 0, .22), rgba(0, 0, 0, .06) 4%, transparent 12%); }
body.spread .page.right::after { background: linear-gradient(to right, rgba(0, 0, 0, .22), rgba(0, 0, 0, .06) 4%, transparent 12%); }
.page a.hot { position: absolute; border-radius: 6px; z-index: 2; }
.page a.hot:hover, .page a.hot:focus-visible { background: rgba(255, 255, 255, .25); outline: 2px solid rgba(255, 255, 255, .9); }

.edge {
  position: absolute; top: 50%; z-index: 5; transform: translateY(-50%);
  width: 44px; height: 72px; border: 0; border-radius: 10px;
  background: rgba(0, 0, 0, .28); color: #fff; cursor: pointer;
  display: grid; place-items: center; transition: background .15s, opacity .2s;
}
.edge svg { width: 26px; height: 26px; }
.edge:hover { background: rgba(0, 0, 0, .55); }
.edge.prev { left: 10px; } .edge.next { right: 10px; }
.edge:disabled { opacity: 0; pointer-events: none; }

#hint {
  position: absolute; left: 50%; bottom: 14px; z-index: 6; transform: translateX(-50%);
  margin: 0; padding: 8px 16px; border-radius: 999px; white-space: nowrap;
  background: rgba(0, 0, 0, .7); font-size: 13px; pointer-events: none;
  transition: opacity .6s;
}
#hint.off { opacity: 0; }

/* ---- 一覧・目次 ---- */
#drawer {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; max-height: 72vh;
  display: flex; flex-direction: column;
  background: var(--panel); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; box-shadow: 0 -12px 40px rgba(0, 0, 0, .5);
  padding-bottom: env(safe-area-inset-bottom);
}
#drawer[hidden], #zoom[hidden], .drawer-body[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; }
.tab { height: 34px; padding: 0 14px; border: 0; border-radius: 999px; background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.tab.on { background: var(--accent); color: #1d1300; font-weight: 700; }
.drawer-body { overflow: auto; padding: 14px; margin: 0; -webkit-overflow-scrolling: touch; }

#thumbs { display: flex; flex-wrap: wrap; gap: 14px 18px; justify-content: center; }
.thumb { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; }
.thumb .imgs { display: flex; border: 2px solid transparent; border-radius: 3px; overflow: hidden; box-shadow: 0 3px 10px rgba(0, 0, 0, .5); }
.thumb img { display: block; width: 84px; height: 110px; background: #fff; }
.thumb:hover .imgs { border-color: rgba(255, 255, 255, .6); }
.thumb.on .imgs { border-color: var(--accent); }
.thumb.on { color: var(--accent); }

#toc { list-style: none; max-width: 560px; width: 100%; margin: 0 auto; }
#toc button { display: flex; width: 100%; gap: 12px; align-items: baseline; padding: 12px 8px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
#toc button:hover { background: rgba(255, 255, 255, .07); }
#toc .no { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- 拡大 ---- */
#zoom { position: fixed; inset: 0; z-index: 30; background: rgba(18, 16, 14, .97); }
#zoomScroll { position: absolute; inset: 0; overflow: auto; cursor: grab; -webkit-overflow-scrolling: touch; }
#zoomScroll.drag { cursor: grabbing; }
#zoomInner { display: flex; margin: 0 auto; padding-bottom: 80px; min-height: 100%; align-items: flex-start; }
#zoomInner img { display: block; width: 50%; height: auto; user-select: none; -webkit-user-drag: none; background: #fff; }
#zoomInner.single img { width: 100%; }
.zoom-tools {
  position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
#zoomPct { min-width: 52px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---- スマホ ---- */
@media (max-width: 640px) {
  :root { --bar-h: 46px; }
  h1 { font-size: 13px; } h1 small { display: none; }
  .btn span { display: none; }
  .btn { padding: 0; width: 38px; justify-content: center; }
  #zoomClose { width: auto; padding: 0 12px; } #zoomClose span { display: inline; }
  #btnFirst, #btnLast { display: none; }
  #pageNo { min-width: 64px; font-size: 12px; }
  .edge { display: none; }
  .thumb img { width: 66px; height: 86px; }
}
@media (max-height: 480px) { .bar.top { display: none; } body { grid-template-rows: 1fr auto; } }
@media (prefers-reduced-motion: reduce) { #holder, #hint { transition: none; } }
