:root {
  --bg-0: #06111e;
  --bg-1: #0a1a2a;
  --panel: rgba(13, 29, 45, .86);
  --panel-2: rgba(255, 255, 255, .07);
  --line: rgba(255, 255, 255, .13);
  --text: #f6f8fb;
  --muted: #9fb0c2;
  --accent: #4691c9;
  --accent-soft: #75b9e6;
  --page-ratio: 1.4142857143;
  --zoom: 1;
  --turn-time: 760ms;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg-0); }
body {
  min-width: 320px;
  color: var(--text);
  font-family: "Noto Sans KR", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -8%, rgba(70, 145, 201, .22), transparent 36%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
  overflow-x: hidden;
}
button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(117,185,230,.48); outline-offset: 3px; }

.topbar {
  height: 78px;
  padding: 0 clamp(18px, 3vw, 48px);
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 15, 26, .73);
  backdrop-filter: blur(18px);
}
.brand-block { min-width: 0; }
.eyebrow { font-size: 10px; letter-spacing: .21em; color: var(--accent-soft); font-weight: 700; }
.title { margin-top: 3px; font-size: 17px; font-weight: 750; letter-spacing: .045em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { margin-top: 2px; font-size: 11px; color: var(--muted); letter-spacing: .035em; }
.header-actions { display: flex; gap: 7px; flex: 0 0 auto; }
.tool-btn {
  min-height: 39px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  text-decoration: none;
  background: rgba(255,255,255,.055);
  cursor: pointer;
  font-size: 12px;
  transition: background .16s ease, transform .16s ease;
}
.tool-btn:hover { background: rgba(255,255,255,.1); transform: translateY(-1px); }

.app-shell { min-height: 100vh; padding-top: 78px; }
.viewer {
  min-height: calc(100vh - 78px);
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 72px;
  overflow: hidden;
}
.viewer-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 52%, rgba(255,255,255,.055), transparent 44%),
    linear-gradient(90deg, rgba(255,255,255,.018), transparent 18%, transparent 82%, rgba(255,255,255,.018));
}

.desktop-stage {
  min-height: 0;
  padding: clamp(28px, 4vh, 52px) clamp(58px, 7vw, 110px) 18px;
  display: grid;
  place-items: center;
  overflow: auto;
  perspective: 2400px;
}
.book-shift {
  width: min(78vw, 1500px);
  aspect-ratio: calc(var(--page-ratio) * 2) / 1;
  transform: translateX(-25%) scale(var(--zoom));
  transform-origin: center center;
  transition: transform 420ms cubic-bezier(.22,.7,.25,1);
}
.book {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  filter: drop-shadow(0 34px 36px rgba(0,0,0,.30));
  user-select: none;
}
.page-base {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: #f8f8f7;
  box-shadow: inset 0 0 22px rgba(0,0,0,.035);
}
.page-base-left { left: 0; border-radius: 8px 0 0 8px; }
.page-base-right { right: 0; border-radius: 0 8px 8px 0; }
.spine {
  position: absolute;
  z-index: 4000;
  left: calc(50% - 1px);
  top: 0;
  width: 3px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.18), rgba(255,255,255,.25), rgba(0,0,0,.14));
  opacity: .54;
  box-shadow: 0 0 18px rgba(0,0,0,.18);
}
.leaf {
  position: absolute;
  left: 50%;
  top: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--turn-time) cubic-bezier(.2,.63,.27,1), filter var(--turn-time) ease;
  will-change: transform;
}
.leaf.turning { filter: drop-shadow(-18px 16px 17px rgba(0,0,0,.24)); }
.leaf.turned { transform: rotateY(-180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  overflow: hidden;
  background: white;
}
.face.front { border-radius: 0 8px 8px 0; }
.face.back { transform: rotateY(180deg); border-radius: 8px 0 0 8px; }
.face img { width: 100%; height: 100%; display: block; object-fit: fill; pointer-events: none; }
.face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .18;
}
.face.front::after { background: linear-gradient(90deg, rgba(0,0,0,.13), transparent 7%, transparent 88%, rgba(255,255,255,.13)); }
.face.back::after { background: linear-gradient(270deg, rgba(0,0,0,.13), transparent 7%, transparent 88%, rgba(255,255,255,.13)); }

.edge-nav {
  position: absolute;
  z-index: 65;
  top: calc(50% - 16px);
  width: 50px;
  height: 78px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(6,17,30,.58);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: background .16s ease, opacity .16s ease, transform .16s ease;
}
.edge-nav:hover { background: rgba(70,145,201,.32); transform: scale(1.03); }
.edge-nav:disabled { opacity: .2; cursor: default; transform: none; }
.edge-nav span { font-size: 39px; line-height: 1; margin-top: -4px; }
.edge-left { left: 22px; }
.edge-right { right: 22px; }

.bottom-controls {
  position: relative;
  z-index: 70;
  min-height: 72px;
  padding: 11px clamp(18px, 3vw, 46px) 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  border-top: 1px solid var(--line);
  background: rgba(5,15,26,.57);
  backdrop-filter: blur(14px);
}
.zoom-controls { display: flex; align-items: center; gap: 5px; }
.zoom-controls button, .page-control button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,.055);
  cursor: pointer;
}
.zoom-controls button {
  width: 36px; height: 36px; border-radius: 10px; font-size: 17px;
}
.zoom-controls .zoom-value { width: 64px; font-size: 11px; }
.page-control { display: flex; align-items: center; gap: 9px; }
.page-control button { height: 36px; min-width: 38px; border-radius: 10px; }
#pageStatus { min-width: 112px; padding: 0 12px; font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 650; }
#prevSmall, #nextSmall { font-size: 22px; }
.viewer-hint { justify-self: end; text-align: right; color: var(--muted); font-size: 10px; }

