/* Color palette inspired by the book cover */
:root {
  --teal: #169ba3;
  --teal-dark: #12838a;
  --yellow: #d3e94f;
  --yellow-dark: #b6c93e;
  --blue: #3b4e9c;
  --red: #d05c6b;
  --orange: #f7b94b;
  --white: #fff;
  --gray: #f5f5f5;
  --text: #1a2a2a;
}

body {
  background: var(--teal);
  color: var(--white);
  font-family: 'Segoe UI', 'Arial', sans-serif;
  margin: 0;
  padding: 0;
  line-height: 1.6;
}

header {
  background: var(--teal-dark);
  padding: 2rem 0 1rem 0;
  text-align: center;
}

header h1 {
  margin: 0 0 0.5rem 0;
  font-size: 2.5rem;
  letter-spacing: 1px;
  font-weight: 700;
}

nav {
  margin: 1rem 0 0 0;
}

nav a {
  color: var(--yellow);
  background: transparent;
  text-decoration: none;
  font-weight: 600;
  margin: 0 1rem;
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

nav a:hover,
nav a:focus {
  background: var(--yellow);
  color: var(--teal-dark);
}

main {
  max-width: 900px;
  margin: 2rem auto 2rem auto;
  background: var(--gray);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 2rem 2rem 2.5rem 2rem;
}

.cover-about-container {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 2.5rem;
  margin-bottom: 2rem;
}

.cover-section {
  flex: 0 0 auto;
  text-align: center;
  margin-bottom: 0;
}

.book-cover {
  max-width: 320px;
  width: 100%;
  border-radius: 8px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.12);
  background: var(--yellow);
  padding: 0.5rem;
}

.description {
  flex: 1 1 0;
  min-width: 0;
}

.description h2,
.authors h2,
.reviews h2,
.toc h2,
.software h2,
.datasets h2,
.latex-resources h2,
.errata h2 {
  color: var(--blue);
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 2rem;
  border-bottom: 2px solid var(--yellow);
  display: inline-block;
  padding-bottom: 0.2rem;
}

.description ul {
  margin: 1rem 0 1rem 1.5rem;
}

.description li {
  margin-bottom: 0.5rem;
}

.description strong {
  color: var(--teal-dark);
}

.authors {
  margin-top: 2.5rem;
}

.author {
  display: flex;
  align-items: flex-start; /* Align image and text at the top */
  gap: 1.5rem;
  margin-bottom: 2rem;
  background: var(--white);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
}

.author img {
  width: 90px;
  border-radius: 50%;
  background: var(--gray);
  object-fit: cover;
  border: 2px solid var(--yellow);
  margin-top: 1em; /* Slight nudge to align with author name text */
}

.author strong {
  color: var(--blue);
  font-size: 1.1rem;
}

.reviews blockquote {
  background: var(--teal);
  color: var(--white);
  border-left: 6px solid var(--yellow);
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  border-radius: 6px;
  font-style: italic;
  box-shadow: 0 1px 8px rgba(0,0,0,0.04);
}

.reviewer {
  display: block;
  margin-top: 0.7rem;
  color: var(--yellow-dark);
  font-style: normal;
  font-weight: 600;
  font-size: 1rem;
}

.toc ol {
  margin-left: 1.5rem;
  margin-bottom: 0.5rem;
}

.toc > ol > li {
  margin-bottom: 0.7rem;
  font-weight: 600;
  color: var(--blue);
}

.toc ol ol {
  margin-top: 0.3rem;
  margin-bottom: 0.3rem;
}

.toc ol ol li {
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.2rem;
}

footer {
  background: var(--teal-dark);
  color: var(--yellow);
  text-align: center;
  padding: 1.2rem 0 1.2rem 0;
  margin-top: 2rem;
  font-size: 1.1rem;
  border-radius: 0 0 12px 12px;
}

footer a {
  color: var(--yellow);
  text-decoration: underline;
  font-weight: 600;
}

.book-links {
  margin-top: 0.7rem;
  margin-left: 2rem;
  margin-right: 2rem;
  flex-wrap: wrap;  
  gap: 1.2rem;
  align-items: center;
}

