/* ============================================================
   電子カタログ ビューア スタイル
   ============================================================ */
:root {
  --bar: #ffffff;
  --bar-border: #e3e6ec;
  --text: #1f2430;
  --text-sub: #6b7280;
  --accent: #1a6dd4;
  --accent-soft: #e8f1fd;
  --stage: #464c56;
  --stage-deep: #383d46;
  --panel: #ffffff;
  --shadow: 0 6px 28px rgba(15, 20, 30, .18);
  --bar-h: 52px;
  --foot-h: 52px;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* hidden属性を最優先で効かせる。
   .panel や .fatal などに display:flex を指定しているため、これが無いと
   作成者スタイルがブラウザ標準の [hidden]{display:none} を上書きしてしまい、
   隠したはずのパネルが表示されたままになる。 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  background: var(--stage);
  color: var(--text);
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: var(--bar-h) 1fr var(--foot-h);
}

/* ---------------------------------------------------------- バー */
.bar {
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px;
  background: var(--bar);
  border-bottom: 1px solid var(--bar-border);
  z-index: 30;
  user-select: none;
}
.bar-bottom { border-bottom: none; border-top: 1px solid var(--bar-border); gap: 2px; }
.grow { flex: 1 1 auto; }

.cat-title {
  font-size: 15px; font-weight: 700; margin: 0 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 34vw;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 11px;
  border: none; border-radius: 9px;
  background: transparent; color: var(--text);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .13s, color .13s;
  white-space: nowrap;
}
.btn:hover { background: #f0f2f6; }
.btn:active { background: #e4e8ef; }
.btn.icon { padding: 0; width: 38px; justify-content: center; }
.btn.on { background: var(--accent-soft); color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.zoom-group { display: flex; align-items: center; background: #f4f6f9; border-radius: 9px; padding: 2px; margin: 0 2px; }
.zoom-label { width: 56px; justify-content: center; padding: 0; font-variant-numeric: tabular-nums; font-size: 12px; }
.zoom-group .btn:hover { background: #e6eaf1; }

/* ---------------------------------------------------------- ドロップダウン */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 260px; padding: 6px;
  background: #fff; border: 1px solid var(--bar-border); border-radius: 11px;
  box-shadow: var(--shadow); z-index: 60;
  animation: menuIn .13s ease both;
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-4px); } }
.menu-head {
  padding: 7px 12px 8px; font-size: 11px; font-weight: 700; color: var(--text-sub);
  border-bottom: 1px solid var(--bar-border); margin-bottom: 4px;
}
.menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 10px 12px;
  border: none; border-radius: 7px; background: none;
  font: inherit; font-size: 13px; text-align: left; color: var(--text); cursor: pointer;
}
.menu-item:hover { background: #f2f5f9; }
.menu-item[disabled] { color: #b6bcc7; cursor: default; }
.menu-item[disabled]:hover { background: none; }
.menu-note { font-size: 11px; color: var(--text-sub); white-space: nowrap; }
.menu-warn {
  margin: 2px 6px 6px; padding: 9px 11px;
  background: #fdf4e3; border-radius: 7px;
  font-size: 11.5px; line-height: 1.7; color: #8a5a12;
}
.menu-sep { height: 1px; background: var(--bar-border); margin: 5px 8px; }

/* ---------------------------------------------------------- 表示領域 */
.stage {
  position: relative;
  overflow: hidden;
  background: radial-gradient(120% 120% at 50% 0%, var(--stage) 0%, var(--stage-deep) 100%);
  touch-action: none;
  contain: strict;
}

.zoomwrap {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transform-origin: 50% 50%;   /* app.js のズーム計算は中央基準 */
}
/* 操作中だけ合成レイヤーに固定して滑らかに動かす。
   常時 will-change を付けると、拡大時に「縮小状態で描いた絵」を引き伸ばすため
   文字がぼやける（拡大後は解除して、その倍率で描き直させる）。 */
.zoomwrap.gesture { will-change: transform; }
.zoomwrap.animate { transition: transform .22s cubic-bezier(.22,.7,.3,1); }

.spread-layer { position: relative; display: block; }

.spread {
  display: flex; align-items: flex-start; justify-content: center;
  gap: 0;
}
.spread.rtl { flex-direction: row-reverse; }

.page {
  position: relative;
  background: #fff;
  box-shadow: 0 3px 18px rgba(0, 0, 0, .35);
  overflow: hidden;
  flex: none;
}
.page img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  object-fit: fill;
  -webkit-user-drag: none; user-select: none;
}
.page img.pv { filter: blur(1px); }
/* 本画像は常に不透明。読み込み完了までは何も描画されず、下のサムネイルが見える。
   opacityの遷移で見せる方式だと、非アクティブなタブ等で遷移が停止したときに
   ページが表示されないため、遷移には依存させない。 */
.page img.hd { opacity: 1; }

.page .links { position: absolute; inset: 0; }
.page .links a {
  position: absolute; display: block;
  border-radius: 3px;
  background: rgba(60, 140, 255, 0);
  transition: background .15s;
}
.page .links a:hover { background: rgba(60, 140, 255, .22); box-shadow: 0 0 0 2px rgba(60, 140, 255, .5) inset; }

.page .marks { position: absolute; inset: 0; pointer-events: none; }
.page .marks i {
  position: absolute; display: block;
  background: rgba(255, 214, 0, .45);
  box-shadow: 0 0 0 1.5px rgba(220, 150, 0, .55);
  border-radius: 2px;
  animation: markIn .45s ease both;
}
@keyframes markIn { from { opacity: 0; transform: scale(1.35); } to { opacity: 1; transform: scale(1); } }

.page .pgnum {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  font-size: 10px; color: rgba(0,0,0,.35); pointer-events: none;
}

/* 左右のめくりエリア */
.edge {
  position: absolute; top: 0; bottom: 0; width: 15%;
  min-width: 56px; max-width: 130px;
  border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 10; color: #fff; padding: 0;
  opacity: 0; transition: opacity .18s;
}
.edge-prev { left: 0; }
.edge-next { right: 0; }
.edge span {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(20, 24, 32, .55);
  backdrop-filter: blur(3px);
}
.edge span svg { width: 26px; height: 26px; stroke-width: 2; }
.stage:hover .edge { opacity: .75; }
.edge:hover { opacity: 1 !important; }
.edge[disabled] { display: none; }
.zoomed .edge { display: none; }

/* 読み込み中 */
.loading {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--stage-deep); color: #fff; font-size: 13px;
  transition: opacity .3s;
}
.loading p { margin: 0; opacity: .8; }
/* display:none で確実に消す(透過アニメーションに依存しない) */
.app:not(.is-loading) .loading { opacity: 0; pointer-events: none; display: none; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- 下部バー */
.pager {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--text-sub);
  padding: 0 4px;
}
#pageInput {
  width: 52px; height: 32px; text-align: center;
  border: 1px solid var(--bar-border); border-radius: 7px;
  font: inherit; font-weight: 700; color: var(--text);
  background: #fff; font-variant-numeric: tabular-nums;
}
#pageInput:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.slider {
  flex: 1 1 auto; margin: 0 10px 0 6px;
  height: 4px; -webkit-appearance: none; appearance: none;
  background: #dfe3ea; border-radius: 3px; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
}
.slider.rtl { direction: rtl; }

