body {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
    font-family: sans-serif;
    padding-top: 20px;
    box-sizing: border-box;
    /* overflow-x: hidden; */
    /* overflow-y: hidden; */
}

/* 메인 컨텐츠 영역 */
.main-content {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 헤더 스타일 */
#header {
    text-align: center;
    margin-bottom: 20px;
    width: 100%;
}

.header-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    gap: 15px;
}

#header h1 {
    color: #333;
    margin: 0;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.other-services-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-label {
    font-size: 0.9em;
    color: #666;
    font-weight: 500;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-service-link {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.nav-service-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    filter: brightness(1.1);
}

#languageToggle {
    background: #27ae60;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.3s ease;
    white-space: nowrap;
}

#languageToggle:hover {
    background: #2ecc71;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
}

#challenge-message {
    margin-top: 15px;
    font-size: 1.1em;
    color: #555;
    font-weight: 500;
}

/* 모바일 반응형 */
@media (max-width: 768px) {
    .other-services-nav {
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }
    
    .nav-links {
        justify-content: center;
        gap: 8px;
    }
    
    .nav-service-link {
        padding: 5px 10px;
        font-size: 0.8em;
    }
    
    #header h1 {
        font-size: 2em;
    }
}

/* 반응형 디자인 */
@media (max-width: 768px) {
    body {
        padding-top: 10px;
    }
    #header h1 {
        font-size: 2em;
    }
    .game-container {
        flex-direction: column;
        gap: 15px;
        align-items: center;
    }
    canvas {
        width: 100%;
        max-width: 400px;
        height: auto;
        aspect-ratio: 6/5;
    }
    #ranking-container {
        width: 100%;
        max-width: 400px;
    }
    .modal-content {
        width: 90%;
        max-width: 350px;
        margin: 10% auto;
        padding: 20px;
    }
    .modal-content h2 {
        font-size: 1.5em;
    }
}

/* 모바일 컨트롤 스타일 */
.mobile-controls {
    display: block;
    margin-top: 20px;
    user-select: none;
    touch-action: manipulation;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}
.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 5px 0;
}

/* 개선된 FPS 스타일 조이스틱 컨테이너 */
.joystick-container {
    position: relative;
    width: 140px;
    height: 140px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.4) 70%, rgba(0, 0, 0, 0.2) 100%);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

