/* Bible Memory Pills - shared styles. Colours come from the MFM Teens logo. */

:root {
    --plum: #4a1f5c;
    --plum-light: #6b2d7b;
    --plum-soft: #f3e9f5;
    --red: #d62839;
    --flame: #f59e0b;
    --gold: #ffc83d;
    --gold-soft: #fff3d1;
    --cream: #fff8ec;
    --card: #ffffff;
    --ink: #24152b;
    --muted: #6e6077;
    --line: #eadfcf;
    --green: #1f9d55;
    --green-soft: #e3f6ea;
    --red-soft: #fde7e9;
    --radius: 16px;
    --shadow: 0 2px 4px rgba(74, 31, 92, 0.06), 0 8px 24px rgba(74, 31, 92, 0.08);
    --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --scripture: "Lora", Georgia, "Times New Roman", serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--cream);
}

main { flex: 1; }

[hidden] { display: none !important; }

a { color: var(--plum-light); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }

.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ---------- Header & footer ---------- */

.site-header {
    background: var(--plum);
    color: #fff;
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 1.15rem;
}

.brand img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
}

.site-nav { display: flex; gap: 4px; }

.site-nav a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 999px;
}

.site-nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.site-nav a.active { color: var(--plum); background: var(--gold); }

.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    padding: 24px 16px;
}

/* ---------- Building blocks ---------- */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 10px 22px;
    border: 2px solid transparent;
    border-radius: 999px;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible, .option-btn:focus-visible, .choice input:focus-visible + span { outline: 3px solid var(--flame); outline-offset: 2px; }

.btn-primary { background: var(--red); color: #fff; box-shadow: 0 4px 0 #a51d2b; }
.btn-primary:hover { background: #c22232; }
.btn-secondary { background: var(--plum); color: #fff; }
.btn-secondary:hover { background: var(--plum-light); }
.btn-ghost { background: transparent; color: var(--plum); border-color: var(--line); }
.btn-ghost:hover { background: var(--plum-soft); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.15rem; }

label.field { display: block; font-weight: 700; margin-bottom: 6px; }

.input, select.input, textarea.input {
    width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    border: 2px solid var(--line);
    border-radius: 12px;
    font: inherit;
    color: var(--ink);
    background: #fff;
}

.input:focus { outline: none; border-color: var(--plum-light); box-shadow: 0 0 0 3px var(--plum-soft); }

textarea.input { min-height: 120px; resize: vertical; }

.hint { color: var(--muted); font-size: 0.9rem; }

.form-error { color: var(--red); font-weight: 700; margin: 8px 0 0; }

.section-title {
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 24px 0 10px;
}

/* ---------- Home page ---------- */

.hero {
    background: linear-gradient(160deg, var(--plum) 0%, var(--plum-light) 100%);
    color: #fff;
    padding: 40px 0 88px;
    text-align: center;
}

.hero img {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 6px rgba(255, 200, 61, 0.35);
}

.hero h1 { font-size: clamp(2rem, 6vw, 3rem); font-weight: 900; margin: 16px 0 8px; }
.hero h1 span { color: var(--gold); }
.hero p { max-width: 560px; margin: 0 auto; color: rgba(255, 255, 255, 0.85); font-size: 1.1rem; }

.start-card { margin-top: -56px; position: relative; }

/* Selectable tiles (difficulty and category) */
.choices { display: grid; gap: 10px; }
.choices-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }

.choice span {
    display: block;
    height: 100%;
    padding: 14px 16px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: #fff;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.choice strong { display: block; font-size: 1.05rem; }
.choice small { display: block; color: var(--muted); }
.choice .tag {
    display: inline-block;
    margin-top: 6px;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--plum-light);
    background: var(--plum-soft);
    padding: 2px 8px;
    border-radius: 999px;
}

.choice:hover span { border-color: var(--plum-light); }
.choice input:checked + span { border-color: var(--plum); background: var(--plum-soft); box-shadow: inset 0 0 0 1px var(--plum); }

#books-list {
    margin-top: 12px;
    padding: 16px;
    border: 2px dashed var(--line);
    border-radius: 14px;
}

#books-list h3 { font-size: 0.95rem; color: var(--plum); margin: 4px 0 8px; }
#books-list h3:not(:first-child) { margin-top: 16px; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; }
.book-grid label { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.book-grid input { width: 18px; height: 18px; accent-color: var(--plum); }

.how-to { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 24px 0; }
.how-to .card { padding: 20px; }
.how-to h3 { font-size: 1.05rem; color: var(--plum); }
.how-to p, .how-to ul { margin: 0; color: var(--muted); }
.how-to ul { padding-left: 18px; }

/* ---------- Quiz page ---------- */

.quiz-main { padding: 20px 0 32px; }

.hud {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.stat-label { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 900; color: var(--plum); }
.stat-graces .stat-value { color: var(--red); }
.stat-value.bump { animation: bump 0.4s ease; }

@keyframes bump { 50% { transform: scale(1.3); } }

.timer-bar {
    position: relative;
    height: 28px;
    background: var(--plum-soft);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 16px;
}

.timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--flame), var(--gold));
    border-radius: 999px;
    transition: width 1s linear, background 0.3s ease;
}

.timer-bar.low .timer-fill { background: var(--red); }

#timer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: var(--ink);
}

