/* =========================================================================
   02._.library — หน้าจออื่น ๆ (นอกจากหน้าแรก)
   ใช้ tokens + base.css ร่วมกัน · โทนเดียวกับหลังบ้าน
   ========================================================================= */

/* ---------------------------------------------------------------- header extras */
.header-tools { display: flex; align-items: center; gap: 8px; }
.cart-btn { position: relative; }
.cart-count {
  position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px;
  display: grid; place-items: center; border-radius: var(--r-pill); background: var(--gold);
  color: var(--gold-ink); font-size: 11px; font-weight: 700; border: 2px solid var(--paper);
}
.avatar {
  display: inline-grid; place-items: center; border-radius: var(--r-pill); background: var(--navy);
  color: #f6f1e7; font-family: var(--display); font-weight: 600; letter-spacing: .02em;
  overflow: hidden; flex: 0 0 auto;
}
.user-btn {
  display: flex; align-items: center; gap: 9px; padding: 4px 13px 4px 4px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--surface); font-size: var(--fs-xs); font-weight: 500;
  transition: all var(--dur-fast) var(--ease-out);
}
.user-btn:hover { border-color: var(--ink); box-shadow: var(--shadow-2); }

/* ---------------------------------------------------------------- page head */
.page-head { padding: clamp(26px, 3.4vw, 44px) 0 22px; }
.page-head h1 { font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); line-height: 1.12; letter-spacing: var(--tracking-tight); margin-top: 12px; }
.page-head .section-text { margin-top: 8px; }

