/* 調剤報酬STARTLINE ビューアー */

:root {
  --brand: #2589d0;
  --ink: #1a2733;
  --muted: #6b7d8d;
  --line: #dfe6ec;
  --bg: #eef2f6;
  --panel: #fff;
  --hit: #ffd84d;
  --bar-h: 52px;
  --foot-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP",
               "Yu Gothic UI", "Meiryo", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

/* アイコンボタン共通 */
.icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon:hover { background: rgba(0, 0, 0, .06); }
.icon:active { background: rgba(0, 0, 0, .12); }
.icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ============================================================ 起動中 */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--muted);
  z-index: 100;
}
.boot[hidden] { display: none; }

/* ============================================================ 本棚 */

.shelf {
  min-height: 100%;
  padding: 40px 20px calc(40px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
}
.shelf[hidden] { display: none; }

.shelf-head { text-align: center; margin-bottom: 32px; }
.shelf-head h1 {
  margin: 0 0 6px;
  font-size: clamp(22px, 5vw, 30px);
  letter-spacing: .02em;
}
.shelf-head h1 span {
  color: var(--brand);
  margin-left: .35em;
  letter-spacing: .06em;
}
.shelf-head p { margin: 0; color: var(--muted); font-size: 14px; }

.shelf-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 280px));
  gap: 20px;
  justify-content: center;
  width: 100%;
  max-width: 640px;
}

.book {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(20, 40, 60, .07);
  transition: transform .15s, box-shadow .15s;
}
.book:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(20, 40, 60, .12); }

.book-main { display: block; text-decoration: none; color: inherit; }

.book-cover {
  aspect-ratio: 1 / 1.414;
  background: var(--bg) center / cover no-repeat;
  border-bottom: 1px solid var(--line);
}
.book-body { padding: 14px 16px 12px; }
.book-title { font-size: 19px; font-weight: 700; margin: 0 0 2px; }
.book-sub { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.book-meta { font-size: 12px; color: var(--muted); }

.book-resume {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
}
.book-marks { margin-top: 3px; font-size: 12px; color: var(--muted); }

.book-offline {
  border-top: 1px solid var(--line);
  padding: 10px 16px 12px;
}
.offline-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.offline-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.offline-btn:disabled { opacity: .6; cursor: default; }
.offline-btn.is-saved { color: var(--muted); font-weight: 500; }
.offline-note {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.book.is-empty { opacity: .55; pointer-events: none; }

.shelf-foot { margin-top: 28px; color: var(--muted); font-size: 12px; text-align: center; }
.shelf-foot p { margin: 0; }

/* ============================================================ ビューアー */

.viewer {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: var(--bar-h) 1fr auto;
}
.viewer[hidden] { display: none; }

.bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.bar h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- ページの帯（横スクロール＋スナップ） --- */

.rail {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  background: var(--bg);
  outline: none;
}
.rail::-webkit-scrollbar { display: none; }

.pg {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  place-items: center;
  padding: 10px;
  min-width: 0;
}

/* 見開き（PC・横向き）。左ページ（奇数）だけをスナップ位置にする */
.rail.spread .pg { flex: 0 0 50%; padding: 10px 5px; }
.rail.spread .pg:nth-child(even) { scroll-snap-align: none; scroll-snap-stop: normal; }

/* 紙面。リンクとハイライトの座標基準になるので、画像とぴったり同じ大きさにする。
   大きさは JS が --sheet-w / --sheet-h に入れる（画像が来る前からガタつかせないため） */
.sheet {
  position: relative;
  width: var(--sheet-w, auto);
  height: var(--sheet-h, auto);
  background: #fff;
  box-shadow: 0 2px 12px rgba(20, 40, 60, .16);
  border-radius: 2px;
  overflow: hidden;
}
.sheet img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}
/* 画像が来るまでの下地 */
.sheet.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #f4f7fa 30%, #e9eef3 50%, #f4f7fa 70%) 0 0 / 300% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -300% 0; } }

/* QR・リンクのタップ領域 */
.hot {
  position: absolute;
  display: block;
  border-radius: 4px;
  background: transparent;
  -webkit-tap-highlight-color: rgba(37, 137, 208, .3);
}
.hot.qr { outline: 2px solid rgba(37, 137, 208, .55); outline-offset: 1px; }
.hot:hover { background: rgba(37, 137, 208, .18); }
.hot:focus-visible { outline: 3px solid var(--brand); }

/* 検索ヒットのハイライト */
.hl {
  position: absolute;
  background: rgba(255, 216, 77, .5);
  mix-blend-mode: multiply;
  border-radius: 2px;
  pointer-events: none;
  animation: pop .5s ease-out;
}
@keyframes pop { from { background: rgba(255, 140, 0, .75); } }

/* --- 左右送りボタン（PCのみ） --- */

.nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 76px;
  display: none;
  place-items: center;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  border-radius: 10px;
  cursor: pointer;
  z-index: 5;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav.prev { left: 10px; }
.nav.next { right: 10px; }
.nav:disabled { opacity: .3; cursor: default; }
@media (hover: hover) and (min-width: 900px) { .nav { display: grid; } }

/* --- 下のバー --- */

.foot {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 6px 14px calc(6px + var(--safe-b));
}
.foot-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
}
.pageno { font-variant-numeric: tabular-nums; white-space: nowrap; }
.chapter { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#slider {
  width: 100%;
  margin: 0 0 4px;
  accent-color: var(--brand);
  height: 22px;
}

