/* Book Club UI */
:root {
    /* Light mode */
    --bg: #f8f6f2;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --text: #212A31;
    --text-muted: #748D92;
    --border: #D3D9D4;
    --primary: #7B2D3B;
    --primary-hover: #64232f;
    --primary-soft: rgba(123, 45, 59, 0.1);
    --up: #2e7d6f;
    --down: #c45c5c;
    --shadow: 0 1px 3px 0 rgb(33 42 49 / 0.06);
    --shadow-md: 0 4px 6px -1px rgb(33 42 49 / 0.08);
    --shadow-lg: 0 20px 25px -5px rgb(33 42 49 / 0.1);
    --radius: 16px;
    --radius-sm: 12px;
}

[data-theme="dark"] {
    /* Dark mode */
    --bg: #1a2228;
    --bg-card: #212A31;
    --bg-elevated: #2E3944;
    --text: #e8eceb;
    --text-muted: #748D92;
    --border: #3a4652;
    --primary: #d4848f;
    --primary-hover: #e19aa4;
    --primary-soft: rgba(212, 132, 143, 0.15);
    --up: #4caf9a;
    --down: #e07a7a;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.4s ease, color 0.4s ease;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
main { flex: 1 0 auto; width: 100%; }
.container { max-width: 1280px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Header */
header {
    background: color-mix(in srgb, var(--bg-card) 85%, transparent);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
}
.header-inner {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.5rem; max-width: 1280px; margin: 0 auto;
}
.logo {
    font-size: 1.65rem; font-weight: 700; letter-spacing: -0.03em;
    text-decoration: none; color: var(--text);
}
.logo span { color: var(--primary); }
.logo { display: inline-flex; align-items: center; }
.logo-mark { width: 34px; height: 34px; margin-right: 0.55rem; flex: none; }
nav { display: flex; gap: 0.5rem; align-items: center; }
nav a {
    color: var(--text-muted); text-decoration: none; font-weight: 500;
    padding: 0.5rem 0.9rem; border-radius: 999px; transition: all 0.2s;
    font-size: 0.95rem;
}
nav a:hover, nav a.active { color: var(--text); background: var(--primary-soft); }
.theme-toggle {
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: 999px; padding: 0.4rem; cursor: pointer;
    color: var(--text); font-size: 0.85rem; font-weight: 500;
    transition: all 0.2s; margin-left: 0.5rem;
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
}
.theme-toggle .material-icons { font-size: 20px; }
.theme-toggle:hover { background: var(--border); }

/* Page header */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem;
}
.page-header h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; }

/* Cards */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.75rem;
}
.book-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.35s;
    border: 1px solid var(--border);
    position: relative;
    display: flex;
    flex-direction: column;
}
.book-card:hover {
    transform: translateY(-8px) scale(1.01);
    box-shadow: var(--shadow-lg);
}
.poster-wrap { position: relative; overflow: hidden; }
.poster {
    width: 100%; aspect-ratio: 2/3; object-fit: cover;
    background: var(--border); transition: transform 0.5s ease;
}
.book-card:hover .poster { transform: scale(1.05); }
.card-body {
    padding: 1.15rem 1.15rem 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.card-title {
    font-weight: 600; font-size: 1.05rem; line-height: 1.35;
    margin-bottom: 0.3rem; display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta {
    display: flex; flex-direction: column; gap: 0.15rem;
    font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem;
    line-height: 1.4;
}
.card-added { word-break: break-word; }

/* Vote bar */
.vote-bar {
    display: flex; align-items: center; justify-content: center;
    gap: 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--border);
    margin-top: auto;
}
.vote-btn {
    border: none; background: transparent; cursor: pointer;
    padding: 0.45rem 0.65rem; border-radius: 10px; font-size: 1.15rem;
    transition: all 0.2s; color: var(--text-muted); display: flex; align-items: center;
}
.vote-btn.up:hover, .vote-btn.up.active { background: rgba(16, 185, 129, 0.12); color: var(--up); }
.vote-btn.down:hover, .vote-btn.down.active { background: rgba(244, 63, 94, 0.12); color: var(--down); }
.score {
    font-weight: 700; font-size: 1.05rem; min-width: 2.2rem; text-align: center;
    color: var(--text);
}

/* Buttons & forms */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.65rem 1.35rem; border-radius: 12px; font-weight: 600;
    text-decoration: none; border: none; cursor: pointer; transition: all 0.2s;
    font-size: 0.95rem;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg-elevated); border-color: var(--text-muted); }