/* ---------------------------------------------------------- パネル */
.panel {
  position: absolute; top: var(--bar-h); bottom: var(--foot-h);
  width: 320px; max-width: 86vw;
  background: var(--panel);
  z-index: 40;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideIn .2s ease both;
}
.panel-left { left: 0; border-right: 1px solid var(--bar-border); }
.panel-right { right: 0; border-left: 1px solid var(--bar-border); --from: 1; }
@keyframes slideIn { from { opacity: 0; transform: translateX(calc(var(--from, -1) * 16px)); } }
.panel-left { --from: -1; }

.panel-head, .overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 10px 16px;
  border-bottom: 1px solid var(--bar-border);
}
.panel-head h2, .overlay-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.panel-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 6px 0 14px; }

/* 目次 */
.ol-item {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 9px 16px; border: none; background: none;
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
  color: var(--text); line-height: 1.5;
}
.ol-item:hover { background: #f3f6fa; }
.ol-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.ol-item .t { flex: 1 1 auto; }
.ol-item .p { color: var(--text-sub); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ol-item[data-d="1"] { padding-left: 32px; font-size: 12.5px; }
.ol-item[data-d="2"] { padding-left: 48px; font-size: 12px; color: var(--text-sub); }
.ol-item[data-d="3"] { padding-left: 62px; font-size: 12px; color: var(--text-sub); }
.empty { padding: 28px 18px; color: var(--text-sub); font-size: 12.5px; text-align: center; line-height: 1.8; }

/* 検索 */
.search-box {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 14px 8px; padding: 0 10px;
  background: #f4f6f9; border-radius: 9px;
  border: 1px solid transparent;
}
.search-box:focus-within { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box .sicon { flex: none; color: var(--text-sub); }
#searchInput {
  flex: 1 1 auto; height: 40px; border: none; background: none;
  font: inherit; font-size: 14px; color: var(--text); min-width: 0;
}
#searchInput:focus { outline: none; }
#searchInput::-webkit-search-cancel-button { display: none; }
.search-status { padding: 4px 16px 10px; font-size: 11.5px; color: var(--text-sub); }

.res {
  display: flex; gap: 10px; width: 100%; padding: 10px 14px;
  border: none; background: none; text-align: left; cursor: pointer; font: inherit;
  border-left: 3px solid transparent;
}
.res:hover { background: #f3f6fa; }
.res.on { background: var(--accent-soft); border-left-color: var(--accent); }
.res img { width: 40px; height: auto; flex: none; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); align-self: flex-start; }
.res .body { flex: 1 1 auto; min-width: 0; }
.res .pg { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.res .sn { font-size: 12px; line-height: 1.6; color: var(--text-sub); word-break: break-all; }
.res .sn mark { background: #ffe680; color: var(--text); border-radius: 2px; padding: 0 1px; font-weight: 700; }
.res .sn mark.fz { background: #ffeab8; }

/* あいまい一致(OCRの誤読を吸収した結果) */
.res-sep {
  padding: 14px 16px 6px; margin-top: 6px;
  border-top: 1px solid var(--bar-border);
  font-size: 11px; color: var(--text-sub); font-weight: 700;
}
.res.fz .pg { color: #9a6b1f; }
.res.ol { background: #f2f7ff; }
.res.ol .pg { color: var(--accent); }
.res .tag.ol { background: var(--accent-soft); color: var(--accent); }
.res .tag {
  display: inline-block; margin-left: 6px; padding: 0 5px;
  border-radius: 3px; background: #fdf0d5; color: #9a6b1f;
  font-size: 10px; font-weight: 700; vertical-align: 1px;
}

/* ---------------------------------------------------------- オーバーレイ(一覧・ヘルプ) */
.overlay {
  position: absolute; inset: 0; z-index: 50;
  background: #1c2028;   /* 背面が透けないよう不透明にする */
  display: flex; flex-direction: column;
  animation: fadeIn .16s ease both;
  color: #fff;
}
@keyframes fadeIn { from { opacity: 0; } }
.overlay .overlay-head { border-bottom-color: rgba(255,255,255,.12); padding-right: 12px; }
.overlay .btn { color: #fff; }
.overlay .btn:hover { background: rgba(255,255,255,.14); }

.thumb-grid {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  display: grid; gap: 18px 14px;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  padding: 18px 20px 32px;
  align-content: start;
}
.tcell { border: none; background: none; padding: 0; cursor: pointer; color: inherit; font: inherit; }
.tcell figure { margin: 0; }
.tcell .fr {
  display: block; background: #fff; border-radius: 2px;
  box-shadow: 0 2px 10px rgba(0,0,0,.45);
  outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color .12s, transform .12s;
  overflow: hidden;
}
.tcell img { display: block; width: 100%; height: auto; }
.tcell:hover .fr { transform: translateY(-2px); outline-color: rgba(255,255,255,.5); }
.tcell.on .fr { outline-color: #ffc83d; }
.tcell figcaption { font-size: 11px; text-align: center; margin-top: 6px; opacity: .75; font-variant-numeric: tabular-nums; }
.tcell.on figcaption { opacity: 1; font-weight: 700; color: #ffc83d; }

.overlay-center { background: rgba(20, 24, 32, .6); align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.help-card {
  width: min(560px, 92vw); max-height: 86%; overflow-y: auto;
  background: #fff; color: var(--text); border-radius: 14px; box-shadow: var(--shadow);
}
.help-card .overlay-head { border-bottom-color: var(--bar-border); }
.help-card .btn { color: var(--text); }
.help-card .btn:hover { background: #f0f2f6; }
.help-list {
  display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px;
  margin: 0; padding: 18px 20px;
  font-size: 13px; line-height: 1.7;
}
.help-list dt { font-weight: 700; }
.help-list dd { margin: 0; color: var(--text-sub); }
kbd {
  display: inline-block; padding: 1px 6px; margin: 0 1px;
  border: 1px solid #d6dae2; border-bottom-width: 2px; border-radius: 5px;
  background: #f7f9fc; font: inherit; font-size: 11px; font-weight: 700; color: var(--text);
}
.help-settings { padding: 4px 20px 20px; border-top: 1px solid var(--bar-border); margin-top: 4px; padding-top: 16px; }
.switch { display: inline-flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; }
.switch input { width: 17px; height: 17px; accent-color: var(--accent); }

/* ---------------------------------------------------------- トースト等 */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--foot-h) + 18px);
  transform: translateX(-50%);
  background: rgba(24, 28, 36, .92); color: #fff;
  padding: 9px 18px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
  z-index: 60; pointer-events: none;
  animation: toastIn .18s ease both;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } }

.fatal {
  position: absolute; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: var(--stage-deep); color: #fff; padding: 30px;
  text-align: center; font-size: 14px; line-height: 2;
}
.fatal code { background: rgba(255,255,255,.14); padding: 2px 7px; border-radius: 5px; font-size: 13px; }

/* ---------------------------------------------------------- レスポンシブ */
@media (max-width: 900px) {
  .btn .lbl { display: none; }
  .btn { padding: 0; width: 38px; justify-content: center; }
  .cat-title { max-width: 30vw; font-size: 13.5px; }
}
@media (max-width: 640px) {
  :root { --bar-h: 48px; --foot-h: 48px; }
  .zoom-group { display: none; }
  .cat-title { font-size: 13px; max-width: 40vw; }
  .panel { top: 0; bottom: 0; width: 100%; max-width: 100%; }
  .edge { opacity: 0 !important; }
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 14px 10px; padding: 14px; }
  #btnHelp { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