.book-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: 1.1em;
  font-weight: 600;
  text-decoration: none;
  border-radius: 5px;
  padding: 0.2em 0.6em;
  border: 1.5px solid;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  vertical-align: middle; /* Ensures vertical alignment in inline context */
  line-height: 1.2; /* Tighter vertical spacing */
  text-align: center;
  margin: 0.3em 0; /* Add vertical margin for spacing when wrapping */
}

.book-link i {
  font-size: 1.3em;
  vertical-align: middle;
  display: flex;
  align-items: center; /* Ensures icon is centered with text */
}

/* Shared hover/focus effect */
.book-link:hover,
.book-link:focus {
  box-shadow: 0 2px 8px rgba(27, 79, 114, 0.13);
}

/* Cambridge and Amazon color variants */
.book-link.cambridge {
  color: var(--blue);
  background: var(--yellow);
  border-color: var(--blue);
}
.book-link.cambridge:hover,
.book-link.cambridge:focus {
  background: var(--blue);
  color: var(--yellow);
}

.book-link.amazon {
  background: var(--orange);
  color: var(--blue); 
  border-color: var(--blue);
}
.book-link.amazon:hover,
.book-link.amazon:focus {
  background: var(--blue);
  color: var(--orange); 
  border-color: var(--blue);
}

/* Author PDF color variant */
.book-link.pdf {
  background: var(--white);
  color: var(--blue); 
  border-color: var(--blue);
}
.book-link.pdf:hover,
.book-link.pdf:focus {
  background: var(--blue);
  color: var(--white); 
  border-color: var(--blue);
}

.dataset-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.dataset-card {
  background: var(--white);
  border-radius: 10px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 370px;
  max-width: 100%;
  padding: 1.2rem 1rem 1rem 1rem;
  box-sizing: border-box;
  margin-bottom: 0.5rem;
}

.dataset-img {
  width: 100%;
  max-width: 340px;
  height: auto;
  border-radius: 6px;
  margin-bottom: 1rem;
  background: var(--gray);
  object-fit: contain;
  display: block;
}

.dataset-info {
  text-align: center;
}

.dataset-info strong {
  color: var(--blue);
  font-size: 1.1rem;
  display: block;
  margin-bottom: 0.4rem;
}

.dataset-info p {
  margin: 0 0 0.7rem 0;
  color: var(--text);
  font-size: 1rem;
}

.dataset-info a {
  color: var(--teal-dark);
  font-weight: 600;
  text-decoration: underline;
  transition: color 0.2s;
}
.dataset-info a:hover,
.dataset-info a:focus {
  color: var(--blue);
}

/* Responsive: 2 per row on wide, 1 per row on narrow */
@media (max-width: 900px) {
  .dataset-cards {
    gap: 1.2rem;
  }
  .dataset-card {
    width: 100%;
    max-width: 500px;
  }
}
@media (max-width: 600px) {
  .dataset-cards {
    flex-direction: column;
    gap: 1rem;
    align-items: center;
  }
  .dataset-card {
    width: 100%;
    max-width: 98vw;
    padding: 1rem 0.5rem;
  }
}

@media (max-width: 700px) {
  main {
    padding: 1rem 0.5rem 1.5rem 0.5rem;
  }
  .author {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem 0.5rem;
  }
  .book-cover {
    max-width: 95vw;
    margin: 0 auto;
  }
}

/* Responsive: stack vertically on small screens */
@media (max-width: 900px) {
  .cover-about-container {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
  }
  .description {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .book-links {
    flex-direction: column;
    gap: 0.6rem;
    align-items: stretch;
  }
  .book-link {
    justify-content: center;
    width: 100%;
    font-size: 1em;
    padding: 0.5em 0;
  }
}

/* --- Back to Top Button Styles --- */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--yellow);
  color: var(--blue);
  border: none;
  border-radius: 50%;
  width: 2.7rem;
  height: 2.7rem;
  box-shadow: 0 2px 8px rgba(27, 79, 114, 0.13);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.back-to-top:hover,
.back-to-top:focus {
  background: var(--blue);
  color: var(--yellow);
}

.author-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700; /* Corrected from 1200 to 700 */
  font-size: 1.3rem;
  transition: color 0.2s;
}
.author-link:hover,
.author-link:focus {
  color: var(--teal-dark);
  text-decoration: none;
}