input, select {
    width: 100%; padding: 0.8rem 1rem; border-radius: 12px;
    border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
    font-size: 1rem; transition: all 0.2s; font-family: inherit;
}
input:focus, select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeInUp 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards; opacity: 0; }

/* Empty state */
.empty-state {
    text-align: center; padding: 4rem 1rem; color: var(--text-muted);
}
.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; font-weight: 600; }

/* Mobile */
@media (max-width: 640px) {
    .header-inner { padding: 0.85rem 1rem; }
    nav { width: 100%; justify-content: center; flex-wrap: wrap; }
    .book-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1.25rem; }
    .container { padding: 1.25rem 1rem; }
    .page-header h1 { font-size: 1.65rem; }
    .card-added { font-size: 0.74rem; }
}

/* Attribution */
.attribution {
    text-align: center; padding: 2.5rem 1rem; font-size: 0.75rem; color: var(--text-muted);
    border-top: 1px solid var(--border); margin-top: auto;
}
.attribution-note {
    display: block;
    margin-top: 0.4rem;
}

/* Cover overlays: Popular pick (upper left), Details (lower right) */
.popular-badge,
.details-btn {
    position: absolute;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(17, 24, 29, 0.78);
    backdrop-filter: blur(12px) saturate(160%);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
    line-height: 1.2;
}
.popular-badge {
    top: 0.65rem;
    left: 0.65rem;
    max-width: calc(100% - 1.3rem);
    gap: 0.22rem;
    padding: 0.28rem 0.62rem 0.28rem 0.42rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.popular-badge .material-icons {
    font-size: 13px;
    color: #f5c518;
}
.details-btn {
    right: 0.65rem;
    bottom: 0.65rem;
    width: auto;
    margin: 0;
    padding: 0.34rem 0.72rem;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.details-btn:hover {
    color: #fff;
    background: rgba(17, 24, 29, 0.94);
    border-color: rgba(255, 255, 255, 0.42);
}
.details-btn:focus-visible {
    outline: none;
    color: #fff;
    background: rgba(17, 24, 29, 0.94);
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary);
}
[data-theme="dark"] .popular-badge,
[data-theme="dark"] .details-btn {
    background: rgba(8, 12, 16, 0.84);
    border-color: rgba(255, 255, 255, 0.22);
}
[data-theme="dark"] .details-btn:hover,
[data-theme="dark"] .details-btn:focus-visible {
    background: rgba(8, 12, 16, 0.96);
}

@media (max-width: 640px) {
    .popular-badge {
        top: 0.45rem;
        left: 0.45rem;
        font-size: 0.62rem;
        padding: 0.22rem 0.5rem 0.22rem 0.36rem;
        max-width: calc(100% - 0.9rem);
    }
    .popular-badge .material-icons { font-size: 12px; }
    .details-btn {
        right: 0.45rem;
        bottom: 0.45rem;
        font-size: 0.7rem;
        padding: 0.28rem 0.6rem;
    }
}

/* Search result cards: Details sits in the title row, not on the poster.
   Feed cards keep the overlay via .poster-wrap .details-btn. */
.card-title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}
.card-title-row .card-title {
    flex: 1 1 auto;
    min-width: 0;
    margin-bottom: 0;
}
.card-title-row .details-btn,
.card-body .details-btn {
    position: static;
    right: auto;
    bottom: auto;
    flex: 0 0 auto;
    align-self: flex-start;
    z-index: auto;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .add-wrap .book-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
}

