:root {
  --toolbar-height: 58px;
  --status-height: 38px;
  --viewer-bg: #171b21;
  --viewer-panel: #222831;
  --viewer-line: rgba(255,255,255,.15);
  --viewer-text: #f6f8fb;
  --viewer-muted: #aeb8c5;
  --viewer-accent: #11b5cb;
  --page-ratio: .70364;
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; color: var(--viewer-text); background: var(--viewer-bg); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button, a { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.viewer-toolbar { height: var(--toolbar-height); padding: 0 16px; position: fixed; z-index: 30; inset: 0 0 auto; display: grid; grid-template-columns: 220px 1fr auto; align-items: center; background: rgba(18,22,28,.97); border-bottom: 1px solid var(--viewer-line); box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.viewer-back { display: inline-flex; align-items: center; gap: 9px; color: #d9e2eb; font-size: 11px; }
.viewer-back > span { width: 27px; height: 27px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.38); border-radius: 50%; font-size: 24px; line-height: 1; }
.viewer-title { justify-self: center; display: flex; align-items: baseline; gap: 10px; }
.viewer-title strong { font-size: 15px; letter-spacing: .09em; }
.viewer-title span { color: var(--viewer-accent); font: 700 8px/1 Arial, sans-serif; letter-spacing: .12em; }
.viewer-controls { display: flex; align-items: center; gap: 3px; }
.viewer-controls button { min-width: 41px; height: 38px; padding: 4px 7px; display: grid; place-items: center; gap: 1px; border: 0; border-radius: 3px; color: #d7dfe8; background: transparent; cursor: pointer; transition: color .2s ease, background .2s ease; }
.viewer-controls button:hover, .viewer-controls button[aria-expanded="true"] { color: #fff; background: rgba(255,255,255,.1); }
.viewer-controls button:focus-visible, .page-arrow:focus-visible, .thumbnail-card:focus-visible { outline: 2px solid var(--viewer-accent); outline-offset: 2px; }
.viewer-controls svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.viewer-controls button > span { font-size: 7px; }
.viewer-controls button > b { font: 400 21px/1 Arial, sans-serif; }
#zoomReset { min-width: 48px; border-left: 1px solid var(--viewer-line); border-right: 1px solid var(--viewer-line); border-radius: 0; }
#zoomReset span { font: 600 9px/1 Arial, sans-serif; }

.viewer-main { position: fixed; inset: var(--toolbar-height) 0 var(--status-height); }
.catalog-stage-scroll { width: 100%; height: 100%; overflow: auto; overscroll-behavior: contain; scrollbar-color: #65717e #20252b; }
.catalog-stage { min-width: 100%; min-height: 100%; padding: 20px 82px; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 45%, #343a42 0, #23282f 44%, #171b21 80%); }
.catalog-book { display: flex; flex: 0 0 auto; align-items: stretch; position: relative; perspective: 1800px; filter: drop-shadow(0 17px 22px rgba(0,0,0,.42)); transition: width .2s ease, height .2s ease; }
.catalog-book::after { content: ""; position: absolute; z-index: 4; top: 0; bottom: 0; left: 50%; width: 18px; pointer-events: none; opacity: 0; transform: translateX(-50%); background: linear-gradient(90deg, transparent, rgba(0,0,0,.16), rgba(255,255,255,.11), transparent); }
.catalog-book.is-spread::after { opacity: 1; }
.catalog-page { height: 100%; margin: 0; position: relative; overflow: hidden; background: #fff; transform-style: preserve-3d; }
.catalog-page + .catalog-page { border-left: 1px solid rgba(0,0,0,.18); }
.catalog-page img { width: 100%; height: 100%; display: block; object-fit: contain; background: #fff; user-select: none; -webkit-user-drag: none; }
.catalog-page figcaption { position: absolute; right: 7px; bottom: 5px; padding: 2px 5px; color: #fff; background: rgba(0,0,0,.45); border-radius: 2px; font-size: 7px; opacity: 0; transition: opacity .2s ease; }
.catalog-page:hover figcaption { opacity: 1; }
.catalog-page.is-left { transform-origin: right center; }
.catalog-page.is-right { transform-origin: left center; }
.catalog-book.is-entering-next { animation: book-enter-next .18s ease-out both; }
.catalog-book.is-entering-prev { animation: book-enter-prev .18s ease-out both; }
@keyframes book-enter-next { from { opacity: .25; transform: perspective(1400px) rotateY(6deg) translateX(12px); } to { opacity: 1; transform: none; } }
@keyframes book-enter-prev { from { opacity: .25; transform: perspective(1400px) rotateY(-6deg) translateX(-12px); } to { opacity: 1; transform: none; } }

.page-arrow { width: 47px; height: 47px; padding: 0 0 4px; position: fixed; z-index: 10; top: 50%; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.48); border-radius: 50%; color: #fff; background: rgba(12,16,21,.58); backdrop-filter: blur(5px); font-size: 38px; font-weight: 200; line-height: 1; cursor: pointer; transition: background .2s ease, opacity .2s ease, transform .2s ease; }
.page-arrow:hover { background: var(--viewer-accent); transform: scale(1.05); }
.page-arrow:disabled { opacity: .2; pointer-events: none; }
.page-arrow--prev { left: 22px; }
.page-arrow--next { right: 22px; }

.thumbnail-panel { width: 224px; position: fixed; z-index: 25; inset: var(--toolbar-height) auto var(--status-height) 0; overflow: hidden; color: #eff3f7; background: rgba(25,30,37,.98); border-right: 1px solid var(--viewer-line); box-shadow: 8px 0 24px rgba(0,0,0,.28); transform: translateX(-101%); transition: transform .24s ease; }
.thumbnail-panel.is-open { transform: translateX(0); }
.thumbnail-heading { height: 45px; padding: 0 13px 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--viewer-line); font-size: 11px; }
.thumbnail-heading button { width: 28px; height: 28px; border: 0; border-radius: 50%; color: #cbd4de; background: transparent; font-size: 22px; cursor: pointer; }
.thumbnail-list { height: calc(100% - 45px); padding: 14px; overflow: auto; display: grid; grid-template-columns: repeat(2, 1fr); align-content: start; gap: 13px 10px; }
.thumbnail-card { padding: 0; border: 1px solid transparent; color: #c8d0d9; background: transparent; cursor: pointer; }
.thumbnail-card img { width: 100%; display: block; box-shadow: 0 4px 10px rgba(0,0,0,.32); }
.thumbnail-card span { display: block; margin-top: 5px; font-size: 8px; }
.thumbnail-card.is-current { color: #fff; border-color: var(--viewer-accent); }
.thumbnail-card.is-current span { color: var(--viewer-accent); }
.thumbnail-scrim { position: fixed; z-index: 24; inset: var(--toolbar-height) 0 var(--status-height); background: rgba(0,0,0,.32); }

.viewer-status { height: var(--status-height); padding: 0 18px; position: fixed; z-index: 30; inset: auto 0 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; color: var(--viewer-muted); background: rgba(18,22,28,.98); border-top: 1px solid var(--viewer-line); font-size: 8px; }
.page-position { min-width: 94px; height: 25px; display: flex; align-items: center; justify-content: center; gap: 8px; color: #e7ecf1; border: 1px solid var(--viewer-line); border-radius: 14px; font: 500 10px/1 Arial, sans-serif; }
.page-position b { color: var(--viewer-accent); font-size: 12px; }
.viewer-status__links { justify-self: end; display: flex; align-items: center; gap: 16px; }
.viewer-status__links a { color: #dce4ec; }
.viewer-status__links a:first-child { color: #50d987; }
.viewer-status__links a:hover { color: var(--viewer-accent); }
.print-pages { display: none; }

@media (max-width: 760px) {
  :root { --toolbar-height: 54px; --status-height: 34px; }
  .viewer-toolbar { width: 100%; min-width: 0; padding: 0 8px; grid-template-columns: 38px minmax(0, 1fr) auto; }
  .viewer-back { width: 34px; }
  .viewer-back > span { width: 31px; height: 31px; }
  .viewer-back b { display: none; }
  .viewer-title { min-width: 0; justify-self: start; overflow: hidden; white-space: nowrap; }
  .viewer-title strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; }
  .viewer-title span { display: none; }
  .viewer-controls { min-width: 0; gap: 0; }
  .viewer-controls button { min-width: 35px; height: 38px; padding: 4px; }
  .viewer-controls button > span, #modeToggle, #zoomOut, #zoomReset, #zoomIn, #printCatalog { display: none; }
  .catalog-stage { padding: 15px 43px; align-items: center; }
  .page-arrow { width: 36px; height: 36px; top: 52%; font-size: 28px; }
  .page-arrow--prev { left: 5px; }
  .page-arrow--next { right: 5px; }
  .thumbnail-panel { width: min(78vw, 285px); }
  .thumbnail-list { grid-template-columns: repeat(2, 1fr); }
  .viewer-status { width: 100%; min-width: 0; padding: 0 10px; grid-template-columns: 1fr; }
  .viewer-hint, .viewer-status__links { display: none; }
  .page-position { justify-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { height: auto; overflow: visible; background: #fff; }
  .viewer-toolbar, .viewer-main, .viewer-status { display: none !important; }
  .print-pages { display: block; }
  .print-pages img { width: 100%; height: auto; display: block; page-break-after: always; }
  .print-pages img:last-child { page-break-after: auto; }
}
