/*! Milestone Flipbook — viewer styles (no dependencies)
   Layout: one-screen app — top bar / stage (the book, centred) / bottom toolbar.
   The stage is a single deliberate dark world so the printed pages carry the colour. */
:root {
  --fb-bg: #06122e;            /* stage ground: deep bay navy */
  --fb-bg-2: #10285c;          /* light pooling behind the book */
  --fb-ink: #eef3ff;           /* chrome text */
  --fb-ink-dim: rgba(238, 243, 255, .66);
  --fb-line: rgba(238, 243, 255, .14);
  --fb-panel: #0b1a3f;         /* sheets and popovers */
  --fb-accent: #7fb0ff;        /* focus, hints, progress */
  --fb-paper: #f4f6fa;         /* page stock behind images */
  --fb-shadow: rgba(2, 6, 18, .62);
  --fb-font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  --fb-gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --fb-gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: dark;
}

html { box-sizing: border-box; height: 100%; }
*, *::before, *::after { box-sizing: inherit; }
body { height: 100%; margin: 0; overflow: hidden; background: var(--fb-bg); color: var(--fb-ink); font-family: var(--fb-font); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

.fb {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(60% 55% at 50% 46%, var(--fb-bg-2) 0%, transparent 72%),
    var(--fb-bg);
  color: var(--fb-ink);
  font: 14px/1.6 var(--fb-font);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- chrome ---------- */
.fb svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.fb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px;
  padding-left: var(--fb-gutter-l); padding-right: var(--fb-gutter-r);
  padding-block: 6px;
}
.fb-title {
  margin: 0; min-width: 0;
  font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--fb-ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fb-actions { display: flex; gap: 2px; flex: none; }
.fb-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fb-home {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  height: 36px; padding: 0 12px 0 6px; border-radius: 999px;
  border: 1px solid var(--fb-line); color: var(--fb-ink); text-decoration: none;
  font-size: 13px; font-weight: 600; letter-spacing: .04em; white-space: nowrap;
  transition: background-color .15s;
}
.fb-home svg { width: 18px; height: 18px; }
.fb-home:hover { background: rgba(238, 243, 255, .08); }
.fb.is-embed .fb-home { display: none; }

.fb-icon {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; padding: 0;
  border: 0; border-radius: 12px; background: transparent;
  color: var(--fb-ink-dim); cursor: pointer; text-decoration: none;
  transition: background-color .15s, color .15s;
}
.fb-icon:hover { background: rgba(238, 243, 255, .08); color: var(--fb-ink); }
.fb-icon:disabled { opacity: .3; cursor: default; background: transparent; }
.fb :focus-visible { outline: 2px solid var(--fb-accent); outline-offset: 2px; }

.fb-bottom {
  display: grid; justify-items: center; gap: 8px;
  padding-left: var(--fb-gutter-l); padding-right: var(--fb-gutter-r);
  padding-block: 6px 14px;
}
.fb-toolbar {
  display: flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: 999px;
  background: rgba(238, 243, 255, .06);
  border: 1px solid var(--fb-line);
  max-width: 100%;
}
.fb-indicator {
  min-width: 104px; height: 42px; padding: 0 10px;
  border: 0; border-radius: 12px; background: transparent; color: var(--fb-ink);
  font: 600 14px/1 var(--fb-font); letter-spacing: .04em;
  font-variant-numeric: tabular-nums; cursor: pointer;
}
.fb-indicator:hover { background: rgba(238, 243, 255, .08); }
.fb-ind-total { margin-left: 6px; font-weight: 400; color: var(--fb-ink-dim); font-size: 12px; }
.fb-sep { width: 1px; height: 22px; background: var(--fb-line); margin: 0 4px; }
.fb-progress { width: min(240px, 60%); height: 2px; border-radius: 2px; background: var(--fb-line); overflow: hidden; }
.fb-progress span { display: block; height: 100%; width: 0; background: var(--fb-accent); transition: width .5s cubic-bezier(.2, .7, .2, 1); }
.fb-snd-off { display: none; }
.fb-icon[aria-pressed="false"] .fb-snd-on { display: none; }
.fb-icon[aria-pressed="false"] .fb-snd-off { display: block; }

/* ---------- stage & book ---------- */
.fb-stage {
  position: relative; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.fb-book { position: absolute; left: 0; top: 0; will-change: transform; }
.fb-page { position: absolute; top: 0; width: var(--pw); height: 100%; z-index: 1; }
.fb-left { left: 0; }
.fb-right { left: var(--pw); }
.fb[data-mode="single"] .fb-right { left: 0; }
.fb[data-mode="single"] .fb-left { display: none; }
.fb-page.is-empty { visibility: hidden; }
.fb-page:not(.is-empty) { box-shadow: 0 24px 48px -18px var(--fb-shadow), 0 2px 6px rgba(2, 6, 18, .35); }

.fb-pg { position: absolute; inset: 0; background: var(--fb-paper); overflow: hidden; }
.fb-pg > img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}

/* gutter shading at the binding edge */
.fb-page::after, .fb-face::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 4;
}
.fb-left::after, .fb-face-back::before {
  background: linear-gradient(to left, rgba(10, 16, 34, .20), rgba(10, 16, 34, .05) 3.5%, transparent 9%);
}
.fb-right::after, .fb-face-front::before {
  background: linear-gradient(to right, rgba(10, 16, 34, .20), rgba(10, 16, 34, .05) 3.5%, transparent 9%);
}
.fb-page.is-solo::after { opacity: .3; }

.fb-cast { position: absolute; top: 0; height: 100%; width: var(--pw); pointer-events: none; z-index: 2; }
.fb-cast-l { left: 0; }
.fb-cast-r { left: var(--pw); }
.fb[data-mode="single"] .fb-cast-r { left: 0; }
.fb[data-mode="single"] .fb-cast-l { display: none; }

.fb-leaf {
  position: absolute; top: 0; left: var(--pw);
  width: var(--pw); height: 100%;
  transform-origin: 0 50%; transform-style: preserve-3d;
  z-index: 3; will-change: transform;
}
.fb[data-mode="single"] .fb-leaf { left: 0; }
.fb-face {
  position: absolute; inset: 0; overflow: hidden;
  background: var(--fb-paper);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.fb-face-back { transform: rotateY(180deg); }
.fb-face-back.is-paper { background: linear-gradient(90deg, #d9dee8, #eef1f6 45%, #e3e7ee); }
.fb-face::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background: linear-gradient(to right, rgba(6, 12, 28, calc(var(--shade, 0) * .55)), rgba(6, 12, 28, var(--shade, 0)));
}
.fb-face-back::after {
  background: linear-gradient(to left, rgba(6, 12, 28, calc(var(--shade, 0) * .55)), rgba(6, 12, 28, var(--shade, 0)));
}

.fb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 44px; height: 44px; padding: 0; border-radius: 50%;
  border: 1px solid var(--fb-line); background: rgba(6, 18, 46, .5);
  color: var(--fb-ink-dim); cursor: pointer; z-index: 6;
  transition: opacity .2s, background-color .15s, color .15s;
}
.fb-nav:hover { background: rgba(238, 243, 255, .1); color: var(--fb-ink); }
.fb-nav:disabled { opacity: 0; pointer-events: none; }
.fb-nav-prev { left: max(10px, env(safe-area-inset-left, 0px)); }
.fb-nav-next { right: max(10px, env(safe-area-inset-right, 0px)); }
.fb[data-mode="single"] .fb-nav { display: none; }
@media (pointer: coarse) { .fb-nav { display: none; } }

.fb-loading {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--fb-ink-dim); font-size: 12px; letter-spacing: .1em; z-index: 7;
  transition: opacity .3s;
}
.fb.is-ready .fb-loading { opacity: 0; pointer-events: none; }
.fb-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--fb-line); border-top-color: var(--fb-accent);
  animation: fbSpin .9s linear infinite;
}
@keyframes fbSpin { to { transform: rotate(360deg); } }
.fb-noscript { display: grid; gap: 16px; padding: 16px; overflow: auto; height: 100%; }
.fb-noscript img { width: 100%; max-width: 640px; height: auto; margin: 0 auto; }

