/* Reset and base styles */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Press Start 2P', cursive;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

/* Header styles */
header {
    text-align: center;
    padding: 1rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.header-character {
    height: 80px;
    width: auto;
    border-radius: 10px;
    transition: transform 0.2s ease;
    animation: float 2s ease-in-out infinite;
}

/* 호버 효과도 개선 */
.header-character:hover {
    transform: scale(1.05);
    filter: contrast(1.2) brightness(1.1) saturate(1.2);
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-5px);
    }
}

h1 {
    font-family: 'Press Start 2P', cursive;
    font-size: 2.5rem;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin: 0;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    }
    to {
        text-shadow: 2px 2px 20px rgba(255, 255, 255, 0.8);
    }
}

.game-description {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
    max-width: 600px;
    margin: 0 auto;
}

/* Language selector styles */
.language-selector {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 25px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.language-selector label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
    white-space: nowrap;
}

.language-selector select {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 15px;
    padding: 0.3rem 0.8rem;
    font-size: 0.7rem;
    font-family: 'Press Start 2P', cursive;
    color: #333;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
}

.language-selector select:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-1px);
}

.language-selector select:focus {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

/* Main content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* Upload section */
.upload-section {
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.upload-button {
    display: inline-block;
    background: linear-gradient(45deg, #ff6b6b, #ee5a24);
    color: white;
    padding: 1rem 2rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    text-decoration: none;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.upload-button:hover,
.upload-button:focus {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    background: linear-gradient(45deg, #ee5a24, #ff6b6b);
}

.upload-button:active {
    transform: translateY(0);
}

.upload-help {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
}

/* Leaderboard section */
.leaderboard-section {
    text-align: center;
    width: 100%;
    max-width: 500px;
    margin: 1rem 0;
}

.leaderboard-button {
    display: inline-block;
    background: linear-gradient(45deg, #007BFF, #0056b3);
    color: white;
    padding: 1rem 2rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    text-decoration: none;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.leaderboard-button:hover,
.leaderboard-button:focus {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    background: linear-gradient(45deg, #0056b3, #007BFF);
}

.leaderboard-button:active {
    transform: translateY(0);
}

/* Canvas styles */
canvas {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    background: #87CEEB;
    margin: 1rem 0;
    touch-action: manipulation; /* 모바일 터치 최적화 */
    -webkit-touch-callout: none; /* iOS 터치 콜아웃 비활성화 */
    -webkit-user-select: none; /* iOS 텍스트 선택 비활성화 */
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Game instructions */
.game-instructions {
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 15px;
    margin-top: 2rem;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: 100%;
}

.game-instructions h2 {
    font-family: 'Press Start 2P', cursive;
    font-size: 1.2rem;
    color: #333;
    margin: 0 0 1rem 0;
    text-align: center;
}

.game-instructions ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.game-instructions li {
    font-size: 0.8rem;
    margin-bottom: 0.8rem;
    padding-left: 1.5rem;
    position: relative;
    color: #555;
}

.game-instructions li:before {
    content: "▶";
    position: absolute;
    left: 0;
    color: #ff6b6b;
    font-weight: bold;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    background: rgba(0, 0, 0, 0.1);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.7rem;
    margin-top: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

footer .footer-link {
    color: #fff;
    text-decoration: none;
    font-weight: bold;
}

/* Responsive design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .header-character {
        height: 60px;
        order: -1;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .game-description {
        font-size: 0.9rem;
    }
    
    .upload-button {
        padding: 0.8rem 1.5rem;
        font-size: 0.8rem;
    }
    
    .leaderboard-button {
        padding: 0.8rem 1.5rem;
        font-size: 0.8rem;
    }
    
    .game-instructions {
        padding: 1.5rem;
        margin-top: 1.5rem;
    }
    
    .game-instructions h2 {
        font-size: 1rem;
    }
    
    .game-instructions li {
        font-size: 0.8rem;
    }
    
    footer {
        padding: 1rem;
        font-size: 0.8rem;
    }

    footer .footer-text {
        display: block;
        margin-top: 10px;
    }
    
    .language-selector {
        position: static;
        margin: 1rem auto 0 auto;
        width: fit-content;
    }
    
    .language-selector label {
        font-size: 0.8rem;
    }
    
    .language-selector select {
        font-size: 0.8rem;
        padding: 0.2rem 0.6rem;
    }
    
    /* 모바일에서 캔버스 터치 최적화 */
    canvas {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
}

@media (max-width: 480px) {
    .header-character {
        height: 50px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    main {
        padding: 1rem 0.5rem;
    }
    
    footer {
        padding: 1rem 0.3rem;
        font-size: 0.7rem;
        line-height: 1.5;
    }

    footer .footer-text {
        display: block;
        margin-top: 10px;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    h1 {
        animation: none;
    }
    
    .upload-button {
        transition: none;
    }

    .header-character {
        animation: none;
    }
    
    .header-character:hover {
        transform: none;
    }
}

/* Focus styles for keyboard navigation */
.upload-button:focus {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    body {
        background: #000;
        color: #fff;
    }
    
    .game-instructions {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}



.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 620px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-family: 'Press Start 2P', cursive;
    font-size: 18px;
}

.close {
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    opacity: 0.7;
}

.modal-body {
    padding: 20px;
}

/* Leaderboard Styles */
.leaderboard-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.tab-button {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    color: #666;
    transition: all 0.3s ease;
}

.tab-button.active {
    color: #667eea;
    border-bottom: 3px solid #667eea;
}

.tab-button:hover {
    background: #f5f5f5;
}

.leaderboard-content {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.leaderboard-rank {
    font-size: 24px;
    font-weight: bold;
    color: #667eea;
    margin-right: 15px;
    min-width: 40px;
    text-align: center;
}

.leaderboard-face {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-right: 15px;
    object-fit: cover;
    border: 2px solid #ddd;
}

.leaderboard-info {
    flex: 1;
}

.leaderboard-name {
    font-weight: bold;
    font-size: 16px;
    color: #333;
    margin-bottom: 5px;
}

.leaderboard-score {
    font-size: 18px;
    color: #667eea;
    font-weight: bold;
}

.leaderboard-comment {
    font-size: 12px;
    color: #666;
    font-style: italic;
    margin-top: 5px;
}

.leaderboard-time {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
}

/* Save Score Modal Styles */
.score-preview {
    text-align: center;
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 10px;
}

.preview-face {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 10px;
    object-fit: cover;
    border: 3px solid #667eea;
}

.score-display {
    font-family: 'Press Start 2P', cursive;
}

.score-label {
    font-size: 14px;
    color: #666;
}

.score-value {
    font-size: 24px;
    color: #667eea;
    font-weight: bold;
    margin-left: 10px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #333;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.save-button,
.cancel-button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-button {
    background: #4CAF50;
    color: white;
}

.save-button:hover {
    background: #45a049;
}

.cancel-button {
    background: #f44336;
    color: white;
}

.cancel-button:hover {
    background: #da190b;
}

/* Share Modal Styles */
.share-preview {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    color: white;
}

.share-face {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    margin-right: 15px;
    object-fit: cover;
    border: 3px solid white;
}

.share-info {
    flex: 1;
}

.share-score {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 5px;
}

.share-name {
    font-size: 14px;
    opacity: 0.9;
}

.share-link {
    margin-bottom: 20px;
}

.share-link label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #333;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
}

.link-container {
    display: flex;
    gap: 10px;
}

.link-container input {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: #f8f9fa;
}

.copy-button {
    padding: 12px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    transition: background 0.3s ease;
}

.copy-button:hover {
    background: #5a6fd8;
}

.share-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.share-button {
    flex: 1;
    min-width: 120px;
    padding: 12px;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 11px;
    transition: all 0.3s ease;
}

.share-button.twitter {
    background: #1DA1F2;
}

.share-button.facebook {
    background: #4267B2;
}

.share-button.whatsapp {
    background: #25D366;
}

.share-button:hover {
    opacity: 0.8;
    transform: translateY(-1px);
}

/* Loading and Error States */
.loading {
    text-align: center;
    padding: 40px;
    color: #666;
    font-style: italic;
}

.error {
    text-align: center;
    padding: 40px;
    color: #d32f2f;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 10% auto;
        max-height: 85vh;
    }
    
    .modal-header h2 {
        font-size: 16px;
    }
    
    .tab-button {
        font-size: 10px;
        padding: 10px 8px;
    }
    
    .leaderboard-item {
        padding: 12px;
    }
    
    .leaderboard-rank {
        font-size: 20px;
        min-width: 35px;
    }
    
    .leaderboard-face {
        width: 80px;
        height: 80px;
    }
    
    .leaderboard-name {
        font-size: 14px;
    }
    
    .leaderboard-score {
        font-size: 16px;
    }
    
    .share-buttons {
        flex-direction: column;
    }
    
    .share-button {
        min-width: auto;
    }

    .play-now {
        display: block;
    }
}