:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface2: #efe9df;
  --border: #ddd6ca;
  --text: #1a1611;
  --text-dim: #6b6155;
  --text-light: #9b9183;
  --accent: #7c4d2a;
  --accent-hover: #945d35;
  --accent-light: rgba(124, 77, 42, 0.07);
  --green: #2d7a4f;
  --red: #b93e3e;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --font-serif: 'Georgia', 'Times New Roman', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }

/* ===== Header ===== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.logo {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: var(--text);
}
.logo-icon {
  width: 36px; height: 36px; background: var(--accent); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.1rem; font-weight: 700;
}
.logo-name {
  font-family: var(--font-serif);
  font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em;
}
.logo-tagline {
  font-size: 0.65rem; color: var(--text-light);
  text-transform: uppercase; letter-spacing: 0.15em;
}

nav { display: flex; align-items: center; gap: 24px; font-size: 0.88rem; font-weight: 500; }
nav a { color: var(--text-dim); text-decoration: none; transition: color 0.15s; }
nav a:hover { color: var(--accent); }
.cart-link { display: flex; align-items: center; gap: 6px; }
.cart-count {
  background: var(--accent); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

/* ===== Footer ===== */
footer {
  margin-top: auto;
  background: var(--text);
  padding: 32px 0;
  text-align: center;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
}
.footer-links a { color: rgba(255,255,255,0.7); text-decoration: none; }
.footer-links a:hover { color: #fff; }

/* ===== Main ===== */
main { flex: 1; padding: 0 0 48px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 22px; border: none; border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.88rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 36px; font-size: 0.95rem; letter-spacing: 0.02em; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Hero ===== */
.hero {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 48px 24px;
  margin-bottom: 32px;
  text-align: center;
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: 2.2rem; font-weight: 700; margin-bottom: 8px;
  color: var(--text);
}
.hero p {
  font-size: 1.05rem; color: var(--text-dim);
  max-width: 520px; margin: 0 auto; line-height: 1.7;
}

/* ===== Search/Filter Bar ===== */
.store-controls {
  display: flex; gap: 10px; margin-bottom: 28px; flex-wrap: wrap; align-items: center;
}
.store-search {
  display: flex; gap: 10px; flex: 1; min-width: 280px;
}
.store-search input {
  flex: 1;
  padding: 10px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.88rem; background: var(--surface); color: var(--text);
}
.store-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,77,42,0.08); }
.store-filters {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.store-filters select {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.84rem; background: var(--surface); color: var(--text); cursor: pointer;
}
.store-filters select:focus { outline: none; border-color: var(--accent); }

/* Genre tabs */
.genre-tabs {
  display: flex; gap: 6px; margin-bottom: 24px; flex-wrap: wrap;
}
.genre-tab {
  padding: 6px 16px; border-radius: 20px; font-size: 0.82rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.genre-tab:hover { border-color: var(--accent); color: var(--accent); }
.genre-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== Product Grid ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 24px;
}
.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.25s, transform 0.25s;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.product-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
}