/* ---------- link hotspots ---------- */
.fb-hot {
  position: absolute; z-index: 3; display: block;
  margin: 0; padding: 0; border: 0; border-radius: 6px;
  background: transparent; cursor: pointer;
  transition: background-color .2s, box-shadow .2s;
}
.fb-hot:hover, .fb-hot:focus-visible {
  outline: none;
  background: rgba(127, 176, 255, .16);
  box-shadow: 0 0 0 2px rgba(127, 176, 255, .9);
}
.fb-hot.is-hint { animation: fbHint 1.8s ease-out 1; }
@keyframes fbHint {
  0% { background: transparent; box-shadow: 0 0 0 0 rgba(127, 176, 255, 0); }
  30% { background: rgba(127, 176, 255, .24); box-shadow: 0 0 0 2px rgba(127, 176, 255, .95); }
  100% { background: transparent; box-shadow: 0 0 0 6px rgba(127, 176, 255, 0); }
}

/* ---------- sheets ---------- */
.fb-scrim { position: fixed; inset: 0; z-index: 20; background: rgba(2, 6, 18, .5); }
.fb-sheet {
  position: fixed; z-index: 21;
  top: calc(64px + env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  width: min(380px, calc(100% - 24px));
  display: flex; flex-direction: column;
  background: var(--fb-panel); color: var(--fb-ink);
  border: 1px solid var(--fb-line); border-radius: 16px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .7);
}
.fb-sheet-wide { width: min(600px, calc(100% - 24px)); }
.fb-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 6px 6px 18px; border-bottom: 1px solid var(--fb-line);
}
.fb-sheet-head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .06em; }
.fb-sheet-body { overflow: auto; padding: 18px; min-height: 0; overscroll-behavior: contain; }
@media (max-width: 640px) {
  .fb-sheet, .fb-sheet-wide {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 82%;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

.fb-thumbs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.fb-thumb {
  display: grid; gap: 8px; padding: 6px; border: 0; border-radius: 10px;
  background: transparent; color: var(--fb-ink-dim); cursor: pointer; text-align: center;
  font: 12px/1.3 var(--fb-font); font-variant-numeric: tabular-nums;
}
.fb-thumb-imgs { display: flex; justify-content: center; }
.fb-thumb img { display: block; width: auto; max-width: 100%; height: 150px; object-fit: contain; background: var(--fb-paper); box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .7); }
.fb-thumb.is-spread img { max-width: 50%; }
.fb-thumb:hover { background: rgba(238, 243, 255, .06); color: var(--fb-ink); }
.fb-thumb[aria-current="true"] { color: var(--fb-ink); box-shadow: inset 0 0 0 2px var(--fb-accent); }

.fb-share { display: grid; gap: 12px; }
.fb-field { font-size: 12px; color: var(--fb-ink-dim); letter-spacing: .06em; }
.fb-copyrow { display: flex; gap: 8px; }
.fb-copyrow input, .fb-embed textarea {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px;
  border: 1px solid var(--fb-line); border-radius: 10px;
  background: rgba(2, 6, 18, .35); color: var(--fb-ink); font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fb-embed textarea { width: 100%; height: auto; padding: 10px 12px; resize: none; margin-top: 8px; }
.fb-embed summary { cursor: pointer; color: var(--fb-ink-dim); font-size: 13px; }
.fb-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--fb-ink-dim); cursor: pointer; }
.fb-check input { width: 16px; height: 16px; accent-color: var(--fb-accent); }
.fb-share-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 4px; }
.fb-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--fb-line); border-radius: 10px;
  background: rgba(238, 243, 255, .06); color: var(--fb-ink);
  font: 600 13px/1.2 var(--fb-font); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.fb-btn:hover { background: rgba(238, 243, 255, .12); }
