:root {
    --primary: #0A84FF;
    /* iOS Blue */
    --primary-hover: #007AFF;
    --secondary: #32D74B;
    /* iOS Green */
    --danger: #FF453A;
    /* iOS Red */
    --bg-dark: #000000;
    --card-surface: rgba(28, 28, 30, 0.65);
    /* iOS System Gray 6 equivalent-ish with alpha */
    --input-surface: rgba(142, 142, 147, 0.12);
    /* System Fill */
    --text: #ffffff;
    --text-secondary: #8E8E93;
    /* System Gray */
    --glass-border: rgba(255, 255, 255, 0.08);
    /* Fainter border */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overflow: hidden;
    background: radial-gradient(circle at 50% 10%, #2f3542 0%, #0f0f13 80%);
}

.app-container {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: relative;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    z-index: 50;
    position: relative;
}

h1 {
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(45deg, #ff6b81, #ffa502);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.glass-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

#voting-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

.cards-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    width: 100%;
    height: 400px;
    position: relative;
}

.card {
    width: 45%;
    height: 100%;
    background: var(--glass);
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--glass-border);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s;
    touch-action: none;
    /* Prevent scroll while dragging */
    user-select: none;
}

.card:hover {
    transform: scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.card-info {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 20px 10px 10px;
    display: flex;
    justify-content: center;
}

.elo-badge {
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--glass-border);
}

.vs-badge {
    position: absolute;
    background: #ff4757;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 0.9rem;
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.5);
    z-index: 5;
}

.card.winner {
    animation: winFlash 0.5s ease;
    border: 2px solid var(--secondary);
}

.card.loser {
    filter: grayscale(1);
    opacity: 0.5;
    transform: scale(0.9);
}

@keyframes winFlash {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(46, 213, 115, 0);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 30px rgba(46, 213, 115, 0.5);
    }

    100% {
        transform: scale(1);
    }
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(46, 213, 115, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s;
}

.card:active .overlay {
    opacity: 1;
}

.controls-hint {
    margin-top: 30px;
    opacity: 0.5;
    font-size: 0.9rem;
    text-align: center;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    background: #1e272e;
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--glass-border);
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 20px;
}

.close-btn {
    align-self: flex-end;
    font-size: 1.5rem;
    cursor: pointer;
    margin-bottom: -20px;
}

.ranking-list {
    overflow-y: auto;
    flex: 1;
}

.rank-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.highlight-user {
    background: rgba(10, 132, 255, 0.2);
    border: 1px solid var(--primary);
    border-radius: 10px;
}

.rank-item:nth-child(1) {
    color: #ffd700;
}

.rank-item:nth-child(2) {
    color: #c0c0c0;
}

.rank-item:nth-child(3) {
    color: #cd7f32;
}

.rank-num {
    width: 30px;
    font-weight: bold;
}

.rank-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 15px;
}

.rank-name {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rank-elo {
    font-weight: bold;
    color: var(--secondary);
}

/* Auth UI */
#firebaseui-auth-container {
    margin-top: 20px;
}

/* View Management */
.view-section {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease;
}

.view-section.hidden {
    display: none;
    opacity: 0;
}

.hidden {
    display: none !important;
}

.view-section.active {
    display: flex;
    opacity: 1;
}

/* Loading State */
#loading-state {
    text-align: center;
    padding: 40px;
    background: var(--glass);
    border-radius: 20px;
}

.sub-text {
    font-size: 0.9rem;
    color: #ccc;
    margin-top: 10px;
}

/* Profile View Styling - Premium Glass */
.profile-card {
    width: 100%;
    max-width: 400px;
    background: rgba(30, 30, 40, 0.7);
    border-radius: 30px;
    padding: 30px 24px;
    margin: 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.profile-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 30px;
}

.profile-nav h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
    letter-spacing: 0.5px;
}

.spacer {
    width: 40px;
    /* Balance for back button */
}

.icon-only {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
}

.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
    width: 100%;
}

.profile-img-container {
    width: 110px;
    height: 110px;
    position: relative;
    margin-bottom: 15px;
}

#profile-preview {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.edit-overlay {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background: var(--primary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 2px solid #1C1C1E;
    color: white;
    transition: transform 0.2s;
}

.edit-overlay:hover {
    transform: scale(1.1);
}

.profile-title {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    justify-content: center;
}

#display-name-input {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    width: auto;
    max-width: 200px;
    padding: 5px;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s;
}

#display-name-input:focus {
    outline: none;
    border-bottom: 1px solid var(--primary);
}

.icon-btn-small {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--secondary);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.icon-btn-small:hover {
    background: rgba(50, 215, 75, 0.2);
}

.profile-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    width: 100%;
    margin-bottom: 30px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-icon {
    font-size: 1.2rem;
    color: #ffd700;
    margin-bottom: 5px;
}

.stat-card:nth-child(2) .stat-icon {
    color: #ff4757;
}

.stat-val {
    font-size: 1.4rem;
    font-weight: 700;
    color: white;
    display: block;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.profile-footer {
    width: 100%;
    margin-top: auto;
}

.danger-btn {
    background: rgba(255, 69, 58, 0.15);
    color: var(--danger);
    width: 100%;
    border: 1px solid rgba(255, 69, 58, 0.3);
    border-radius: 15px;
    height: 50px;
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    transition: background 0.3s;
}

.danger-btn:hover {
    background: rgba(255, 69, 58, 0.25);
}

/* FirebaseUI Dark Mode Overrides */
.firebaseui-container {
    background-color: transparent !important;
    max-width: 100% !important;
}

.firebaseui-card-content {
    padding: 0px !important;
}

.firebaseui-title {
    color: white !important;
}

.firebaseui-label {
    color: #ccc !important;
}

.firebaseui-input,
.firebaseui-input-invalid {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: white !important;
    border-color: transparent !important;
    border-radius: 8px !important;
}

.firebaseui-id-submit,
.firebaseui-id-secondary-link {
    background-color: var(--primary) !important;
    color: white !important;
    border-radius: 20px !important;
    box-shadow: none !important;
}

.mdl-button--raised.mdl-button--colored {
    background: var(--primary) !important;
    color: white !important;
}

.firebaseui-button {
    font-weight: normal !important;
}

.firebaseui-textfield.mdl-textfield .firebaseui-label::after {
    background-color: var(--primary) !important;
}