/* Live display - full-screen projector view for events.
   Dark background, big numbers, leaderboard left, feed right, QR top-right.
   Accent color is themed per-org via --accent CSS var. */

/* The HTML `hidden` attribute must win over any display:flex rule below.
   Without this override, splash/error/celebration overlays stay rendered
   on top of the dashboard even after JS sets `el.hidden = true`. */
[hidden] { display: none !important; }

* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.4);
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-new: #1e3a5f;
    --text: #ffffff;
    --text-muted: #94a3b8;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
}

/* Loading splash + error state */
.live-splash, .live-error {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 18px; padding: 32px;
}
.live-splash-spinner {
    width: 48px; height: 48px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.live-splash-text { opacity: 0.5; font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

.live-error h1 { font-size: 32px; margin-bottom: 8px; }
.live-error p { opacity: 0.7; max-width: 480px; text-align: center; line-height: 1.6; }
.live-error code {
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.9em;
}
.live-error-hint { margin-top: 16px; opacity: 0.4 !important; font-size: 14px; }

/* Main wrap */
.live-wrap {
    display: flex; flex-direction: column;
    height: 100vh; padding: 36px 48px;
    position: relative;
}

/* Fullscreen toggle - top-right corner, fades in only on hover */
.live-fs-btn {
    position: absolute; top: 12px; right: 12px;
    width: 44px; height: 44px;
    background: rgba(255,255,255,0.06);
    color: white; border: none; border-radius: 8px;
    font-size: 22px; cursor: pointer;
    opacity: 0; transition: opacity 0.2s;
    z-index: 10;
}
.live-wrap:hover .live-fs-btn { opacity: 0.6; }
.live-fs-btn:hover { opacity: 1 !important; background: rgba(255,255,255,0.12); }

/* Header */
.live-header { text-align: center; margin-bottom: 24px; }
.org-row {
    display: inline-flex; align-items: center;
    gap: 8px; font-size: 16px; opacity: 0.6;
    margin-bottom: 4px;
}
.live-pulse {
    width: 8px; height: 8px; border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
.live-header h1 { font-size: 42px; font-weight: 800; }

/* Body row: meter + QR card side by side */
.live-body {
    display: flex; gap: 32px;
    align-items: center; justify-content: center;
    margin-bottom: 28px;
}

.live-meter { text-align: center; flex: 1; max-width: 720px; }
.live-raised {
    font-size: 88px; font-weight: 900; color: var(--accent);
    letter-spacing: -0.02em;
    text-shadow: 0 0 40px var(--accent-glow);
    transition: transform 0.3s;
}
.live-raised.bump { transform: scale(1.05); }
.live-goal { font-size: 18px; opacity: 0.5; margin-bottom: 10px; }
.live-bar {
    height: 18px; background: var(--bg-card);
    border-radius: 10px; overflow: hidden;
    max-width: 700px; margin: 0 auto;
}
.live-fill {
    height: 100%; width: 0;
    background: linear-gradient(90deg, #fbbf24, #f59e0b, var(--accent), #8b5cf6);
    background-size: 300% 100%;
    border-radius: 10px;
    transition: width 1s ease-out;
    animation: shimmer 4s ease infinite;
    box-shadow: 0 0 24px var(--accent-glow);
}
@keyframes shimmer { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.live-stats {
    display: flex; justify-content: center;
    gap: 32px; margin-top: 10px;
    font-size: 15px; opacity: 0.55;
}
.live-stats strong { color: var(--text); opacity: 0.85; }

/* QR card - top-right of meter */
.live-qr-card {
    background: white; color: #0f172a;
    border-radius: 14px; padding: 16px;
    text-align: center; box-shadow: 0 6px 30px rgba(0,0,0,0.4);
    flex-shrink: 0;
}
.live-qr-label {
    font-size: 13px; font-weight: 800;
    text-transform: uppercase; letter-spacing: 1.2px;
    color: var(--accent); margin-bottom: 10px;
}
#qr-canvas { display: block; margin: 0 auto; }
.live-qr-url {
    font-size: 11px; color: #64748b;
    margin-top: 8px; max-width: 200px;
    overflow-wrap: anywhere;
}

/* Two-panel layout: leaderboard + feed side by side */
.live-panels {
    flex: 1;
    display: flex; gap: 24px;
    min-height: 0; overflow: hidden;
}
.live-panels h2 {
    font-size: 16px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    opacity: 0.4; margin-bottom: 12px;
}

/* Leaderboard */
.live-leaderboard { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#leaderboard { flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 6px; }
.lb-row {
    display: flex; align-items: center;
    gap: 12px; padding: 10px 14px;
    background: var(--bg-card);
    border-radius: 10px;
    transition: background 0.4s;
}
.lb-row.lb-changed {
    background: var(--bg-card-new);
    box-shadow: 0 0 16px var(--accent-glow);
}
.lb-rank {
    width: 28px; font-size: 16px; font-weight: 800;
    text-align: center; color: var(--text-muted);
}
.lb-row:nth-child(1) .lb-rank { color: #fbbf24; font-size: 20px; }
.lb-row:nth-child(2) .lb-rank { color: #cbd5e1; font-size: 18px; }
.lb-row:nth-child(3) .lb-rank { color: #d97706; font-size: 18px; }
.lb-name { flex: 1; font-size: 16px; font-weight: 700; min-width: 0;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-bar-w { width: 80px; height: 6px; background: #334155; border-radius: 3px; overflow: hidden; }
.lb-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #8b5cf6); border-radius: 3px; }
.lb-amt { font-size: 16px; font-weight: 800; color: var(--accent); min-width: 70px; text-align: right; }

/* Feed */
.live-feed-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.live-feed { flex: 1; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.feed-item {
    padding: 12px 16px; background: var(--bg-card);
    border-radius: 10px;
    display: flex; justify-content: space-between; align-items: center;
    animation: slideIn 0.5s ease-out;
}
.feed-left { min-width: 0; flex: 1; }
.feed-donor {
    font-size: 16px; font-weight: 700;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.feed-for {
    font-size: 12px; opacity: 0.45; margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.feed-amount {
    font-size: 22px; font-weight: 800;
    color: var(--accent); flex-shrink: 0; margin-left: 16px;
}
.feed-item.new {
    background: var(--bg-card-new);
    box-shadow: 0 0 20px var(--accent-glow);
}

@keyframes slideIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Goal-reached celebration overlay */
.live-celebration {
    position: fixed; inset: 0;
    background: radial-gradient(circle at center, rgba(0,0,0,0.85), rgba(0,0,0,0.95));
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    animation: fadeIn 0.6s ease-out;
}
.live-celebration-inner { text-align: center; animation: bounceIn 0.8s ease-out; }
.live-celebration-emoji { font-size: 120px; animation: bounce 1.2s ease-in-out infinite; }
.live-celebration-inner h2 {
    font-size: 56px; font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 40px var(--accent-glow);
    margin-top: 16px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes bounceIn { 0% { transform: scale(0.3); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

/* Footer */
.live-footer {
    text-align: center; padding-top: 16px;
    font-size: 12px; opacity: 0.2;
    display: flex; justify-content: center; gap: 24px;
}
.live-footer-help kbd {
    background: rgba(255,255,255,0.1);
    padding: 1px 6px; border-radius: 3px;
    font-family: inherit;
}

/* Responsive: smaller projector / TV */
@media (max-width: 1024px) {
    .live-wrap { padding: 24px 28px; }
    .live-header h1 { font-size: 32px; }
    .live-raised { font-size: 64px; }
    .live-body { flex-direction: column; gap: 16px; }
    .live-qr-card { padding: 12px; }
    #qr-canvas { width: 160px !important; height: 160px !important; }
    .live-panels { flex-direction: column; }
    .live-celebration-emoji { font-size: 80px; }
    .live-celebration-inner h2 { font-size: 36px; }
}
