html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* Desktop: fixed-height shell so the table scrolls internally */
.app-main {
    height: 100vh;
    overflow: hidden;
}

/* Mobile: let the page scroll naturally */
@media (max-width: 959px) {
    .app-main {
        height: auto;
        overflow: visible;
    }
}

/* Desktop: header + options fixed, table scrolls */
@media (min-width: 960px) {
    .page-outer {
        display: flex;
        flex-direction: column;
        height: 100vh;
        padding: 1.25rem 2rem 1rem 2rem;
        overflow: hidden;
    }
    .page-static {
        flex-shrink: 0;
        padding-bottom: 0.75rem;
    }
    .page-scroll {
        flex: 1;
        overflow: auto;
    }
}

/* Mobile: vertical natural scroll, horizontal scroll on table */
@media (max-width: 959px) {
    .page-outer {
        padding: 0.5rem;
    }
    .page-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .col-hide-mobile {
        display: none;
    }
    .library-table td.col-title {
        white-space: normal;
        max-width: 40vw;
    }
}

.library-table {
    width: auto;
    border-collapse: collapse;
    border: 1px solid var(--mud-palette-divider);
}

.library-table th,
.library-table td {
    padding: 4px 8px;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-right: 1px solid var(--mud-palette-table-lines);
}

/* Drag handle on the right edge of each header for resizing the column.
   The header is position:sticky (a positioning context), so the absolutely
   positioned handle anchors to it without needing position:relative. */
.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
}

.col-resizer:hover {
    background-color: var(--mud-palette-primary);
    opacity: 0.4;
}

/* Leave room so the sort icon / label don't sit under the resize handle. */
.library-table th .th-label {
    margin-right: 2px;
}

.library-table th {
    vertical-align: top;
}

.th-top {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Per-column filter input that lives inside the (sticky) header cell. */
.col-filter-wrap {
    position: relative;
}

.col-filter {
    width: 100%;
    box-sizing: border-box;
    margin-top: 3px;
    padding: 1px 18px 1px 4px;
    font-size: 0.8rem;
    font-weight: normal;
    color: inherit;
    background-color: var(--mud-palette-background);
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 3px;
}

/* X button that clears a column filter's text. */
.col-filter-clear {
    position: absolute;
    right: 3px;
    top: calc(50% + 1px); /* re-center for the input's 3px top margin */
    transform: translateY(-50%);
    padding: 0 3px;
    font-size: 0.7rem;
    line-height: 1;
    color: var(--mud-palette-text-secondary);
    background: none;
    border: none;
    cursor: pointer;
}

.col-filter-clear:hover {
    color: var(--mud-palette-text-primary);
}

/* Small option row under a column filter input (e.g. "Series names only" for Title). */
.col-filter-option {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    font-size: 0.7rem;
    font-weight: normal;
    cursor: pointer;
    user-select: none;
}

.library-table th:last-child,
.library-table td:last-child {
    border-right: none;
}

.library-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: color-mix(in srgb, var(--mud-palette-background) 75%, grey);
    border-bottom: 2px solid var(--mud-palette-divider);
    cursor: pointer;
    user-select: none;
}

.library-table th.no-sort {
    cursor: default;
}

.library-table tr:hover td {
    background-color: var(--mud-palette-action-default-hover);
}

.library-table td {
    border-bottom: 1px solid var(--mud-palette-divider);
}

/* Narrator can list many names; cap the width and truncate with an ellipsis
   (full list shown via the cell's title tooltip). An inner inline-block is used
   because max-width on a <td> is not honored in an auto-layout table. */
.narrator-cell {
    display: inline-block;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.title-unowned {
    font-weight: bold;
}

.title-link {
    color: var(--mud-palette-primary);
    cursor: pointer;
    text-decoration: underline;
}

/* Author/narrator names that open the works-by-person dialog. */
.person-link {
    color: var(--mud-palette-primary);
    cursor: pointer;
}

.person-link:hover {
    text-decoration: underline;
}

.depth-1 {
    padding-left: 2.5rem;
}

/* --- Landing / legal pages (static SSR: no MudThemeProvider, so colors are
   self-contained here with a prefers-color-scheme dark variant) --------------- */

.landing-root {
    --lp-bg: #ffffff;
    --lp-text: #1f2430;
    --lp-muted: #5b6472;
    --lp-accent: #6a5bd8;
    --lp-accent-text: #ffffff;
    --lp-card: #f5f6f9;
    --lp-border: #e0e3ea;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--lp-bg);
    color: var(--lp-text);
    font-family: 'Roboto', sans-serif;
    line-height: 1.6;
}

@media (prefers-color-scheme: dark) {
    .landing-root {
        --lp-bg: #15171c;
        --lp-text: #e8eaf0;
        --lp-muted: #a0a8b8;
        --lp-accent: #8577e8;
        --lp-card: #1e2128;
        --lp-border: #333845;
    }
}

.landing {
    flex: 1;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1.25rem;
    box-sizing: border-box;
}

.landing-hero {
    text-align: center;
    padding: 4rem 0 3rem 0;
}

.landing-brand {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--lp-muted);
    margin-bottom: 2.5rem;
}

