body {
    font-family: Arial, Helvetica, sans-serif;
    margin: 0;
}

/* Adjust body padding when game mode is active */
body.game-mode {
    padding-top: 80px;
}

/* Game Controls */
#gameControls {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
}

/* Hide game controls during game mode only */
body.game-mode #gameControls {
    display: none;
}

#gameModeToggle {
    padding: 10px 20px;
    background-color: #333;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    min-height: 44px; /* iOS minimum touch target size */
    min-width: 44px;
    touch-action: manipulation;
}

#gameModeToggle:hover {
    background-color: #555;
}

/* Game UI */
#gameUI {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgba(255, 255, 255, 1);
    padding: 10px 10px;
    z-index: 500;
    pointer-events: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

#gameQuestion {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    text-align: center;
}

.flag-label {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

#questionFlag {
    width: 80px;
    height: auto;
    border: 2px solid #ddd;
    border-radius: 5px;
}

#gameTimer {
    font-size: 16px;
    font-weight: bold;
    color: #007bff;
}

#giveUpButton {
    padding: 8px 16px;
    background-color: #ffc107;
    color: #333;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

#giveUpButton:hover {
    background-color: #e0a800;
}

#gameResult {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#gameResultButtons {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

#gameResult h3 {
    margin: 0;
}

#nextQuestion, #endGame, #endGameResult {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 20px;
}

#nextQuestion {
    background-color: #007bff;
    color: white;
}

#nextQuestion:hover {
    background-color: #0056b3;
}

#endGame, #endGameResult {
    background-color: #dc3545;
    color: white;
}

#endGame:hover, #endGameResult:hover {
    background-color: #c82333;
}

/* Language Selector Styles */
#langSelector {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

/* Hide language selector during game mode only */
body.game-mode #langSelector {
    display: none;
}

#langButton {
    background-color: #333;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    min-width: 90px;
    min-height: 44px; /* iOS minimum touch target size */
    touch-action: manipulation;
}

#langButton:hover {
    background-color: #555;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #f9f9f9;
    min-width: 150px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    border-radius: 5px;
    z-index: 1001;
    max-height: 300px;
    overflow-y: auto;
}

.dropdown-content a {
    color: black;
    padding: 8px 12px;
    text-decoration: none;
    display: block;
    font-size: 13px;
}

.dropdown-content a:hover {
    background-color: #f1f1f1;
}

.dropdown-content a:first-child {
    border-radius: 5px 5px 0 0;
}

.dropdown-content a:last-child {
    border-radius: 0 0 5px 5px;
}

#langSelector.show .dropdown-content {
    display: block;
}

/* Flag List Button */
.flag-list-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #333;
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: background-color 0.3s;
    z-index: 999;
    text-align: center;
    touch-action: manipulation;
    /* Ensure minimum touch target size for iOS */
    min-width: 44px;
    min-height: 44px;
    /* Perfect centering for emoji on iOS */
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    /* Prevent emoji scaling issues */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI Emoji', 'Apple Color Emoji', sans-serif;
}

/* Hide flag list button during game mode only */
body.game-mode .flag-list-button {
    display: none;
}

.flag-list-button:hover {
    background-color: #555;
}

.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1001; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
    /* Flexbox for better centering */
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
}

.modal.show {
    display: flex;
}

.modal-content {
    margin: 0;
    display: block;
    max-width: 90vw;
    max-height: 70vh;
    width: auto;
    height: auto;
    border: 1px solid #333;
    object-fit: contain;
}

#caption {
    margin: 10px auto 0;
    display: block;
    max-width: 90vw;
    text-align: center;
    color: #ccc;
    padding: 10px;
    background-color: rgba(0,0,0,0.7);
    border-radius: 5px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    box-sizing: border-box;
    line-height: 1.4;
    font-size: 16px;
}

.close {
    position: fixed;
    top: 20px;
    right: 30px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    z-index: 1002;
    background: none;
    border: none;
    padding: 5px;
    line-height: 1;
    /* Ensure it's visible on all backgrounds */
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
    transform: scale(1.1);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #gameQuestion {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .flag-label {
        font-size: 16px;
    }

    #gameTimer {
        font-size: 14px;
    }

    #gameUI {
        padding: 8px 10px;
    }
}

/* Flag List Modal Content */
.flag-list-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 10px;
    position: relative;
}

.flag-list-close {
    color: #aaa;
    font-size: 60px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
}

.flag-list-close:hover,
.flag-list-close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.region-section {
    margin-bottom: 30px;
}

.region-title {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 15px;
    color: #333;
    border-bottom: 2px solid #4CAF50;
    padding-bottom: 5px;
}

.flags-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
}

.flag-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.flag-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.flag-item img {
    width: 60px;
    height: auto;
    margin-bottom: 8px;
    border: 1px solid #ccc;
}

.flag-item .country-name {
    font-size: 12px;
    text-align: center;
    color: #666;
    font-weight: 500;
}

/* iOS and touch device support */
button {
    -webkit-tap-highlight-color: rgba(0,0,0,0.3);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: pointer;
    /* Ensure buttons are properly recognized as clickable on iOS */
    -webkit-appearance: none;
    appearance: none;
}

/* Touch support for buttons */
#gameModeToggle,
#langButton {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255,255,255,0.3);
    /* Additional iOS touch fixes */
    pointer-events: auto;
    position: relative;
}

/* Touch support for flag list button (keeping its fixed positioning) */
.flag-list-button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255,255,255,0.3);
    pointer-events: auto;
}

/* iOS パフォーマンス最適化 */
#globeViz {
  /* GPU レイヤー最適化 */
  will-change: transform;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  
  /* iOS Safari 向けスムーズスクロール無効化 */
  -webkit-overflow-scrolling: auto;
  
  /* レンダリング最適化 */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  
  /* iOS での3Dアクセラレーション強制 */
  perspective: 1000px;
  -webkit-perspective: 1000px;
}

/* モーダル表示時のパフォーマンス最適化 */
.modal.show {
  display: flex;
  /* GPU レイヤー分離 */
  will-change: opacity, transform;
  transform: translateZ(0);
}

.modal-content {
  /* 画像描画最適化 */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: optimize-contrast;
  
  /* iOS での画像スムージング */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* フラッグリストの最適化 */
.flag-item {
  /* レンダリング最適化 */
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flag-item img {
  /* 画像描画の最適化 */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: optimize-contrast;
  transform: translateZ(0);
}

/* iOS向けタッチ最適化 */
@media screen and (max-device-width: 1024px) {
  #globeViz {
    /* モバイルでさらに軽量化 */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
  }
  
  /* バッテリー節約モード対応 */
  @media (prefers-reduced-motion: reduce) {
    #globeViz {
      will-change: auto;
    }
    
    .flag-item {
      transition: none !important;
    }
  }
}
