:root {
  --bg: #faf6ee;
  --paper: #ffffff;
  --ink: #23201c;
  --muted: #6b655c;
  --green: #1f4d3a;
  --green-dark: #153828;
  --accent: #b5532f;
  --line: #e4dccb;
  --ok: #2d6a3e;
  --bad: #a3331f;
  --radius: 10px;
  --maxw: 1100px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3, .logo {
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.2;
}

a { color: var(--green); }
img { max-width: 100%; display: block; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

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

/* Header */
.site-header {
  background: var(--green);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
}
.logo { color: #fff; text-decoration: none; font-size: 1.5rem; font-weight: 700; }
.logo small { display: block; font-family: system-ui, sans-serif; font-size: 0.7rem; font-weight: 400; opacity: 0.85; letter-spacing: 0.04em; }
.nav { display: flex; gap: 4px; align-items: center; }
.nav a {
  color: #fff;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.nav a:hover, .nav a[aria-current="page"] { background: rgba(255, 255, 255, 0.16); }
.cart-count {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.8rem;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 0 6px;
}
.cart-count[hidden] { display: none; }

/* Hero */
.hero { background: var(--green-dark); color: #fff; padding: 36px 0 40px; }
.hero h1 { margin: 0 0 8px; font-size: 1.9rem; }
.hero p { margin: 0 0 18px; opacity: 0.9; max-width: 56ch; }
.search { display: flex; gap: 8px; max-width: 560px; }
.search input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 8px;
  border: 0;
  font-size: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(0.93); }
.btn[disabled] { background: #b9b2a5; cursor: not-allowed; filter: none; }
.btn.secondary { background: transparent; color: var(--green); border: 2px solid var(--green); }

/* Sections */
section { padding: 28px 0 8px; }
section h2 { margin: 0 0 14px; font-size: 1.4rem; }

.genres { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.genre-tile {
  display: block;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  color: var(--ink);
}
.genre-tile:hover { border-color: var(--green); }
.genre-tile strong { display: block; font-family: Georgia, serif; font-size: 1.05rem; }
.genre-tile span { color: var(--muted); font-size: 0.9rem; }

/* Book grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
}
.card:hover { border-color: var(--green); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); }
.cover {
  aspect-ratio: 3 / 4;
  background: #efe8d8;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  font-family: Georgia, serif;
  color: var(--muted);
  overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.card .info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.card h3 { margin: 0; font-size: 1rem; }
.card .author { color: var(--muted); font-size: 0.9rem; }
.card .price { font-weight: 700; margin-top: auto; padding-top: 6px; }

.badge { display: inline-block; font-size: 0.8rem; font-weight: 600; border-radius: 999px; padding: 2px 10px; }
.badge.in { background: #e3f1e6; color: var(--ok); }
.badge.out { background: #f6e2de; color: var(--bad); }
.badge.low { background: #fdf0d5; color: #8a5a00; }

/* Catalogue filters */
.page-title { padding: 24px 0 0; }
.page-title h1 { margin: 0; font-size: 1.7rem; }
.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 16px 0;
}
@media (min-width: 760px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr; } }
.filters label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.filters input[type="search"], .filters select, .field input, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c9c0ac;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  font-family: inherit;
  min-height: 44px;
}
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input { width: 20px; height: 20px; }
.result-info { color: var(--muted); margin: 0 0 12px; }
.empty { background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; }
.error-box { background: #f6e2de; color: var(--bad); border-radius: var(--radius); padding: 16px; margin: 20px 0; }

/* Book page */
.book { display: grid; grid-template-columns: 1fr; gap: 22px; padding: 24px 0; }
@media (min-width: 760px) { .book { grid-template-columns: 340px 1fr; gap: 36px; } }
.book .cover { border-radius: var(--radius); border: 1px solid var(--line); }
.book h1 { margin: 0 0 6px; font-size: 1.8rem; }
.book .meta { color: var(--muted); margin: 0 0 14px; }
.book .meta a { color: var(--green); }
.book .big-price { font-size: 1.7rem; font-weight: 700; margin: 8px 0; }
.buy { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 16px 0 8px; }
.qty { display: inline-flex; align-items: center; border: 1px solid #c9c0ac; border-radius: 8px; background: #fff; }
.qty button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 1.3rem; cursor: pointer; }
.qty span { min-width: 36px; text-align: center; font-weight: 600; }
.notice { background: #e3f1e6; color: var(--ok); border-radius: 8px; padding: 10px 14px; margin-top: 10px; }
.back { display: inline-block; margin-top: 18px; }

/* Order page */
.order-grid { display: grid; grid-template-columns: 1fr; gap: 24px; padding: 20px 0 30px; }
@media (min-width: 860px) { .order-grid { grid-template-columns: 1.1fr 1fr; align-items: start; } }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel h2 { margin-top: 0; }
.line { display: grid; grid-template-columns: 60px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.line:last-of-type { border-bottom: 0; }
.line .cover { width: 60px; padding: 0; }
.line h3 { margin: 0; font-size: 1rem; }
.line .author { color: var(--muted); font-size: 0.9rem; }
.line .sum { font-weight: 700; text-align: right; }
.line .controls { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.linkbtn { background: none; border: 0; color: var(--bad); cursor: pointer; font-size: 0.9rem; text-decoration: underline; padding: 8px 4px; min-height: 44px; }
.total { display: flex; justify-content: space-between; font-size: 1.2rem; font-weight: 700; padding-top: 14px; border-top: 2px solid var(--ink); margin-top: 6px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: 0.85rem; }
.field .err { color: var(--bad); font-size: 0.9rem; min-height: 1.1em; }
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"] { border-color: var(--bad); }
.pay-note { background: #fdf0d5; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.testmode { background: #fff3cd; border: 1px solid #e6cf7a; border-radius: 8px; padding: 12px 14px; margin: 14px 0; }
.success { text-align: center; padding: 40px 16px; }
.success h2 { color: var(--ok); }

/* Footer */
.site-footer { margin-top: 40px; background: var(--green-dark); color: #e9e4d6; padding: 22px 0; font-size: 0.95rem; }
.site-footer p { margin: 4px 0; }
