:root {
    --bg: #fffaf2;
    --bg-soft: #f3ece0;
    --text: #2a1a08;
    --text-muted: #82715b;
    --border: #ecdfca;
    --accent: #c2410c;        /* warm rust */
    --accent-soft: #fde7d3;
    --chip-bg: #efe4cf;
    --chip-text: #6b3a1a;
    --shadow: 0 1px 4px rgba(80, 40, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter",
                 "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;     /* kills double-tap zoom + 300ms tap delay; keeps pinch */
}

body { padding-bottom: 88px; min-height: 100vh; }
.hidden { display: none !important; }
.screen { padding: 12px 16px; }

.screen-title {
    margin: 8px 4px 16px;
    font-size: 24px;
    font-weight: 700;
}

/* --- Hero (Discover header) ----------------------------------------- */

.hero {
    margin: 4px 4px 18px;
}
.hero-title {
    font-size: 30px;
    font-weight: 800;
    margin: 0;
    letter-spacing: -0.01em;
}
.hero-tag {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
    font-style: italic;
}

/* --- Currently-reading carousel ------------------------------------- */

.reading-carousel { margin-bottom: 14px; }

.reading-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 0 6px;
    scrollbar-width: none;
}
.reading-row::-webkit-scrollbar { display: none; }

.reading-card {
    width: 100px;
    flex-shrink: 0;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    box-shadow: var(--shadow);
    font: inherit; color: inherit;
}
.reading-card .book-cover {
    width: 84px;
    height: 126px;
    margin-bottom: 6px;
}
.reading-card-body {
    background: none; border: none; padding: 0;
    text-align: left; font: inherit; color: inherit;
    cursor: pointer;
    width: 100%;
}
.reading-card-title {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-bottom: 4px;
}
.finished-btn {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 6px 4px;
    border: 1px solid var(--accent);
    background: var(--bg);
    color: var(--accent);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.progress-bar {
    height: 6px;
    background: var(--bg-soft);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 200ms ease;
}
.progress-pct {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    text-align: right;
}

.progress-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0 4px;
    flex-wrap: wrap;
}
.pages-input {
    width: 80px;
    padding: 6px 8px;
    /* font-size inherits from .text-input (16px) so iOS doesn't zoom */
}

/* --- Search bar ----------------------------------------------------- */

.search-bar {
    margin-bottom: 14px;
}
.search-bar input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;             /* iOS won't auto-zoom at >=16px */
    -webkit-appearance: none;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
}

/* --- Chip filter (shelf statuses) ----------------------------------- */

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.chip {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chip-active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

/* --- Book list ------------------------------------------------------ */

.book-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 8px;
}

.book {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    text-align: left;
    width: 100%;
    font: inherit;
    color: inherit;
}

.book-cover {
    width: 56px;
    height: 84px;
    border-radius: 8px;
    background: var(--chip-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    flex-shrink: 0;
    overflow: hidden;
}
.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.add-btn {
    margin-top: 8px;
    padding: 6px 12px;
    border: 1px solid var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.add-btn:disabled {
    background: var(--bg-soft);
    color: var(--text-muted);
    border-color: var(--border);
    cursor: default;
}

.section-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 6px 4px 4px;
}

.book-body { min-width: 0; }

.book-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 2px;
    overflow-wrap: anywhere;
}

.book-author {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 8px;
}

.book-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 11px;
}

.tag {
    background: var(--chip-bg);
    color: var(--chip-text);
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
}

.tag-status {
    background: var(--accent-soft);
    color: var(--accent);
}

.book-counts {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 6px;
}

/* --- Profile -------------------------------------------------------- */

.profile-body {
    background: var(--bg-soft);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.profile-row { display: flex; justify-content: space-between; align-items: center; }
.profile-key { color: var(--text-muted); font-size: 13px; }
.profile-val { font-weight: 700; font-size: 16px; }

/* --- Clubs ---------------------------------------------------------- */

.clubs-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.clubs-actions .primary-btn,
.clubs-actions .secondary-btn { flex: 1; }

.secondary-btn {
    background: var(--bg);
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.club-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.club-card {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    text-align: left;
    width: 100%;
    font: inherit;
    color: inherit;
}

.club-mini-cover {
    width: 56px;
    height: 84px;
    border-radius: 8px;
    background: var(--chip-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    overflow: hidden;
    flex-shrink: 0;
}
.club-mini-cover img { width: 100%; height: 100%; object-fit: cover; }

.club-card-name {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 4px;
}
.club-card-meta {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
}

/* Detail */

.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0 8px;
}
.club-header { margin-bottom: 12px; }
.club-meta { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 4px; }

.invite-pill {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
}
.members-pill {
    background: var(--chip-bg);
    color: var(--chip-text);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
}
.share-pill {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.current-pick { margin-bottom: 14px; }
.current-pick .empty-pick {
    background: var(--bg-soft);
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 18px;
    text-align: center;
    color: var(--text-muted);
}
.current-pick .change-pick-btn {
    margin-top: 8px;
    width: 100%;
    padding: 9px;
    border: 1px solid var(--accent);
    background: var(--bg);
    color: var(--accent);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.member-status {
    background: var(--bg-soft);
    border-radius: 12px;
    padding: 8px 12px;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.member-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    padding: 4px 0;
}
.member-name { font-weight: 600; }
.member-status-tag { color: var(--text-muted); font-size: 12px; }

.past-picks {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 14px;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.past-picks::-webkit-scrollbar { display: none; }
.past-pick {
    width: 64px;
    flex-shrink: 0;
    text-align: center;
    cursor: pointer;
}
.past-pick .book-cover {
    width: 64px;
    height: 96px;
    margin-bottom: 4px;
}
.past-pick .past-title {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.club-actions {
    margin-top: 18px;
    display: flex;
    justify-content: center;
}

/* Inputs in dialogs */
.text-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;             /* iOS won't auto-zoom at >=16px */
    -webkit-appearance: none;
}
.text-input:focus { outline: none; border-color: var(--accent); }

/* --- Footer / version badge ----------------------------------------- */

.app-footer {
    text-align: center;
    padding: 16px 16px 8px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.6;
}

/* --- Bottom tabbar -------------------------------------------------- */

.tabbar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}

.tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 4px;
    border: none; background: transparent;
    color: var(--text-muted);
    font-size: 11px; font-weight: 500;
    cursor: pointer;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab-active { color: var(--accent); }

/* --- Book dialog ---------------------------------------------------- */

.dialog {
    border: none;
    border-radius: 18px;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    width: min(90vw, 360px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-body {
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.dialog-cover {
    align-self: center;
    width: 96px;
    height: 138px;
    border-radius: 10px;
    background: var(--chip-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 50px;
    overflow: hidden;
}
.dialog-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.dialog-title { margin: 0; font-size: 20px; font-weight: 800; text-align: center; }
.dialog-author { margin: 0; color: var(--text-muted); font-size: 14px; text-align: center; }
.dialog-blurb { margin: 4px 0 0; font-size: 14px; line-height: 1.45; }

.dialog-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}
.status-btn {
    flex: 1;
    padding: 10px 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.status-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.rating-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0 4px;
}
.rating-row[hidden] { display: none; }
.rating-label { font-size: 13px; color: var(--text-muted); }
.stars { font-size: 22px; letter-spacing: 4px; cursor: pointer; user-select: none; }
.star { opacity: 0.35; transition: opacity 100ms; }
.star.lit { opacity: 1; }

.dialog-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
}
.link-btn {
    background: none; border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
}
.link-btn-danger {
    color: #b91c1c;
    font-weight: 700;
}
.primary-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