.fb-btn-primary { background: var(--fb-accent); border-color: transparent; color: #061230; }
.fb-btn-primary:hover { background: #a3c6ff; }
.fb-btn-quiet { background: transparent; }

.fb-text { font-size: 15px; line-height: 1.9; }
.fb-text-page + .fb-text-page { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--fb-line); }
.fb-text h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .18em;
  color: var(--fb-accent); font-variant-numeric: tabular-nums;
}
.fb-text h4 { margin: 18px 0 4px; font-size: 16px; line-height: 1.5; text-wrap: balance; }
.fb-text p { margin: 0 0 10px; max-width: 38em; overflow-wrap: anywhere; }
.fb-text a { color: var(--fb-accent); }

/* ---------- zoom ---------- */
.fb-zoom { position: fixed; inset: 0; z-index: 30; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: rgba(3, 9, 24, .97); }
.fb-zoom-canvas { position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.fb-zoom-canvas.is-panning { cursor: grabbing; }
.fb-zoom-content { position: absolute; left: 0; top: 0; display: flex; transform-origin: 0 0; will-change: transform; }
.fb-zpage { position: relative; flex: none; background: var(--fb-paper); }
.fb-zpage img { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.fb-zoom-bar {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding-left: var(--fb-gutter-l); padding-right: var(--fb-gutter-r);
  padding-block: 8px calc(12px + env(safe-area-inset-bottom, 0px));
}
.fb-zoom-level { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; color: var(--fb-ink-dim); font-size: 13px; }

/* ---------- popover / toast ---------- */
.fb-pop {
  position: fixed; z-index: 35; width: min(300px, calc(100% - 32px));
  display: grid; gap: 6px; padding: 14px 16px;
  background: var(--fb-panel); border: 1px solid var(--fb-line); border-radius: 14px;
  box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .75);
}
.fb-pop-label { font-size: 12px; color: var(--fb-ink-dim); letter-spacing: .06em; }
.fb-pop-value { font-size: 17px; font-weight: 600; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.fb-pop-actions { display: flex; gap: 8px; margin-top: 6px; }
.fb-pop-actions .fb-btn { flex: 1; }

.fb-toast {
  position: fixed; left: 50%; z-index: 40;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px;
  background: var(--fb-ink); color: var(--fb-bg); font-size: 13px; font-weight: 600;
  transition: opacity .2s, transform .2s;
}
.fb-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.fb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- embed & small screens ---------- */
.fb.is-embed .fb-title { visibility: hidden; }
@media (max-width: 520px) { .fb-home + .fb-title { display: none; } }
@media (max-width: 480px) {
  .fb-top { min-height: 50px; }
  .fb-indicator { min-width: 84px; }
  .fb-bottom { padding-block: 4px 10px; }
}
@media (max-height: 520px) {
  .fb-top { min-height: 44px; padding-block: 2px; }
  .fb-icon, .fb-indicator { height: 36px; }
  .fb-icon { width: 36px; }
  .fb-bottom { padding-block: 2px 6px; }
  .fb-progress { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .fb-hot.is-hint { animation: none; }
  .fb-progress span, .fb-toast { transition: none; }
}