/* ---------------------------------------------------------------- book cards */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(214px, 1fr)); gap: 22px; }
.book-card {
  position: relative; display: grid; gap: 14px; text-align: left; padding: 0; background: none;
  transition: transform .34s var(--ease-out);
}
.book-card:hover { transform: translateY(-6px); }
.book-card__media {
  position: relative; aspect-ratio: 3 / 4.2; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); box-shadow: var(--shadow-2); transition: box-shadow .34s var(--ease-out);
}
.book-card:hover .book-card__media { box-shadow: 0 24px 46px rgba(15,23,42,.18); }
.book-card__media .cover { position: absolute; inset: 0; border-radius: 10px; }
.book-card__media .cover--type { padding: 22px 18px; }
.book-card__media .cover__title { font-size: 17px; }
.book-card__media .cover__author { font-size: 10.5px; }
.book-card__badge { position: absolute; top: 10px; left: 10px; z-index: 2; }
.book-card__price { position: absolute; right: 10px; bottom: 10px; z-index: 2; background: rgba(15,23,42,.88); color: #f6f1e7; border-radius: 999px; padding: 5px 11px; font-size: 12.5px; font-weight: 600; backdrop-filter: blur(6px); }
.book-card__body { display: grid; gap: 4px; }
.book-card__title { font-family: var(--display); font-weight: 500; font-size: 15.5px; line-height: 1.32; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card__meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.book-card__meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }
.book-card__free { color: var(--ok); font-weight: 600; }
.book-card__ribbon { position: absolute; top: 10px; right: -30px; transform: rotate(38deg); background: var(--gold); color: #1a1405; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; padding: 3px 34px; z-index: 2; }

/* ---------------------------------------------------------------- filters */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.filter-bar .chip { min-height: 38px; }
.search-wrap { position: relative; margin-left: auto; min-width: 240px; }
.search-wrap .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.search-wrap .input { padding-left: 40px; border-radius: 999px; }

/* ---------------------------------------------------------------- landing blocks */
.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.feature { padding: 26px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.feature__icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--navy); color: #f6f1e7; margin-bottom: 16px; }
.feature h3 { font-family: var(--display); font-weight: 600; font-size: 17px; margin-bottom: 6px; }
.feature p { color: var(--muted); font-size: 13.5px; }

.zones { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.zone-card {
  position: relative; overflow: hidden; padding: 32px; border-radius: var(--r-xl); min-height: 236px;
  display: grid; align-content: space-between; gap: 20px; text-align: left;
}
.zone-card--light { background: var(--surface); border: 1px solid var(--line); }
.zone-card--dark { background: linear-gradient(155deg, var(--navy), #050a15); color: #f6f1e7; }
.zone-card h3 { font-family: var(--display); font-weight: 600; font-size: 24px; }
.zone-card p { font-size: 13.5px; max-width: 38ch; opacity: .85; }
.zone-card--dark .eyebrow { color: var(--gold); }
.zone-card__badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: rgba(246,241,231,.12); font-size: 11.5px; font-weight: 600; }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; counter-reset: step; }
.step-item { position: relative; padding: 24px 20px 22px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.step-item::before {
  counter-increment: step; content: counter(step, decimal-leading-zero);
  font-family: var(--display); font-weight: 600; font-size: 13px; color: var(--gold-3);
  display: block; margin-bottom: 12px; letter-spacing: .1em;
}
.step-item h4 { font-family: var(--display); font-weight: 500; font-size: 15.5px; margin-bottom: 6px; }
.step-item p { font-size: 13px; color: var(--muted); }

.cta-band {
  position: relative; overflow: hidden; border-radius: var(--r-xl); padding: 48px 44px;
  background: linear-gradient(150deg, #0f172a, #060b16); color: #f6f1e7;
  display: flex; align-items: center; justify-content: space-between; gap: 30px; flex-wrap: wrap;
}
.cta-band::before {
  content: ''; position: absolute; right: -60px; top: -80px; width: 340px; height: 340px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201,162,39,.30), transparent 66%);
}
.cta-band h2 { font-family: var(--display); font-weight: 600; font-size: clamp(23px, 3vw, 32px); }
.cta-band p { color: rgba(246,241,231,.72); margin-top: 6px; font-size: 14px; }

/* ---------------------------------------------------------------- book detail */
.book-detail { display: grid; grid-template-columns: 340px 1fr; gap: 46px; align-items: start; }
.book-detail__cover { position: sticky; top: 96px; }
.book-detail__cover .cover { aspect-ratio: 3 / 4.15; border-radius: 10px; box-shadow: var(--shadow-4); }
.book-detail__cover .cover--type { padding: 30px 26px; }
.book-detail__cover .cover__title { font-size: 24px; }
.book-detail__cover .cover__author { font-size: 11.5px; }
.book-detail h1 { font-family: var(--display); font-weight: 600; font-size: clamp(27px, 3.6vw, 40px); line-height: 1.15; letter-spacing: -.015em; }
.book-detail__sub { color: var(--muted); font-size: 16px; margin-top: 8px; }
.book-meta-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 16px; color: var(--muted); font-size: 13.5px; }
.book-meta-row span { display: inline-flex; align-items: center; gap: 6px; }
.book-price-row { display: flex; align-items: baseline; gap: 12px; margin-top: 26px; }
.book-price { font-family: var(--display); font-weight: 600; font-size: 38px; letter-spacing: -.02em; }
.book-price small { font-family: var(--font); font-size: 14px; font-weight: 500; color: var(--muted); }
.book-compare { color: var(--muted-2); text-decoration: line-through; font-size: 16px; }
.book-buy { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.book-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; margin-top: 30px; }
.book-fact { background: var(--surface); padding: 15px 17px; }
.book-fact span { display: block; font-size: 12px; color: var(--muted); }
.book-fact b { font-weight: 600; font-size: 14.5px; }
.book-body { margin-top: 40px; }
.book-body h2 { font-family: var(--display); font-weight: 600; font-size: 20px; margin-bottom: 12px; }
.book-body p { color: var(--ink-2); font-size: 14.5px; white-space: pre-line; line-height: 1.75; }
.owned-banner { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: var(--r-md); background: var(--ok-soft); color: var(--ok); font-size: 13.5px; font-weight: 500; margin-top: 20px; }

/* ---------------------------------------------------------------- auth */
.auth-shell { display: grid; grid-template-columns: 1fr 1fr; min-height: calc(100vh - 68px); }
.auth-aside {
  position: relative; overflow: hidden; padding: 56px 48px; color: #f6f1e7;
  background: linear-gradient(160deg, #0f172a, #050a15); display: grid; align-content: space-between;
}
.auth-aside::before { content: ''; position: absolute; inset: auto -20% -40% 20%; height: 520px; background: radial-gradient(circle, rgba(201,162,39,.28), transparent 68%); }
.auth-aside h2 { font-family: var(--display); font-weight: 600; font-size: clamp(28px, 3.4vw, 38px); line-height: 1.15; position: relative; }
.auth-aside p { color: rgba(246,241,231,.72); margin-top: 14px; font-size: 14px; max-width: 40ch; position: relative; }
.auth-quote { position: relative; font-family: var(--display); font-size: 15px; line-height: 1.6; border-left: 2px solid var(--gold); padding-left: 16px; color: rgba(246,241,231,.86); }
.auth-main { padding: 56px 24px; display: grid; place-items: center; }
.auth-box { width: min(100%, 420px); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 999px; background: var(--paper-2); margin-bottom: 24px; }
.auth-tabs button { min-height: 40px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 7px; transition: all .2s var(--ease-out); }
.auth-tabs button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.auth-form { display: grid; gap: 15px; }
.auth-switch { margin-top: 20px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-switch button { color: var(--navy); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.school-note { display: flex; gap: 11px; padding: 13px 15px; border-radius: var(--r-md); background: var(--navy); font-size: 12.5px; color: var(--navy-2); line-height: 1.6; }
.alt-login { display: grid; gap: 10px; margin-top: 22px; }
.alt-login__divider { display: flex; align-items: center; gap: 12px; color: var(--muted-2); font-size: 12px; }
.alt-login__divider::before, .alt-login__divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.auth-error { padding: 12px 14px; border-radius: var(--r-md); background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* ---------------------------------------------------------------- profile */
.profile-head { display: flex; align-items: center; gap: 20px; padding: 28px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); flex-wrap: wrap; }
.profile-head h1 { font-family: var(--display); font-weight: 600; font-size: 26px; }
.profile-kind { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--gold-3); letter-spacing: .04em; text-transform: uppercase; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 20px; }
.profile-fact { padding: 18px 20px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.profile-fact span { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
.profile-fact b { font-weight: 600; font-size: 15px; }
.locked-row { display: grid; gap: 10px; }
.locked-item { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: var(--r-md); background: var(--surface-2); border: 1px dashed var(--line-2); font-size: 13.5px; color: var(--muted); }
.locked-item .icon { color: var(--gold-3); }

/* ---------------------------------------------------------------- checkout */
.checkout-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 30px; align-items: start; }
.checkout-summary { position: sticky; top: 96px; }
.cart-line { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.cart-line:last-child { border-bottom: 0; }
.cart-line__cover { width: 58px; aspect-ratio: 3 / 4.15; border-radius: 5px; overflow: hidden; flex: 0 0 auto; box-shadow: var(--shadow-1); }
.cart-line__cover .cover--type { padding: 8px; }
.cart-line__cover .cover__title { font-size: 7px; -webkit-line-clamp: 3; }
.cart-line__cover .cover__author, .cart-line__cover .cover__rule { display: none; }
.cart-line__body { flex: 1; min-width: 0; }
.cart-line__title { font-weight: 600; font-size: 14px; line-height: 1.4; }
.cart-line__meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 999px; overflow: hidden; }
.qty button { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); }
.qty button:hover { background: rgba(15,23,42,.06); color: var(--ink); }
.qty span { min-width: 26px; text-align: center; font-size: 13px; font-weight: 600; }
.total-row { display: flex; justify-content: space-between; padding: 9px 0; font-size: 14px; }
.total-row b { font-weight: 600; }
.total-row--grand { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 16px; font-size: 16px; }
.total-row--grand b { font-family: var(--display); font-size: 24px; }

.pay-panel { display: grid; grid-template-columns: 260px 1fr; gap: 26px; align-items: start; }
.qr-frame {
  width: 252px; height: 252px; padding: 14px; border-radius: var(--r-lg); background: #fff;
  border: 1px solid var(--line); display: grid; place-items: center; box-shadow: var(--shadow-2);
}
.qr-frame img, .qr-img { width: 224px; height: 224px; }
.qr-fallback { display: grid; gap: 6px; padding: 18px; text-align: center; font-size: 12px; color: var(--muted); }
.pay-steps { display: grid; gap: 12px; font-size: 13.5px; }
.pay-step { display: flex; gap: 11px; }
.pay-step__num { width: 22px; height: 22px; border-radius: 999px; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 11.5px; font-weight: 700; flex: 0 0 auto; }
.pay-amount { font-family: var(--display); font-weight: 600; font-size: 30px; }
.pay-code { font-family: var(--display); font-weight: 600; font-size: 18px; letter-spacing: .06em; }

/* แถบความคืบหน้าคำสั่งซื้อ */
.pay-progress { display: grid; gap: 0; list-style: none; padding: 0; margin: 0; }
.pay-progress li { position: relative; display: flex; align-items: baseline; gap: 10px; padding: 0 0 16px 26px; font-size: 13.5px; }
.pay-progress li::before {
  content: ''; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--paper-2); border: 2px solid var(--line-2);
}
.pay-progress li::after { content: ''; position: absolute; left: 8px; top: 17px; bottom: 0; width: 1px; background: var(--line); }
.pay-progress li:last-child::after { display: none; }
.pay-progress li b { font-weight: 600; }
.pay-progress li span { color: var(--muted); font-size: 12.5px; }
.pay-progress li.is-done::before { background: var(--ok); border-color: var(--ok); }
.pay-progress li.is-current::before { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 0 4px rgba(201,162,39,.18); }
.pay-progress li.is-current b { color: var(--gold-3); }

/* ---------------------------------------------------------------- shelf */
.shelf-list { display: grid; gap: 12px; }
.shelf-row {
  display: grid; grid-template-columns: 58px 1fr auto; gap: 16px; align-items: center;
  padding: 14px 18px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line);
  transition: border-color .2s var(--ease-out), box-shadow .2s var(--ease-out);
}
.shelf-row:hover { border-color: var(--navy); box-shadow: var(--shadow-2); }
.shelf-row__cover { width: 58px; aspect-ratio: 3 / 4.15; border-radius: 5px; overflow: hidden; box-shadow: var(--shadow-1); }
.shelf-row__cover .cover--type { padding: 8px; }
.shelf-row__cover .cover__title { font-size: 7px; }
.shelf-row__cover .cover__author, .shelf-row__cover .cover__rule { display: none; }
.progress-track { height: 5px; border-radius: 3px; background: var(--paper-2); overflow: hidden; margin-top: 8px; max-width: 220px; }
.progress-track i { display: block; height: 100%; background: var(--gold); border-radius: 3px; }

/* ---------------------------------------------------------------- reader */
body.reader-mode { background: #14161c; overflow: hidden; }
.reader { display: grid; grid-template-rows: 60px 1fr; height: 100vh; }
.reader-top {
  display: flex; align-items: center; gap: 14px; padding: 0 18px; color: #e8e4dc;
  background: #0d0f14; border-bottom: 1px solid rgba(255,255,255,.08);
}
.reader-top__title { font-family: var(--display); font-weight: 500; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.reader-top .icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px; color: rgba(232,228,220,.8); }
.reader-top .icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.reader-top .icon-btn.is-on { background: var(--gold); color: #1a1405; }
.reader-pageinfo { font-size: 12.5px; color: rgba(232,228,220,.6); font-variant-numeric: tabular-nums; }
.reader-stage { position: relative; overflow-y: auto; overflow-x: hidden; background: #1b1e25; scroll-behavior: smooth; }
.reader-pages { display: grid; justify-items: center; gap: 18px; padding: 22px 0 120px; }
.reader-page { position: relative; max-width: min(920px, 96vw); width: 100%; }
.reader-page canvas { width: 100%; height: auto; border-radius: 3px; background: #fff; box-shadow: 0 16px 40px rgba(0,0,0,.45); display: block; }
.reader-page__num { position: absolute; right: 8px; bottom: 8px; font-size: 10.5px; color: rgba(15,23,42,.45); background: rgba(255,255,255,.86); border-radius: 4px; padding: 1px 7px; }
.reader-page .page-wm { position: absolute; inset: 0; overflow: hidden; pointer-events: none; user-select: none; border-radius: 3px; }
.page-wm span {
  position: absolute; font-family: var(--font); font-size: 13px; font-weight: 600; color: rgba(15,23,42,.10);
  white-space: nowrap; transform: rotate(-26deg);
}
.reader-hud {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 999px;
  background: rgba(13,15,20,.94); border: 1px solid rgba(255,255,255,.1); box-shadow: var(--shadow-4);
  color: #e8e4dc; backdrop-filter: blur(10px);
}
.reader-hud button { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 999px; color: rgba(232,228,220,.8); }
.reader-hud button:hover { background: rgba(255,255,255,.1); color: #fff; }
.reader-hud .zoom-level { min-width: 54px; text-align: center; font-size: 12.5px; font-variant-numeric: tabular-nums; color: rgba(232,228,220,.7); }
.reader-toast {
  position: fixed; left: 50%; top: 82px; transform: translate(-50%, -12px); z-index: 60;
  background: rgba(201,162,39,.96); color: #1a1405; font-weight: 600; font-size: 13px;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow-3); opacity: 0;
  transition: all .3s var(--ease-out); pointer-events: none;
}
.reader-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
#guard-blur {
  position: fixed; inset: 0; z-index: 55; background: #14161c; display: grid; place-items: center;
  opacity: 0; pointer-events: none; transition: opacity .18s var(--ease-out);
}
#guard-blur.is-on { opacity: 1; pointer-events: all; }
#guard-blur div { color: rgba(232,228,220,.6); font-size: 13.5px; display: grid; justify-items: center; gap: 10px; }
body.is-guarding .reader-pages { filter: blur(16px); transition: filter .18s; }
.reader-loading { display: grid; place-items: center; gap: 14px; padding: 110px 0; color: rgba(232,228,220,.7); font-size: 13.5px; }

/* ---------------------------------------------------------------- key redeem */
.redeem-hero { display: grid; gap: 18px; padding: 34px; border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); }
.reader-hud { display: none; }
body.reader-mode .reader-hud { display: flex; }
.key-code-inline { font-family: var(--display); font-weight: 600; letter-spacing: .08em; font-size: 14px; }
.key-input {
  font-family: var(--display); font-weight: 600; font-size: 22px; letter-spacing: .16em; text-align: center;
  text-transform: uppercase; min-height: 62px;
}
.key-result { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: var(--r-md); background: var(--ok-soft); color: var(--ok); }
.key-result--error { background: var(--danger-soft); color: var(--danger); }


/* ---------------------------------------------------------------- mobile buy bar */
.buy-bar { display: none; }
@media (max-width: 820px) {
  .buy-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); box-shadow: 0 -10px 30px rgba(14, 23, 40, .1);
  }
  .buy-bar__price { font-family: var(--display); font-weight: 600; font-size: 20px; }
  .buy-bar .btn { margin-left: auto; }
  .book-detail { padding-bottom: 82px; }
  .book-detail .book-buy { display: none; }
}
