/* ==========================================================================
   SQUADRA Digital Catalog — ビューア
   ========================================================================== */

:root {
  --ink:      #0E131A;
  --ink-2:    #151C25;
  --ink-3:    #1D2733;
  --rule:     #2A3644;
  --paper:    #EDF1F5;
  --dim:      #8593A5;
  --accent:   #3D6BFF;

  --display: "Barlow Condensed", "Noto Sans JP", sans-serif;
  --body: "Barlow", "Noto Sans JP", sans-serif;

  --bar-h: 58px;
  --top-h: 52px;
}

* { box-sizing: border-box; }

/* hidden 属性は必ず非表示に（display を持つクラスに負けないよう !important） */
[hidden] { display: none !important; }

html, body { height: 100%; }

body.v {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--body);
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* --- top bar ------------------------------------------------------------- */

.vtop {
  flex: 0 0 auto;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(12px, 3vw, 28px);
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--top-h) + env(safe-area-inset-top));
}

.vback {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--dim);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  transition: color .2s;
}
.vback:hover { color: var(--paper); }

.vtitle {
  flex: 1 1 auto;
  margin: 0;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.vpdf {
  flex: 0 0 auto;
  font-family: var(--display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .16em;
  color: var(--dim);
  text-decoration: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 5px 14px;
  transition: color .2s, border-color .2s;
}
.vpdf:hover { color: var(--paper); border-color: var(--dim); }

/* --- stage --------------------------------------------------------------- */

.vstage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: clamp(10px, 2.4vh, 28px) clamp(8px, 5vw, 72px);
}

.vflip {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .45s cubic-bezier(.2,.85,.25,1);
}

.flipbook {
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  min-width: 0 !important;   /* 極端に狭い画面ではみ出さないように */
}

/* ページ本体 */
.pg { background: #fff; overflow: hidden; }
.pg-in { width: 100%; height: 100%; }
.pg-in img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
}

/* 右綴じ：全体を反転し、誌面だけ戻す */
body.rtl .vflip { transform: translateX(var(--rtl-dx, 0px)) scaleX(-1); }
body.rtl .pg-in { transform: scaleX(-1); }

/* stPageFlip 必須スタイル */
.stf__parent { position: relative; display: block; box-sizing: border-box; transform: translateZ(0); touch-action: pan-y; }
.sft__wrapper { position: relative; width: 100%; box-sizing: border-box; }
.stf__parent canvas { position: absolute; width: 100%; height: 100%; left: 0; top: 0; }
.stf__block { position: absolute; width: 100%; height: 100%; box-sizing: border-box; perspective: 2000px; }
.stf__item { display: none; position: absolute; transform-style: preserve-3d; }
.stf__outerShadow, .stf__innerShadow, .stf__hardShadow, .stf__hardInnerShadow { position: absolute; left: 0; top: 0; }

/* --- 左右ナビ ------------------------------------------------------------ */

.vnav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 44px;
  height: 76px;
  display: grid;
  place-items: center;
  appearance: none;
  border: 1px solid var(--rule);
  background: rgba(21, 28, 37, .72);
  backdrop-filter: blur(6px);
  color: var(--dim);
  font-size: 26px;
  line-height: 1;
  border-radius: 3px;
  cursor: pointer;
  transition: color .2s, border-color .2s, opacity .2s;
}
.vnav:hover { color: var(--paper); border-color: var(--dim); }
.vnav[disabled] { opacity: .25; pointer-events: none; }
.vnav-prev { left: max(6px, 1.2vw); }
.vnav-next { right: max(6px, 1.2vw); }

/* 右綴じは「次へ」が左側 */
body.rtl .vnav-prev { left: auto; right: max(6px, 1.2vw); }
body.rtl .vnav-next { right: auto; left: max(6px, 1.2vw); }

@media (max-width: 700px) { .vnav { display: none; } }

/* --- loading ------------------------------------------------------------- */

.vloading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--ink);
  color: var(--dim);
  font-size: 13px;
  letter-spacing: .08em;
  z-index: 20;
  transition: opacity .4s;
}
.vloading.is-done { opacity: 0; pointer-events: none; }

.vspin {
  width: 15px; height: 15px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- bottom bar ---------------------------------------------------------- */

.vbar {
  flex: 0 0 auto;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2vw, 22px);
  border-top: 1px solid var(--rule);
  background: var(--ink-2);
  padding: 0 10px;
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--bar-h) + env(safe-area-inset-bottom));
}

.vbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--dim);
  font-family: var(--body);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .18s, background .18s;
}
.vbtn:hover { color: var(--paper); background: var(--ink-3); }
.vbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.vbtn[aria-expanded="true"] { color: var(--paper); background: var(--ink-3); }

@media (max-width: 560px) { .vbtn span:not(.no) { display: none; } }

.vcount {
  font-family: var(--body);
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  letter-spacing: .06em;
  color: var(--paper);
  min-width: 9ch;
  text-align: center;
}

/* --- thumbnails ---------------------------------------------------------- */

.vthumbs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 62vh;
  background: var(--ink-2);
  border-top: 1px solid var(--rule);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  animation: sheet-up .3s cubic-bezier(.2,.85,.25,1);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet-up { from { transform: translateY(100%); } }

.vthumbs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--display);
  letter-spacing: .16em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--dim);
}

.vclose {
  appearance: none; border: 0; background: transparent;
  color: var(--dim); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.vclose:hover { color: var(--paper); }

.vthumbs-grid {
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 14px;
  padding: 18px;
}

.vthumb {
  appearance: none; border: 0; padding: 0; background: transparent; cursor: pointer;
  display: block; text-align: center;
}
.vthumb img {
  width: 100%; height: auto; display: block;
  background: var(--ink-3);
  border: 1px solid transparent;
  transition: border-color .18s, transform .18s;
}
.vthumb:hover img { border-color: var(--dim); transform: translateY(-2px); }
.vthumb[aria-current="true"] img { border-color: var(--accent); }
.vthumb span {
  display: block; margin-top: 5px; font-size: 11px;
  font-variant-numeric: tabular-nums; color: var(--dim);
}

/* --- zoom ---------------------------------------------------------------- */

.vzoom {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #06090D;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.vzoom img {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  cursor: grab;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}
.vzoom.dragging img { cursor: grabbing; }

.vzoom-bar {
  position: absolute;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(21, 28, 37, .9);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 4px 8px;
  backdrop-filter: blur(8px);
}
.vzoom-bar .vcount { min-width: 8ch; font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}