.thumb-drawer {
  position: fixed;
  z-index: 120;
  inset: 78px auto 0 0;
  width: min(390px, 90vw);
  transform: translateX(-102%);
  transition: transform .24s cubic-bezier(.22,.7,.25,1);
  border-right: 1px solid var(--line);
  background: rgba(5,15,26,.96);
  box-shadow: 24px 0 50px rgba(0,0,0,.27);
  backdrop-filter: blur(18px);
}
.thumb-drawer.open { transform: translateX(0); }
.drawer-head { height: 66px; padding: 0 15px 0 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.drawer-head strong { display: block; font-size: 14px; }
.drawer-head span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.drawer-close { width: 36px; height: 36px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; font-size: 27px; }
.thumb-grid { height: calc(100% - 66px); overflow: auto; padding: 17px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; align-content: start; }
.thumb {
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.thumb:hover, .thumb.active { border-color: rgba(117,185,230,.52); background: rgba(70,145,201,.1); }
.thumb img { width: 100%; display: block; aspect-ratio: var(--page-ratio) / 1; object-fit: cover; border-radius: 5px; box-shadow: 0 7px 18px rgba(0,0,0,.22); }
.thumb span { display: block; margin: 6px 2px 0; font-size: 10px; }

.mobile-stage { display: none; }
.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: 27px;
  padding: 11px 15px;
  border-radius: 11px;
  background: #13293a;
  color: white;
  box-shadow: 0 16px 40px rgba(0,0,0,.28);
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  font-size: 11px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.fullscreen .topbar { display: none; }
body.fullscreen .app-shell { padding-top: 0; }
body.fullscreen .viewer { min-height: 100vh; }
body.fullscreen .thumb-drawer { inset-top: 0; }

@media (max-width: 980px) {
  .header-actions .tool-btn:nth-child(3) { display: none; }
  .book-shift { width: min(82vw, 1200px); }
  .desktop-stage { padding-inline: 58px; }
}

@media (max-width: 760px) {
  .topbar { height: 66px; padding: 0 12px 0 14px; gap: 10px; }
  .eyebrow { font-size: 8px; }
  .title { max-width: 47vw; font-size: 12px; letter-spacing: .02em; }
  .subtitle { font-size: 9px; }
  .header-actions { gap: 5px; }
  .tool-btn { min-height: 35px; padding: 0 9px; font-size: 10px; }
  .header-actions .tool-btn:nth-child(3) { display: none; }
  .app-shell { padding-top: 66px; }
  .viewer { min-height: calc(100vh - 66px); grid-template-rows: minmax(0,1fr) 66px; }
  .desktop-stage { display: none; }
  .mobile-stage {
    min-height: 0;
    padding: 18px 44px 14px;
    display: grid;
    place-items: center;
    perspective: 1700px;
    overflow: hidden;
  }
  .mobile-page-wrap {
    width: min(88vw, 720px);
    aspect-ratio: var(--page-ratio) / 1;
    position: relative;
    transform-origin: center;
    transform-style: preserve-3d;
    background: white;
    border-radius: 7px;
    overflow: hidden;
    box-shadow: 0 24px 40px rgba(0,0,0,.33);
  }
  .mobile-page-wrap.next-out { animation: mobileNextOut 260ms ease-in forwards; }
  .mobile-page-wrap.next-in { animation: mobileNextIn 320ms ease-out forwards; }
  .mobile-page-wrap.prev-out { animation: mobilePrevOut 260ms ease-in forwards; }
  .mobile-page-wrap.prev-in { animation: mobilePrevIn 320ms ease-out forwards; }
  @keyframes mobileNextOut { to { transform: translateX(-12%) rotateY(-58deg) scale(.97); opacity: .18; } }
  @keyframes mobileNextIn { from { transform: translateX(12%) rotateY(58deg) scale(.97); opacity: .18; } to { transform: none; opacity: 1; } }
  @keyframes mobilePrevOut { to { transform: translateX(12%) rotateY(58deg) scale(.97); opacity: .18; } }
  @keyframes mobilePrevIn { from { transform: translateX(-12%) rotateY(-58deg) scale(.97); opacity: .18; } to { transform: none; opacity: 1; } }
  .mobile-page-wrap img { width: 100%; height: 100%; display: block; object-fit: fill; }
  .mobile-shine { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(100deg, transparent 0 46%, rgba(255,255,255,.14) 49%, transparent 53%); opacity: .45; }
  .edge-nav { width: 34px; height: 58px; top: calc(50% - 18px); border-radius: 12px; }
  .edge-left { left: 5px; }
  .edge-right { right: 5px; }
  .edge-nav span { font-size: 30px; }
  .bottom-controls { min-height: 66px; padding: 9px 12px 12px; grid-template-columns: 1fr; place-items: center; }
  .desktop-only { display: none !important; }
  .page-control { gap: 8px; }
  #pageStatus { min-width: 105px; }
  .thumb-drawer { inset: 66px auto 0 0; width: min(360px, 92vw); }
  .thumb-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  body.fullscreen .thumb-drawer { inset: 0 auto 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
