@import url('https://fonts.googleapis.com/css2?family=Kantumruy+Pro:wght@300;400;500;600;700&family=Hanuman:wght@300;400;700;900&display=swap');

:root {
    --primary-color: #1a3d7c;
    --secondary-color: #d4af37;
    --card-width: 224px; /* 280px * 0.8 */
    --card-height: 320px; /* 400px * 0.8 */
    --khmer-font: 'Kantumruy Pro', 'Hanuman', 'Khmer OS', 'Khmer OS System', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--khmer-font);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

html {
    height: 100%;
}

body {
    background: linear-gradient(135deg, #1a3d7c 0%, #0a1a3a 100%);
    color: white;
    min-height: 100vh;
    padding: 16px; /* 20px * 0.8 */
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    position: relative;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    font-family: var(--khmer-font);
    line-height: 1.5; /* Reduced from 1.6 */
    font-size: 14px; /* Base font size reduced */
}

.container {
    max-width: 800px; /* 1000px * 0.8 */
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    height: auto;
    min-height: 100vh;
    padding-bottom: 1.6rem; /* 2rem * 0.8 */
    overflow: visible;
}

header {
    text-align: center;
    margin-bottom: 24px; /* 30px * 0.8 */
    width: 100%;
}

.logo-container {
    margin: 0 auto 16px; /* 20px * 0.8 */
    width: 96px; /* 120px * 0.8 */
    height: 96px; /* 120px * 0.8 */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.logo {
    max-width: 100%;
    max-height: 100%;
}

h1 {
    text-align: center;
    font-size: 1.76rem; /* 2.2rem * 0.8 */
    margin-bottom: 8px; /* 10px * 0.8 */
    color: var(--secondary-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    font-weight: 700;
    font-family: 'Hanuman', var(--khmer-font);
}

.subtitle {
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    opacity: 0.9;
    font-weight: 400;
}

/* Screen 1 - Player Selection */
.screen-1 {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: visible;
    position: relative;
}

.cards-container {
    position: relative;
    width: 100%;
    height: 360px; /* 450px * 0.8 */
    margin: 24px 0 16px 0; /* 30px * 0.8, 20px * 0.8 */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    touch-action: pan-x;
}

.card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 16px; /* 20px * 0.8 */
    background: white;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3); /* 15px * 0.8, 35px * 0.8 */
    transition: transform 0.5s ease, opacity 0.5s ease, box-shadow 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #333;
    -webkit-user-drag: none;
}

.card.active {
    transform: translateY(-12px); /* 15px * 0.8 */
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4); /* 20px * 0.8, 45px * 0.8 */
}

.card.selected {
    box-shadow: 0 0 0 4px var(--secondary-color), 0 20px 40px rgba(0, 0, 0, 0.7); /* 5px * 0.8, 25px * 0.8, 50px * 0.8 */
    transform: translateY(-12px) scale(1.05); /* 15px * 0.8 */
}

.card-img {
    height: 78%;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    -webkit-user-drag: none;
}