/* Book cover — preserve natural aspect ratio */
.product-cover-wrap {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-cover {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 12px 12px 0 12px;
  display: block;
}
.product-cover-placeholder {
  font-size: 3rem;
  color: var(--border);
}

.product-info {
  padding: 12px 14px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.product-title {
  font-family: var(--font-serif);
  font-size: 0.92rem; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; margin-bottom: 3px;
}
.product-author {
  font-size: 0.78rem; color: var(--text-dim); margin-bottom: auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.product-bottom {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--surface2);
}
.product-price {
  font-size: 1.05rem; font-weight: 700; color: var(--accent);
}
.product-condition {
  font-size: 0.65rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-light); background: var(--surface2);
  padding: 2px 8px; border-radius: 3px;
}

/* Result count */
.result-count {
  font-size: 0.82rem; color: var(--text-light); margin-bottom: 16px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 32px 0;
}
.page-info { font-size: 0.85rem; color: var(--text-dim); }

/* ===== Product Detail ===== */
.product-detail { display: flex; gap: 40px; }
.detail-image-col { flex: 0 0 360px; }
.detail-image-col img {
  width: 100%; border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.detail-image-placeholder {
  width: 100%; aspect-ratio: 2/3; background: var(--surface2); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 4rem; color: var(--border);
}
.detail-info { flex: 1; }
.detail-title {
  font-family: var(--font-serif);
  font-size: 1.75rem; font-weight: 700; margin-bottom: 6px; line-height: 1.25;
}
.detail-author { font-size: 1.05rem; color: var(--text-dim); margin-bottom: 16px; }
.detail-publisher { font-size: 0.84rem; color: var(--text-light); margin-bottom: 20px; }
.genre-badge {
  display: inline-block;
  padding: 4px 12px; border-radius: 14px; font-size: 0.78rem; font-weight: 500;
  background: var(--accent-light); color: var(--accent); border: 1px solid var(--accent);
  margin-bottom: 16px;
}
.genre-badge:hover { background: var(--accent); color: #fff; }

.detail-description {
  font-size: 0.9rem; color: var(--text-dim); line-height: 1.75;
  margin-bottom: 24px; max-height: 200px; overflow-y: auto;
}
.detail-price {
  font-family: var(--font-serif);
  font-size: 2rem; font-weight: 700; color: var(--accent); margin-bottom: 4px;
}
.detail-shipping { font-size: 0.8rem; color: var(--text-light); margin-bottom: 20px; }

.detail-options { margin-bottom: 24px; }
.option-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 8px; cursor: pointer; transition: all 0.15s;
}
.option-card:hover, .option-card.selected {
  border-color: var(--accent); background: var(--accent-light);
}
.option-cond { font-size: 0.88rem; font-weight: 600; }
.option-stock { font-size: 0.75rem; color: var(--text-light); }
.option-price { font-weight: 700; color: var(--accent); font-size: 1.05rem; }

.breadcrumb { font-size: 0.82rem; color: var(--text-light); margin-bottom: 24px; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ===== Cart ===== */
.cart-empty { text-align: center; padding: 80px 20px; color: var(--text-dim); }
.cart-empty h2 { font-family: var(--font-serif); margin-bottom: 8px; }
.cart-item {
  display: flex; gap: 16px; padding: 20px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.cart-item-img {
  width: 65px; height: 90px; object-fit: contain; border-radius: 4px;
  flex-shrink: 0; background: var(--surface2); padding: 4px;
}
.cart-item-img-placeholder {
  width: 65px; height: 90px; background: var(--surface2); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--border); flex-shrink: 0;
}
.cart-item-info { flex: 1; }
.cart-item-title { font-family: var(--font-serif); font-weight: 600; font-size: 0.95rem; }
.cart-item-meta { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }
.cart-item-price { font-weight: 700; color: var(--accent); font-size: 1.05rem; white-space: nowrap; }
.cart-item-remove {
  background: none; border: none; color: var(--text-light); cursor: pointer;
  font-size: 0.78rem; margin-top: 6px;
}
.cart-item-remove:hover { color: var(--red); }

.cart-summary {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-top: 24px; box-shadow: var(--shadow-sm);
}
.cart-summary-row {
  display: flex; justify-content: space-between; margin-bottom: 10px;
  font-size: 0.9rem;
}
.cart-summary-total {
  font-weight: 700; font-size: 1.15rem;
  border-top: 2px solid var(--border); padding-top: 12px; margin-top: 12px;
}

/* ===== Order Confirmation ===== */
.order-confirm { max-width: 600px; margin: 0 auto; text-align: center; padding-top: 40px; }
.order-confirm h1 { font-family: var(--font-serif); color: var(--green); margin-bottom: 8px; font-size: 1.8rem; }
.order-number { font-family: monospace; font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.order-details { text-align: left; margin-top: 24px; }
.order-details table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.order-details th { text-align: left; padding: 10px 8px; color: var(--text-light); font-weight: 500; border-bottom: 1px solid var(--border); }
.order-details td { padding: 10px 8px; border-bottom: 1px solid var(--border); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 12px 24px; border-radius: var(--radius);
  font-size: 0.85rem; z-index: 300; opacity: 0;
  transition: opacity 0.3s; pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ===== Loading ===== */
.spinner {
  display: inline-block; width: 24px; height: 24px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 80px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container { padding: 0 16px; }
  .header-inner { height: 56px; }
  .logo-name { font-size: 1.05rem; }
  .hero { padding: 32px 16px; }
  .hero h1 { font-size: 1.6rem; }
  .hero p { font-size: 0.92rem; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
  .product-cover { padding: 8px 8px 0 8px; }
  .product-detail { flex-direction: column; gap: 24px; }
  .detail-image-col { flex: none; max-width: 280px; margin: 0 auto; }
  .detail-title { font-size: 1.35rem; }
  .genre-tabs { gap: 4px; }
  .genre-tab { padding: 5px 12px; font-size: 0.75rem; }
}

@media (max-width: 480px) {
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .product-info { padding: 8px 10px 10px; }
  .product-title { font-size: 0.82rem; }
  .product-price { font-size: 0.92rem; }
  .store-controls { flex-direction: column; }
}
