/* ============================================
   Book Reviewer — Vintage Theme (v2)
   Font: Cormorant Garamond (heading) + Be Vietnam Pro (body)
   ============================================ */

@import url("https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,500;0,600;0,700;1,500;1,600&family=Be+Vietnam+Pro:ital,wght@0,400;0,500;0,600;1,400&display=swap");

/* ---------- Variables ---------- */
:root {
  /* Nền giữ tone ấm vintage nhưng sáng hơn để tăng contrast */
  --bg: #f8f4ed;
  --bg-card: #fefcf8;

  /* Text tối hơn đáng kể so với v1 — contrast ratio ~13:1 */
  --text: #231608;
  /* Muted tối hơn — contrast ratio ~6.5:1, pass WCAG AA */
  --text-muted: #5a3e2b;

  --accent: #b8922a;
  --accent-dk: #8f6e18;
  --border: #ddd0b8;
  --border-lt: #ece5d6;
  --shadow: rgba(35, 22, 8, 0.1);

  --font-heading: "Cormorant Garamond", Georgia, serif;
  --font-body: "Be Vietnam Pro", system-ui, sans-serif;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  height: 100%;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem; /* 17px — dễ đọc hơn 16px cho tiếng Việt */
  line-height: 1.85; /* dấu tiếng Việt cần line-height cao */
  min-height: 100vh;
  height: 100%;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle paper texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 32px,
    rgba(184, 146, 42, 0.035) 32px,
    rgba(184, 146, 42, 0.035) 33px
  );
  pointer-events: none;
  z-index: 0;
}

/* ---------- Site Header ---------- */
.site-header,
.site-footer {
  flex-shrink: 0;
}

.site-header {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.site-title {
  font-family: var(--font-heading);
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.site-title .ornament {
  color: var(--accent);
  font-style: italic;
  font-size: 0.65em;
  vertical-align: middle;
}

.site-hits {
  margin-top: 0.6rem;
}
.site-hits img {
  height: 20px;
}

.site-tagline {
  margin-top: 0.25rem;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.divider {
  margin: 0.6rem auto 0;
  width: 56px;
  height: 1.5px;
  background: linear-gradient(
    to right,
    transparent,
    var(--accent),
    transparent
  );
}

/* ---------- Back link (book pages) ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: color 0.2s;
  padding: 2rem 2rem 0;
}

.back-link:hover {
  color: var(--accent-dk);
}

/* ---------- Main Container ---------- */
.container {
  position: relative;
  z-index: 1;
  max-width: 1120px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

/* Index page: flex column so table fills remaining height */
.container.container--table {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 0.75rem;
  padding-bottom: 0.5rem;
  max-width: 880px;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

/* ---------- Section Heading ---------- */
.section-heading {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 2.2rem;
  text-align: center;
}

/* ---------- Book Grid ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.2rem;
}

/* ---------- Book Card ---------- */
.book-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border-lt);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease;
}

.book-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px var(--shadow);
}

/* Book cover area */
.book-cover {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--border);
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    160deg,
    rgba(255, 255, 255, 0.04) 0%,
    transparent 50%,
    rgba(0, 0, 0, 0.15) 100%
  );
}

.book-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 11px;
  background: rgba(0, 0, 0, 0.18);
  box-shadow: inset -2px 0 5px rgba(0, 0, 0, 0.12);
}

/* Book info area */
.book-info {
  padding: 0.8rem 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.book-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  letter-spacing: 0.01em;
}

.book-author {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.book-excerpt {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 0.3rem;
  flex: 1;
}

.read-more {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-dk);
  letter-spacing: 0.03em;
}

/* ---------- Empty State ---------- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 5rem 2rem;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
}

.empty-state p {
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.9;
}

/* ---------- Book Detail Page ---------- */
.book-page .site-header {
  text-align: left;
  padding: 0;
  border-bottom: none;
}

.book-detail {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 6rem;
}

/* Hero section */
.book-hero {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
  margin-bottom: 3rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
}

