/* Bees, Bots & Balance · Listen — mobile-first reading player */
:root {
    --ink: #1a1a1a;
    --ink-soft: #5f6368;
    --paper: #faf8f4;
    --card: #ffffff;
    --line: #e8e2d6;
    --accent: #b8860b;        /* honey */
    --accent-soft: #fdf3dc;
    --blue: #3182ce;
    --danger: #c62828;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--paper);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ---------- loading bar ---------- */
#loading-bar {
    position: fixed; top: 0; left: 0; width: 100%; height: 3px;
    background: linear-gradient(90deg, #b8860b, #e6b422);
    transform: scaleX(0); transform-origin: left; opacity: 0; z-index: 99999;
    transition: opacity 0.2s;
}
#loading-bar.active { opacity: 1; animation: loading-bar 1.5s ease-in-out infinite; }
@keyframes loading-bar { 0% { transform: scaleX(0); } 50% { transform: scaleX(0.7); } 100% { transform: scaleX(1); } }

/* ---------- login ---------- */
#login-screen {
    position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
    background: var(--paper); padding: 24px;
}
.login-card { text-align: center; max-width: 320px; }
.login-bee { font-size: 56px; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; margin: 0 0 4px; }
.login-card p { color: var(--ink-soft); margin: 0 0 24px; }
.btn-login { width: 100%; padding: 14px; font-size: 16px; }

/* ---------- buttons ---------- */
.btn-primary {
    background: var(--accent); color: #fff; border: none; border-radius: 8px;
    padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.6; }
.btn-secondary {
    background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
    padding: 10px 18px; font-size: 14px; cursor: pointer;
}
.btn-ghost {
    background: none; border: none; color: var(--accent); font-size: 15px;
    cursor: pointer; padding: 8px; font-weight: 600; white-space: nowrap;
}
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; cursor: pointer; }

/* ---------- chapter list ---------- */
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 16px 10px; max-width: 44rem; margin: 0 auto;
}
.app-header-title { display: flex; align-items: center; gap: 10px; }
.app-header-title .bee { font-size: 28px; }
.app-header h1 { font-size: 19px; margin: 0; line-height: 1.2; }
.app-header .subtitle { font-size: 13px; color: var(--ink-soft); }

#resume-banner { max-width: 44rem; margin: 4px auto 0; padding: 0 16px; }
.resume-btn {
    width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
    background: var(--accent); color: #fff; border: none; border-radius: 12px;
    padding: 14px 16px; font-size: 15px; cursor: pointer; font-weight: 600;
}
.resume-play { font-size: 18px; }

