/* Global base theme styles */

:root {
    --bg-color: #f0f0f0;
    --text-color: #000;
    --main-font-size: 1.05rem;
}

.dark {
    --bg-color: #242424;
    --text-color: #ccc;
}

.light {
    --bg-color: #f0f0f0;
    --text-color: #000;
}

.gray {
    --bg-color: #808080;
    --text-color: #333;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    transition: background-color 300ms, color 300ms;
    padding-top: 4rem;
}

main {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
}

em {
    font-weight: bolder;
}

/* Shared UI component styles used across static pages */

/* Grid list for books/cards */
.book-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2rem;
  margin-top: 1rem;
}

/* Responsive tweaks for book list */
@media (max-width: 768px) {
  .book-list {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
  }
}

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

/* Card component */
.book-card {
  min-height: 0;
  border: 1px solid rgba(128, 128, 128, 0.3);
  border-radius: 9px;
  padding: 0.6rem 0.7rem;
  background-color: var(--bg-color);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
}

a.book-card {
  display: block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

a.book-card:hover {
  /* removed translateY to prevent small vertical shift on hover */
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  border-color: rgba(128, 128, 128, 0.5);
}

a.book-card:focus-visible {
  outline: 2px solid var(--text-color);
  outline-offset: 3px;
}

.book-card h3 {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 1.08rem;
  color: var(--text-color);
  line-height: 1.35;
  font-weight: 600;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.book-card-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
  margin-top: 0.25rem;
  color: var(--muted-color);
  font-size: 0.84rem;
  line-height: 1.35;
}

/* Metadata lines within cards */
.book-meta {
  opacity: 0.8;
}

.book-meta strong {
  color: var(--text-color);
  opacity: 1;
}

.book-list-title {
  margin-bottom: 1rem;
  font-size: 1.25em;
}

/* Book meta used across book-cards */
.book-author {
  opacity: 0.8;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-year {
  opacity: 0.7;
  margin: 0;
  flex: 0 0 auto;
  margin-left: auto;
  white-space: nowrap;
}

/* Clickable author pill/button */
.author-button {
  background: none;
  border: 1px solid rgba(128, 128, 128, 0.5);
  color: var(--text-color);
  text-decoration: none;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: inherit;
  transition: all 0.2s ease;
  display: inline-block;
  margin: 0.1rem 0.2rem 0.1rem 0;
  cursor: pointer;
}

.author-button:hover {
  background: rgba(128, 128, 128, 0.2);
  border-color: rgba(128, 128, 128, 0.7);
}

.author-button:focus-visible {
  outline: 2px solid var(--text-color);
  outline-offset: 2px;
}

/* Common button styles used across header/settings */
:is(.menu-button, .toc-button, .settings-button, .bookmark-button, .theme-button, .font-size-button) {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--text-color);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 300ms, color 300ms, border-color 300ms;
  font-size: 1rem;
  white-space: nowrap;
  /* Allow text-labeled buttons to expand while keeping a sensible minimum */
  min-width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

:is(.menu-button, .toc-button, .settings-button, .bookmark-button, .theme-button, .font-size-button):hover {
  background-color: rgba(128, 128, 128, 0.2);
}

/* Theme and font-size button states */
:is(.theme-button, .font-size-button).active {
  background-color: var(--text-color);
  color: var(--bg-color);
}

:is(.theme-button, .font-size-button).active:hover {
  background-color: var(--text-color);
  opacity: 0.8;
}

.font-size-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#font-size-small { font-size: 0.95rem; }
#font-size-medium { font-size: 1.05rem; }
#font-size-large { font-size: 1.2rem; }

/* Header and navigation styles */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--bg-color);
    padding: 0.5rem 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: background-color 300ms, transform 300ms ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header.hide-header {
    transform: translateY(-100%);
}

.dark .app-header {
    box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
}

.header-left {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-container {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

/* Button base styles are defined earlier in this file. */
/* Ensure icon-only buttons match the standard 40px button height */
.settings-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0.4rem;
}
.bookmark-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 8px;
}

/* Ensure icons inside the small square buttons are readable */
.settings-button .icon,
.bookmark-button .icon {
    width: 1.25rem;
    height: 1.25rem;
    display: block; /* avoid inline baseline alignment quirks */
}

.toc-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.bookmark-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--bg-color);
    border: 1px solid var(--text-color);
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    min-width: 150px;
    display: none;
}