.landing h1 {
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 1rem 0;
}

.landing-sub {
    font-size: 1.15rem;
    color: var(--lp-muted);
    max-width: 640px;
    margin: 0 auto 2rem auto;
}

.landing-cta {
    display: inline-block;
    padding: 0.85rem 2.2rem;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--lp-accent-text);
    background: var(--lp-accent);
    border-radius: 8px;
    text-decoration: none;
}

.landing-cta:hover {
    filter: brightness(1.1);
}

.landing-cta-note {
    font-size: 0.85rem;
    color: var(--lp-muted);
    margin-top: 0.75rem;
}

.landing-section {
    padding: 2rem 0;
    border-top: 1px solid var(--lp-border);
}

.landing-section h2 {
    font-size: 1.5rem;
    margin: 0 0 1rem 0;
}

.landing-shots {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.landing-shot {
    flex: 1 1 260px;
    max-width: 420px;
    margin: 0;
    text-align: center;
}

/* Fixed tile height keeps the three-across row even though the captures have
   different aspect ratios; contain letterboxes each shot inside its frame. */
.landing-shot img {
    width: 100%;
    height: 240px;
    object-fit: contain;
    border: 1px solid var(--lp-border);
    border-radius: 8px;
    background: var(--lp-card);
    cursor: zoom-in;
}

/* Click-to-zoom lightbox for the screenshots. */
.shot-lightbox {
    border: none;
    padding: 0;
    background: transparent;
    cursor: zoom-out;
}

.shot-lightbox img {
    display: block;
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 8px;
}

.shot-lightbox::backdrop {
    background: rgba(0, 0, 0, 0.75);
}

/* Until real screenshots are dropped into wwwroot/img, show a framed placeholder. */
.landing-shot-missing img {
    display: none;
}

.landing-shot-missing::before {
    content: "Screenshot coming soon";
    display: flex;
    align-items: center;
    justify-content: center;
    height: 180px;
    border: 1px dashed var(--lp-border);
    border-radius: 8px;
    background: var(--lp-card);
    color: var(--lp-muted);
    font-size: 0.9rem;
}

.landing-shot figcaption {
    font-size: 0.85rem;
    color: var(--lp-muted);
    margin-top: 0.5rem;
}

.landing-steps li,
.landing-features li {
    margin-bottom: 0.6rem;
}

.landing-faq dt {
    font-weight: 600;
    margin-top: 1.1rem;
}

.landing-faq dd {
    margin: 0.25rem 0 0 0;
    color: var(--lp-muted);
}

.landing-bottom-cta {
    border-top: 1px solid var(--lp-border);
}

.legal-page {
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
}

.legal-page h1 {
    font-size: 1.9rem;
}

.legal-page h2 {
    font-size: 1.25rem;
    margin-top: 1.75rem;
}

.legal-updated {
    color: var(--lp-muted);
    font-size: 0.9rem;
}

.legal-page a,
.landing a:not(.landing-cta) {
    color: var(--lp-accent);
}

/* --- Site footer (rendered on app pages via MainLayout and on static pages via
   LandingLayout; Mud palette vars fall back to self-contained colors) ---------- */

.app-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    justify-content: center;
    padding: 1rem;
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary, var(--lp-muted, #5b6472));
    border-top: 1px solid var(--mud-palette-lines-default, var(--lp-border, #e0e3ea));
}

.app-footer a {
    color: inherit;
}

.app-footer-links {
    display: flex;
    gap: 1rem;
}

.book-thumb {
    width: 32px;
    height: 32px;
    object-fit: contain;
    cursor: pointer;
}

.book-preview {
    width: 300px;
    height: 300px;
    object-fit: contain;
}

.series-image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 420px;
    padding: 4px;
}

.series-book-preview {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 4px 8px;
}

.related-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.related-row:hover {
    background: var(--mud-palette-action-default-hover);
}

.related-row-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.related-row-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.related-row-sub {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
}

.similar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
    padding: 6px 8px;
    justify-items: center;
}

.similar-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
}

.similar-tile:hover {
    background: var(--mud-palette-action-default-hover);
}

.similar-tile-img {
    width: 88px;
    height: 88px;
    object-fit: contain;
}

.similar-tile-title {
    font-weight: 600;
    font-size: 0.8rem;
    line-height: 1.2;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.similar-tile-author {
    font-size: 0.72rem;
    color: var(--mud-palette-text-secondary);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.similar-tooltip {
    display: flex;
    gap: 0.75rem;
    max-width: 440px;
    padding: 4px;
    text-align: left;
}

.similar-tooltip-img {
    width: 170px;
    height: 170px;
    object-fit: contain;
    flex-shrink: 0;
}

.similar-tooltip-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.similar-tooltip-title {
    font-weight: 700;
    font-size: 1rem;
}

.similar-tooltip-author {
    font-size: 0.85rem;
    opacity: 0.85;
    margin-bottom: 0.35rem;
}

.similar-tooltip-desc {
    font-size: 0.8rem;
    line-height: 1.35;
}