/* Book details modal */
body.md-locked { overflow: hidden; }
.md-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center; padding: 2vh 1.5rem;
    background: rgb(17 24 29 / 0.55);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    opacity: 0; transition: opacity 0.22s ease;
}
.md-overlay[hidden] { display: none; }
.md-overlay.is-open { opacity: 1; }
.md-dialog {
    position: relative; width: 100%; max-width: 760px; max-height: 96vh;
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: none; -ms-overflow-style: none;
    background: var(--bg-card); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    transform: translateY(12px) scale(0.97); opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.md-dialog:focus { outline: none; }
.md-dialog::-webkit-scrollbar { display: none; }
.md-overlay.is-open .md-dialog { transform: none; opacity: 1; }
.md-close-wrap {
    position: sticky; top: 0; height: 0; z-index: 2;
    display: flex; justify-content: flex-end;
}
.md-close {
    margin: 0.75rem 0.75rem 0 0; flex-shrink: 0;
    width: 38px; height: 38px; border-radius: 999px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--bg-card) 85%, transparent); color: var(--text);
    border: 1px solid var(--border); box-shadow: var(--shadow-md);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: all 0.2s;
}
.md-close:hover { background: var(--bg-elevated); border-color: var(--text-muted); }
.md-close:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); border-color: var(--primary); }
.md-close .material-icons { font-size: 20px; }

.md-hero { position: relative; aspect-ratio: 16 / 6; background: var(--primary-soft); overflow: hidden; }
.md-hero--plain { aspect-ratio: auto; height: 72px; }
.md-backdrop { width: 100%; height: 100%; object-fit: cover; display: block; }
.md-hero::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(to bottom, transparent 35%, var(--bg-card) 100%);
}
.md-head {
    position: relative; display: flex; gap: 1.25rem; align-items: flex-start;
    padding: 0 1.75rem; margin-top: -4.5rem;
}
.md-poster {
    width: 128px; flex-shrink: 0; aspect-ratio: 2 / 3; object-fit: cover;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    box-shadow: var(--shadow-lg); background: var(--border);
}
.md-poster--empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.md-head-text { min-width: 0; padding-top: 4.85rem; }
.md-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; }
.md-year { color: var(--text-muted); font-weight: 500; }
.md-tagline { color: var(--text-muted); font-style: italic; margin-top: 0.3rem; font-size: 0.95rem; }
.md-chips, .md-genres { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem; }
.md-chip {
    display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.65rem;
    border-radius: 999px; font-size: 0.8rem; font-weight: 500;
    background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
}
.md-chip .material-icons { font-size: 16px; color: var(--text-muted); }
.md-cert { font-weight: 700; letter-spacing: 0.03em; border-color: var(--text-muted); }
.md-rating .material-icons { color: #e3a008; }
.md-genre {
    font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.6rem; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary);
}
.md-muted { color: var(--text-muted); }