.dropdown-menu.show {
    display: block;
}

.menu-item {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-color);
    text-decoration: none;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
    transition: background-color 300ms;
    text-align: left;
}

.menu-item:hover {
    background-color: rgba(128, 128, 128, 0.1);
}

.menu-item:last-child {
    border-bottom: none;
}

.settings-window {
    position: fixed;
    top: 4rem;
    left: 1rem;
    background-color: var(--bg-color);
    border: 1px solid var(--text-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1002;
    padding: 1rem;
    min-width: 200px;
    display: none;
}

.bookmark-window {
    position: fixed;
    top: 4rem;
    left: 1rem;
    background-color: var(--bg-color);
    border: 1px solid var(--text-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1002;
    padding: 1rem;
    min-width: 260px;
    max-width: 80vw;
    display: none;
}

.toc-floating-window {
    position: fixed;
    top: 4rem;
    left: 1rem;
    background-color: var(--bg-color);
    border: 1px solid var(--text-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1002;
    padding: 1rem;
    min-width: 200px;
    display: none;
}

.settings-window.show, .toc-floating-window.show, .bookmark-window.show {
    display: block;
}

.settings-window h3, .toc-floating-window h3, .bookmark-window h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.bookmark-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.bookmark-list-container {
    max-height: 60vh;
    overflow-y: auto;
}

.bookmark-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.bookmark-item:last-child {
    border-bottom: none;
}

.bookmark-jump {
    font-size: 1rem; /* override any global button font-size rules */
    line-height: 1.3;
    flex: 1 1 auto;
    text-align: left;
    color: var(--text-color);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 300ms;
}

.bookmark-jump:hover {
    background-color: rgba(128, 128, 128, 0.1);
}

.bookmark-delete {
    background: transparent;
    border: 1px solid var(--text-color);
    color: var(--text-color);
    border-radius: 4px;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    aspect-ratio: 1 / 1; /* keep width equal to height */
}
.bookmark-delete .icon {
    width: 16px;
    height: 16px;
}

.theme-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* Install app button row */
.install-app-row {
    margin-bottom: 0.75rem;
}
.install-app-button {
    width: 100%;
}

/* .theme-button base and hover styles are defined earlier in this file. */

/* Ensure all buttons inside windows render at 1rem */
.settings-window button,
.toc-floating-window button,
.bookmark-window button {
    font-size: 1rem;
}
/* Settings rows */
.settings-item {
    margin-top: 0.5rem;
}
.settings-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    user-select: none;
    cursor: pointer;
}
.settings-toggle input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
}

.toc-content {
    max-height: 60vh;
    overflow-y: auto;
}

.toc-content ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.toc-content li {
    margin: 0.25rem 0;
}

.toc-content .toc-level-1 { margin-left: 0; }
.toc-content .toc-level-2 { margin-left: 1rem; }
.toc-content .toc-level-3 { margin-left: 2rem; }
.toc-content .toc-level-4 { margin-left: 3rem; }
.toc-content .toc-level-5 { margin-left: 4rem; }
.toc-content .toc-level-6 { margin-left: 5rem; }

.toc-content a {
    color: var(--text-color);
    text-decoration: none;
    display: block;
    padding: 0.25rem 0;
    border-radius: 2px;
    transition: background-color 300ms;
}

.toc-content a:hover {
    background-color: rgba(128, 128, 128, 0.1);
}

@media (max-width: 768px) {
    .header-left {
        gap: 0.5rem;
    }
    
    .menu-button, .toc-button, .bookmark-button {
        padding: 0.4rem 0.8rem;
        font-size: 1rem;
    }
    .settings-button {
        width: 40px;
        height: 40px;
        padding: 0.4rem;
    }
    .bookmark-button {
        width: 40px;
        height: 40px;
        padding: 0.4rem;
    }
    /* Keep icons comfortably sized on small screens */
    .settings-button .icon,
    .bookmark-button .icon {
        width: 1.25rem;
        height: 1.25rem;
    }
}

/* Footer styles */

.footer {
    margin-top: auto;
    padding: 2rem 1rem 1rem 1rem;
    border-top: 1px solid rgba(128, 128, 128, 0.3);
    background-color: var(--bg-color);
    color: var(--text-color);
    text-align: center;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer-content p {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.footer-link {
    color: var(--text-color);
    text-decoration: underline;
    transition: opacity 0.2s ease;
}

.footer-link:hover {
    text-decoration: underline;
    opacity: 0.8;
}

.copyright {
    padding: 2rem;
    text-align: center;
    background-color: var(--bg-color);
    border-top: 1px solid rgba(128, 128, 128, 0.2);
    color: var(--text-color);
    font-size: 1rem;
}

/* Book page styles */

.main-content {
    max-width: 800px;
    margin: 0 auto;
    font-size: var(--main-font-size);
}

.book-page-content {
    min-width: 0;
    max-width: 800px;
    width: 100%;
    justify-self: start;
}

.book-metadata {
    background-color: rgba(128, 128, 128, 0.1);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.book-metadata p {
    margin: 0.75rem 0 !important;
}

.book-metadata h1 {
    margin-top: 0.5rem !important;
}

.book-metadata .original-title {
    font-style: italic;
    font-size: 1.1rem;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 1rem;
}

.expand-button {
    background: none;
    border: none;
    color: var(--text-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    padding: 0;
    margin-left: 0.5rem;
    transition: opacity 0.2s ease;
}

.expand-button:hover {
    opacity: 0.7;
}

.expand-button:focus {
    outline: 1px solid var(--text-color);
    outline-offset: 2px;
}

.main-content h1, .main-content h2, .main-content h3,
.main-content h4, .main-content h5, .main-content h6 {
    margin: 1.5em 0 0.5em 0;
    line-height: 1.2;
    scroll-margin-top: 100px;
}

.main-content h1 {
    margin-top: 0;
    font-size: 1.75rem;
    border-bottom: 2px solid var(--text-color);
    padding-bottom: 0.3em;
}

.main-content h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid var(--text-color);
    padding-bottom: 0.2em;
}

.main-content p {
    margin: 1em 0;
    text-align: left;
}

.main-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1em auto;
}

.main-content blockquote {
    margin: 1em 0;
    padding-left: 1em;
}

.main-content pre {
    padding: 1em;
    border-radius: 6px;
    margin: 1em 0;
    white-space: pre-wrap;
}

.main-content code {
    background-color: rgba(128, 128, 128, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
}

.main-content pre code {
    background: none;
    padding: 0;
}

.home-button-container {
    text-align: center;
    padding: 3rem 0;
}

.home-button {
    display: inline-block;
    padding: 0.75rem 2rem;
    background-color: var(--bg-color);
    color: var(--text-color);
    text-decoration: none;
    border: 2px solid var(--text-color);
    border-radius: 8px;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 120px;
}

.home-button:hover {
    background-color: var(--text-color);
    color: var(--bg-color);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    text-decoration: none;
}

.home-button:active {
    /* removed translateY to prevent vertical jitter - previously translateY(0) */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.dark .home-button {
    box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
}

.dark .home-button:hover {
    box-shadow: 0 4px 8px rgba(255, 255, 255, 0.2);
}

.after-content {
    border-top: 2px solid rgba(128, 128, 128, 0.8);
    margin-top: 2rem;
    padding: 20rem 0 2rem 0;
}

.share-rank {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.info-bottom {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: var(--text-color);
    opacity: 0.7;
    text-align: center;
}

.info-bottom p {
    margin: 0;
}

.social-link {
    display: inline-block;
    transition: transform 0.2s ease, opacity 0.3s ease;
    border-radius: 4px;
    overflow: hidden;
    /* Ensure a small, consistent horizontal gap between share buttons */
    margin-right: 0.5rem;
}

/* Remove extra right margin on the last share button so layout remains tidy */
.share-rank .social-link:last-child {
    margin-right: 0;
}

.social-link:hover {
    /* removed translateY to prevent vertical jitter - previously translateY(-2px) */
    opacity: 0.8;
}

.social-icon {
    width: 32px;
    height: 32px;
    display: block;
}

.light .x-logo,
.light .threads-logo {
    filter: invert(1);
}

.dark .x-logo,
.dark .threads-logo {
    filter: none;
}

.ranking-link {
    display: inline-block;
    transition: transform 0.2s ease, opacity 0.3s ease;
}

.ranking-link:hover {
    /* removed translateY to prevent vertical jitter - previously translateY(-1px) */
    opacity: 0.9;
}

.ranking-banner {
    border: 0;
    display: block;
    max-width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .toc-floating-window {
        width: 90%;
        left: 5%;
    }
    
    .share-rank {
        gap: 0.75rem;
        padding: 1.5rem 0;
    }
}

@media (max-width: 480px) {
    .menu-container {
        display: flex;
        justify-content: flex-start;
        gap: 0.3rem;
    }

    .share-rank {
        gap: 0.5rem;
        padding: 1rem 0;
    }

    .social-icon {
        width: 28px;
        height: 28px;
    }
}

/* Home page styles */

.home-title {
    text-align: center;
}

.reading-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.75rem;
    margin: 0 0 2rem 0;
}

.authors-button-container {
    text-align: center;
    padding: 3rem 0;
}

.intro {
    text-align: center;
    margin: 1rem auto;
    padding: 1rem 1.5rem;
    background-color: rgba(128, 128, 128, 0.05);
    border-radius: 8px;
    max-width: fit-content;
    display: block;
    width: auto;
}

.authors-button {
    display: inline-block;
    padding: 0.75rem 2rem;
    background-color: var(--bg-color);
    color: var(--text-color);
    text-decoration: none;
    border: 2px solid var(--text-color);
    border-radius: 8px;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.authors-button:hover {
    background-color: var(--text-color);
    color: var(--bg-color);
    /* removed translateY to prevent small vertical jump */
}

@media (max-width: 768px) {
    .intro p {
        font-size: 1rem;
    }

    .reading-list {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* Author pages styles */

.author-header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid rgba(128, 128, 128, 0.2);
}

.author-name {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.book-count {
    font-size: 1.1rem;
    opacity: 0.8;
    margin-bottom: 1rem;
}

.back-link {
    display: inline-block;
    color: var(--text-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border: 1px solid rgba(128, 128, 128, 0.3);
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.back-link:hover {
    background-color: rgba(128, 128, 128, 0.1);
    text-decoration: none;
}

.books-section {
    margin-top: 2rem;
}

.section-title {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    text-align: center;
}

/* Authors index page */
.author-section {
    padding-top: 1rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.author-section:last-child {
    border-bottom: none;
}

.author-section h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    cursor: pointer;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.author-section h2:hover {
    opacity: 0.8;
}

.author-section .book-count {
    font-size: 0.9rem;
    opacity: 0.7;
    font-weight: normal;
}

.arrow {
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.author-section h2:hover .arrow {
    opacity: 1;
}

@media (max-width: 768px) {
    .author-name {
        font-size: 2rem;
    }
    
    .header-left {
        gap: 0.25rem;
    }
    
    .menu-button, .toc-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .author-name {
        font-size: 1.8rem;
    }
}

/* Special pages (recently opened, etc.) styles */

.main-content {
    max-width: 1000px;
    margin: 0 auto;
}

.page-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    text-align: center;
}

.page-description {
    text-align: center;
    margin-bottom: 2rem;
    opacity: 0.7;
}

/* book-card related rules are centralized in this file */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    opacity: 0.6;
}

.empty-state h3 {
    margin-bottom: 1rem;
}

.clear-history-container {
    text-align: center;
    margin: 2rem 0;
}

.clear-history-button {
    background-color: rgba(255, 0, 0, 0.1);
    color: var(--text-color);
    border: 1px solid rgba(255, 0, 0, 0.3);
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease;
}

.clear-history-button:hover {
    background-color: rgba(255, 0, 0, 0.2);
}

.home-button-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 2.5rem 0;
}

.home-button {
    display: inline-block;
    padding: 0.75rem 2rem;
    background-color: var(--bg-color);
    color: var(--text-color);
    text-decoration: none;
    border: 2px solid var(--text-color);
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.2s ease;
    min-width: 140px;
    text-align: center;
}

.home-button:hover {
    background-color: var(--text-color);
    color: var(--bg-color);
}

/* Download table styles */

.table-container {
    overflow-x: auto;
    margin-top: 2rem;
}

.author-book-group {
    margin-top: 1.5rem;
}

.author-book-group + .author-book-group {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.author-book-group-title {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.author-book-group .table-container {
    margin-top: 0.75rem;
}

.download-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    text-align: left;
}

.download-table th, 
.download-table td {
    padding: 1rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.download-table th {
    background-color: rgba(128, 128, 128, 0.05);
    font-weight: 600;
}

.download-table tr:hover {
    background-color: rgba(128, 128, 128, 0.03);
}

.download-table .book-row-link {
    cursor: pointer;
}

.download-table .book-row-link:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: -2px;
}

.download-button-cell {
    text-align: left;
    width: 1%;
    white-space: nowrap;
}

@media (max-width: 600px) {
    .download-table th, .download-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }
}

/* Breadcrumbs */
.breadcrumbs {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.breadcrumbs ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
}

.breadcrumbs li {
  display: flex;
  align-items: center;
}

.breadcrumbs li:not(:last-child)::after {
  content: "›";
  margin: 0 0.5rem;
  opacity: 0.5;
}

.breadcrumbs a {
  color: var(--text-color);
  text-decoration: none;
  opacity: 0.7;
}

.breadcrumbs a:hover {
  opacity: 1;
  text-decoration: underline;
}

.breadcrumbs .active {
  opacity: 1;
  font-weight: 600;
}

/* Download table title links */
.download-table .book-title-cell a {
  color: inherit;
  text-decoration: none;
}

.download-table .book-title-cell a:hover {
  text-decoration: underline;
}

/* Back to Home Button */
.back-to-home-container {
  margin-top: 3rem;
  text-align: center;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  padding-top: 2rem;
}

.back-to-home-button {
    display: inline-flex;
    min-width: 150px;
    justify-content: center;
    text-decoration: none;
}

/* Site-wide UI polish */
:root {
    --surface-color: #f7f7f7;
    --surface-hover: #ededed;
    --border-color: rgba(0, 0, 0, 0.16);
    --muted-color: rgba(0, 0, 0, 0.80);
    --focus-color: #2457a6;
    --soft-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.dark {
    --surface-color: #2e2e2e;
    --surface-hover: #393939;
    --border-color: rgba(255, 255, 255, 0.2);
    --muted-color: rgba(255, 255, 255, 0.68);
    --focus-color: #9fc3ff;
    --soft-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

html {
    scroll-behavior: smooth;
}

[hidden] {
    display: none !important;
}

body {
    min-height: 100vh;
    font-size: var(--main-font-size);
    transition: background-color 300ms, color 300ms;
}

main {
    padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) 4rem;
}

header:not(.app-header) {
    margin-bottom: 2rem;
}

.app-header {
    margin: 0;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.header-inner {
    width: min(1180px, 100%);
    min-height: 40px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
}

.header-left,
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions {
    margin-left: 0;
}

:is(.menu-button, .toc-button, .settings-button, .bookmark-button, .theme-button, .font-size-button, .home-button, .authors-button, .back-link, .clear-history-button, .expand-button):focus-visible,
.menu-item:focus-visible,
.author-card:focus-visible,
.section-link:focus-visible,
.social-link:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 3px;
}

.menu-button[aria-expanded="true"],
.menu-item.active {
    background-color: var(--text-color);
    color: var(--bg-color);
}

.menu-item {
    border-radius: 4px;
}

.menu-item:hover,
.menu-item.active:hover {
    background-color: var(--surface-hover);
    color: var(--text-color);
}

.dropdown-menu,
.settings-window,
.bookmark-window,
.toc-floating-window {
    border-color: var(--border-color);
    box-shadow: var(--soft-shadow);
}

.dropdown-menu {
    top: calc(100% + 0.5rem);
}

.settings-window,
.bookmark-window,
.toc-floating-window {
    top: var(--popup-top, 4.5rem);
    left: var(--popup-left, 1rem);
}

.settings-download {
    margin-bottom: 1.5rem;
}

.settings-download-link {
    width: 100%;
}

.book-list {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: clamp(0.75rem, 1.5vw, 1rem);
}

a.book-card {
    background-color: var(--surface-color);
    border-color: var(--border-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: box-shadow 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

a.book-card:hover {
    background-color: var(--surface-hover);
    border-color: var(--text-color);
    box-shadow: var(--soft-shadow);
}

.home-page-content {
    max-width: 1100px;
}

.home-hero {
    margin-bottom: clamp(2rem, 5vw, 4rem);
    text-align: center;
}

.eyebrow {
    margin: 0 0 0.5rem;
    color: var(--muted-color);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.home-title {
    margin-bottom: 1rem;
    font-size: clamp(2rem, 5vw, 3.25rem);
    letter-spacing: 0.02em;
    border: 0;
    padding-bottom: 0;
}

.intro {
    max-width: 42rem;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

.intro p {
    margin: 0.25rem 0;
}

.collection-summary {
    color: var(--muted-color);
    font-size: 0.95rem;
}

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-heading .book-list-title,
.section-heading .section-title {
    margin: 0;
}

.section-heading .book-list-title a,
.section-heading .section-title a {
    color: inherit;
    text-decoration: none;
}

.section-heading .book-list-title a:hover,
.section-heading .section-title a:hover {
    text-decoration: underline;
}

.section-link {
    flex: 0 0 auto;
    color: var(--text-color);
    font-size: 0.9rem;
    opacity: 0.72;
    text-decoration: none;
}

.section-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.reading-section,
.book-collection {
    margin-bottom: clamp(2.5rem, 6vw, 4rem);
}

.authors-button-container {
    display: flex;
    justify-content: center;
    padding: 1rem 0 2rem;
}

.authors-button {
    padding: 0.8rem 1.4rem;
    border-color: var(--text-color);
}

.author-header {
    margin-bottom: clamp(2rem, 5vw, 3.5rem);
    padding: clamp(1.5rem, 4vw, 2.5rem);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
    text-align: center;
}

.author-header .eyebrow {
    margin-bottom: 0.75rem;
}

.author-name {
    margin: 0 0 0.75rem;
    font-size: clamp(2rem, 6vw, 3.25rem);
    line-height: 1.15;
    border: 0;
    padding-bottom: 0;
}

.author-header .book-count {
    margin-bottom: 1.25rem;
    color: var(--muted-color);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.95rem;
    text-decoration: none;
}

.back-link:hover {
    background-color: var(--surface-hover);
}

.books-section {
    margin-top: 0;
}

.section-title {
    font-size: clamp(1.35rem, 3vw, 1.75rem);
    border: 0;
    padding-bottom: 0;
}

.section-count {
    color: var(--muted-color);
    font-size: 0.95rem;
}

.authors-directory,
.books-directory {
    margin-top: 2rem;
}

.directory-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.directory-count {
    margin: 0;
    color: var(--muted-color);
    font-size: 0.95rem;
}

.search-field {
    width: min(100%, 22rem);
}

.search-field label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.search-input-wrap {
    position: relative;
}

.search-input-wrap input {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.55rem 2.5rem 0.55rem 0.8rem;
    color: var(--text-color);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font: inherit;
}

.search-input-wrap input:focus {
    border-color: var(--focus-color);
    outline: 3px solid color-mix(in srgb, var(--focus-color) 25%, transparent);
}

.search-clear {
    position: absolute;
    top: 50%;
    right: 0.45rem;
    width: 2rem;
    height: 2rem;
    transform: translateY(-50%);
    color: var(--muted-color);
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
}

.search-clear:hover {
    color: var(--text-color);
    background: var(--surface-hover);
}

.authors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: 1rem;
}

.author-card {
    display: flex;
    min-height: 7rem;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 1.25rem;
    color: var(--text-color);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    text-decoration: none;
    transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.author-card:hover {
    background: var(--surface-hover);
    border-color: var(--text-color);
    box-shadow: var(--soft-shadow);
}

.author-card-name {
    font-size: 1.15rem;
    font-weight: 650;
    line-height: 1.35;
}

.author-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--muted-color);
    font-size: 0.9rem;
}

.author-card-arrow {
    color: var(--text-color);
    font-size: 1.2rem;
    opacity: 0.65;
    transition: transform 180ms ease, opacity 180ms ease;
}

.author-card:hover .author-card-arrow {
    opacity: 1;
    transform: translateX(0.2rem);
}

.authors-no-results,
.books-no-results {
    margin: 1rem 0 0;
    padding: 2rem 1rem;
}

.author-book-group {
    margin-top: 2rem;
    padding: 1.25rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.author-book-group + .author-book-group {
    margin-top: 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.author-book-group-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin: 0;
}

.author-book-group-title a {
    color: var(--text-color);
    text-decoration: none;
}

.author-book-group-title a:hover {
    text-decoration: underline;
}

.author-book-group-count {
    flex: 0 0 auto;
    color: var(--muted-color);
    font-size: 0.85rem;
    font-weight: 400;
}

.author-book-group .table-container {
    margin-top: 1rem;
}

.download-table {
    margin-bottom: 0;
    background: var(--bg-color);
}

.download-table th,
.download-table td {
    border-color: var(--border-color);
}

.download-table th {
    color: var(--muted-color);
    background: var(--surface-hover);
    font-size: 0.85rem;
}

.download-table .book-title-cell {
    font-weight: 550;
}

.download-table .book-year-cell {
    width: 8rem;
    white-space: nowrap;
    color: var(--muted-color);
}

.download-table .book-row-link:hover {
    background-color: var(--surface-hover);
}

.download-table .book-row-link:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: -3px;
}

.empty-state {
    color: var(--muted-color);
    background: var(--surface-color);
    border: 1px dashed var(--border-color);
    border-radius: 10px;
}

.clear-history-button {
    border-color: rgba(180, 0, 0, 0.45);
}

.book-metadata {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.book-metadata .eyebrow {
    margin: 0 0 0.75rem;
}

.book-metadata h1 {
    margin: 0 0 1rem !important;
    border: 0;
    padding: 0;
    font-size: clamp(1.5rem, 5vw, 2rem);
}

.book-fact {
    display: grid;
    grid-template-columns: 5rem minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
}

.book-fact > strong {
    color: var(--muted-color);
    font-size: 0.9rem;
}

.book-fact > span {
    min-width: 0;
}

.summary-content {
    overflow-wrap: anywhere;
}

.summary-content .expand-button {
    color: var(--focus-color);
    font-weight: 600;
}

.after-content {
    padding-top: clamp(4rem, 12vw, 10rem);
}

.page-title {
    border: 0;
    padding-bottom: 0;
}

body.page-book main {
    max-width: 1240px;
}

.social-link {
    display: inline-flex;
    padding: 0.25rem;
}

@media (max-width: 700px) {
    .directory-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 1rem;
    }

    .search-field {
        width: 100%;
    }

    .author-book-group {
        padding: 0.85rem;
    }

    .download-table th,
    .download-table td {
        padding: 0.8rem 0.65rem;
    }
}

@media (max-width: 480px) {
    body {
        padding-top: 4rem;
    }

    .app-header {
        padding-inline: 0.65rem;
    }

    .header-inner {
        gap: 0.5rem;
    }

    .header-left,
    .header-actions {
        gap: 0.3rem;
    }

    .menu-button,
    .toc-button {
        padding-inline: 0.65rem;
    }

    .settings-button,
    .bookmark-button {
        width: 38px;
        height: 38px;
    }

    .book-fact {
        grid-template-columns: 4.25rem minmax(0, 1fr);
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.35rem;
    }

    .section-link {
        font-size: 0.85rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
