:root {
  --ink: #f4efe8;
  --muted: #b9aea2;
  --gold: #c9a66b;
  --wine: #761f26;
  --bg: #171210;
  --panel: rgba(35, 27, 24, .9);
  --bar-h: 74px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }
body {
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, rgba(153, 111, 63, .25), transparent 42%),
    linear-gradient(145deg, #211916, #100d0c 70%);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  overflow-x: hidden;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.grain { position: fixed; inset: 0; pointer-events: none; opacity: .12; z-index: 20; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.25'/%3E%3C/svg%3E"); }

.topbar { height: var(--bar-h); display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(18px, 4vw, 54px); border-bottom: 1px solid rgba(201,166,107,.25); background: rgba(16,13,12,.75); backdrop-filter: blur(18px); position: relative; z-index: 12; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold); font-family: serif; font-size: 20px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .18em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 8px; letter-spacing: .13em; }
.top-actions { display: flex; gap: 8px; }
.icon-button { min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 13px; border: 1px solid rgba(255,255,255,.13); border-radius: 999px; color: var(--ink); background: rgba(255,255,255,.04); text-decoration: none; cursor: pointer; transition: .2s ease; }
.icon-button:hover { border-color: var(--gold); color: #fff; background: rgba(201,166,107,.12); }
.grid-icon { width: 13px; height: 13px; background: linear-gradient(90deg, currentColor 42%, transparent 42%, transparent 58%, currentColor 58%), linear-gradient(currentColor 42%, transparent 42%, transparent 58%, currentColor 58%); }

main { min-height: calc(100svh - var(--bar-h)); }
.viewer { min-height: calc(100svh - var(--bar-h)); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 22px 20px 14px; }
.book-stage { position: relative; display: grid; place-items: center; width: min(1180px, 100%); flex: 1; min-height: 0; perspective: 2200px; }
.book { --page-ratio: .7047; position: relative; height: min(70svh, 760px); aspect-ratio: 1.4094 / 1; display: grid; grid-template-columns: 1fr 1fr; filter: drop-shadow(0 28px 35px rgba(0,0,0,.55)); transform-style: preserve-3d; }
.page-slot { position: relative; min-width: 0; background: #eee9e0; overflow: hidden; }
.left-slot { border-radius: 5px 0 0 5px; transform-origin: right center; }
.right-slot { border-radius: 0 5px 5px 0; transform-origin: left center; }
.page-slot.blank { background: linear-gradient(110deg,#e8e0d4,#fffaf0); }
.page-slot.blank::after { content: "新韻傳音"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(91,63,42,.14); font: 600 16px serif; letter-spacing: .4em; }
.page-slot img { width: 100%; height: 100%; display: block; object-fit: contain; background: #fff; user-select: none; -webkit-user-drag: none; cursor: zoom-in; }
.purchase-links { position: absolute; z-index: 7; left: 7%; right: 7%; bottom: 13%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 2.4%; padding: 2.5%; border: 1px solid rgba(121,90,51,.18); border-radius: 12px; background: rgba(255,252,246,.88); box-shadow: 0 9px 28px rgba(46,32,21,.16); backdrop-filter: blur(8px); }
.channel-logo { aspect-ratio: 1.55; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.08); text-decoration: none; font-weight: 800; line-height: 1; transition: transform .18s ease, box-shadow .18s ease; }
.channel-logo:hover, .channel-logo:focus-visible { transform: translateY(-3px); box-shadow: 0 7px 15px rgba(0,0,0,.15); outline: 2px solid #c9a66b; outline-offset: 2px; }
.channel-logo.official { color: #a88445; font-family: serif; font-size: clamp(14px, 2.2vw, 26px); border: 1px solid rgba(168,132,69,.5); }
.channel-logo.shopee { color: #ee4d2d; font-size: clamp(14px, 2vw, 24px); border: 1px solid rgba(238,77,45,.25); }
.channel-logo.momo { color: #d4145a; font-family: Arial, sans-serif; font-size: clamp(9px, 1.5vw, 18px); letter-spacing: -.08em; }
.channel-logo.coupang { color: #e34732; font-family: Arial, sans-serif; font-size: clamp(6px, .95vw, 12px); letter-spacing: -.06em; background: linear-gradient(90deg,#e8472f,#f39a23,#52a83f,#1c9ac7,#7651a8); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; border: 1px solid rgba(40,40,40,.12); }
.spine { position: absolute; top: 0; bottom: 0; left: 50%; width: 16px; z-index: 6; transform: translateX(-50%); pointer-events: none; background: linear-gradient(90deg, rgba(0,0,0,.23), rgba(255,255,255,.12) 42%, rgba(0,0,0,.24)); mix-blend-mode: multiply; }
.page-slot::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.left-slot::after { background: linear-gradient(90deg, transparent 75%, rgba(0,0,0,.18)); }
.right-slot::after { background: linear-gradient(90deg, rgba(0,0,0,.18), transparent 25%); }
.flip-sheet { display: none; position: absolute; top: 0; left: 50%; width: 50%; height: 100%; z-index: 8; transform-origin: left center; transform-style: preserve-3d; pointer-events: none; }
.flip-front, .flip-back { position: absolute; inset: 0; backface-visibility: hidden; background-size: contain; background-repeat: no-repeat; background-position: center; background-color: white; }
.flip-back { transform: rotateY(180deg); filter: brightness(.93); }
.book.turn-next .flip-sheet { display: block; animation: turnNext .54s cubic-bezier(.62,.05,.36,1) both; }
.book.turn-prev .flip-sheet { display: block; left: 0; transform-origin: right center; animation: turnPrev .54s cubic-bezier(.62,.05,.36,1) both; }
@keyframes turnNext { from { transform: rotateY(0); } 55% { box-shadow: -24px 8px 32px rgba(0,0,0,.35); } to { transform: rotateY(-180deg); } }
@keyframes turnPrev { from { transform: rotateY(0); } 55% { box-shadow: 24px 8px 32px rgba(0,0,0,.35); } to { transform: rotateY(180deg); } }
.edge { position: absolute; top: 7%; bottom: 7%; width: 12%; z-index: 9; border: 0; background: transparent; cursor: pointer; }
.edge-prev { left: 0; cursor: w-resize; }
.edge-next { right: 0; cursor: e-resize; }
.edge:disabled { cursor: default; }

.controls { width: min(560px, 92vw); display: flex; align-items: center; gap: 15px; margin-top: 14px; }
.nav-button { flex: 0 0 46px; height: 46px; border: 1px solid rgba(201,166,107,.45); border-radius: 50%; background: rgba(0,0,0,.2); color: var(--ink); font-size: 29px; line-height: 1; cursor: pointer; transition: .2s; }
.nav-button:hover:not(:disabled) { background: var(--gold); color: #171210; transform: scale(1.04); }
.nav-button:disabled { opacity: .25; }
.progress-wrap { flex: 1; }
.page-readout { display: flex; justify-content: space-between; align-items: baseline; margin: 0 3px 7px; }
.page-readout span:first-child { color: var(--gold); font-size: 12px; letter-spacing: .1em; }
.page-readout span:last-child { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; height: 3px; display: block; appearance: none; border-radius: 5px; background: linear-gradient(90deg,var(--gold) var(--progress,0%),rgba(255,255,255,.15) var(--progress,0%)); cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 15px; height: 15px; border: 3px solid var(--bg); border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.hint { margin: 9px 0 0; color: rgba(255,255,255,.35); font-size: 10px; letter-spacing: .08em; }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 94vw); padding: 27px; z-index: 31; background: #211916; border-left: 1px solid rgba(201,166,107,.3); box-shadow: -25px 0 60px rgba(0,0,0,.5); transform: translateX(105%); transition: transform .32s ease; overflow: auto; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; position: sticky; top: -27px; z-index: 2; padding: 14px 0 18px; background: linear-gradient(#211916 75%,transparent); }
.drawer-head small { color: var(--gold); font-size: 9px; letter-spacing: .22em; }
.drawer-head h2 { margin: 3px 0 0; font-family: serif; font-weight: 500; letter-spacing: .12em; }
.drawer-head button, .zoom-viewer button { width: 40px; height: 40px; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: rgba(0,0,0,.2); color: white; font-size: 25px; cursor: pointer; }
.thumb-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 17px 11px; }
.thumb { position: relative; border: 0; padding: 0; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.thumb img { width: 100%; display: block; background: white; border: 2px solid transparent; box-shadow: 0 6px 12px rgba(0,0,0,.25); transition: .18s; }
.thumb span { display: block; margin-top: 5px; font-size: 9px; }
.thumb:hover img, .thumb.active img { border-color: var(--gold); transform: translateY(-2px); }
.thumb.active span { color: var(--gold); }
.backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.65); backdrop-filter: blur(4px); }

.zoom-viewer { position: fixed; inset: 0; z-index: 40; overflow: auto; padding: 76px 6vw 40px; background: rgba(10,8,7,.96); opacity: 0; visibility: hidden; transition: .2s; text-align: center; }
.zoom-viewer.open { opacity: 1; visibility: visible; }
.zoom-viewer button { position: fixed; right: 22px; top: 20px; z-index: 2; }
.zoom-viewer img { width: min(1100px, 100%); height: auto; display: block; margin: auto; box-shadow: 0 25px 80px #000; }
.zoom-viewer p { color: var(--muted); font-size: 11px; }

@media (max-width: 760px) {
  :root { --bar-h: 62px; }
  .topbar { padding: 0 14px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand strong { font-size: 13px; }
  .wide-label { display: none; }
  .icon-button { width: 39px; justify-content: center; padding: 0; }
  .viewer { padding: 13px 8px 8px; }
  .book-stage { width: 100%; flex: 0 0 auto; }
  .book { width: min(89vw, calc((100svh - 160px) * .7047), 470px); height: auto; aspect-ratio: .7047 / 1; display: block; }
  .page-slot { position: absolute; inset: 0; border-radius: 5px; }
  .left-slot { display: none; }
  .right-slot { display: block; }
  .spine, .page-slot::after { display: none !important; }
  .book-stage { touch-action: pan-y; }
  .flip-sheet {
    display: none;
    left: 0;
    width: 100%;
    border-radius: 5px;
    transform-origin: left center;
    will-change: transform, filter;
  }
  .flip-sheet.mobile-dragging {
    display: block;
    filter: drop-shadow(calc(20px * var(--fold, 0)) 8px calc(24px * var(--fold, 0)) rgba(0,0,0,.5));
  }
  .flip-sheet.mobile-dragging::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    backface-visibility: hidden;
    background: linear-gradient(90deg, rgba(0,0,0,.28), transparent 15%, transparent 72%, rgba(255,255,255,.22));
    opacity: var(--fold, 0);
    mix-blend-mode: multiply;
  }
  .flip-sheet.mobile-settling { transition: transform .38s cubic-bezier(.2,.72,.2,1), filter .38s ease; }
  .flip-front, .flip-back { border-radius: 5px; overflow: hidden; }
  .edge { width: 24%; }
  .controls { margin-top: 10px; gap: 10px; }
  .nav-button { flex-basis: 42px; height: 42px; }
  .hint { display: none; }
  .thumb-grid { grid-template-columns: repeat(3,1fr); }
}

@media (max-height: 710px) and (min-width: 761px) { .book { height: 63svh; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
