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

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --accent-color: #f093fb;
    --success-color: #4ade80;
    --warning-color: #fbbf24;
    --danger-color: #f87171;
    --text-light: #ffffff;
    --text-dark: #e2e8f0;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --wheel-item-height: 50px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    /* iOS 배경 고정 문제 해결 */
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-size: cover;
    min-height: 100vh;
    height: 100%;
    padding: 20px;
    color: var(--text-light);
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    /* iOS Safari 호환성 개선 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 배경 애니메이션 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* iOS에서 더 안정적인 배경 처리 */
    background: 
        radial-gradient(circle at 30% 30%, rgba(240, 147, 251, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    animation: pulse 4s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
    /* iOS 호환성 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem;
    color: var(--text-light);
    text-decoration: none;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    font-size: 1.2rem;
    z-index: 10;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(-2px);
}

.container {
    max-width: 450px;
    width: 100%;
    text-align: center;
    z-index: 1;
    /* Fixed: Add margin auto and remove flex centering from body */
    margin: 0 auto;
    padding-top: 2rem;
}

.header {
    margin-bottom: 1rem;
}

.title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0rem;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.subtitle {
    color: var(--text-dark);
    font-size: 1.1rem;
    font-weight: 300;
}

.input-section {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem 2rem;
    margin-bottom: 2rem;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    /* iOS 백업 배경 추가 */
    background-color: rgba(255, 255, 255, 0.15);
    /* iOS에서 backdrop-filter가 안될 경우 대체 */
    background-image: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.1) 0%, 
        rgba(255, 255, 255, 0.05) 100%);
}

.input-label {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
}

/* 플레이어 선택 섹션 */
.player-selector-section {
    margin-bottom: 2.1rem;
}

.wheel-picker-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

/* PC Layout: wheel-picker on the left, code-input on the right */
@media (min-width: 769px) {
    .wheel-picker-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 3rem;
    }
    
    .wheel-picker {
        flex-shrink: 0;
        order: 1;
    }
    
    .code-input-section {
        order: 2;
        flex: 1;
        margin-bottom: 0;
    }
    
    .selected-player {
        display: none; /* Hide selected player display on PC since wheel is visible */
    }
}

/* Mobile Layout: wheel-picker on top, code-input on bottom */
@media (max-width: 768px) {
    .wheel-picker-container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .wheel-picker {
        order: 1;
    }
    
    .code-input-section {
        order: 2;
        margin-bottom: 0rem;
    }
    
    .selected-player {
        order: 3;
    }
}

.wheel-picker {
    position: relative;
    width: 120px;
    height: 200px;
    overflow: hidden;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    user-select: none;
    -webkit-user-select: none;
}

.wheel-highlight {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: var(--wheel-item-height);
    transform: translateY(-50%);
    background: rgba(240, 147, 251, 0.2);
    border: 2px solid var(--accent-color);
    border-radius: 10px;
    pointer-events: none;
    z-index: 2;
}

.wheel-items {
    position: relative;
    padding: 75px 0; /* (200px - 50px) / 2 = 75px */
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.wheel-item {
    height: var(--wheel-item-height);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-light);
    transition: all 0.3s ease;
    cursor: pointer;
    /* Enhanced: Make wheel items more clickable */
    position: relative;
    z-index: 3;
}

.wheel-item:hover {
    color: var(--accent-color);
    transform: scale(1.05);
}

.wheel-item.selected {
    color: var(--accent-color);
    font-weight: 800;
    font-size: 1.4rem;
    transform: scale(1.1);
}

.wheel-fade-top,
.wheel-fade-bottom {
    position: absolute;
    left: 0;
    right: 0;
    height: 75px;
    pointer-events: none;
    z-index: 4;
}

.wheel-fade-top {
    top: 0;
    background: linear-gradient(to bottom, 
        rgba(255, 255, 255, 0.1) 0%, 
        rgba(255, 255, 255, 0.05) 50%,
        transparent 100%);
}

.wheel-fade-bottom {
    bottom: 0;
    background: linear-gradient(to top, 
        rgba(255, 255, 255, 0.1) 0%, 
        rgba(255, 255, 255, 0.05) 50%,
        transparent 100%);
}

.selected-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.selected-text {
    font-size: 1rem;
    color: var(--text-dark);
    font-weight: 500;
}

.selected-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent-color);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    min-width: 60px;
    text-align: center;
}

/* 코드 입력 섹션 */
.code-input-section {
    margin-bottom: 0rem;
}

.code-input-container {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 0;
}

.code-input {
    width: 60px;
    height: 70px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    text-align: center;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-light);
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
    transition: all 0.3s ease;
    outline: none;
}

.code-input:focus {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(240, 147, 251, 0.3);
    transform: scale(1.05);
}

.code-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.code-input.filled {
    background: rgba(74, 222, 128, 0.1);
    border-color: var(--success-color);
}

.code-input.error {
    background: rgba(248, 113, 113, 0.1);
    border-color: var(--danger-color);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.join-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-color), #ec4899);
    border: none;
    border-radius: 20px;
    padding: 1.5rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 6px 20px rgba(240, 147, 251, 0.3);
    position: relative;
    overflow: hidden;
    margin-top: 2rem;
}

.join-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.join-btn:hover::before {
    left: 100%;
}

.join-btn:hover {
    background: linear-gradient(135deg, #f472b6, #db2777);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(240, 147, 251, 0.4);
}

.join-btn:active {
    transform: translateY(-1px);
}

.join-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: 0 6px 20px rgba(240, 147, 251, 0.1);
}

.error-message,
.success-message {
    border-radius: 12px;
    padding: 1rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    display: none;
}

.error-message {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--danger-color);
}

.success-message {
    background: rgba(74, 222, 128, 0.1);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: var(--success-color);
}

.help-text {
    color: var(--text-dark);
    font-size: 0.9rem;
    margin-top: 1rem;
    font-style: italic;
    line-height: 1.4;
}

/* 로딩 상태 */
.loading {
    pointer-events: none;
}

.loading .join-btn {
    background: linear-gradient(135deg, #94a3b8, #64748b);
    cursor: not-allowed;
}

.loading .join-btn::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

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

/* 모바일 최적화 */
@media (max-width: 480px) {
    .title {
        font-size: 2rem;
    }
    
    .input-section {
        padding: 2rem 1.5rem;
    }
    
    .wheel-picker {
        width: 100px;
        height: 180px;
    }
    
    .selected-number {
        font-size: 2rem;
    }
    
    .code-input {
        width: 50px;
        height: 60px;
        font-size: 1.5rem;
    }
    
    .join-btn {
        padding: 1.2rem;
        font-size: 1.1rem;
    }
}

/* 터치 디바이스용 스크롤 최적화 */
@media (hover: none) and (pointer: coarse) {
    .wheel-picker {
        touch-action: pan-y;
    }
    
    .wheel-items {
        transition: transform 0.2s ease-out;
    }
}

/* iOS Safari 특별 처리 */
@supports (-webkit-touch-callout: none) {
    body {
        background-attachment: scroll;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        background-size: 100% 100%;
    }
    
    /* iOS에서 backdrop-filter가 제대로 안 될 경우 */
    .input-section,
    .wheel-picker,
    .back-btn {
        background-color: rgba(255, 255, 255, 0.2) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
    }
}

/* iPhone 전용 추가 최적화 */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 812px) {
    body {
        background: #667eea;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        background-size: 100% 100vh;
        background-repeat: no-repeat;
    }
    
    html {
        height: 100%;
    }
}