/* Full App Overlay Fixes */
:root {
    --bg-color: #0c111d;
    --card-bg: rgba(23, 28, 41, 0.85);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #14b8a6;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --radius: 24px;
    --transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

#app { height: 100vh; display: flex; flex-direction: column; position: relative; }

/* Header Fix */
header { 
    position: absolute; top: 0; left: 0; right: 0; z-index: 1000; 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 25px 30px; pointer-events: none;
}
header * { pointer-events: auto; }

.logo { font-size: 1.4rem; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.logo span { color: var(--primary); }
.logo small { font-size: 0.6rem; background: var(--accent); color: black; padding: 2px 6px; border-radius: 4px; font-weight: 800; }

.icon-btn { background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.1); color: white; padding: 12px; border-radius: 12px; cursor: pointer; backdrop-filter: blur(10px); }

/* Screens */
.screen { display: none; height: 100vh; width: 100vw; position: relative; padding-top: 100px; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* Identity Screen */
#screen-identity { justify-content: center; align-items: center; padding: 20px; text-align: center; overflow: hidden; }

/* Landing Collage */
#landing-collage {
    position: absolute; inset: -20px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-auto-rows: 150px;
    gap: 4px;
    z-index: 0;
    transform: scale(1.05);
    animation: collagePan 20s ease-in-out infinite alternate;
    filter: brightness(0.45) saturate(0.7);
}
@keyframes collagePan {
    from { transform: scale(1.05) translateY(0); }
    to   { transform: scale(1.05) translateY(-50px); }
}
.collage-tile { background-size: cover; background-position: center; }

/* Dark vignette overlay so text stays readable */
#screen-identity::after {
    content: '';
    position: absolute; inset: 0; z-index: 1;
    background: radial-gradient(ellipse 80% 70% at 50% 50%,
        rgba(12,17,29,0.72) 0%,
        rgba(12,17,29,0.50) 100%);
}

/* Lift content above the collage & overlay */
#screen-identity .hero,
#screen-identity .card { position: relative; z-index: 2; }

.hero { margin-bottom: 2.5rem; }
.hero h1 { font-size: 3.5rem; font-weight: 800; line-height: 1.1; margin-bottom: 0.5rem; }
.hero span { display: block; font-size: 1.4rem; color: var(--text-dim); font-weight: 400; }

/* Battle Layout (Vertical Split) */
#screen-battle { padding-top: 0; }
.tournament-info {
    position: absolute; top: 90px; left: 0; right: 0; z-index: 50;
    padding: 0 40px; text-align: center; pointer-events: none;
}
.round-text { font-weight: 800; font-size: 1.4rem; color: white; text-shadow: 0 2px 10px rgba(0,0,0,0.5); }
.progress-bar { width: 100%; height: 4px; background: rgba(255,255,255,0.1); margin-top: 10px; border-radius: 2px; }
#battle-progress { width: 0%; height: 100%; background: var(--primary); transition: width 0.3s ease; }

.battle-arena { flex: 1; display: flex; width: 100vw; height: 100vh; position: relative; }
.battle-side { flex: 1; height: 100%; cursor: pointer; position: relative; overflow: hidden; transition: var(--transition); }
.side-bg { position: absolute; inset: 0; background-size: cover; background-position: center; transition: transform 0.8s ease; }
.battle-side:hover .side-bg { transform: scale(1.05); }
.side-content {
    position: absolute; bottom: 0; left: 0; right: 0; padding: 50px 30px;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
    display: flex; flex-direction: column; align-items: center; text-align: center;
}
.side-content h2 { font-size: 2.4rem; font-weight: 800; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
.side-content p { font-size: 1rem; color: var(--text-dim); max-width: 90%; line-height: 1.4; margin-bottom: 15px; }
.highlights { 
    display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; 
    margin: 15px 0; max-width: 90%; 
}
.highlights span { 
    font-size: 0.8rem; font-weight: 600;
    background: rgba(255,255,255,0.1); 
    padding: 6px 14px; border-radius: 12px; 
    color: white; border: 1px solid rgba(255,255,255,0.15);
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.selection-hint { font-size: 0.7rem; font-weight: 800; color: var(--primary); margin-top: 15px; text-transform: uppercase; letter-spacing: 2px; opacity: 0.6; }

.vs-line { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.3), transparent); transform: translateX(-50%); z-index: 10; }
.vs-line span {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: var(--bg-color); color: white; width: 44px; height: 44px;
    border-radius: 50%; border: 2px solid var(--primary);
    display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 0.9rem;
    box-shadow: 0 0 15px var(--primary); transition: all 0.3s ease;
}