.md-body { padding: 1.5rem 1.75rem 1.75rem; display: grid; gap: 1.5rem; }
.md-section h3 {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted); margin-bottom: 0.6rem;
}
.md-overview { font-size: 0.98rem; line-height: 1.7; }
.md-facts {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem;
    padding: 1rem 1.1rem; border-radius: var(--radius-sm);
    background: var(--bg); border: 1px solid var(--border);
}
.md-fact dt { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.md-fact dd { font-size: 0.92rem; font-weight: 500; margin-top: 0.1rem; }

.md-cast { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
.md-person { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.md-person img, .md-avatar {
    width: 44px; height: 44px; border-radius: 999px; object-fit: cover; flex-shrink: 0;
    background: var(--border); border: 1px solid var(--border);
}
.md-avatar { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.md-avatar .material-icons { font-size: 22px; }
.md-person-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.md-person-name { font-weight: 600; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-person-role { font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.md-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.md-actions .btn { gap: 0.4rem; }
.md-actions .material-icons { font-size: 20px; }

.md-state { padding: 3.5rem 1.75rem; text-align: center; display: grid; justify-items: center; gap: 0.75rem; }
.md-state-title { font-size: 1.1rem; font-weight: 600; }
.md-state-icon { font-size: 40px; color: var(--down); }
.md-retry { gap: 0.35rem; margin-top: 0.25rem; }
.md-spinner {
    width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--primary);
    animation: md-spin 0.8s linear infinite;
}
@keyframes md-spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
    .md-overlay { align-items: flex-end; padding: 0; }
    .md-dialog {
        max-width: none; max-height: 92vh; border-radius: var(--radius) var(--radius) 0 0;
        border-bottom: none; transform: translateY(40px);
    }
    .md-head { padding: 0 1.1rem; gap: 0.9rem; margin-top: -3rem; }
    .md-head-text { padding-top: 3.3rem; }
    .md-poster { width: 92px; }
    .md-title { font-size: 1.25rem; }
    .md-body { padding: 1.25rem 1.1rem 1.5rem; }
    .md-cast { grid-template-columns: 1fr 1fr; }
    .md-actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
    .md-overlay, .md-dialog { transition: none; }
    .md-spinner { animation-duration: 2s; }
}

/* Account avatar and dropdown */
.header-inner { gap: 0.75rem; }
.logo { margin-right: auto; }
.header-actions { display: flex; align-items: center; margin-left: 0.5rem; }

.avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
    box-shadow: var(--shadow);
}
.avatar-btn:hover { background: var(--primary-hover); }
.avatar-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary);
}
.avatar-btn[aria-expanded="true"] {
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.avatar-initials { pointer-events: none; text-transform: uppercase; }

.account-menu { position: relative; }
.account-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 272px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.7rem;
    z-index: 200;
    display: none;
}
.account-dropdown.is-open,
.account-dropdown:not([hidden]) { display: block; }
.account-dropdown[hidden] { display: none !important; }

.account-identity {
    padding: 0.45rem 0.65rem 0.7rem;
}
.account-identity-name {
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    color: var(--text);
}
.account-identity-email {
    font-size: 0.78rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.theme-segment {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem;
    padding: 0.2rem;
    margin: 0.15rem 0 0.45rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.theme-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.28rem;
    width: 100%;
    padding: 0.48rem 0.35rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}
.theme-option .material-icons { font-size: 16px; }
.theme-option:hover { color: var(--text); background: var(--bg-elevated); }
.theme-option.is-active,
.theme-option[aria-checked="true"] {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: var(--shadow);
}
[data-theme="dark"] .theme-option.is-active,
[data-theme="dark"] .theme-option[aria-checked="true"] {
    background: var(--bg-elevated);
}
.theme-option:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary);
}

.account-sep {
    height: 1px;
    background: var(--border);
    margin: 0.35rem 0.25rem;
    border: 0;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.account-item .material-icons { font-size: 20px; color: var(--text-muted); }
.account-item:hover,
.account-item:focus-visible {
    background: var(--primary-soft);
    outline: none;
}
.account-item.danger:hover,
.account-item.danger:focus-visible { background: rgba(196, 92, 92, 0.12); }
.account-item.danger:hover .material-icons,
.account-item.danger:focus-visible .material-icons { color: var(--down); }

@media (max-width: 640px) {
    .header-inner {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "logo account"
            "nav nav";
        align-items: center;
        gap: 0.65rem 1rem;
        flex-direction: unset;
    }
    .logo { grid-area: logo; margin-right: 0; }
    nav { grid-area: nav; width: 100%; justify-content: center; margin: 0; }
    .header-actions, .account-menu { grid-area: account; justify-self: end; margin-left: 0; position: static; }
    .account-dropdown {
        width: min(272px, calc(100vw - 1.5rem));
        top: calc(100% + 8px);
        right: 1rem;
    }
}

/* Auth and settings forms */
.auth-card {
    max-width: 400px;
    margin: 3rem auto;
}
.auth-card h1,
.settings-page h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 1.5rem;
}
.auth-form,
.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}
.form-hint { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-muted);
}
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }
.auth-card .section-lead {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin: -0.5rem 0 1.25rem;
    line-height: 1.45;
}
.auth-forgot {
    margin: 0.15rem 0 0;
    text-align: right;
}
.auth-forgot a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-forgot a:hover { text-decoration: underline; }

