/* game-style.css */

/* ==========================================================================
   基本リセットと全体設定
   ========================================================================== */
body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* ゲーム画面外のスクロールを禁止 */
    font-family: 'Mochiy Pop One', 'Noto Sans JP', sans-serif;
    /* フォントを統一 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    /* 全体の背景グラデーション */
    color: #f0f0f0;
    display: flex;
    flex-direction: column; /* 子要素を縦に並べる */
    justify-content: center;
    align-items: center;
    user-select: none; /* ゲーム中の意図しないテキスト選択を防止 */
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   ゲームキャンバス
      ========================================================================== */
#gameCanvas {
    display: block;
    max-width: 100vw;
    max-height: 90vh;
    /* 上下のUIとの余白を確保 */
    aspect-ratio: 1280 / 720;
    background: linear-gradient(45deg, #ffeaa7, #fab1a0);
    /* パステル調のグラデーション */
    cursor: crosshair;
    border: 3px solid transparent;
    /* 初期状態では枠線を透明に */
    border-radius: 20px;
    /* 角を丸める */
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.3),
        /* 柔らかい外側の光 */
        inset 0 0 20px rgba(255, 255, 255, 0.1);
    /* 内側の光 */
    transition: all 0.3s ease;
    /* スムーズな変化を適用 */
    z-index: 1;
    /* UI要素の下に配置 */
}

#gameCanvas.placement-mode {
    cursor: cell;
    border: 3px solid #00b894;
    /* タワー設置モードを視覚的に示す */
    box-shadow: 0 0 40px #00b894,
        /* 強い光で強調 */
        inset 0 0 20px rgba(0, 184, 148, 0.2);
    animation: pulse 1s infinite alternate;
    /* 脈動アニメーション */
}

@keyframes pulse {
    from {
        box-shadow: 0 0 40px #00b894, inset 0 0 20px rgba(0, 184, 148, 0.2);
    }

    to {
        box-shadow: 0 0 60px #00b894, inset 0 0 30px rgba(0, 184, 148, 0.3);
    }
}

/* ==========================================================================
   ゲームUIコンテナとオーバーレイ
      ========================================================================== */
#game-ui-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* UI要素以外はクリックイベントを透過させる */
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 画面オーバーレイ共通スタイル (スタート画面, ゲームオーバー画面など) */
.game-screen,
.game-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(116, 75, 162, 0.9), rgba(102, 126, 234, 0.9));
    backdrop-filter: blur(10px);
    /* 背景をぼかす効果 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    pointer-events: none;
}

.game-screen.active,
.game-modal.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    /* アクティブな時だけ操作可能に */
}

.game-title {
    font-size: 4rem;
    color: #fff;
    text-shadow: 0 0 20px #ff6b9d, 0 0 40px #ff6b9d;
    /* ネオン風の輝き */
    margin-bottom: 1rem;
    animation: sparkle 2s infinite;
    /* will-change: transform; */ /* アニメーションのパフォーマンスを最適化 */
}

@keyframes sparkle {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.game-subtitle,
.final-score {
    font-size: 1.8rem;
    margin-bottom: 2rem;
    color: #ffeaa7;
    /* 柔らかい黄色 */
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   ボタン共通スタイル
      ========================================================================== */
.game-button {
    padding: 18px 40px;
    font-size: 1.3rem;
    font-family: inherit;
    /* bodyのフォントを継承 */
    background: linear-gradient(145deg, #ff6b9d, #ff8fab);
    /* ピンク系のグラデーション */
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(255, 107, 157, 0.4), inset 0 -4px 0 rgba(0, 0, 0, 0.2);
    /* 立体感を出す影 */
    transition: all 0.3s ease;
    margin: 15px;
    position: relative;
    overflow: hidden;
    /* :before要素のはみ出しを隠す */
}

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

.game-button:hover {
    transform: translateY(-5px);
    /* ホバー時に少し浮き上がる */
    box-shadow: 0 12px 25px rgba(255, 107, 157, 0.6), inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

.game-button:hover:before {
    left: 100%;
    /* ホバー時に光が流れるエフェクト */
}

.game-button:active {
    transform: translateY(-2px);
    /* クリック時に押し込む表現 */
}

.game-button.secondary {
    background: linear-gradient(145deg, #74b9ff, #0984e3);
    /* 青系のグラデーション */
    box-shadow: 0 8px 20px rgba(116, 185, 255, 0.4), inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

.game-button.secondary:hover {
    box-shadow: 0 12px 25px rgba(116, 185, 255, 0.6), inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   モーダル (遊び方など)
      ========================================================================== */
.modal-content {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9), rgba(44, 44, 58, 0.9));
    backdrop-filter: blur(15px);
    padding: 40px;
    border-radius: 30px;
    max-width: 90%;
    width: 600px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   HUD (ヘッドアップディスプレイ)
      ========================================================================== */
#game-hud {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 30px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
    /* グラスモーフィズム風 */
    backdrop-filter: blur(10px);
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 1.3rem;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    opacity: 0;
    /* 初期状態は非表示 */
    transition: opacity 0.5s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
    pointer-events: auto;
}

.hud-item {
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==========================================================================
   ゲーム内通知
      ========================================================================== */
#notification-area {
    position: absolute;
    bottom: 150px;
    /* スマートフォンUIの上に表示 */
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.game-notification {
    background: linear-gradient(135deg, #ff6b9d, #ff8fab);
    color: white;
    padding: 15px 25px;
    border-radius: 30px;
    font-size: 1.1rem;
    font-family: inherit;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    animation: notification-bounce 3s ease-in-out forwards;
    box-shadow: 0 5px 15px rgba(255, 107, 157, 0.4);
}

@keyframes notification-bounce {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }

    10% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    90% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
}

/* ==========================================================================
   スマートフォン用UI
      ========================================================================== */
#touch-controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%; /* 幅を調整 */
    max-width: 400px; /* 最大幅を設定 */
    display: flex; /* 常に表示 */
    justify-content: space-around;
    align-items: flex-end;
    padding: 0 30px;
    box-sizing: border-box;
    pointer-events: auto; /* 操作可能に */
    z-index: 20;
}

#joystick-area {
    width: 130px;
    height: 130px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
    border-radius: 50%;
    position: relative;
    pointer-events: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

#joystick {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #ff6b9d, #ff8fab);
    border-radius: 50%;
    transition: transform 0.1s linear;
    box-shadow: 0 3px 10px rgba(255, 107, 157, 0.5);
}

#tower-button,
#barracks-button {
    padding: 18px 30px;
    font-size: 1.2rem;
    font-family: inherit;
    background: linear-gradient(135deg, #00b894, #00a085);
    /* 緑系のグラデーション */
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(0, 184, 148, 0.4);
    pointer-events: auto;
    transition: all 0.3s ease;
}

#tower-button.active,
#barracks-button.active,
#tower-button:hover,
#barracks-button:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 184, 148, 0.6);
}

#tower-button.active,
#barracks-button.active {
    background: linear-gradient(135deg, #55efc4, #00b894);
}

/* ==========================================================================
   ゲーム操作ボタン (PC用)
      ========================================================================== */
#game-controls {
    position: fixed;
    top: 30px;
    right: 30px;
    z-index: 30;
    pointer-events: auto;
    display: flex;
    flex-wrap: wrap;
    /* ボタンが増えても折り返すように */
    gap: 10px;
    justify-content: flex-end;
    /* 右揃え */
}

.control-button,
#save-button,
#load-button,
#lang-toggle {
    padding: 12px 20px;
    font-size: 1rem;
    font-family: inherit;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-button:hover,
#save-button:hover,
#load-button:hover,
#lang-toggle:hover {
    transform: translateY(-3px);
}

.control-button:active,
#save-button:active,
#load-button:active,
#lang-toggle:active {
    transform: translateY(-1px);
}