/* 개선된 조이스틱 스틱 */
.joystick-stick {
    width: 50px;
    height: 50px;
    background: radial-gradient(circle, #4a90e2 0%, #357abd 50%, #2c5aa0 100%);
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* 조이스틱 내부 링 표시 */
.joystick-rings {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
}

.joystick-ring {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.joystick-ring.ring-1 {
    width: 60%;
    height: 60%;
}

.joystick-ring.ring-2 {
    width: 80%;
    height: 80%;
}

/* 방향 표시 개선 */
.joystick-direction {
    position: absolute;
    font-size: 16px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.6);
    opacity: 0;
    transition: opacity 0.2s ease;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.joystick-direction.up { top: 10px; }
.joystick-direction.down { bottom: 10px; }
.joystick-direction.left { left: 10px; }
.joystick-direction.right { right: 10px; }

/* 조이스틱 활성화 상태 */
.joystick-container:active,
.joystick-container.pressed {
    background: radial-gradient(circle, rgba(74, 144, 226, 0.3) 0%, rgba(0, 0, 0, 0.4) 70%, rgba(0, 0, 0, 0.2) 100%);
    transform: scale(0.95);
    border-color: rgba(74, 144, 226, 0.5);
}

.joystick-container:active .joystick-stick,
.joystick-container.pressed .joystick-stick {
    background: radial-gradient(circle, #5ba0f0 0%, #4a90e2 50%, #357abd 100%);
    transform: scale(1.05);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* 방향별 시각적 피드백 */
.joystick-container.up .joystick-direction.up,
.joystick-container.down .joystick-direction.down,
.joystick-container.left .joystick-direction.left,
.joystick-container.right .joystick-direction.right {
    opacity: 1;
    color: rgba(255, 255, 255, 0.9);
}

/* 대각선 방향 표시 */
.joystick-container.up-left .joystick-direction.up,
.joystick-container.up-left .joystick-direction.left,
.joystick-container.up-right .joystick-direction.up,
.joystick-container.up-right .joystick-direction.right,
.joystick-container.down-left .joystick-direction.down,
.joystick-container.down-left .joystick-direction.left,
.joystick-container.down-right .joystick-direction.down,
.joystick-container.down-right .joystick-direction.right {
    opacity: 1;
    color: rgba(255, 255, 255, 0.9);
}

/* 대각선 방향 스틱 위치 */
.joystick-container.up-left .joystick-stick { 
    top: 15px; 
    left: 15px; 
}
.joystick-container.up-right .joystick-stick { 
    top: 15px; 
    right: 15px; 
}
.joystick-container.down-left .joystick-stick { 
    bottom: 15px; 
    left: 15px; 
}
.joystick-container.down-right .joystick-stick { 
    bottom: 15px; 
    right: 15px; 
}

/* 압력 표시 (스틱 이동 거리에 따른 시각적 피드백) */
.joystick-pressure {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(74, 144, 226, 0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.joystick-container.pressed .joystick-pressure {
    opacity: 1;
}

/* 모바일에서만 컨트롤 표시 */
@media (max-width: 768px) {
    #retry-btn {
        display: inline-block;
    }
    
    /* 모바일에서 조이스틱 크기 조정 */
    .joystick-container {
        width: 120px;
        height: 120px;
    }
    
    .joystick-stick {
        width: 45px;
        height: 45px;
    }
}

/* 데스크톱에서는 컨트롤 숨김 및 중앙정렬, scale(0.9) */
@media (min-width: 769px) {
    body {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    .game-container {
        margin: 0;
        transform: scale(0.9);
        transform-origin: top center;
    }
}

.game-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
}

#timer-box {
    /* position: relative; */
    left: 140px;
    top: -30px;
    padding: 8px 16px;
    font-size: 1.1em;
    font-weight: bold;
    z-index: 10;
    pointer-events: none;
    text-align: center;
    white-space: nowrap;
    min-width: 120px;
    width: 120px;
    box-sizing: border-box;
    display: inline-block;
    margin-bottom: -20px; /* 아래쪽 여백 보정 */
}

.game-area {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#giveup-btn {
    padding: 10px 20px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

#giveup-btn:hover {
    background-color: #c0392b;
}

#retry-btn {
    padding: 10px 20px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    margin-left: 10px;
}

#retry-btn:hover {
    background-color: #c0392b;
}

/* 모달 스타일 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    padding: 32px 24px 24px 24px;
    width: 400px;
    max-width: 95vw;
    margin: 6vh auto 0 auto;
    animation: modalSlideIn 0.2s cubic-bezier(0.4,0,0.2,1);
    position: relative;
    z-index: 1001;
}

@media (max-width: 768px) {
    .modal-content {
        width: 90%;
        max-width: 350px;
        margin: 4vh auto 0 auto;
        padding: 20px;
    }
}

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

.modal-content h2 {
    margin: 0 0 20px 0;
    color: #333;
    font-size: 2em;
}

.modal-content p {
    margin: 15px 0;
    font-size: 1.1em;
    color: #555;
}

#finalTime {
    font-weight: bold;
    color: #e74c3c;
    font-size: 1.2em;
}

#playerNameInput {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    box-sizing: border-box;
}

#playerNameInput:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 5px rgba(74, 144, 226, 0.3);
}

/* 국가 선택 컨테이너 */
.country-select-container {
    margin: 15px 0;
}

.country-select-container label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #333;
}

.select-wrapper {
    position: relative;
    width: 100%;
}

#countrySelect {
    width: 100%;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    background: white;
    max-height: 200px;
    overflow-y: auto;
}

#countrySelect option {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

#countrySelect option:hover {
    background-color: #f5f5f5;
}

#countrySelect option:checked {
    background-color: #4a90e2;
    color: white;
}

/* 모바일에서 국가 선택 최적화 */
@media (max-width: 768px) {
    #countrySelect {
        max-height: 150px;
    }
    
    #countrySearchInput {
        font-size: 16px; /* 모바일에서 자동 확대 방지 */
    }
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.modal-buttons button {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#saveRankingBtn {
    background-color: #27ae60;
    color: white;
}

#saveRankingBtn:hover {
    background-color: #229954;
}

#closeModalBtn {
    background-color: #95a5a6;
    color: white;
}