.hero-cover {
  position: relative;
  flex-shrink: 0;
  width: 130px;
  height: 188px;
  border-radius: 2px 6px 6px 2px;
  box-shadow:
    5px 8px 24px var(--shadow),
    -2px 0 6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.hero-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.hero-cover .book-spine {
  width: 13px;
}

.hero-meta {
  flex: 1;
  padding-top: 0.25rem;
}

.hero-title {
  font-family: var(--font-heading);
  font-size: clamp(1.75rem, 4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.5rem;
  letter-spacing: 0.01em;
}

.hero-author {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 400;
  margin-bottom: 1.1rem;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.hits-badge {
  margin-top: 0.75rem;
}
.hits-badge img {
  height: 20px;
}

.tag {
  background: var(--border-lt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.2rem 0.65rem;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

/* ---------- Review body typography ---------- */
.review-body {
  font-size: 1.0625rem;
  line-height: 1.9;
  color: var(--text);
}

.review-body h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  margin: 2.8rem 0 1.1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.01em;
  line-height: 1.3;
}

/* Không có margin trên cho h2 đầu tiên */
.review-body h2:first-child {
  margin-top: 0.5rem;
}

.review-body h3 {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 2rem 0 0.6rem;
  letter-spacing: 0.01em;
}

.review-body p {
  margin-bottom: 1.25rem;
}

.review-body blockquote {
  margin: 2rem 0;
  padding: 1.2rem 1.6rem;
  border-left: 3px solid var(--accent);
  background: rgba(184, 146, 42, 0.07);
  border-radius: 0 5px 5px 0;
}

.review-body blockquote p {
  font-style: italic;
  color: var(--text); /* Đủ contrast — không dùng muted */
  margin-bottom: 0.5rem;
  font-size: 1rem;
  line-height: 1.85;
}

.review-body blockquote cite {
  display: block;
  font-size: 0.88rem;
  font-style: normal;
  font-weight: 500;
  color: var(--accent-dk);
}

.review-body ul,
.review-body ol {
  margin: 0.6rem 0 1.4rem 1.4rem;
}

.review-body li {
  margin-bottom: 0.7rem;
  line-height: 1.85;
}

.review-body strong {
  font-weight: 600;
  color: var(--text);
}

/* ---------- Footer ---------- */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.88rem;
  letter-spacing: 0.08em;
}

/* ---------- Tag Filter Bar ---------- */
.tag-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.tag-filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.15rem 0.6rem;
  border-radius: 99px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition:
    background 0.18s,
    color 0.18s,
    border-color 0.18s;
}

.tag-filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent-dk);
}

.tag-filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Card Tags ---------- */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.2rem;
}

.card-tag {
  display: inline-block;
  background: var(--border-lt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
  user-select: none;
}

.card-tag:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Card hidden when filtered out */
.book-card[hidden] {
  display: none;
}

/* Tag links on book detail pages */
.tag.tag-link {
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.tag.tag-link:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Book Table ---------- */
.table-wrapper {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.book-table {
  width: 100%;
  border-collapse: collapse;
}

/* Sticky header */
.book-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: 0.6rem 0.9rem;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

/* Sticky name column */
.book-table .col-cover {
  position: sticky;
  left: 0;
  width: 104px;
  min-width: 104px;
}

.book-table .col-name {
  position: sticky;
  left: 104px;
  min-width: 190px;
  max-width: 230px;
}

/* Sticky header cells need higher z-index (corner: both axes) */
.book-table thead .col-cover,
.book-table thead .col-name {
  z-index: 3;
}

/* Section heading compact */
.section-heading {
  margin-bottom: 0.75rem;
}

/* Background on sticky body cells */
.book-table tbody td.col-cover,
.book-table tbody td.col-name {
  background: var(--bg-card);
  transition: background 0.15s;
}

.book-table thead th.col-cover,
.book-table thead th.col-name {
  background: var(--bg);
}

/* Rows */
.book-table tbody tr {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-lt);
  cursor: pointer;
  transition: background 0.15s;
}

.book-table tbody tr:hover {
  background: var(--bg);
}

.book-table tbody tr:hover td.col-cover,
.book-table tbody tr:hover td.col-name {
  background: var(--bg);
}

.book-table tbody tr:last-child {
  border-bottom: none;
}

.book-table tbody td {
  padding: 0.55rem 0.9rem;
  vertical-align: middle;
  font-size: 0.83rem;
  color: var(--text);
}

/* Cover thumbnail */
.row-cover {
  width: 68px;
  height: 94px;
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.row-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

/* Row title link */
.row-title {
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.3;
  display: block;
}

.row-title:hover {
  color: var(--accent-dk);
}

/* Author column */
.book-table .col-author {
  width: 155px;
  min-width: 120px;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Excerpt column */
.book-table .col-excerpt {
  color: var(--text-muted);
  font-size: 0.77rem;
  line-height: 1.5;
  max-width: 420px;
}

/* Search input inside th */
#search-name {
  display: block;
  margin-top: 0.35rem;
  width: 160px;
  padding: 0.28rem 0.55rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 3px;
  outline: none;
  letter-spacing: normal;
  text-transform: none;
}

#search-name:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(184, 146, 42, 0.15);
}

#search-name::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

/* Hidden rows */
.book-row[hidden] {
  display: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .book-hero {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1.5rem;
  }

  .hero-tags {
    justify-content: center;
  }

  .book-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
}

@media (max-width: 480px) {
  .book-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
