:root {
  --paper: #f7f3ec;
  --ink: #1c1b19;
  --ink-soft: #4a4640;
  --haze: #8a847a;
  --accent: #c45c26;
  --accent-press: #a34a1c;
  --line: #e4ddd0;
  --card: #fffdf8;
  --ok: #2f6b4f;
  --err: #9b2c2c;
  --shadow: 0 10px 28px rgba(28, 27, 25, 0.08);
  --radius: 12px;
  --font-display: "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --font-body: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --tap: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background:
    radial-gradient(ellipse 120% 60% at 50% -10%, #fff9ef 0%, transparent 55%),
    var(--paper);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 8px;
}

.site-header .brand {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
}

.site-header .brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.site-header .meta {
  font-size: 0.8125rem;
  color: var(--haze);
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 20px 48px;
}

.page-narrow {
  max-width: 520px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.25;
  margin: 12px 0 8px;
}

.page-desc {
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

/* —— Bookshelf —— */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
  margin-top: 8px;
}

.book-card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.book-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(28, 27, 25, 0.12);
}

.book-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.book-card .cover {
  aspect-ratio: 3 / 4;
  width: 100%;
  object-fit: cover;
  background: #e8e0d2;
  display: block;
}

.book-card .cover-fallback {
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #d9cfc0, #efe6d8 50%, #c4b5a0);
  font-family: var(--font-display);
  color: var(--ink-soft);
  font-size: 0.875rem;
  padding: 12px;
  text-align: center;
}

.book-card .body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.book-card .title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.35;
  margin: 0;
}

.book-card .sub {
  font-size: 0.8125rem;
  color: var(--haze);
  margin: 0;
}

.book-card .price {
  margin-top: auto;
  padding-top: 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9375rem;
}

.empty-state,
.error-state {
  margin-top: 28px;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.error-state {
  border-color: #e8c4c4;
  color: var(--err);
}

/* —— Purchase —— */
.purchase-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 24px 20px 20px;
}

.purchase-cover {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: var(--radius);
  background: #e8e0d2;
  display: block;
}

.purchase-cover-fallback {
  width: 100%;
  height: 200px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #d9cfc0, #efe6d8 50%, #c4b5a0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  color: var(--ink-soft);
}

.book-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.25;
  margin: 18px 0 4px;
}

.book-sub {
  margin: 0 0 12px;
  color: var(--haze);
  font-size: 0.875rem;
}

.book-blurb {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.book-price {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 18px;
  letter-spacing: 0.02em;
}

.panel {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.status-line {
  margin: 0 0 12px;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.status-line strong {
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 12px 20px;
  border-radius: 999px;
  border: none;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-press);
  color: #fff;
}

.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
  background: #c9c2b6;
  color: #6b655c;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  border-color: var(--haze);
  color: var(--ink);
}

.btn-download {
  width: 100%;
  background: var(--ok);
  color: #fff;
}

.btn-download:hover {
  background: #255540;
  color: #fff;
}

.btn-download:disabled {
  background: #c9c2b6;
  color: #6b655c;
  cursor: not-allowed;
}

.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.hint {
  margin: 10px 0 0;
  font-size: 0.8125rem;
  color: var(--haze);
  line-height: 1.5;
}

.verify-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.verify-steps {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  color: var(--haze);
  line-height: 1.5;
}

.verify-status {
  margin: 10px 0 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.verify-status.is-error {
  color: var(--err);
}

/* Mobile-first purchase */
.page-mobile body,
body.page-mobile {
  font-size: 17px;
}

.btn-block {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
}

.page-mobile .purchase-card {
  padding: 20px 16px 16px;
}

.page-mobile .book-title {
  font-size: 1.65rem;
}

.page-mobile .book-price {
  font-size: 2.1rem;
  margin-bottom: 14px;
}

.page-mobile .verify-steps {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

.page-mobile .verify-steps strong {
  color: var(--accent);
}

.page-mobile .qr-wrap img,
.page-mobile .qr-fallback {
  width: min(72vw, 280px);
  height: min(72vw, 280px);
}

.page-mobile .modal-amount {
  font-size: 1.75rem;
}

.page-mobile .modal-desc {
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.page-mobile .status-line {
  font-size: 1rem;
}

@media (max-width: 374px) {
  .page-mobile .book-title {
    font-size: 1.45rem;
  }
}

.footer-note {
  margin: 20px auto 0;
  max-width: 520px;
  padding: 0 4px;
  font-size: 0.75rem;
  color: var(--haze);
  text-align: center;
  line-height: 1.5;
}

/* QR modal */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(28, 27, 25, 0.45);
}

.modal-dialog {
  width: min(100%, 420px);
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px 28px;
  box-shadow: var(--shadow);
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 24px;
  }

  .modal-dialog {
    border-radius: var(--radius);
  }
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin: 0 0 6px;
  text-align: center;
}

.modal-amount {
  text-align: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 0 0 12px;
}

.modal-desc {
  margin: 0 0 14px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.qr-wrap img,
.qr-fallback {
  width: 200px;
  height: 200px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.qr-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--haze);
  font-size: 0.8125rem;
  text-align: center;
  padding: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .book-card,
  .btn {
    transition: none;
  }
}