.card-info {
    padding: 16px; /* 20px * 0.8 */
    height: 22%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(to bottom, #f8f8f8, #e8e8e8);
}

.player-name {
    font-weight: bold;
    font-size: 1.12rem; /* 1.4rem * 0.8 */
    margin-bottom: 6.4px; /* 8px * 0.8 */
    text-align: center;
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.player-position {
    font-size: 0.88rem; /* 1.1rem * 0.8 */
    color: #666;
    text-align: center;
    font-weight: 500;
}

.card-number {
    position: absolute;
    top: 12px; /* 15px * 0.8 */
    left: 12px; /* 15px * 0.8 */
    background-color: var(--primary-color);
    color: white;
    width: 32px; /* 40px * 0.8 */
    height: 32px; /* 40px * 0.8 */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 0.88rem; /* 1.1rem * 0.8 */
    z-index: 2;
    font-family: var(--khmer-font);
}

.selected-badge {
    position: absolute;
    top: 12px; /* 15px * 0.8 */
    right: 12px; /* 15px * 0.8 */
    background-color: var(--secondary-color);
    color: var(--primary-color);
    padding: 6.4px 9.6px; /* 8px * 0.8, 12px * 0.8 */
    border-radius: 16px; /* 20px * 0.8 */
    font-size: 0.72rem; /* 0.9rem * 0.8 */
    font-weight: bold;
    z-index: 2;
    display: none;
    font-family: var(--khmer-font);
}

.card.selected .selected-badge {
    display: block;
}

/* Navigation buttons positioned over cards */
.navigation-container {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px; /* 20px * 0.8 */
    pointer-events: none;
    z-index: 25;
    max-width: 640px; /* 800px * 0.8 */
    margin: 0 auto;
}

.nav-btn {
    background-color: var(--secondary-color);
    color: var(--primary-color);
    border: none;
    border-radius: 50%;
    width: 48px; /* 60px * 0.8 */
    height: 48px; /* 60px * 0.8 */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.44rem; /* 1.8rem * 0.8 */
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4.8px 16px rgba(0, 0, 0, 0.4); /* 6px * 0.8, 20px * 0.8 */
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
    z-index: 30;
    font-family: var(--khmer-font);
}

.nav-btn:hover {
    background-color: #e6c44c;
    transform: scale(1.15);
    box-shadow: 0 6.4px 20px rgba(0, 0, 0, 0.5); /* 8px * 0.8, 25px * 0.8 */
}

.nav-btn:active {
    transform: scale(0.95);
}

/* Select button positioned below cards */
.controls {
    display: flex;
    justify-content: center;
    margin: 16px 0 24px 0; /* 20px * 0.8, 30px * 0.8 */
    width: 100%;
    z-index: 10;
    position: relative;
}

.select-btn {
    background-color: var(--secondary-color);
    color: var(--primary-color);
    padding: 12.8px 32px; /* 16px * 0.8, 40px * 0.8 */
    border: none;
    border-radius: 24px; /* 30px * 0.8 */
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.04rem; /* 1.3rem * 0.8 */
    min-width: 160px; /* 200px * 0.8 */
    box-shadow: 0 3.2px 12px rgba(0, 0, 0, 0.3); /* 4px * 0.8, 15px * 0.8 */
    -webkit-tap-highlight-color: transparent;
    z-index: 10;
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.select-btn:hover {
    background-color: #e6c44c;
    transform: translateY(-1.6px); /* 2px * 0.8 */
    box-shadow: 0 4.8px 16px rgba(0, 0, 0, 0.4); /* 6px * 0.8, 20px * 0.8 */
}

.select-btn:disabled {
    background-color: #666;
    color: #999;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Screen 2 - Confirmation and Form */
.screen-2 {
    width: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: none;
    padding-bottom: 16px; /* 20px * 0.8 */
    min-height: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
}

.selected-player-card {
   
    
    
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #ffffff;
    margin: 5px 0; /* 30px * 0.8 */
    transform: scale(1.05);
    transition: transform 0.3s ease;
}

.selected-player-card .card-number {
    position: absolute;
    top: 12px; /* 15px * 0.8 */
    left: 12px; /* 15px * 0.8 */
    background-color: var(--primary-color);
    color: white;
    width: 32px; /* 40px * 0.8 */
    height: 32px; /* 40px * 0.8 */

    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 0.88rem; /* 1.1rem * 0.8 */
    z-index: 2;
}

.selected-player-card .card-img {
    height: 78%;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.selected-player-card .card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.selected-player-card .card-info {
    padding: 16px; /* 20px * 0.8 */
    height: 22%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(to bottom, #f8f8f8, #e8e8e8);
}

.selected-player-card .player-name {
    font-weight: bold;
    font-size: 1.12rem; /* 1.4rem * 0.8 */
    margin-bottom: 6.4px; /* 8px * 0.8 */
    text-align: center;
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.selected-player-card .player-position {
    font-size: 0.88rem; /* 1.1rem * 0.8 */
    color: #666;
    text-align: center;
    font-weight: 500;
}

.confirmation-title {
    text-align: center;
    margin: 5px 0; /* 30px * 0.8 */
    color: var(--secondary-color);
    font-size: 1.6rem; /* 2rem * 0.8 */
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.user-form {
    width: 100%;
    max-width: 400px; /* 500px * 0.8 */
    background-color: rgba(255, 255, 255, 0.1);
    padding: 28px; /* 35px * 0.8 */
    border-radius: 20px; /* 25px * 0.8 */
    margin-top: 24px; /* 30px * 0.8 */
}

.form-title {
    text-align: center;
    margin-bottom: 24px; /* 30px * 0.8 */
    color: var(--secondary-color);
    font-size: 1.44rem; /* 1.8rem * 0.8 */
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.form-group {
    margin-bottom: 24px; /* 30px * 0.8 */
}

label {
    display: block;
    margin-bottom: 9.6px; /* 12px * 0.8 */
    font-weight: 600;
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    font-family: 'Hanuman', var(--khmer-font);
}

input {
    width: 100%;
    padding: 14.4px 16px; /* 18px * 0.8, 20px * 0.8 */
    border-radius: 9.6px; /* 12px * 0.8 */
    border: 1.6px solid #ccc; /* 2px * 0.8 */
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    background-color: rgba(255, 255, 255, 0.95);
    transition: border-color 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-family: var(--khmer-font);
}

input:focus {
    border-color: var(--secondary-color);
    outline: none;
}

.submit-btn {
    position: relative;
    width: 100%;
    background-color: var(--secondary-color);
    color: var(--primary-color);
    font-size: 1.04rem; /* 1.3rem * 0.8 */
    padding: 16px; /* 20px * 0.8 */
    margin-top: 12px; /* 15px * 0.8 */
    border: none;
    border-radius: 9.6px; /* 12px * 0.8 */
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.submit-btn:hover {
    background-color: #e6c44c;
    transform: translateY(-1.6px); /* 2px * 0.8 */
}

.back-btn {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    margin-top: 20px; /* 25px * 0.8 */
    width: 100%;
    padding: 14.4px 16px; /* 18px * 0.8, 20px * 0.8 */
    border: none;
    border-radius: 9.6px; /* 12px * 0.8 */
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.back-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1.6px); /* 2px * 0.8 */
}

.loading {
    display: none;
    text-align: center;
    margin-top: 32px; /* 40px * 0.8 */
}

.spinner {
    border: 4.8px solid rgba(255, 255, 255, 0.3); /* 6px * 0.8 */
    border-radius: 50%;
    border-top: 4.8px solid var(--secondary-color); /* 6px * 0.8 */
    width: 48px; /* 60px * 0.8 */
    height: 48px; /* 60px * 0.8 */
    animation: spin 1s linear infinite;
    margin: 0 auto 16px; /* 20px * 0.8 */
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    font-family: var(--khmer-font);
}

.success-message {
    text-align: center;
    padding: 32px; /* 40px * 0.8 */
    background-color: rgba(46, 204, 113, 0.2);
    border-radius: 16px; /* 20px * 0.8 */
    margin-top: 32px; /* 40px * 0.8 */
    display: none;
}

.success-message h3 {
    font-size: 1.6rem; /* 2rem * 0.8 */
    margin-bottom: 16px; /* 20px * 0.8 */
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.success-message p {
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    font-family: var(--khmer-font);
}

.error-message {
    text-align: center;
    padding: 32px; /* 40px * 0.8 */
    background-color: rgba(231, 76, 60, 0.2);
    border-radius: 16px; /* 20px * 0.8 */
    margin-top: 32px; /* 40px * 0.8 */
    display: none;
}

.error-message h3 {
    font-size: 1.6rem; /* 2rem * 0.8 */
    margin-bottom: 16px; /* 20px * 0.8 */
    font-family: 'Hanuman', var(--khmer-font);
    font-weight: 700;
}

.error-message p {
    font-size: 0.96rem; /* 1.2rem * 0.8 */
    font-family: var(--khmer-font);
}

/* Enhanced Responsive Design for Mobile */
@media (max-width: 1024px) {
    :root {
        --card-width: 208px; /* 260px * 0.8 */
        --card-height: 296px; /* 370px * 0.8 */
    }
    
    .container {
        max-width: 720px; /* 900px * 0.8 */
    }
    
    .cards-container {
        height: 336px; /* 420px * 0.8 */
    }
    
    .navigation-container {
        max-width: 560px; /* 700px * 0.8 */
    }
}

@media (max-width: 768px) {
    :root {
        --card-width: 192px; /* 240px * 0.8 */
        --card-height: 272px; /* 340px * 0.8 */
    }
    
    h1 {
        font-size: 1.6rem; /* 2rem * 0.8 */
    }
    
    .container {
        max-width: 100%;
        padding: 0 12px; /* 15px * 0.8 */
    }
    
    .cards-container {
        height: 304px; /* 380px * 0.8 */
    }
    
    .navigation-container {
        max-width: 440px; /* 550px * 0.8 */
        padding: 0 12px; /* 15px * 0.8 */
    }
    
    .nav-btn {
        width: 44px; /* 55px * 0.8 */
        height: 44px; /* 55px * 0.8 */
        font-size: 1.2rem; /* 1.5rem * 0.8 */
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
        gap: 12px; /* 15px * 0.8 */
        margin: 20px 0; /* 25px * 0.8 */
    }
    
    .select-btn,
    .submit-btn,
    .back-btn {
        width: 100%;
        padding: 14.4px 22.4px; /* 18px * 0.8, 28px * 0.8 */
        font-size: 0.96rem; /* 1.2rem * 0.8 */
    }
    
    .user-form {
        padding: 24px 20px; /* 30px * 0.8, 25px * 0.8 */
        margin: 20px 12px; /* 25px * 0.8, 15px * 0.8 */
    }
    
    .card-info {
        padding: 14.4px; /* 18px * 0.8 */
    }
    
    .player-name {
        font-size: 1.04rem; /* 1.3rem * 0.8 */
    }
    
    .player-position {
        font-size: 0.8rem; /* 1rem * 0.8 */
    }
}

@media (max-width: 640px) {
    :root {
        --card-width: 176px; /* 220px * 0.8 */
        --card-height: 256px; /* 320px * 0.8 */
    }
    
    .cards-container {
        height: 288px; /* 360px * 0.8 */
    }
    
    .navigation-container {
        max-width: 360px; /* 450px * 0.8 */
        padding: 0 8px; /* 10px * 0.8 */
    }
    
    .nav-btn {
        width: 40px; /* 50px * 0.8 */
        height: 40px; /* 50px * 0.8 */
        font-size: 1.12rem; /* 1.4rem * 0.8 */
    }
    
    .card-number {
        width: 28px; /* 35px * 0.8 */
        height: 28px; /* 35px * 0.8 */
        font-size: 0.8rem; /* 1rem * 0.8 */
    }
    
    .selected-badge {
        padding: 4.8px 8px; /* 6px * 0.8, 10px * 0.8 */
        font-size: 0.64rem; /* 0.8rem * 0.8 */
    }
}

@media (max-width: 480px) {
    :root {
        --card-width: 160px; /* 200px * 0.8 */
        --card-height: 240px; /* 300px * 0.8 */
    }
    
    body {
        padding: 12px 8px; /* 15px * 0.8, 10px * 0.8 */
    }
    
    h1 {
        font-size: 1.44rem; /* 1.8rem * 0.8 */
    }
    
    .subtitle {
        font-size: 0.88rem; /* 1.1rem * 0.8 */
    }
    
    .logo-container {
        width: 80px; /* 100px * 0.8 */
        height: 80px; /* 100px * 0.8 */
    }
    
    .cards-container {
        height: 272px; /* 340px * 0.8 */
    }
    
    .navigation-container {
        max-width: 304px; /* 380px * 0.8 */
        padding: 0 4px; /* 5px * 0.8 */
    }
    
    .nav-btn {
        width: 36px; /* 45px * 0.8 */
        height: 36px; /* 45px * 0.8 */
        font-size: 1.04rem; /* 1.3rem * 0.8 */
    }
    
    .controls {
        margin: 16px 0; /* 20px * 0.8 */
    }
    
    .select-btn,
    .submit-btn,
    .back-btn {
        font-size: 0.88rem; /* 1.1rem * 0.8 */
        padding: 12.8px 19.2px; /* 16px * 0.8, 24px * 0.8 */
        min-width: 96px; /* 120px * 0.8 */
    }
    
    .user-form {
        padding: 20px 16px; /* 25px * 0.8, 20px * 0.8 */
    }
    
    .form-title {
        font-size: 1.28rem; /* 1.6rem * 0.8 */
    }
    
    .confirmation-title {
        font-size: 1.36rem; /* 1.7rem * 0.8 */
    }
    
    input {
        padding: 12.8px 14.4px; /* 16px * 0.8, 18px * 0.8 */
        font-size: 0.88rem; /* 1.1rem * 0.8 */
    }
    
    .card-img {
        height: 76%;
    }
    
    .card-info {
        height: 24%;
        padding: 12px; /* 15px * 0.8 */
    }
    
    .player-name {
        font-size: 0.96rem; /* 1.2rem * 0.8 */
    }
    
    .player-position {
        font-size: 0.76rem; /* 0.95rem * 0.8 */
    }
}

@media (max-width: 380px) {
    :root {
        --card-width: 144px; /* 180px * 0.8 */
        --card-height: 224px; /* 280px * 0.8 */
    }
    
    .cards-container {
        height: 256px; /* 320px * 0.8 */
    }
    
    .navigation-container {
        max-width: 272px; /* 340px * 0.8 */
    }
    
    .nav-btn {
        width: 32px; /* 40px * 0.8 */
        height: 32px; /* 40px * 0.8 */
        font-size: 0.96rem; /* 1.2rem * 0.8 */
    }
    
    h1 {
        font-size: 1.28rem; /* 1.6rem * 0.8 */
    }
    
    .subtitle {
        font-size: 0.8rem; /* 1rem * 0.8 */
    }
    
    .card-number {
        width: 25.6px; /* 32px * 0.8 */
        height: 25.6px; /* 32px * 0.8 */
        font-size: 0.72rem; /* 0.9rem * 0.8 */
    }
}

@media (max-width: 320px) {
    :root {
        --card-width: 136px; /* 170px * 0.8 */
        --card-height: 208px; /* 260px * 0.8 */
    }
    
    .cards-container {
        height: 240px; /* 300px * 0.8 */
    }
    
    .navigation-container {
        max-width: 240px; /* 300px * 0.8 */
    }
    
    .nav-btn {
        width: 30.4px; /* 38px * 0.8 */
        height: 30.4px; /* 38px * 0.8 */
        font-size: 0.88rem; /* 1.1rem * 0.8 */
    }
    
    .card-number {
        width: 24px; /* 30px * 0.8 */
        height: 24px; /* 30px * 0.8 */
        font-size: 0.68rem; /* 0.85rem * 0.8 */
    }
    
    .selected-badge {
        padding: 4px 6.4px; /* 5px * 0.8, 8px * 0.8 */
        font-size: 0.6rem; /* 0.75rem * 0.8 */
    }
}

/* Prevent zoom on mobile inputs */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* Android Chrome specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS specific styles if needed */
}

@supports not (-webkit-touch-callout: none) {
    /* Android and other browsers */
    body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    .screen-2 {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

/* Ensure scrolling works on all mobile browsers */
html, body {
    height: 100%;
}

body {
    /* Critical for Android Chrome scrolling */
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
}

/* Remove any potential scroll blocking */
.container,
.screen-1,
.screen-2 {
    overflow: visible;
}

/* Hide scrollbars but allow scrolling */
.screen-2::-webkit-scrollbar {
    display: none;
}

.screen-2 {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Khmer font specific adjustments */
.khmer-text {
    font-family: var(--khmer-font);
}

/* Improve Khmer text rendering */
* {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}