:root {
    --ink: #1f2328;
    --muted: #5b6570;
    --border: #dde1e5;
    --bg: #ffffff;
    --bg-alt: #f6f7f8;
    --accent: #09f;
    --accent-hover: rgb(35, 167, 255);
    --error: #b3261e;
    --error-bg: #fdecea;
    --notice: #1e5b3a;
    --notice-bg: #e8f5ec;
    --radius: 6px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ink: #e7eaed;
        --muted: #9aa4ad;
        --border: #33393f;
        --bg: #17191c;
        --bg-alt: #202327;
        --accent: #09f;
        --accent-hover: rgb(35, 167, 255);
        --error: #f2897f;
        --error-bg: #3a2223;
        --notice: #7fd7a3;
        --notice-bg: #17301f;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --ink: #e7eaed;
    --muted: #9aa4ad;
    --border: #33393f;
    --bg: #17191c;
    --bg-alt: #202327;
    --accent: #09f;
    --accent-hover: rgb(35, 167, 255);
    --error: #f2897f;
    --error-bg: #3a2223;
    --notice: #7fd7a3;
    --notice-bg: #17301f;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    margin: 0;
    line-height: 1.5;
}

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

h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h1:first-child { margin-top: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Header / nav */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.site-header .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--ink);
}
.brand svg { height: 1.7rem; width: auto; }
.brand svg path { fill: currentColor; }

.site-header nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.site-header nav a i, .brand i { margin-right: 0.3rem; color: var(--accent); }
.brand i { color: inherit; }

.theme-toggle {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.theme-toggle-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.theme-toggle-track {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--border);
    flex: none;
    transition: background 0.15s ease;
}

.theme-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.15s ease;
}

.theme-toggle-input:checked ~ .theme-toggle-track {
    background: var(--accent);
}

.theme-toggle-input:checked ~ .theme-toggle-track .theme-toggle-thumb {
    transform: translateX(18px);
}

.theme-toggle-input:focus-visible ~ .theme-toggle-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle-icon {
    width: 1.1rem;
    font-size: 1rem;
    text-align: center;
    color: var(--accent);
}

/* Higher-specificity ancestor qualifier so this beats Font Awesome's
   injected .svg-inline--fa { display: inline-block } rule, which otherwise
   ties on specificity and wins on source order, keeping both icons visible. */
.theme-toggle .theme-toggle-icon-dark { display: none; }
.theme-toggle .theme-toggle-input:checked ~ .theme-toggle-icon-dark { display: inline-block; }
.theme-toggle .theme-toggle-input:checked ~ .theme-toggle-icon-light { display: none; }

.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    padding: 2rem 1rem;
    border-top: 1px solid var(--border);
}

/* Notices */
.notice {
    background: var(--notice-bg);
    color: var(--notice);
    border: 1px solid var(--notice);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

.error, ul.error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    list-style: none;
    margin: 0 0 1rem;
}
ul.error li { margin: 0.2rem 0; }

/* Forms (shared: login, upload, edit, submit) */
form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    max-width: 640px;
    margin-bottom: 1.5rem;
}

form.filters {
    max-width: none;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filters-search {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.filters-search label {
    font-size: 0.9rem;
    color: var(--muted);
}
.search-input-wrap { position: relative; }
.search-input-wrap i {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}
.filters-search input[type="text"] {
    width: 100%;
    padding: 0.65rem 0.75rem 0.65rem 2.3rem;
    font-size: 1.05rem;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}
.filters-grid label { flex: initial; }

.filters-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}
.filters-actions button { align-self: center; }

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: var(--muted);
}

input, select, textarea {
    font: inherit;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--ink);
    background: var(--bg);
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.9rem; }

button {
    font: inherit;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    align-self: flex-start;
}
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: var(--error); border-color: var(--error); }
button.danger:hover { background: #8f1d17; border-color: #8f1d17; }
button[type="button"] {
    background: var(--bg);
    color: var(--accent-hover);
    border-color: var(--border);
}
button[type="button"]:hover { background: var(--bg-alt); color: var(--accent-hover); }

.passage-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: flex-end;
    border-top: 1px dashed var(--border);
    padding-top: 0.6rem;
}
.passage-row label { flex: 1 1 100px; }

