* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: #f2e8d9;
  color: #1a1a1a;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2 {
  font-family: "Fraunces", Georgia, serif;
}

.hero {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 1rem 2.5rem;
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: 2.5rem;
}

header p {
  margin: 0;
  color: #555;
}

.search-form {
  position: relative;
  margin-top: 2rem;
  width: 100%;
  max-width: 820px;
}

.search-form textarea {
  display: block;
  width: 100%;
  min-height: 58px;
  max-height: 400px;
  resize: none;
  padding: 1rem 3.5rem 1rem 1.4rem;
  border: 1px solid #d8cfc0;
  border-radius: 29px;
  background: #faf6ef;
  box-shadow: 0 4px 16px rgba(26, 20, 10, 0.06);
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.4;
  color: #1a1a1a;
  overflow-y: hidden;
}

.search-form textarea::placeholder {
  color: #999;
}

.search-form textarea:focus {
  outline: none;
  border-color: #1a1a1a;
}

.search-form button {
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #1a1a1a;
  color: #fff;
  cursor: pointer;
}

.search-form button:hover {
  background: #333;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1.1rem;
  max-width: 960px;
}

.tag {
  padding: 0.45rem 1rem;
  border: 2px solid #b8a888;
  border-radius: 999px;
  background: transparent;
  color: #555;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.tag:hover {
  border-color: #1a1a1a;
  color: #1a1a1a;
}

.tag.active {
  background: #1a1a1a;
  border-color: #1a1a1a;
  color: #fff;
}

main {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.book-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  align-items: start;
  gap: 1.5rem;
}

.book-card {
  background: #faf6ef;
  border: 1px solid #e5e2dc;
  border-radius: 8px;
  padding: 1.25rem;
  min-height: 183px;
  display: flex;
  flex-direction: column;
  overflow-wrap: anywhere;
}

.book-card h2 {
  font-size: 1.1rem;
  margin: 0 0 0.25rem;
}

.book-card .author {
  color: #777;
  font-size: 0.9rem;
  font-style: italic;
  margin: 0 0 0.75rem;
}

.description-details {
  margin-top: auto;
}

.description-details summary {
  font-size: 0.85rem;
  color: #8a7a5c;
  cursor: pointer;
  list-style: none;
  width: fit-content;
}

.description-details summary::-webkit-details-marker {
  display: none;
}

.description-details summary::after {
  content: " ▾";
}

.description-details[open] summary {
  display: none;
}

.description-details summary:hover {
  color: #1a1a1a;
}

.description-details p {
  font-size: 0.9rem;
  line-height: 1.45;
  color: #444;
  margin: 0.6rem 0 0;
}

.description-details .show-less {
  display: none;
  margin-top: 0.6rem;
  padding: 0;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.85rem;
  color: #8a7a5c;
  cursor: pointer;
}

.description-details .show-less::after {
  content: " ▴";
}

.description-details .show-less:hover {
  color: #1a1a1a;
}

.description-details[open] .show-less {
  display: inline-block;
  width: fit-content;
}

.book-card a.buy-link {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.6rem 1rem;
  background: #1a1a1a;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  text-align: center;
  font-size: 0.9rem;
}

.book-card a.buy-link:hover {
  background: #333;
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: #888;
  font-size: 0.8rem;
}

footer p {
  margin: 0.25rem 0;
}

footer a {
  color: #8a7a5c;
}

footer a:hover {
  color: #1a1a1a;
}

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

.page h1 {
  font-size: 2rem;
  margin: 1rem 0 0.25rem;
}

.page .updated {
  color: #888;
  font-size: 0.85rem;
  margin: 0 0 2rem;
}

.page h2 {
  font-size: 1.15rem;
  margin: 2rem 0 0.5rem;
}

.page p {
  line-height: 1.6;
  color: #333;
}

.page a {
  color: #8a7a5c;
}

.back-link {
  display: inline-block;
  color: #8a7a5c;
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover {
  color: #1a1a1a;
}

@media (max-width: 600px) {
  .hero {
    justify-content: center;
    flex: none;
    min-height: 100vh;
    min-height: 100svh;
  }

  .hero.has-results {
    justify-content: flex-start;
    padding-top: 2rem;
  }

  header {
    padding-bottom: 1.5rem;
  }

  header h1 {
    font-size: 2.1rem;
  }

  .search-form {
    margin-top: 1.25rem;
  }

  .search-form textarea {
    display: block;
    min-height: 54px;
    padding: 0.85rem 3.5rem 0.85rem 1.1rem;
    border-radius: 27px;
  }

  .search-form button {
    right: 0.45rem;
    bottom: 0.45rem;
    width: 40px;
    height: 40px;
  }

  .tag-row {
    width: 100%;
    gap: 0.5rem;
    margin-top: 0.9rem;
  }

  .tag {
    flex: 0 0 calc((100% - 1rem) / 3);
    padding: 0.6rem 0.25rem;
    text-align: center;
  }

  main {
    padding: 0 1rem;
  }

  .book-grid {
    gap: 1rem;
  }

  .book-card {
    min-height: 0;
    padding: 0.85rem 1rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title buy"
      "author buy"
      "more more";
    column-gap: 0.75rem;
    align-items: center;
  }

  .book-card h2 {
    grid-area: title;
    align-self: end;
    margin: 0;
    font-size: 1.1rem;
  }

  .book-card .author {
    grid-area: author;
    align-self: start;
    margin: 0.1rem 0 0;
  }

  .description-details {
    grid-area: more;
    margin-top: 0.15rem;
  }

  .description-details summary,
  .description-details .show-less {
    padding: 0.55rem 0;
    font-size: 0.9rem;
  }

  .book-card a.buy-link {
    grid-area: buy;
    margin: 0;
    padding: 0.75rem 1.1rem;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .buy-prefix {
    display: none;
  }

  footer {
    padding: 1.25rem 1rem 1.5rem;
  }

  .page {
    padding: 2rem 1.25rem 3rem;
  }
}

.inapp-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #1a1a1a;
  color: #f2e8d9;
  font-size: 0.85rem;
  line-height: 1.4;
}

.inapp-banner[hidden] {
  display: none;
}

.inapp-banner p {
  margin: 0;
  flex: 1;
}

.inapp-banner button {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.book-grid > .results-message {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  color: #555;
}

h3 {
  font-family: "Fraunces", Georgia, serif;
}

.how-it-works {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 3rem 1.5rem 2.5rem;
  text-align: center;
}

.how-it-works h2 {
  font-size: 1.4rem;
  margin: 0 0 1.5rem;
}

.how-it-works ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  counter-reset: step;
}

.how-it-works li {
  counter-increment: step;
}

.how-it-works li::before {
  content: counter(step);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-bottom: 0.75rem;
  border: 2px solid #b8a888;
  border-radius: 50%;
  font-size: 0.9rem;
  color: #555;
}

.how-it-works h3 {
  font-size: 1.05rem;
  margin: 0 0 0.4rem;
}

.how-it-works li p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: #555;
}

@media (max-width: 600px) {
  .how-it-works {
    padding: 2rem 1rem 1.5rem;
  }

  .how-it-works ol {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
}

.results-message.loading {
  animation: loading-pulse 1.6s ease-in-out infinite;
}

.dots span {
  display: inline-block;
  animation: dot-bounce 1.2s ease-in-out infinite;
}

.dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  .results-message.loading,
  .dots span {
    animation: none;
  }
}