/* ============================================================ パネル（目次・検索） */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 45, .45);
  z-index: 20;
}
.scrim[hidden] { display: none; }

.panel {
  position: fixed;
  z-index: 21;
  inset: 0 auto 0 0;
  width: min(400px, 88vw);
  background: var(--panel);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  box-shadow: 4px 0 24px rgba(20, 40, 60, .2);
  animation: slide-in .18s ease-out;
}
.panel[hidden] { display: none; }
@keyframes slide-in { from { transform: translateX(-100%); } }

#panel-search { inset: 0 0 0 auto; animation-name: slide-in-r; }
@keyframes slide-in-r { from { transform: translateX(100%); } }

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head .close { margin-left: auto; }

.tabs { display: flex; gap: 4px; }
.tab {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab.is-on { background: rgba(37, 137, 208, .12); color: var(--brand); }

.panel-body { overflow-y: auto; overscroll-behavior: contain; padding: 8px 0 24px; }

/* 目次 */
.toc-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
  border-left: 3px solid transparent;
}
.toc-item:hover { background: rgba(37, 137, 208, .07); }
.toc-item.is-on { border-left-color: var(--brand); background: rgba(37, 137, 208, .1); color: var(--brand); font-weight: 600; }
.toc-item .t { flex: 1; min-width: 0; }
.toc-item .p { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.toc-item.d1 { padding-left: 32px; font-size: 13px; }
.toc-item.d2 { padding-left: 48px; font-size: 13px; color: var(--muted); }
.toc-item.d3 { padding-left: 64px; font-size: 12px; color: var(--muted); }

/* しおり一覧 */
.mark-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
}
.mark-row:hover { background: rgba(37, 137, 208, .07); }
.mark-row.is-on { border-left-color: var(--brand); background: rgba(37, 137, 208, .1); }

.mark-go {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 12px 6px 12px 13px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
}
.mark-go .p {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
}
.mark-go .t { flex: 1; min-width: 0; }
.mark-del { flex: 0 0 40px; align-self: center; margin-right: 6px; color: var(--muted); }
.mark-del svg { width: 16px; height: 16px; }

/* しおりボタン（上のバー） */
#btn-mark svg { fill: none; }
#btn-mark.is-on { color: var(--brand); }
#btn-mark.is-on svg { fill: currentColor; }

/* ページ一覧（サムネイル） */
.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  padding: 14px;
  align-content: start;
}
.thumb { border: 0; background: transparent; padding: 0; cursor: pointer; }
.thumb img {
  width: 100%;
  aspect-ratio: 1 / 1.414;
  object-fit: cover;
  object-position: top;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: block;
}
.thumb.is-on img { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(37, 137, 208, .35); }
.thumb span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }

/* 検索 */
.searchbox {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border-radius: 10px;
  padding: 0 4px 0 10px;
}
.searchbox svg { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.searchbox input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 10px 0;
  font-size: 16px; /* iOSで拡大されないよう16px以上 */
  outline: none;
}
.searchbox .icon { width: 32px; height: 32px; flex: 0 0 32px; }
.searchbox .icon svg { width: 16px; height: 16px; }

.scope {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.scope input { accent-color: var(--brand); width: 16px; height: 16px; }

.hits-info { padding: 10px 16px; font-size: 12px; color: var(--muted); }
.hits-info:empty { display: none; }

.hit {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.65;
}
.hit:hover { background: rgba(37, 137, 208, .07); }
.hit .h-top { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; }
.hit .h-page { font-size: 12px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }
.hit .h-book { font-size: 11px; color: #fff; background: var(--muted); border-radius: 4px; padding: 1px 6px; }
.hit .h-more { font-size: 11px; color: var(--muted); margin-left: auto; }
.hit .h-text { color: var(--ink); }
.hit mark { background: var(--hit); color: inherit; border-radius: 2px; padding: 0 1px; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.8; }

/* ============================================================ 広い画面 */

@media (min-width: 900px) {
  .panel { animation: none; }
  #panel-toc { position: fixed; }
}
