:root {
    --bg: #0f1a2e;
    --card: #1a2744;
    --text: #e8e8e8;
    --accent: #f0c040;
    --btn: #2ecc71;
    --btn-text: #000;
    --btn-secondary: #3a5a8a;
    --error: #e74c3c;
    --subtle: #8899aa;
    --prophet-gold: #f0c040;
    --profit-green: #2ecc71;
    --celestial: #f0c040;
    --terrestrial: #8bc34a;
    --telestial: #78909c;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overscroll-behavior: none;
}

#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100%;
    padding: 1rem;
    padding-top: 60px;
}

/* --- Score Bar --- */
#score-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--card);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    border-bottom: 2px solid var(--accent);
    z-index: 100;
    gap: 8px;
}
#score-bar.hidden { display: none; }
#my-score { color: var(--accent); font-size: 1.1rem; }
.quit-btn {
    width: auto;
    padding: 4px 12px;
    font-size: 0.75rem;
    background: var(--error);
    color: #fff;
    border-radius: 6px;
}

/* --- Kingdom Badge --- */
.kingdom-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.kingdom-badge.celestial { background: var(--celestial); color: #000; }
.kingdom-badge.terrestrial { background: var(--terrestrial); color: #000; }
.kingdom-badge.telestial { background: var(--telestial); color: #fff; }
.kingdom-badge.gold { background: #f0c040; color: #000; }
.kingdom-badge.silver { background: #c0c0c0; color: #000; }
.kingdom-badge.bronze { background: #cd7f32; color: #fff; }

.kingdom-badge-sm {
    font-size: 0.6rem;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 6px;
}
.kingdom-badge-sm.celestial { background: var(--celestial); color: #000; }
.kingdom-badge-sm.terrestrial { background: var(--terrestrial); color: #000; }
.kingdom-badge-sm.telestial { background: var(--telestial); color: #fff; }
.kingdom-badge-sm.gold { background: #f0c040; color: #000; }
.kingdom-badge-sm.silver { background: #c0c0c0; color: #000; }
.kingdom-badge-sm.bronze { background: #cd7f32; color: #fff; }

/* --- Status Dots --- */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
.status-dot.online { background: #2ecc71; }
.status-dot.offline { background: #e74c3c; }

/* --- Connection Status --- */
#conn-status {
    position: fixed;
    bottom: 10px;
    right: 10px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    z-index: 100;
}
.conn-ok { background: #2ecc71; color: #000; }
.conn-wait { background: #f39c12; color: #000; }
.conn-bad { background: #e74c3c; color: #fff; }

/* --- Screens --- */
.screen {
    display: none;
    width: 100%;
    max-width: 420px;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.screen.active { display: flex; }

.hidden { display: none !important; }

/* --- Typography --- */
h1 { color: var(--accent); font-size: 2rem; margin-bottom: 0; }
h2 { color: var(--accent); font-size: 1.5rem; }
h3 { color: var(--accent); font-size: 1.25rem; }
.subtitle { color: var(--subtle); font-size: 0.95rem; margin-bottom: 0.5rem; }

/* --- Inputs --- */
input[type="text"], input[type="number"] {
    width: 85%;
    padding: 14px;
    border: 2px solid var(--btn-secondary);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 1.15rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}
input:focus { border-color: var(--accent); }
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* --- Buttons --- */
button {
    width: 85%;
    padding: 16px;
    border: none;
    border-radius: 10px;
    background: var(--btn);
    color: var(--btn-text);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}
button:active { transform: scale(0.96); }
.secondary-btn {
    background: var(--btn-secondary);
    color: var(--text);
}

/* --- MC Option Buttons --- */
.mc-option-btn {
    width: 100%;
    margin-bottom: 8px;
    background: var(--btn-secondary);
    color: var(--text);
    padding: 14px;
    font-size: 1.1rem;
    border-radius: 10px;
    text-align: left;
    padding-left: 20px;
}
.mc-option-btn:active { background: var(--accent); color: var(--btn-text); }

/* --- Repentance Mode Buttons --- */
.rep-mode-btn {
    width: 100%;
    margin-bottom: 10px;
    padding: 18px;
    font-size: 1.15rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.rep-desc {
    font-size: 0.8rem;
    font-weight: normal;
    opacity: 0.7;
}
.rep-mode-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #333;
}

/* --- Timer --- */
.timer-display {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent);
    margin: 0.5rem 0;
}
.timer-display.timer-urgent {
    color: var(--error);
    animation: pulse 0.5s infinite alternate;
}
@keyframes pulse {
    from { opacity: 1; }
    to { opacity: 0.5; }
}

/* --- Minister Note --- */
.minister-note {
    background: rgba(46, 204, 113, 0.15);
    border: 1px solid var(--profit-green);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.95rem;
    color: var(--profit-green);
    text-align: center;
    width: 100%;
}

/* --- Speed Bonus --- */
.speed-line {
    color: #29b6f6;
    font-weight: bold;
}

/* --- Dividers --- */
.divider { width: 80%; height: 1px; background: var(--btn-secondary); margin: 0.75rem 0; }
.or-divider {
    width: 80%;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--subtle);
    font-size: 0.9rem;
    margin: 0.5rem 0;
}
.or-divider::before, .or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--btn-secondary);
}

/* --- Error --- */
.error-msg { color: var(--error); font-size: 0.95rem; min-height: 1.2rem; }

/* --- Lobby --- */
#lobby-player-list {
    list-style: none;
    width: 100%;
}
#lobby-player-list li {
    background: var(--card);
    padding: 12px 16px;
    margin-bottom: 6px;
    border-radius: 8px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
}
.subtle-msg { color: var(--subtle); font-size: 0.9rem; }

/* --- Room Code --- */
#room-code-display {
    font-size: 2rem;
    letter-spacing: 6px;
    color: var(--accent);
    font-weight: bold;
}

/* --- Question --- */
#question-text, #mc-question-text, #rep-question-text {
    font-size: 1.35rem;
    line-height: 1.5;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}

/* --- Waiting --- */
.waiting-text {
    color: var(--profit-green);
    font-size: 1.1rem;
    font-weight: bold;
}

/* --- Vouch Buttons --- */
.vouch-button {
    width: 100%;
    margin-bottom: 8px;
    background: var(--btn-secondary);
    color: var(--text);
    padding: 14px;
    font-size: 1.15rem;
    border-radius: 10px;
}
.vouch-button:active { background: var(--accent); color: var(--btn-text); }

/* --- Results --- */
#results-box {
    width: 100%;
    background: var(--card);
    border-radius: 10px;
    padding: 1rem;
    text-align: left;
    margin-bottom: 1rem;
}
#results-box p { margin: 6px 0; }
.answer-line { font-size: 1.2rem; }
.answer-line strong { color: var(--accent); font-size: 1.3rem; }
.all-guesses {
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 8px 12px;
    margin: 8px 0;
}
.all-guesses p { font-size: 0.95rem; color: var(--subtle); }
.prophet-guess { color: var(--prophet-gold) !important; font-weight: bold; }
.prophet-line { color: var(--prophet-gold); font-weight: bold; }
.profit-line { color: var(--profit-green); }

/* --- Leaderboard --- */
#leaderboard-list, #final-leaderboard {
    list-style: none;
    width: 100%;
    counter-reset: lb;
}
#leaderboard-list li, #final-leaderboard li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
    padding: 12px 16px;
    margin-bottom: 6px;
    border-radius: 8px;
    border-left: 4px solid transparent;
    counter-increment: lb;
}
#leaderboard-list li::before, #final-leaderboard li::before {
    content: counter(lb) ".";
    margin-right: 10px;
    color: var(--subtle);
    font-weight: bold;
    min-width: 24px;
}
#leaderboard-list li.first, #final-leaderboard li.first { border-left-color: var(--prophet-gold); }
#leaderboard-list li.second, #final-leaderboard li.second { border-left-color: #bbb; }
#leaderboard-list li.third, #final-leaderboard li.third { border-left-color: #cd7f32; }
.lb-name { flex: 1; }
.lb-score { color: var(--accent); font-weight: bold; }

/* --- Rules --- */
.rules-box {
    width: 100%;
    background: var(--card);
    border-radius: 10px;
    padding: 1.25rem;
    text-align: left;
    line-height: 1.6;
    margin-bottom: 1rem;
}
.rules-box p { margin-bottom: 0.5rem; }
.rules-box ul {
    margin: 0.25rem 0 0.75rem 1.25rem;
    list-style: disc;
}
.rules-box li { margin-bottom: 0.25rem; }

/* --- Round Label --- */
#round-label, #mc-round-label, #rep-round-label {
    color: var(--subtle);
    font-size: 1rem;
    font-weight: normal;
}

/* --- Minister Chat --- */
.chat-area {
    width: 100%;
    max-height: 120px;
    overflow-y: auto;
    background: rgba(46, 204, 113, 0.1);
    border: 1px solid var(--profit-green);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 0.5rem;
}
.chat-message {
    font-size: 0.9rem;
    margin-bottom: 4px;
    color: var(--text);
}
.chat-message strong {
    color: var(--profit-green);
}
.chat-input-area {
    width: 100%;
    display: flex;
    gap: 8px;
    margin-bottom: 0.5rem;
}
.chat-input-area input {
    flex: 1;
    width: auto;
    padding: 10px;
    font-size: 1rem;
    border-radius: 8px;
}
.chat-send-btn {
    width: auto;
    padding: 10px 16px;
    font-size: 0.95rem;
    border-radius: 8px;
}

/* --- Group Chat Bar (bottom) --- */
.chat-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    border-top: 2px solid var(--btn-secondary);
    z-index: 200;
    display: flex;
    flex-direction: column;
}
.chat-bar.hidden { display: none; }
.chat-bar-messages {
    max-height: 100px;
    overflow-y: auto;
    padding: 6px 12px;
}
.chat-bar-messages .chat-message {
    font-size: 0.85rem;
    margin-bottom: 3px;
}
.chat-bar-input {
    display: flex;
    gap: 6px;
    padding: 6px 10px;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.chat-bar-input input {
    flex: 1;
    width: auto;
    padding: 8px;
    font-size: 0.9rem;
    border-radius: 8px;
}

/* --- Theme Picker --- */
.theme-picker {
    width: 85%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0.5rem 0;
}
.theme-picker label {
    color: var(--subtle);
    font-size: 0.95rem;
}
.theme-picker select {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--btn-secondary);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-size: 0.95rem;
}

/* --- PDF Upload --- */
.pdf-upload-row {
    width: 85%;
    display: flex;
    align-items: center;
    gap: 10px;
}
.pdf-upload-label {
    padding: 10px 16px;
    background: var(--btn-secondary);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    white-space: nowrap;
}
.pdf-upload-input {
    display: none;
}
.pdf-filename {
    font-size: 0.85rem;
    color: var(--subtle);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* --- Question Count Picker --- */
.question-count-picker {
    width: 85%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0.25rem 0;
}
.question-count-picker label {
    color: var(--subtle);
    font-size: 0.95rem;
}
.question-count-picker select {
    padding: 10px;
    border: 2px solid var(--btn-secondary);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-size: 1rem;
}

/* --- Lesson Setup --- */
.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--btn-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 10px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

#lesson-preview {
    width: 100%;
    background: var(--card);
    border-radius: 10px;
    padding: 1rem;
    margin-top: 0.5rem;
}
#lesson-question-list {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 1rem;
}
.lesson-q-item {
    font-size: 0.9rem;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    color: var(--text);
}
.lesson-q-item strong { color: var(--accent); }
.q-editor-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.q-edit-input {
    flex: 1;
    width: auto !important;
    padding: 6px 8px !important;
    font-size: 0.85rem !important;
    text-align: left !important;
    border-radius: 6px;
}
.q-delete-btn {
    width: auto;
    padding: 4px 10px;
    font-size: 1.1rem;
    background: var(--error);
    color: #fff;
    border-radius: 6px;
    min-width: 30px;
}
.q-options-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    padding-left: 20px;
}
.q-opt {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    color: var(--subtle);
}
.q-opt-correct {
    background: rgba(46, 204, 113, 0.2);
    color: var(--profit-green);
    font-weight: bold;
}
.q-expand-btn {
    width: auto;
    padding: 4px 10px;
    font-size: 0.75rem;
    background: var(--btn-secondary);
    color: var(--text);
    border-radius: 6px;
    min-width: 40px;
}
.q-edit-panel {
    margin: 6px 0 6px 20px;
    padding: 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}
.q-opt-edit-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.q-opt-input {
    flex: 1;
    width: auto !important;
    padding: 6px 8px !important;
    font-size: 0.85rem !important;
    text-align: left !important;
    border-radius: 6px;
}
.q-correct-radio {
    width: auto;
    cursor: pointer;
}
.q-correct-label {
    font-size: 0.75rem;
    color: var(--subtle);
    white-space: nowrap;
}
.q-done-btn {
    margin-top: 6px;
    padding: 6px 16px !important;
    font-size: 0.85rem !important;
    width: auto !important;
}

/* --- Game Over / Winner --- */
#winner-box {
    width: 100%;
    background: var(--card);
    border-radius: 10px;
    padding: 1.5rem;
    text-align: center;
    margin-bottom: 1rem;
    border: 2px solid var(--prophet-gold);
}
#winner-box .winner-name {
    font-size: 2rem;
    color: var(--prophet-gold);
    font-weight: bold;
}
#winner-box .winner-score {
    font-size: 1.2rem;
    color: var(--text);
}

/* --- Game Logo --- */
.game-logo {
    max-width: 320px;
    width: 90%;
    height: auto;
    margin-bottom: 1rem;
}

/* --- Footer --- */
#site-footer {
    width: 100%;
    text-align: center;
    padding: 2rem 1rem;
    margin-top: auto;
    border-top: 1px solid var(--card);
}
.havari-logo {
    max-width: 120px;
    height: auto;
    margin-bottom: 0.5rem;
    opacity: 0.9;
}
.copyright {
    font-size: 0.75rem;
    color: var(--subtle);
    margin: 0;
}
