:root {
  --ink: #14161a;
  --paper: #f1f2f4;
  --mute: #666b73;
  --line: #d6d9de;
  --accent: #2f4bff;
  --font: "Noto Sans TC", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); -webkit-font-smoothing: antialiased; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button { font-family: inherit; }

/* =============== 書庫（首頁／品牌頁） =============== */
.g-page { background: var(--paper); color: var(--ink); height: auto; min-height: 100%; }
.g-wrap { max-width: 1120px; margin: 0 auto; padding: 28px 28px 110px; }
.g-top { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 700; }
.g-top a { color: var(--mute); font-weight: 500; text-decoration: none; }
.g-top a:hover { text-decoration: underline; text-underline-offset: 4px; }
.g-top .sep { color: var(--mute); font-weight: 400; }
.g-hero { padding: 56px 0 44px; }
.g-hero h1 { margin: 0; font-weight: 700; font-size: clamp(26px, 3.4vw, 36px); line-height: 1.25;
  letter-spacing: -.01em; overflow-wrap: anywhere; }
.g-logo { display: block; height: clamp(44px, 8vw, 72px); max-width: min(70%, 320px); width: auto; object-fit: contain; margin: 0 0 4px; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.blogo { height: 24px; max-width: 120px; object-fit: contain; display: block; }
.blogo[hidden], .bl[hidden] { display: none !important; }
.ad-logo { width: 56px; height: 56px; object-fit: contain; background: #e6e9ee; border-radius: 8px; padding: 4px; flex: none; }
.g-hero p { margin: 10px 0 0; font-size: 15px; color: var(--mute); }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 48px 32px; align-items: end; }
.book { display: block; color: inherit; text-decoration: none; }
.book .cover { position: relative; display: block; border-radius: 3px 8px 8px 3px; overflow: hidden;
  background: color-mix(in oklab, var(--tone, #888) 40%, #fff);
  box-shadow: 0 22px 32px -16px color-mix(in oklab, var(--tone, #444) 75%, transparent), 0 2px 5px rgba(0,0,0,.12);
  transition: transform .2s ease, box-shadow .2s ease; }
.book .cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.book .cover::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 10px;
  background: linear-gradient(90deg, rgba(0,0,0,.26), rgba(255,255,255,.2) 45%, rgba(0,0,0,0)); }
.book:hover .cover, .book:focus-visible .cover { transform: translateY(-6px);
  box-shadow: 0 30px 36px -16px color-mix(in oklab, var(--tone, #444) 85%, transparent), 0 2px 5px rgba(0,0,0,.12); }
.book .t { display: block; margin-top: 16px; font-weight: 700; font-size: 15px; line-height: 1.4; }
.book .m { display: block; margin-top: 3px; font-size: 13px; color: var(--mute); }

.brand-row { border-top: 2px solid var(--ink); padding: 26px 0 64px; }
.brand-head { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 36px; }
.brand-head a { color: inherit; text-decoration: none; font-weight: 900; font-size: clamp(40px, 7.5vw, 88px);
  line-height: 1; letter-spacing: -.03em; overflow-wrap: anywhere; }
.brand-head a:hover { text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 8px; }
.brand-head .n { color: var(--mute); font-size: 15px; white-space: nowrap; }
.empty { padding: 60px 0; font-size: 17px; color: var(--mute); }

/* =============== 閱讀頁 =============== */
.v-page {
  --tone: #3d4048;
  color: #f4f5f7; height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden;
  background: #121317;
  background: radial-gradient(120% 90% at 50% 38%,
    color-mix(in oklab, var(--tone) 34%, #15161b) 0%,
    color-mix(in oklab, var(--tone) 22%, #0d0e11) 60%,
    color-mix(in oklab, var(--tone) 8%, #050506) 100%);
}
.vhead { display: flex; align-items: center; gap: 14px; padding: 14px 18px 4px; min-width: 0; }
.back { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 8px 14px 8px 8px; border-radius: 999px;
  background: rgba(255,255,255,.11); color: #fff; text-decoration: none; font-size: 14px; font-weight: 500;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.back:hover { background: rgba(255,255,255,.2); }
.vtitle { margin: 0; font-size: 15px; font-weight: 700; opacity: .92; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.stage { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 16px 10px; }
#book { filter: drop-shadow(0 28px 36px rgba(0,0,0,.5)); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.7); font-size: 15px; pointer-events: none; text-align: center; padding: 0 24px; }
.loading i { width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.zoom { position: absolute; inset: 0; z-index: 6; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  background: color-mix(in srgb, var(--tone) 16%, #14161a); }
.zoom[hidden] { display: none; }
.zoom.drag { cursor: grabbing; }
.zi { position: absolute; left: 0; top: 0; transform-origin: 0 0; display: flex; will-change: transform; }
.zi img { display: block; -webkit-user-drag: none; pointer-events: none; background: #fff; }
.zclose { position: absolute; top: 12px; right: 12px; z-index: 2; width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; cursor: pointer; }
.zclose:hover { background: rgba(255,255,255,.28); }
.nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 5; width: 46px; height: 46px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.12); color: #fff; display: grid; place-items: center; cursor: pointer; }
.nav:hover { background: rgba(255,255,255,.24); }
.nav.prev { left: 14px; } .nav.next { right: 14px; }
.nav[disabled] { opacity: .22; cursor: default; }

.dock { display: flex; align-items: center; gap: 12px; margin: 0 auto 18px; padding: 8px 10px 8px 16px; max-width: calc(100% - 24px);
  border-radius: 999px; background: rgba(16,17,21,.64); border: 1px solid rgba(255,255,255,.13);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.dock .step { width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.dock .step:hover { background: rgba(255,255,255,.14); }
.dock .step[disabled] { opacity: .3; cursor: default; }
.count { font-size: 14px; font-variant-numeric: tabular-nums; min-width: 62px; text-align: center; white-space: nowrap; }
.count input { width: 34px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: right; -moz-appearance: textfield; }
.count input::-webkit-outer-spin-button, .count input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.count input:focus-visible { outline: 2px solid #fff; border-radius: 4px; }
.dock .sep { width: 1px; height: 24px; background: rgba(255,255,255,.18); flex: none; }

#slider { -webkit-appearance: none; appearance: none; width: clamp(110px, 30vw, 340px); height: 28px; background: transparent; cursor: pointer; margin: 0; }
#slider::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, #fff var(--p, 0%), rgba(255,255,255,.25) var(--p, 0%)); }
#slider::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255,255,255,.25); }
#slider::-moz-range-progress { height: 4px; border-radius: 4px; background: #fff; }
#slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 6px rgba(0,0,0,.5); }
#slider::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 0; }
#slider:focus-visible { outline-offset: 4px; border-radius: 6px; }

.btn-share { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 18px 0 14px; border: 0; border-radius: 999px;
  background: #fff; color: #14161a; font-weight: 700; font-size: 15px; cursor: pointer; flex: none; }
.btn-share:hover { background: #e9ebff; }
.ibtn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.11); color: #fff; display: grid; place-items: center; cursor: pointer; text-decoration: none; flex: none; }
.ibtn:hover { background: rgba(255,255,255,.22); }

.toast { position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 8px); z-index: 80; background: #fff; color: #14161a; font-weight: 700; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 分享面板 */
.sheet { position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center; }
.sheet[hidden] { display: none; }
.sheet .scrim { position: absolute; inset: 0; background: rgba(8,9,12,.6); }
.panel { position: relative; width: min(540px, 100%); max-height: 94dvh; overflow: auto; background: #fff; color: var(--ink);
  border-radius: 22px 22px 0 0; padding: 26px 24px 30px; animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) { .sheet { place-items: center; } .panel { border-radius: 22px; } }
.panel h2 { margin: 0 44px 18px 0; font-size: 20px; line-height: 1.3; font-weight: 900; }
.panel .x { position: absolute; top: 16px; right: 16px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eef0f3; color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.panel .x:hover { background: #e2e5ea; }
.urlrow { display: flex; gap: 8px; }
.urlrow input { flex: 1; min-width: 0; height: 46px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 12px; font: 500 14px var(--font); color: var(--ink); background: #f7f8fa; }
.btn-copy { flex: none; height: 46px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer; }
.btn-copy:hover { background: #2239d9; }
.chk { display: flex; align-items: center; gap: 10px; margin: 14px 2px 0; font-size: 14px; color: var(--mute); cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.channels { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 10px; margin: 22px 0 0; }
.ch { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 4px; border: 0; border-radius: 14px; background: transparent; color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 500; cursor: pointer; }
.ch:hover { background: #f1f3f6; }
.ch b { width: 50px; height: 50px; border-radius: 15px; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 900; letter-spacing: 0; }
.more { display: flex; gap: 20px; align-items: center; margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.qr { flex: none; width: 112px; height: 112px; padding: 8px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; }
.qr svg { width: 100%; height: 100%; display: block; }
.more p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--mute); }
.more p strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 2px; }
.embed-box { margin-top: 18px; }
.embed-box summary { cursor: pointer; font-size: 14px; font-weight: 700; padding: 6px 0; }
.embed-box textarea { width: 100%; margin-top: 8px; height: 76px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; font: 12px/1.5 ui-monospace, Menlo, monospace; color: var(--ink); background: #f7f8fa; resize: none; }
.embed-box .btn-copy { margin-top: 8px; height: 40px; font-size: 14px; background: var(--ink); }

body.embed .vhead, body.embed .btn-share, body.embed .ibtn, body.embed .dock .sep { display: none; }
body.embed .dock { margin-bottom: 10px; }

@media (max-width: 640px) {
  .nav { display: none; }
  .vhead { padding: 12px 12px 2px; }
  .dock { width: calc(100% - 20px); gap: 8px; padding: 6px 8px 6px 12px; margin-bottom: 12px; }
  #slider { flex: 1; width: auto; min-width: 0; }
  .dock .step { display: none; }
  .ibtn.fs { display: none; }
  .dock .sep { display: none; }
  .dock .ibtn { width: 36px; height: 36px; }
  .btn-share { padding: 0 14px; }
  .count { min-width: 54px; }
  .toast { bottom: 84px; }
  .g-hero { padding: 40px 0 32px; }
  .shelf { grid-template-columns: repeat(2, 1fr); gap: 36px 18px; }
  .more { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .book .cover, .toast, .panel, .loading i { transition: none; animation: none; }
}

/* 首頁：品牌 = 該品牌最新一本書的封面 */
.shelf.brands { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 56px 36px; }
.shelf.brands .t { font-size: 18px; margin-top: 18px; }
.shelf.brands .m { font-size: 13px; margin-top: 4px; }

/* =============== 上傳後台 =============== */
.ad { max-width: 860px; }
.g-top { flex-wrap: wrap; }
.ad-link { margin-left: auto; border: 0; background: none; color: var(--mute); font: 500 14px var(--font); cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.ad-hero { padding: 48px 0 28px; }
.ad-card { background: #fff; border-radius: 18px; padding: 28px; margin-bottom: 40px; box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 18px 40px -26px rgba(20,22,26,.35); }
.ad-card h2 { margin: 0 0 14px; font-size: 20px; font-weight: 900; }
.ad-card ol { margin: 0; padding-left: 20px; line-height: 1.9; }
.ad-card code { background: #eef0f3; padding: 2px 7px; border-radius: 6px; font-size: 14px; }
.ad-h2 { margin: 0 0 18px; font-size: 22px; font-weight: 900; }
.ad-field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; font-size: 14px; font-weight: 700; }
.ad-field input, .ad-field select { height: 48px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #f7f8fa; color: var(--ink); font: 500 16px var(--font); }
.ad-field small { font-weight: 400; color: var(--mute); word-break: break-all; }
.ad-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.ad-drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 150px; margin-bottom: 24px; padding: 20px; text-align: center;
  border: 2px dashed #b9bec7; border-radius: 16px; background: #f7f8fa; cursor: pointer; transition: border-color .15s, background .15s; }
.ad-drop:hover, .ad-drop.on { border-color: var(--accent); background: #eef1ff; }
.ad-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.ad-drop:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.ad-drop b { font-size: 18px; overflow-wrap: anywhere; }
.ad-drop span { color: var(--mute); font-size: 14px; }
.ad-check { display: flex; gap: 10px; align-items: center; margin: 4px 0 22px; font-size: 14px; color: var(--mute); }
.ad-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.ad-btn { height: 50px; padding: 0 30px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font: 700 16px var(--font); cursor: pointer; }
.ad-btn:hover { background: #2239d9; }
.ad-btn:disabled { opacity: .5; cursor: default; }
.ad-progress { margin: 4px 0 20px; }
.ad-bar { height: 8px; border-radius: 8px; background: #e3e6eb; overflow: hidden; }
.ad-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.ad-progress p { margin: 10px 0 0; font-size: 14px; color: var(--mute); }
.ad-error { margin: 0 0 14px; min-height: 0; color: #c62828; font-size: 14px; font-weight: 700; }
.ad-error:empty { display: none; }
.ad-done { margin: 0 0 18px; padding: 14px 16px; border-radius: 12px; background: #e8f6ec; color: #14532d; font-size: 14px; line-height: 1.7; font-weight: 500; }
.ad-done a { color: inherit; font-weight: 700; word-break: break-all; }
.ad-list { display: flex; flex-direction: column; gap: 4px; }
.ad-row { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.ad-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px 8px 8px 4px; background: #d9dce1; flex: none; }
.ad-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ad-meta b { font-size: 16px; overflow-wrap: anywhere; }
.ad-meta span { font-size: 13px; color: var(--mute); }
.ad-open, .ad-del { flex: none; padding: 8px 14px; border: 0; border-radius: 999px; background: #e6e9ee; color: var(--ink); font: 700 13px var(--font); text-decoration: none; cursor: pointer; }
.ad-open:hover { background: #d9dde4; }
.ad-del { background: #fde8e8; color: #b71c1c; }
.ad-del:hover { background: #f9d2d2; }
.ad-empty { color: var(--mute); }
@media (max-width: 640px) { .ad-grid { grid-template-columns: 1fr; } .ad-card { padding: 20px; } .ad-row { flex-wrap: wrap; } }
.ad-hint { margin: -6px 0 14px; font-size: 14px; color: var(--mute); }
#brandlist { margin-bottom: 36px; } .ad-row img.ad-logo { object-fit: contain; }
#s-login, #s-setup { margin: 14vh auto 0; max-width: 440px; }

.ad-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.ad-modal[hidden] { display: none; }
.ad-scrim { position: absolute; inset: 0; background: rgba(10,12,16,.55); }
.ad-panel { position: relative; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; }
.ad-actions { display: flex; gap: 10px; margin-top: 16px; }
.ad-btn.ghost { background: #e6e9ee; color: var(--ink); }
.ad-row .ad-meta { min-width: 0; }
.ad-row { flex-wrap: wrap; }