/* Admin Dashboard Fixes */
#screen-admin { padding: 100px 30px 40px; overflow-y: auto; display: none; }
#screen-admin.active { display: block; }

.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.admin-header h2 { font-size: 2rem; font-weight: 800; }
.admin-header-actions { display: flex; gap: 10px; align-items: center; }
.btn-danger { padding: 10px 20px; border-radius: 10px; border: 1px solid rgba(239,68,68,0.4); background: rgba(239,68,68,0.15); color: #f87171; font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: background 0.2s, color 0.2s; }
.btn-danger:hover { background: rgba(239,68,68,0.35); color: white; }

.admin-dashboard { display: grid; gap: 40px; width: 100%; max-width: 800px; margin: 0 auto; }

.ranking-section h3, .voters-section h3 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 2px; color: var(--text-dim); margin-bottom: 20px; }

.ranking-grid { display: grid; gap: 12px; }
.ranking-card {
    background: var(--card-bg); border: 1px solid rgba(255,255,255,0.1); padding: 15px 25px; border-radius: 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.ranking-card.top-1 { border-color: var(--accent); background: rgba(20, 184, 166, 0.1); }
.ranking-card .rank { font-weight: 800; color: var(--primary); width: 40px; }
.ranking-card .name { font-weight: 600; flex: 1; font-size: 1.1rem; }
.ranking-card .count { background: var(--primary); padding: 4px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 800; }

.voters-list { list-style: none; background: var(--card-bg); border-radius: 16px; border: 1px solid rgba(255,255,255,0.05); overflow: hidden; }
.voters-list li {
    padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex; flex-direction: column; gap: 8px;
}
.voters-list li:last-child { border-bottom: none; }
.voter-view { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.voter-name { font-weight: 700; min-width: 80px; }
.voter-choice { color: var(--text-dim); font-size: 0.9rem; }
.voter-actions { margin-left: auto; display: flex; gap: 6px; }
.btn-danger-sm {
    background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.4);
    color: #f87171; border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 0.8rem;
}
.btn-small { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
    color: white; border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 0.8rem;
}
.voter-edit { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.edit-name-input, .edit-select {
    width: 100%; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.15);
    color: white; border-radius: 8px; padding: 8px 12px; font-size: 0.85rem;
}
.edit-select option { background: #1e293b; }
.edit-btns { display: flex; gap: 8px; }
.add-voter-form {
    background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 14px; padding: 16px; margin-bottom: 16px;
    display: flex; flex-direction: column; gap: 8px;
}
.add-voter-form h4 { margin: 0 0 4px; font-size: 0.9rem; color: var(--text-dim); }

/* Choice Animation */
.battle-side.chosen { z-index: 20; transform-origin: left; width: 100vw; }
.battle-side.chosen .side-bg { transform: scale(1.1); }
.battle-side::after { content: ''; position: absolute; inset: 0; background: white; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 5; }
.battle-side.flash::after { opacity: 0.5; }

/* Victory Screen */
.victory-content {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 50px 40px 40px; text-align: center;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.badge { background: var(--accent); color: black; font-weight: 900; padding: 8px 20px; border-radius: 6px; margin-bottom: 20px; font-size: 0.8rem; letter-spacing: 1px; display: inline-block; }
#result-city-name { font-size: 4rem; font-weight: 800; margin-bottom: 16px; color: var(--primary); line-height: 1; }
.champion-hero { width: 100%; max-width: 500px; height: 300px; border-radius: 24px; background-size: cover; background-position: center; border: 1px solid rgba(255,255,255,0.1); margin-bottom: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.winner-desc { font-size: 1.1rem; color: var(--text-dim); margin-bottom: 12px; max-width: 600px; }
.winner-paragraph { font-size: 0.95rem; color: var(--text-dim); line-height: 1.7; margin-bottom: 30px; max-width: 580px; opacity: 0.8; }

/* Shared Utilities */
.card { padding: 45px; border-radius: var(--radius); width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 20px; text-align: left; }
.input-group { display: flex; flex-direction: column; gap: 12px; }
.input-group label { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.input-group input { width: 100%; padding: 18px; border-radius: 14px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.3); color: white; font-size: 1.1rem; outline: none; transition: border-color 0.3s, box-shadow 0.3s; }
.input-group input:focus { border-color: var(--primary); box-shadow: 0 0 15px rgba(99, 102, 241, 0.2); }

.glass { background: var(--card-bg); backdrop-filter: blur(30px); border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 25px 50px rgba(0,0,0,0.5); }
.btn-primary { width: 100%; padding: 20px; border-radius: 16px; background: var(--primary); color: white; border: none; font-size: 1.1rem; font-weight: 800; cursor: pointer; transition: transform 0.2s, background 0.2s, box-shadow 0.2s; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-3px); box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4); }
.btn-primary:active { transform: translateY(-1px); }

.btn-small { padding: 10px 20px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.2); color: white; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.btn-ghost { background: transparent; color: var(--text-dim); border: none; padding: 10px; cursor: pointer; transition: color 0.2s; font-size: 0.9rem; }
.btn-ghost:hover { color: white; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.95); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.hidden { display: none !important; }

#toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); background: var(--primary); color: white; padding: 14px 30px; border-radius: 50px; z-index: 3000; font-weight: 600; box-shadow: 0 15px 40px rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.1); }

/* Backup Picker */
.backup-content {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 90px 20px 30px; overflow-y: auto; -webkit-overflow-scrolling: touch; width: 100%;
}
.backup-header { text-align: center; margin-bottom: 24px; }
.backup-header h2 { font-size: 1.6rem; font-weight: 700; margin-top: 12px; }
.backup-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px; width: 100%; max-width: 860px;
}
.backup-card {
    height: 110px; border-radius: 14px; background-size: cover; background-position: center;
    cursor: pointer; position: relative; overflow: hidden;
    border: 2px solid transparent; transition: transform 0.2s, border-color 0.2s;
}
.backup-card:active { border-color: var(--primary); }
.backup-card:hover { transform: scale(1.04); border-color: var(--primary); }
.backup-card-label {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 6px 8px; font-size: 0.75rem; font-weight: 700;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    text-align: center;
}

/* Confirm Screen */
.confirm-content {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: flex-start; padding: 60px 20px 40px; text-align: center;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.confirm-content h2 { font-size: 1.8rem; font-weight: 700; margin-top: 16px; margin-bottom: 32px; }
.confirm-choices { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 420px; margin-bottom: 32px; }
.confirm-row {
    display: flex; align-items: center; gap: 16px;
    background: var(--card-bg); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px; padding: 12px 18px;
}
.confirm-rank { font-size: 1.4rem; width: 36px; flex-shrink: 0; }
.confirm-city-img { width: 52px; height: 52px; border-radius: 10px; background-size: cover; background-position: center; flex-shrink: 0; }
.confirm-city-name { font-size: 1.1rem; font-weight: 700; text-align: left; }

/* Admin multi-section */
.overall-section { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 30px; }
.score-legend { font-size: 0.7rem; font-weight: 400; color: var(--text-dim); text-transform: none; letter-spacing: 0; margin-left: 8px; }
.empty-msg { color: var(--text-dim); font-size: 0.9rem; padding: 10px 0; }
.voter-choices { color: var(--text-dim); font-size: 0.85rem; }

/* Tom Rejection */
@keyframes tomShake {
    0%   { transform: translateX(0); }
    10%  { transform: translateX(-18px) rotate(-1deg); }
    20%  { transform: translateX(18px) rotate(1deg); }
    30%  { transform: translateX(-16px) rotate(-1deg); }
    40%  { transform: translateX(16px) rotate(1deg); }
    50%  { transform: translateX(-12px); }
    60%  { transform: translateX(12px); }
    70%  { transform: translateX(-8px); }
    80%  { transform: translateX(8px); }
    90%  { transform: translateX(-4px); }
    100% { transform: translateX(0); }
}
@keyframes tomPulse {
    0%, 100% { background-color: #b91c1c; }
    50%       { background-color: #ef4444; }
}
#tom-rejection {
    position: fixed; inset: 0; z-index: 9999;
    background-color: #b91c1c;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 40px;
    animation: tomShake 0.6s ease-in-out, tomPulse 0.6s ease-in-out infinite;
    cursor: pointer;
}
#tom-rejection p {
    font-size: clamp(2.5rem, 10vw, 6rem);
    font-weight: 800;
    color: white;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* Mobile Optimization */
@media (max-width: 768px) {
    header { padding: 16px 20px; }

    /* Identity screen */
    #screen-identity { padding: 20px; }
    #landing-collage { grid-template-columns: repeat(4, 1fr); grid-auto-rows: 110px; }
    .hero { margin-bottom: 1.5rem; }
    .hero h1 { font-size: 2.4rem; }
    .hero span { font-size: 1.1rem; }
    .card { padding: 28px 20px; }
    .btn-primary { padding: 16px; font-size: 1rem; }

    /* Battle screen */
    .battle-arena { flex-direction: column; }
    .tournament-info { top: 60px; padding: 0 20px; }
    .round-text { font-size: 1.1rem; }
    .vs-line { width: 100%; height: 2px; left: 0; top: 50%; transform: translateY(-50%); background: linear-gradient(to right, transparent, rgba(255,255,255,0.3), transparent); }
    .vs-line span { top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(90deg); }
    .side-content { padding: 20px 16px; }
    .side-content h2 { font-size: 1.6rem; }
    .side-content p { font-size: 0.8rem; }
    .highlights { gap: 6px; margin: 8px 0; }
    .highlights span { font-size: 0.6rem; padding: 3px 8px; }
    .selection-hint { margin-top: 8px; font-size: 0.6rem; }
    .side-left.chosen { width: 100vw; height: 100vh; transform-origin: top; }
    .side-right.chosen { width: 100vw; height: 100vh; transform-origin: bottom; }

    /* Result / Victory screen */
    .victory-content { padding: 70px 20px 30px; }
    .badge { margin-bottom: 12px; font-size: 0.7rem; padding: 6px 14px; }
    #result-city-name { font-size: 2.4rem; margin-bottom: 12px; }
    .champion-hero { height: 190px; border-radius: 14px; margin-bottom: 14px; }
    .winner-desc { font-size: 0.95rem; margin-bottom: 10px; }
    .winner-paragraph { font-size: 0.82rem; line-height: 1.6; margin-bottom: 20px; }

    /* Backup picker */
    .backup-content { padding: 70px 10px 80px; }
    .backup-header h2 { font-size: 1.2rem; }
    .backup-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .backup-card { height: 85px; border-radius: 10px; }
    .backup-card-label { font-size: 0.6rem; padding: 4px; }

    /* Confirm screen */
    .confirm-content { padding: 70px 16px 30px; }
    .confirm-content h2 { font-size: 1.4rem; margin-bottom: 20px; }
    .confirm-choices { gap: 10px; margin-bottom: 24px; }
    .confirm-row { padding: 10px 14px; gap: 12px; }
    .confirm-rank { font-size: 1.2rem; width: 28px; }
    .confirm-city-img { width: 44px; height: 44px; }
    .confirm-city-name { font-size: 0.95rem; }

    /* Admin */
    .admin-header h2 { font-size: 1.4rem; }
    .ranking-card { padding: 12px 16px; }
    .ranking-card .name { font-size: 0.95rem; }
    .voters-list li { flex-direction: column; gap: 4px; padding: 12px 16px; }
    .voter-choices { font-size: 0.78rem; }
}