.settings-page { max-width: 560px; margin: 0 auto; }
.settings-page h1 { margin-bottom: 1.75rem; }
.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem 1.5rem 1.4rem;
    margin-bottom: 1.25rem;
}
.settings-card h2 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}
.settings-card .section-lead {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 1.15rem;
}
.settings-form .btn { align-self: flex-start; min-width: 8.5rem; }
.settings-card input { background: var(--bg); }
.pref-toggle {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    cursor: pointer;
    margin-bottom: 0.35rem;
}
.pref-toggle-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}
.pref-switch {
    flex: 0 0 auto;
    width: 2.6rem;
    height: 1.5rem;
    margin-top: 0.1rem;
    border-radius: 999px;
    background: var(--border);
    border: 1px solid var(--border);
    position: relative;
    transition: background 0.2s, border-color 0.2s;
}
.pref-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.5rem - 6px);
    height: calc(1.5rem - 6px);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s;
}
.pref-toggle-input:checked + .pref-switch {
    background: var(--primary);
    border-color: var(--primary);
}
.pref-toggle-input:checked + .pref-switch::after {
    transform: translateX(1.1rem);
}
.pref-toggle-input:focus-visible + .pref-switch {
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.pref-toggle-copy {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}
.pref-toggle-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}
.settings-attribution { margin: 0.35rem 0 0.25rem; }
.settings-card .settings-form + .settings-form { margin-top: 1.1rem; }
.pref-save-status {
    min-height: 1.15em;
    margin: 0.15rem 0 0 3.45rem;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s;
}
.pref-save-status.is-visible { opacity: 1; }
.pref-save-status.is-saved { color: #166534; }
.pref-save-status.is-error { color: #dc2626; }
[data-theme="dark"] .pref-save-status.is-saved { color: #4caf9a; }
[data-theme="dark"] .pref-save-status.is-error { color: #e07a7a; }


input::placeholder, select::placeholder { color: var(--text-muted); opacity: 0.8; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}
.flash-error { background: #fee2e2; color: #dc2626; }
.flash-success { background: #dcfce7; color: #166534; }
[data-theme="dark"] .flash-error { background: rgba(196, 92, 92, 0.18); color: #e07a7a; }
[data-theme="dark"] .flash-success { background: rgba(46, 125, 111, 0.2); color: #4caf9a; }

@media (max-width: 640px) {
    .auth-card { margin: 1.5rem auto; }
    .settings-card { padding: 1.25rem 1.1rem 1.15rem; }
    .theme-option { font-size: 0.68rem; padding: 0.44rem 0.2rem; }
}

/* ---- Clubs feature (mockup additions) ---- */

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-right: auto;
    min-width: 0;
    position: relative;
}
.header-brand .logo { margin-right: 0; }

.club-switcher { position: static; min-width: 0; }
.club-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    max-width: 220px;
    padding: 0.38rem 0.45rem 0.38rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.club-switcher-btn:hover { background: var(--bg-card); border-color: var(--text-muted); }
.club-switcher-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary);
}
.club-switcher-btn[aria-expanded="true"] {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.club-switcher-btn .club-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.club-switcher-btn .material-icons {
    font-size: 20px;
    color: var(--text-muted);
}

.club-menu {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 272px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    z-index: 200;
    display: none;
}
.club-menu.is-open,
.club-menu:not([hidden]) { display: block; }
.club-menu[hidden] { display: none !important; }

.club-menu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.6rem 0.65rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.club-menu-item .material-icons {
    font-size: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.club-menu-item .item-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.club-menu-item:hover,
.club-menu-item:focus-visible {
    background: var(--primary-soft);
    outline: none;
}
.club-menu-item.is-current {
    font-weight: 600;
}
.club-menu-item.is-current .material-icons { color: var(--primary); }
.club-menu-item.create .material-icons { color: var(--primary); }

@media (max-width: 640px) {
    .header-brand { grid-area: logo; margin-right: 0; }
    .header-brand .logo { grid-area: unset; }
    .club-switcher-btn {
        max-width: 148px;
        font-size: 0.82rem;
        padding: 0.32rem 0.35rem 0.32rem 0.7rem;
    }
    .club-menu {
        width: min(272px, calc(100vw - 1.5rem));
    }
}

/* Invite and welcome pages */
.invite-wrap {
    max-width: 440px;
    margin: 2.25rem auto 2rem;
}
.invite-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.invite-banner {
    padding: 1.45rem 1.5rem 1.2rem;
    text-align: center;
    background: var(--primary-soft);
    border-bottom: 1px solid var(--border);
}
.invite-banner-icon {
    font-size: 28px;
    color: var(--primary);
    margin: 0 auto 0.35rem;
    display: block;
    width: 1em;
    line-height: 1;
    text-align: center;
}
.invite-kicker {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
.invite-club-name {
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.25;
    margin: 0 0 0.3rem;
}
.invite-meta {
    font-size: 0.88rem;
    color: var(--text-muted);
}
.invite-body { padding: 1.4rem 1.5rem 1.5rem; }
.invite-body .auth-form .btn,
.invite-body .btn-block { width: 100%; }
.invite-body .auth-switch { margin-top: 1.15rem; }
.invite-body h1 {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0 0 0.45rem;
    text-align: center;
}
.invite-lead {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
.invite-signed-in {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.not-you {
    text-align: center;
    margin-top: 1.1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.not-you a { color: var(--primary); text-decoration: none; font-weight: 600; }
.not-you a:hover { text-decoration: underline; }

.invite-or {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.25rem 0 1.05rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.invite-or::before,
.invite-or::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.code-input {
    text-align: center;
    letter-spacing: 0.16em;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 1.15rem;
}
.code-input::placeholder {
    letter-spacing: 0.18em;
    font-weight: 600;
    text-transform: none;
}

.welcome-page { max-width: 820px; margin: 1.25rem auto 2rem; }
.welcome-page h1 {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 0.4rem;
}
.welcome-lead {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}
.welcome-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.welcome-grid .settings-card { margin-bottom: 0; }
.welcome-grid .btn { width: 100%; }

.settings-kicker {
    color: var(--text-muted);
    margin: -1.35rem 0 1.4rem;
    font-size: 1.02rem;
}

@media (max-width: 700px) {
    .welcome-grid { grid-template-columns: 1fr; }
    .invite-wrap { margin: 0.7rem auto 0.7rem; }
    .invite-banner { padding: 1.1rem 1.25rem 0.95rem; }
    .invite-body { padding: 1.1rem 1.25rem 1.15rem; }
    .attribution { padding: 1.15rem 1rem; }
}

/* Club settings */
.invite-link-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.invite-link-row input {
    flex: 1;
    min-width: 0;
    font-size: 0.88rem;
    background: var(--bg);
}
.invite-link-row .btn {
    flex-shrink: 0;
    gap: 0.3rem;
    padding: 0.65rem 1rem;
    min-width: 0;
}
.invite-link-row .btn .material-icons { font-size: 18px; }

.invite-code-block { margin: 1.2rem 0 1.3rem; text-align: center; }
.invite-code-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.invite-code {
    display: block;
    font-size: 2.05rem;
    font-weight: 800;
    letter-spacing: 0.28em;
    padding: 0.85rem 1rem 0.85rem 1.28rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    line-height: 1.2;
    user-select: all;
}

.btn-danger {
    background: transparent;
    border: 1px solid color-mix(in srgb, var(--down) 45%, var(--border));
    color: var(--down);
}
.btn-danger:hover {
    background: rgba(196, 92, 92, 0.1);
    border-color: var(--down);
    transform: none;
    box-shadow: none;
}

.reset-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}
.reset-row .form-hint { margin: 0; flex: 1; min-width: 12rem; }

.member-list { list-style: none; margin: 0.25rem 0 0; }
.member-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0;
    border-top: 1px solid var(--border);
}
.member-row:first-child { border-top: 0; padding-top: 0.15rem; }
.member-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}
.member-name {
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
}
.admin-tag {
    margin-left: auto;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
}

@media (max-width: 640px) {
    .invite-link-row { flex-wrap: wrap; }
    .invite-link-row input { flex: 1 1 100%; }
    .invite-link-row .btn { width: 100%; }
    .invite-code { font-size: 1.65rem; letter-spacing: 0.18em; }
    .invite-club-name { font-size: 1.4rem; }
}

/* ---- Clubs feature (app additions) ---- */
.club-menu form { margin: 0; }
.club-rename-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
.club-rename-form .form-group { flex: 1; min-width: 12rem; margin-bottom: 0; }
.copy-status { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.35rem; }
.copy-status:empty { display: none; }

/* ---- Book Club additions ---- */
.card-author {
    font-size: 0.86rem; color: var(--text); opacity: 0.8; margin-bottom: 0.2rem;
    line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.cover-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6rem;
    padding: 1rem; text-align: center; color: #fbf3e4;
    background: linear-gradient(160deg, #7B2D3B 0%, #4a1a24 100%);
}
.cover-empty .material-icons { font-size: 40px; opacity: 0.85; }
.cover-empty-title {
    font-weight: 700; font-size: 0.95rem; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.search-form { display: flex; gap: 0.5rem; margin-bottom: 2rem; }
.search-form input { flex: 1; }
.add-wrap .flash a { color: inherit; font-weight: 600; }

.md-hero--book {
    aspect-ratio: auto; height: 112px;
    background: linear-gradient(120deg, var(--primary) 0%, #a8573f 100%);
}
[data-theme="dark"] .md-hero--book { background: linear-gradient(120deg, #5c2230 0%, #6e3a2b 100%); }
.md-hero--book::after { background: linear-gradient(to bottom, transparent 55%, var(--bg-card) 100%); }
.md-author { margin-top: 0.3rem; font-size: 1rem; color: var(--text); opacity: 0.85; }
.md-overview + .md-overview { margin-top: 0.8rem; }
.attribution a { color: var(--primary); font-weight: 600; text-decoration: none; }
.attribution a:hover { text-decoration: underline; }

.wtg { display: grid; gap: 0.55rem; }
.wtg h3 { margin-bottom: 0.1rem; }
.wtg-row {
    display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.75rem; align-items: start;
    padding: 0.7rem 0.85rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg);
}
.wtg-label { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; font-size: 0.9rem; padding-top: 0.35rem; }
.wtg-label .material-icons { font-size: 20px; color: var(--primary); }
.wtg-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.wtg-link {
    display: inline-grid; grid-template-columns: auto auto; column-gap: 0.4rem; align-items: center;
    padding: 0.4rem 0.75rem; border-radius: 10px; text-decoration: none; color: var(--text);
    background: var(--bg-card); border: 1px solid var(--border); transition: border-color 0.2s, box-shadow 0.2s;
}
.wtg-link:hover { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.wtg-link:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.wtg-link-label { font-weight: 600; font-size: 0.88rem; }
.wtg-link-hint { grid-column: 1; grid-row: 2; font-size: 0.72rem; color: var(--text-muted); line-height: 1.25; }
.wtg-ext { grid-column: 2; grid-row: 1 / span 2; font-size: 16px; color: var(--text-muted); }

@media (max-width: 640px) {
    .md-hero--book { height: 96px; }
    .wtg-row { grid-template-columns: 1fr; gap: 0.45rem; }
    .wtg-label { padding-top: 0; }
    .wtg-link { flex: 1 1 calc(50% - 0.5rem); }
    .card-author { font-size: 0.8rem; }
    /* Keep the logo, club switcher and avatar on one row at phone widths. */
    .header-inner { grid-template-columns: minmax(0, 1fr) auto; }
    .header-brand { min-width: 0; gap: 0.55rem; }
    .header-brand .logo { font-size: 1.4rem; flex: none; }
    .logo-mark { width: 30px; height: 30px; margin-right: 0.4rem; }
    .club-switcher { min-width: 0; flex: 0 1 auto; }
    .club-switcher-btn { max-width: 100%; }
    .md-genres .md-genre:nth-child(n+5) { display: none; }
}

/* Dark mode: --primary is a light rose for text on dark cards; filled buttons use a deeper shade so white text stays readable. */
[data-theme="dark"] .btn-primary,
[data-theme="dark"] .avatar-btn,
[data-theme="dark"] .member-avatar { background: #a94456; }
[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .avatar-btn:hover { background: #b84f62; }