.chapter-list { list-style: none; margin: 12px auto; padding: 0 16px; max-width: 44rem; }
.chapter-item {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    padding: 14px 16px; margin-bottom: 10px; cursor: pointer;
}
.chapter-item:active { background: var(--accent-soft); }
.chapter-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chapter-item h2 { font-size: 16px; margin: 0; line-height: 1.3; }
.chapter-meta { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.chapter-sub { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 13px; color: var(--ink-soft); }
.chapter-progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.chapter-progress > div { height: 100%; background: var(--accent); border-radius: 2px; }
.comment-count { color: var(--accent); font-weight: 600; }
.empty-state { text-align: center; color: var(--ink-soft); padding: 48px 16px; }

/* ---------- skeleton ---------- */
.skeleton-container { padding: 12px 16px; max-width: 44rem; margin: 0 auto; }
.skeleton-row {
    height: 72px; margin-bottom: 10px; border-radius: 12px;
    background: linear-gradient(90deg, #f0ece3 25%, #e6e0d2 50%, #f0ece3 75%);
    background-size: 200% 100%; animation: skeleton-shimmer 1.5s ease-in-out infinite;
}
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- reader ---------- */
.reader-header {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 10px 8px;
}
.reader-title {
    font-size: 14px; font-weight: 600; text-align: center; flex: 1;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#follow-btn { color: var(--ink-soft); }
#follow-btn.follow-on { color: var(--accent); }

.reader-blocks {
    max-width: 42rem; margin: 0 auto; padding: 20px 20px 24px;
    font-family: Charter, Georgia, 'Times New Roman', serif;
    font-size: 1.16rem; line-height: 1.72;
}
.block { position: relative; padding: 2px 6px; margin: 0 -6px 1.15em; border-radius: 8px; cursor: pointer; }
.block.h1 { font-size: 1.5em; font-weight: 700; line-height: 1.3; margin-top: 0.4em; font-family: -apple-system, BlinkMacSystemFont, sans-serif; }
.block.h2 { font-size: 1.2em; font-weight: 700; line-height: 1.35; margin-top: 1.4em; font-family: -apple-system, BlinkMacSystemFont, sans-serif; }
.block.quote { font-style: italic; color: var(--ink-soft); border-left: 3px solid var(--line); padding-left: 14px; }
.block.playing { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.block.scene-after { margin-bottom: 2.2em; }
.block.scene-after::after {
    content: '· · ·'; position: absolute; left: 0; right: 0; bottom: -1.7em;
    text-align: center; color: var(--ink-soft); font-size: 0.85em; letter-spacing: 6px;
    pointer-events: none;
}
.block .cmark {
    position: absolute; top: 2px; right: -4px;
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
    font-family: -apple-system, sans-serif; border-radius: 10px; padding: 2px 7px;
    line-height: 1.2;
}
.block .cmark.orphan { background: #e6a23c; }

/* ---------- player bar ---------- */
.player-bar-spacer { height: calc(84px + var(--safe-bottom)); }
.player-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    background: #fffdf8; border-top: 1px solid var(--line);
    padding: 10px 10px calc(10px + var(--safe-bottom));
}
.pb-btn {
    background: none; border: none; font-size: 19px; cursor: pointer; color: var(--ink);
    padding: 10px; border-radius: 10px; min-width: 44px; line-height: 1;
}
.pb-btn:active { background: var(--accent-soft); }
.pb-play {
    font-size: 24px; background: var(--accent); color: #fff; border-radius: 50%;
    width: 56px; height: 56px; min-width: 56px; display: flex; align-items: center; justify-content: center;
}
.pb-right { display: flex; align-items: center; gap: 2px; margin-left: 4px; }
.pb-time { font-size: 11px; color: var(--ink-soft); text-align: center; line-height: 1.3; min-width: 44px; font-variant-numeric: tabular-nums; }
.pb-time span { color: #b0aa9d; }
.pb-speed { font-size: 14px; font-weight: 700; color: var(--accent); }
.pb-comment { font-size: 21px; }

/* ---------- dialog ---------- */
dialog {
    border: none; border-radius: 14px; padding: 0; max-width: 560px; width: calc(100% - 32px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--ink-soft); padding: 0; line-height: 1; }
.comment-quote {
    margin: 12px 18px 0; padding: 10px 12px; background: var(--accent-soft);
    border-left: 3px solid var(--accent); border-radius: 6px;
    font-family: Charter, Georgia, serif; font-size: 14px; line-height: 1.5;
    max-height: 110px; overflow-y: auto; color: #4a4432;
}
#comment-existing { margin: 0 18px; }
.existing-comment {
    margin-top: 10px; padding: 10px 12px; background: #f4f1ea; border-radius: 8px; font-size: 14px;
}
.existing-comment .ec-meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.existing-comment .ec-actions { margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }
.existing-comment .ec-actions button { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 13px; padding: 0; }
.existing-comment .ec-actions button.ec-del { color: var(--danger); }
.ec-resolved { opacity: 0.6; }
button.ec-inc { color: #2e7d32 !important; font-weight: 600; }
.resolved-toggle {
    background: none; border: none; color: var(--ink-soft); cursor: pointer;
    font-size: 13px; padding: 4px 0 12px; text-decoration: underline;
}
.form-group { padding: 0 18px; margin: 14px 0; }
.form-textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 16px; font-family: inherit; box-sizing: border-box; resize: vertical;
}
.form-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.15); }
.modal-actions {
    display: flex; align-items: center; justify-content: flex-end; gap: 8px;
    padding: 12px 18px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line);
}

/* ---------- follow pill ---------- */
#follow-pill {
    position: fixed; bottom: calc(96px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
    z-index: 25; background: var(--ink); color: #fff; border: none; border-radius: 999px;
    padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* ---------- add reader / admin comments ---------- */
.add-reader-form { display: flex; gap: 8px; margin-bottom: 12px; }
.form-input {
    flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 16px; background: #fff;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.comment-card .ec-meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.comment-card-quote {
    font-family: Charter, Georgia, serif; font-size: 13px; color: #6b6250;
    border-left: 3px solid var(--line); padding-left: 10px; margin-bottom: 8px; line-height: 1.45;
}
.comment-card-text { font-size: 15px; margin-bottom: 4px; }
.comment-card .ec-actions { margin-top: 8px; display: flex; gap: 14px; }
.comment-card .ec-actions button { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 13px; padding: 0; }
.comment-card .ec-actions button.ec-del { color: var(--danger); }

/* ---------- access overlay (request access) ---------- */
.access-overlay {
    position: fixed; inset: 0; z-index: 10000; background: var(--paper);
    display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center;
}
.access-overlay h1 { font-size: 24px; margin: 0 0 8px; }
.access-overlay p { color: var(--ink-soft); margin: 0 0 20px; line-height: 1.5; }
.access-overlay .btn-ghost { margin-top: 14px; }

/* ---------- users admin ---------- */
.users-sections { max-width: 44rem; margin: 0 auto; padding: 0 16px 40px; }
.users-h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin: 22px 0 10px; }
.users-empty { color: var(--ink-soft); font-size: 14px; margin: 0; }
.user-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; }
.user-card-closed { opacity: 0.65; }
.user-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-name { font-weight: 600; }
.user-email { font-size: 13px; color: var(--ink-soft); }
.user-actions { display: flex; gap: 8px; }
.chapter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
    border: 1px solid var(--line); background: #fff; border-radius: 999px;
    padding: 6px 12px; font-size: 13px; cursor: pointer; min-width: 40px;
}
.chip-on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip:disabled { opacity: 0.55; cursor: default; }

/* Bottom-sheet feel on phones */
@media (max-width: 640px) {
    dialog#comment-dialog {
        margin: auto auto 0; width: 100%; max-width: 100%;
        border-radius: 16px 16px 0 0;
    }
}