/* 各ボタンの配色 */
.control-button {
    /* Pause, Restartなど */
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    /* 青系 */
    box-shadow: 0 4px 12px rgba(116, 185, 255, 0.4);
}

.control-button:hover {
    box-shadow: 0 6px 18px rgba(116, 185, 255, 0.6);
}

#save-button {
    background: linear-gradient(135deg, #55efc4, #00b894);
    /* 緑系 */
    box-shadow: 0 4px 12px rgba(0, 184, 148, 0.4);
}

#save-button:hover {
    box-shadow: 0 6px 18px rgba(0, 184, 148, 0.6);
}

#load-button {
    background: linear-gradient(135deg, #a29bfe, #6c5ce7);
    /* 紫系 */
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
}

#load-button:hover {
    box-shadow: 0 6px 18px rgba(108, 92, 231, 0.6);
}

#lang-toggle {
    background: linear-gradient(135deg, #fab1a0, #e17055);
    /* オレンジ系 */
    box-shadow: 0 4px 12px rgba(225, 112, 85, 0.4);
}

#lang-toggle:hover {
    box-shadow: 0 6px 18px rgba(225, 112, 85, 0.6);
}

/* ==========================================================================
   フッター
      ========================================================================== */
footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 10px 0;
    text-align: center;
    font-size: 12px;
    font-family: sans-serif;
    /* フッターは可読性の高いゴシック体に */
    z-index: 100;
    pointer-events: none;
}

.footer-content {
    pointer-events: auto;
    padding: 0 20px;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.social-links a {
    color: #fff;
    text-decoration: none;
    margin: 0 10px;
    transition: opacity 0.3s ease;
}

.social-links a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.copyright {
    margin: 0;
    font-size: 11px;
}

/* ==========================================================================
   タワー選択UI
      ========================================================================== */
#tower-select-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    /* JSで制御 */
    gap: 10px;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 10px;
    z-index: 30;
    pointer-events: auto;
}

#game-ui-container.tower-select-active #tower-select-ui {
    display: flex;
}

.tower-select-button {
    padding: 8px 15px; /* 少し大きく */
    border: 2px solid #fff; /* 白い枠線 */
    border-radius: 8px; /* 角丸 */
    cursor: pointer;
    background-color: rgba(255, 255, 255, 0.2); /* 半透明の背景 */
    color: #fff;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.tower-select-button:hover {
    background-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.tower-select-button.selected {
    background-color: #55efc4; /* 選択時の色を強調 */
    border-color: #00b894;
    color: #333;
    box-shadow: 0 0 15px #55efc4, 0 0 25px #55efc4; /* 選択時に光る */
    transform: scale(1.05);
}

/* ==========================================================================
   アクセシビリティ向上: キーボード操作用のフォーカススタイル
   ========================================================================== */
:is(.game-button, .control-button, #save-button, #load-button, #lang-toggle, .tower-select-button):focus-visible {
    outline: 3px solid #00b894;
    outline-offset: 2px;
    box-shadow: 0 0 15px #55efc4;
}

/* ==========================================================================
   レスポンシブ対応
      ========================================================================== */
@media (max-width: 800px) {
    #game-hud {
        flex-direction: column;
        gap: 5px;
        top: 10px;
        left: 10px;
        transform: none;
        align-items: flex-start;
    }

    #game-controls {
        top: 10px;
        right: 10px;
    }

    /* #touch-controls の display はデフォルトで flex になったため、このメディアクエリは不要 */

    .game-title {
        font-size: 2.5rem;
    }

    .game-subtitle {
        font-size: 1.2rem;
    }
}