.church-results {
    list-style: none;
    margin: 0;
    padding: 0;
    max-width: 400px;
}
.church-results li {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-top: none;
    cursor: pointer;
}
.church-results li:first-child { border-top: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.church-results li:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.church-results li:hover { background: var(--bg-alt); }
.church-selected { font-weight: 600; margin: 0; }

/* Browse table */
table.sermon-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
table.sermon-list th, table.sermon-list td {
    text-align: left;
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.sermon-list th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.02em; }
table.sermon-list td.tags { max-width: 220px; }
table.sermon-list tbody tr:nth-child(even) { background: var(--bg-alt); }
.table-scroll { overflow-x: auto; }

.tag-list { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag-pill {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.4;
    white-space: nowrap;
}
.tag-pill:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

.add-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.add-new-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }

.admin-row-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}
.admin-row-actions form { display: contents; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--accent);
    background: var(--bg);
    cursor: pointer;
    font: inherit;
}
.icon-btn:hover { background: var(--accent); color: #fff; text-decoration: none; }
.icon-btn.danger { color: var(--error); border-color: var(--error); background: var(--bg); }
.icon-btn.danger:hover { background: var(--error); color: #fff; }
.icon-btn { align-self: center; }

.read-btn, .btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}
.read-btn:hover, .btn-outline:hover {
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

.btn-outline.btn-danger { border-color: var(--error); color: var(--error); }
.btn-outline.btn-danger:hover { background: var(--error); color: #fff; }

.pagination { display: flex; gap: 0.6rem; margin-top: 1.2rem; }
.pagination strong { color: var(--accent); }

/* Admin edit/upload sidebar layout */
.edit-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    align-items: start;
    max-width: none;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    padding: 0 1.5rem;
}
.edit-form { max-width: none; }
.edit-form fieldset:has(#editor) {
    max-width: 900px;
    margin: 0 auto;
}
#editor.editorjs-holder {
    min-height: 18rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1rem 1rem 3.5rem;
    background: #fff;
    color: #1f2328;
}
.edit-sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    direction: rtl;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.edit-sidebar > * { direction: ltr; }
.edit-sidebar::-webkit-scrollbar { width: 6px; }
.edit-sidebar::-webkit-scrollbar-track { background: transparent; }
.edit-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.edit-sidebar::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

.sidebar-links { display: flex; gap: 0.5rem; }
.sidebar-links .btn-outline {
    flex: 1 1 0;
    justify-content: center;
    text-align: center;
    white-space: normal;
    font-size: 0.78rem;
    padding: 0.45rem 0.5rem;
}
.sidebar-actions { display: flex; gap: 0.5rem; }
.sidebar-actions form { display: contents; }

@media (max-width: 900px) {
    .edit-layout { grid-template-columns: 1fr; }
    .edit-sidebar { position: static; max-height: none; overflow-y: visible; direction: ltr; }
}

/* Author profile page */
.author-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 0.5rem;
}
.author-photo {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    object-fit: cover;
    flex: none;
}
.author-heading { text-align: left; }
.author-heading h1 { margin: 0 0 0.4rem; }
.author-heading .author-bio { margin-left: auto; }
.author-bio { max-width: 640px; }
.author-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0 1.25rem; }

.author-photo-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
}

.author-avatar-cell { width: 1%; }
.author-avatar {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}
.author-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--muted);
}

@media (max-width: 640px) {
    .author-header { flex-direction: column; text-align: center; }
    .author-heading { text-align: center; }
    .author-heading .author-bio { margin-left: 0; }
}

.social-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: flex-end;
    border-top: 1px dashed var(--border);
    padding-top: 0.6rem;
}
.social-row label { flex: 1 1 160px; }

/* Sermon page */

article.sermon {
    width: 750px;
    max-width: 100%;
    margin: 0 auto;
}

.sermon-meta {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    margin: 1.25rem 0;
}
.meta-tile {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
}
.meta-tile-wide { grid-column: 1 / -1; }
.meta-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.meta-label i { width: 1.1em; text-align: center; color: var(--accent); }
.meta-value { font-size: 0.98rem; }
.meta-tile .passage-list, .meta-tile .tag-list { margin-top: 0.1rem; }
.passage-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0;
    padding: 0;
}
.passage-list li {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    font-size: 0.85rem;
}
.primary-badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-left: 0.35rem;
}

.sermon-actions { display: flex; gap: 0.6rem; margin: 1.5rem 0; }

.share-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 1rem 0 1.5rem;
}

.tinylytics_kudos { margin: 0.5rem 0 1.5rem; }
.share-label {
    color: var(--muted);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--accent);
    font: inherit;
    background: var(--bg);
    cursor: pointer;
}
.share-btn:hover {
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

.video-embed {
    position: relative;
    aspect-ratio: 16 / 9;
    margin: 1.5rem 0;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-alt);
}
.video-embed iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.sermon-text, .original-text {
    font-size: 18px;
    line-height: 31px;
}
.sermon-text p, .original-text p { margin: 0 0 1rem; }

.sermon h1, .original-text h1 { font-size: 47px; line-height: 75px; }
.sermon h2, .original-text h2 { font-size: 37px; line-height: 59px; }
.sermon h3, .original-text h3 { font-size: 29px; line-height: 48px; }
.sermon h4, .original-text h4 { font-size: 23px; line-height: 39px; }
.sermon h5, .original-text h5 { font-size: 18px; line-height: 31px; }
.sermon h6, .original-text h6 { font-size: 14px; line-height: 26px; }

details { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 640px) {
    .site-header { flex-direction: column; align-items: flex-start; }
    .filters-grid { grid-template-columns: 1fr; }
    .filters-actions { justify-content: stretch; }
    .filters-actions button { flex: 1; }
    .sermon-meta { grid-template-columns: 1fr; }
}