#closeModalBtn:hover {
    background-color: #7f8c8d;
}

/* 신기록 스타일 */
.new-record {
    color: #e74c3c !important;
    font-weight: bold;
    font-size: 1.3em;
}

.encouragement {
    color: #f39c12;
    font-style: italic;
}

/* 소셜 공유 섹션 */
.share-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    text-align: center;
}

.share-title {
    margin: 0 0 12px 0;
    font-size: 0.95em;
    color: #666;
    font-weight: 500;
}

.share-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.share-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.share-btn:active {
    transform: translateY(0);
}

.twitter-btn {
    background: #000000;
    color: white;
}

.twitter-btn:hover {
    background: #1a1a1a;
}

.facebook-btn {
    background: #1877f2;
    color: white;
}

.facebook-btn:hover {
    background: #0d65d9;
}

.copy-btn {
    background: #6c757d;
    color: white;
}

.copy-btn:hover {
    background: #5a6268;
}

.copy-btn.copied {
    background: #28a745;
    animation: copySuccess 0.5s ease;
}

@keyframes copySuccess {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* 튜토리얼 오버레이 */
.tutorial-overlay {
    display: none; /* 초기에는 숨김 */
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.tutorial-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px 30px;
    max-width: 700px;
    width: 90%;
    margin: 5vh auto;
    color: white;
    animation: slideUp 0.5s ease;
}

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

.tutorial-content h2 {
    text-align: center;
    margin: 0 0 30px 0;
    font-size: 2em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.tutorial-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.tutorial-step {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.tutorial-step:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.tutorial-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

.tutorial-step h3 {
    margin: 10px 0;
    font-size: 1.3em;
}

.tutorial-step p {
    margin: 0;
    font-size: 0.95em;
    opacity: 0.9;
}

.tutorial-tips {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 25px;
    border-left: 4px solid #ffd700;
}

.tutorial-tips p {
    margin: 0;
    font-size: 0.95em;
}

.tutorial-start-btn {
    width: 100%;
    padding: 15px 30px;
    font-size: 1.2em;
    font-weight: bold;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.4);
    margin-bottom: 15px;
}

.tutorial-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.6);
    background: linear-gradient(135deg, #34ce57 0%, #28e1a3 100%);
}

.tutorial-start-btn:active {
    transform: translateY(0);
}

.tutorial-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9em;
    cursor: pointer;
    opacity: 0.8;
}

.tutorial-checkbox input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

@media (max-width: 768px) {
    .tutorial-content {
        padding: 30px 20px;
        margin: 10px;
    }

    .tutorial-content h2 {
        font-size: 1.5em;
    }

    .tutorial-steps {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .tutorial-step {
        padding: 15px;
    }

    .tutorial-icon {
        font-size: 2.5em;
    }
}

canvas {
    border: 2px solid #333;
    background-color: #fff;
}

#ranking-container {
    width: 200px;
    padding: 10px;
    border: 2px solid #333;
    background-color: #fff;
}

#ranking-container .ranking-search-row {
  display: flex;
  gap: 2%;
  margin-bottom: 8px;
}
#ranking-search {
  width: 70%;
  padding: 6px 8px;
  box-sizing: border-box;
  font-size: 1em;
}
#ranking-search-btn {
  width: 28%;
  padding: 6px 8px;
  box-sizing: border-box;
  font-size: 1em;
}

h2 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 2px;
}

#ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#ranking-list li {
    padding: 5px 0;
    border-bottom: 1px solid #eee;
    font-size: 0.85em;
}

#ranking-list li:last-child {
    border-bottom: none;
}

/* 토글 스위치 스타일 */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
  user-select: none;
}
.toggle-switch input[type="checkbox"] {
  display: none;
}
.toggle-switch .slider {
  width: 40px;
  height: 22px;
  background: #ccc;
  border-radius: 22px;
  position: relative;
  transition: background 0.2s;
  cursor: pointer;
  box-sizing: border-box;
}
.toggle-switch .slider:before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.toggle-switch input[type="checkbox"]:checked + .slider {
  background: #3498db;
}
.toggle-switch input[type="checkbox"]:checked + .slider:before {
  transform: translateX(18px);
}
.toggle-switch .toggle-label {
  font-size: 1em;
  color: #333;
  min-width: 70px;
}