.question-card { text-align: center; padding: 28px 24px; }

.question-label { margin: 0 0 8px; font-size: 0.8rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--flame); }

#question-text {
    font-family: var(--scripture);
    font-size: clamp(1.25rem, 3.2vw, 1.75rem);
    font-weight: 500;
    line-height: 1.5;
    margin: 0;
}

#question-text.reference { font-family: var(--font); font-weight: 900; color: var(--plum); font-size: clamp(1.8rem, 6vw, 2.6rem); }

.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }

.option-btn {
    min-height: 72px;
    padding: 14px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    color: var(--plum);
    font: inherit;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 3px 0 var(--line);
    transition: transform 0.1s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.option-btn:hover { border-color: var(--plum-light); background: var(--plum-soft); }
.option-btn:active { transform: translateY(2px); box-shadow: none; }
.option-btn.is-correct { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.option-btn.is-wrong { background: var(--red-soft); border-color: var(--red); color: var(--red); }

#answer-area { margin-top: 16px; }

.reference-pickers { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }

.answer-actions { display: flex; gap: 10px; margin-top: 12px; }
.answer-actions .btn-primary { flex: 1; }

.mic-btn.listening { background: var(--red); color: #fff; border-color: var(--red); animation: pulse 1.2s ease infinite; }

@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(214, 40, 57, 0.2); } }

.quiz-controls { display: flex; justify-content: space-between; gap: 10px; margin-top: 24px; }

/* ---------- Message dialog ---------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(36, 21, 43, 0.55);
    animation: fade 0.15s ease;
}

.modal-box {
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--card);
    border-radius: 20px;
    padding: 28px 24px 24px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: pop 0.2s ease;
}

.modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 2rem;
    font-weight: 900;
    background: var(--plum-soft);
    color: var(--plum);
}

.modal.good .modal-icon { background: var(--green-soft); color: var(--green); }
.modal.bad .modal-icon { background: var(--red-soft); color: var(--red); }
.modal.gold .modal-icon { background: var(--gold-soft); color: var(--flame); }

.modal h2 { font-size: 1.5rem; }
.modal-body { color: var(--muted); margin-bottom: 20px; }
.modal-body .answer { display: block; margin-top: 8px; padding: 12px; border-radius: 12px; background: var(--cream); color: var(--ink); font-family: var(--scripture); font-size: 1.05rem; }
.modal-body .answer.reference { font-family: var(--font); font-weight: 900; color: var(--plum); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }

/* ---------- Leaderboard ---------- */

.page-head { padding: 32px 0 8px; text-align: center; }
.page-head h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); font-weight: 900; color: var(--plum); }

.tabs {
    display: inline-flex;
    padding: 4px;
    margin-bottom: 16px;
    background: var(--plum-soft);
    border-radius: 999px;
}

.tabs button {
    min-height: 40px;
    padding: 6px 18px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    font: inherit;
    font-weight: 800;
    color: var(--plum);
    cursor: pointer;
}

.tabs button.active { background: var(--plum); color: #fff; }

.leaderboard-card { padding: 8px; overflow-x: auto; }

.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th { text-align: left; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 12px; }
.leaderboard-table td { padding: 12px; border-top: 1px solid var(--line); }
.leaderboard-table td:first-child { width: 56px; font-weight: 900; color: var(--muted); }
.leaderboard-table td:nth-child(2) { font-weight: 700; word-break: break-word; }
.leaderboard-table td:nth-child(3) { font-weight: 900; color: var(--plum); }
.leaderboard-table td:nth-child(4) { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

.rank-badge { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; font-weight: 900; }
.rank-1 .rank-badge { background: var(--gold); color: var(--plum); }
.rank-2 .rank-badge { background: #dfe3e8; color: #4b5563; }
.rank-3 .rank-badge { background: #f1c9a5; color: #7c4a1e; }

.leaderboard-table tr.me td { background: var(--gold-soft); }
.leaderboard-table tr.me td:nth-child(2)::after { content: " (you)"; color: var(--flame); font-weight: 800; }

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

.cta-row { text-align: center; margin: 24px 0; }

/* ---------- Admin ---------- */

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.admin-grid .full { grid-column: 1 / -1; }
.status { margin-top: 12px; padding: 12px 14px; border-radius: 12px; font-weight: 700; }
.status.ok { background: var(--green-soft); color: var(--green); }
.status.err { background: var(--red-soft); color: var(--red); }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
    body { font-size: 16px; }
    .site-header .container { flex-wrap: wrap; justify-content: center; padding-top: 8px; padding-bottom: 8px; }
    .brand span { display: none; }
    .card { padding: 18px; }
    .option-grid { grid-template-columns: 1fr; }
    .option-btn { min-height: 60px; }
    .reference-pickers { grid-template-columns: 1fr 1fr; }
    .reference-pickers > :first-child { grid-column: 1 / -1; }
    .admin-grid { grid-template-columns: 1fr; }
    .leaderboard-table td:nth-child(4), .leaderboard-table th:nth-child(4) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Admin book autocomplete */
.autocomplete { position: relative; }
.autocomplete-items {
    position: absolute;
    z-index: 5;
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 2px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.autocomplete-items div { padding: 8px 14px; cursor: pointer; }
.autocomplete-items div:hover, .autocomplete-active { background: var(--plum-soft); }
