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

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

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

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

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

/* 球のアニメーションを修正 */
@keyframes pitchBall {
    0% { 
        top: 65%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(1);
    }
    100% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

@keyframes hitBallRight {
    0% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% { 
        top: 45%; 
        left: 75%;
        transform: translate(-50%, -50%) scale(0.6);
    }
}

@keyframes hitBallLeft {
    0% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% { 
        top: 45%; 
        left: 25%;
        transform: translate(-50%, -50%) scale(0.6);
    }
}

@keyframes hitBallCenter {
    0% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% { 
        top: 20%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.5);
    }
}

@keyframes homerunBall {
    0% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% { 
        top: -10%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.2);
    }
}

@keyframes swingBat {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-45deg); }
    100% { transform: rotate(30deg); }
}

@keyframes runToBase {
    0% { 
        top: 85%; 
        left: 50%;
    }
    100% { 
        top: 70%; 
        left: 70%;
    }
}

@keyframes flash {
    0%, 50%, 100% { background-color: red; }
    25%, 75% { background-color: white; }
}

@keyframes pitchIndicator {
    0% { left: 0; }
    100% { left: 100%; }
}

@keyframes fadeOutUp {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-20px); }
}

/* カウントダウン表示のスタイル */
.countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 80px;
    font-weight: bold;
    color: rgba(231, 76, 60, 0.8);
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    z-index: 30;
    opacity: 0;
    animation: fadeInOut 1s ease-in-out forwards;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f0f0f0;
    padding: 20px;
    min-height: 100vh;
}

.game-container {
    max-width: 950px; /* 800pxから950pxに拡大 */
    margin: 0 auto;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.5s ease-in-out;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #1a5276;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    animation: slideIn 0.5s ease-in-out;
}

h1 i {
    color: #e74c3c;
    margin-left: 10px;
}

.scoreboard {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #2c3e50;
    border-radius: 8px;
    color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.team {
    text-align: center;
    flex: 1;
}

.inning-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    background-color: #3498db;
}

#inning-number {
    font-size: 1.5em;
    font-weight: bold;
}

#inning-half {
    font-size: 0.9em;
}

.score {
    font-size: 2.5em;
    font-weight: bold;
    margin-top: 5px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.score.updated {
    animation: pulse 0.5s ease;
    color: #e74c3c;
}

.game-info {
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f8f8;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.difficulty-selector {
    text-align: center;
    margin-top: 10px;
}

.difficulty-selector select {
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #ccc;
    background-color: white;
    font-size: 0.9em;
    cursor: pointer;
}

.inning {
    text-align: center;
    font-size: 1.2em;
    margin-bottom: 10px;
    font-weight: bold;
    color: #2c3e50;
}

.count {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}

.count-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 10px;
}

.count-label {
    font-weight: bold;
    margin-bottom: 5px;
    color: #2c3e50;
}

.count-dots {
    display: flex;
    gap: 5px;
}

.dot {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background-color: #ddd;
    transition: background-color 0.3s ease;
}

.dot.active {
    background-color: #e74c3c;
}

.field {
    position: relative;
    width: 450px; /* 380pxから450pxに拡大 */
    height: 450px; /* 380pxから450pxに拡大 */
    margin: 0 auto 30px;
    perspective: 800px;
    background-color: #8bc34a; /* 芝生色の背景 */
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.diamond {
    position: absolute;
    width: 220px; /* 180pxから220pxに拡大 */
    height: 220px; /* 180pxから220pxに拡大 */
    top: 62%; /* 60%から62%へ調整 */
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    background-color: #c19a6b; /* 土色 */
    border: 4px solid #996633;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    z-index: 4; /* z-indexを調整してベースが表示されるようにする */
}

/* 塁の視認性を向上 */
.base {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: white;
    border: 2px solid #333;
    transition: all 0.3s ease;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    z-index: 7; /* z-indexをさらに上げて確実に表示されるように */
}

#first-base {
    top: 0;
    right: 0;
}

#second-base {
    top: 0;
    left: 0;
    background-color: #ffffff; /* 明示的に色を指定 */
    border-color: #000000; /* 枠線の色を明示的に設定 */
    display: block !important; /* 強制的に表示 */
    z-index: 10; /* さらにz-indexを上げる */
    width: 22px; /* 少し大きく */
    height: 22px; /* 少し大きく */
}

#third-base {
    bottom: 0;
    left: 0;
}

.home-plate {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 25px;
    height: 25px;
    background-color: white;
    border: 2px solid #333;
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 50% 50%, 0% 100%);
    z-index: 6; /* z-indexを上げて確実に表示されるように */
}

.base.occupied {
    background-color: #e74c3c;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.7);
    animation: pulse 1s infinite;
    border-color: #c0392b;
}

.base.running-to {
    animation: flash 0.5s infinite;
}

.pitcher, .batter, .fielder {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

/* 内野手と外野手の位置修正 - マウンドに合わせて調整 */
.pitcher {
    position: absolute;
    top: 65%; /* 55%から65%にさらに下方向に調整してマウンドに合わせる */
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #3498db;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.pitcher i {
    color: white;
    font-size: 14px;
}

.pitcher.pitching {
    animation: bounce 0.3s ease-in-out;
}

.batter i {
    color: white;
    font-size: 16px;
}

/* バットアイコンの追加 */
.batter .bat {
    position: absolute;
    width: 25px;
    height: 5px;
    background-color: #8B4513; /* 茶色 */
    right: -15px;
    top: 12px;
    border-radius: 2px;
    transform-origin: left center;
    transform: rotate(0deg);
    transition: transform 0.2s;
}

.batter.swinging .bat {
    animation: swingBat 0.3s ease-in-out;
}

.batter {
    bottom: 15%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #e74c3c;
    z-index: 5;
}

.fielder {
    background-color: #3498db;
}

/* 内野手の位置を修正 - より後ろに配置 */
#fielder1 { /* ファースト */
    top: 60%;
    left: 70%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

#fielder2 { /* セカンド */
    top: 40%; /* 50%から40%に後ろに調整 */
    left: 60%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

#fielder3 { /* ショート */
    top: 40%; /* 50%から40%に後ろに調整 */
    left: 40%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

#fielder4 { /* サード */
    top: 60%;
    left: 30%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

/* 外野手の位置をさらに後ろに調整 */
#fielder5 { /* レフト */
    top: 25%; /* 35%から25%に後ろに調整 */
    left: 25%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

#fielder6 { /* センター */
    top: 20%; /* 30%から20%に後ろに調整 */
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

#fielder7 { /* ライト */
    top: 25%; /* 35%から25%に後ろに調整 */
    left: 75%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

/* キャッチャーの位置も微調整 */
#catcher {
    bottom: 8%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #3498db;
    z-index: 4;
}

.outfield {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background-color: #8bc34a; /* 芝生色 */
    border-radius: 50% 50% 0 0;
    z-index: 1;
}

.infield {
    position: absolute;
    top: 30%;
    left: 50%;
    width: 60%;
    height: 60%;
    transform: translate(-50%, -50%);
    background-color: #c19a6b; /* 土色 */
    border-radius: 50%;
    z-index: 2;
}

/* マウンドの位置も調整して一致させる */
.mound {
    position: absolute;
    top: 65%; /* 40%から65%に下方向に調整 */
    left: 50%;
    width: 40px; /* 30pxから40pxに拡大 */
    height: 40px; /* 30pxから40pxに拡大 */
    transform: translate(-50%, -50%);
    background-color: #996633; /* 濃い土色 */
    border-radius: 50%;
    z-index: 3;
}

/* ボールのスタイルと挙動改善 */
.ball {
    position: absolute;
    width: 15px;
    height: 15px;
    background-color: white;
    border: 1px solid #333;
    border-radius: 50%;
    top: 65%;  /* 40%から65%に修正してピッチャーの位置に合わせる */
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    z-index: 15;
    opacity: 0;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    /* アニメーション初期状態 */
    animation: none !important;
    /* 不要なトランジションを防止 */
    transition: none !important;
    will-change: top, left, transform; /* パフォーマンス改善 */
}

.ball.pitching {
    opacity: 1 !important;
    animation: pitchBall 1.2s linear forwards !important;
}

.ball.hitting-right {
    opacity: 1 !important;
    animation: hitBallRight 1s linear forwards !important;
}

.ball.hitting-left {
    opacity: 1 !important;
    animation: hitBallLeft 1s linear forwards !important;
}

.ball.hitting-center {
    opacity: 1 !important;
    animation: hitBallCenter 1s linear forwards !important;
}

.ball.homerun {
    opacity: 1 !important;
    animation: homerunBall 1.5s linear forwards !important;
}

.ball.curve {
    opacity: 1 !important;
    animation: pitchCurve 1.4s linear forwards !important;
}

.ball.slider {
    opacity: 1 !important;
    animation: pitchSlider 1.4s linear forwards !important;
}

.ball.changeup {
    opacity: 1 !important;
    animation: pitchChangeup 1.7s ease-in forwards !important;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

button {
    padding: 12px 25px;
    font-size: 1em;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
    background-color: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.action-btn {
    background-color: #e74c3c;
}

.action-btn:hover {
    background-color: #c0392b;
}

#reset-btn {
    background-color: #7f8c8d;
}

#reset-btn:hover {
    background-color: #6c7a7d;
}

button i {
    margin-right: 8px;
}

.message-container {
    background-color: #f8f8f8;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message {
    padding: 10px;
    min-height: 50px;
    text-align: center;
    font-size: 1.3em;
    font-weight: bold;
    color: #2c3e50;
    transition: all 0.3s ease;
}

.message.highlight {
    color: #e74c3c;
    animation: pulse 0.5s ease-in-out;
}

.effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.effect {
    position: absolute;
    font-size: 24px;
    font-weight: bold;
    animation: effectAnimation 1.5s forwards;
    color: #e74c3c;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

@keyframes effectAnimation {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

/* 投球インジケーターの修正 */
.pitch-indicator {
    position: absolute;
    bottom: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 150px;
    height: 20px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    display: none;
    z-index: 20;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.pitch-timing-bar {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    overflow: hidden;
}

.timing-cursor {
    position: absolute;
    width: 8px;
    height: 100%;
    background-color: white;
    border-radius: 4px;
    left: 0;
    top: 0;
    transition: none;
}

.perfect-timing-zone {
    position: absolute;
    width: 20%;
    height: 100%;
    background-color: rgba(231, 76, 60, 0.7);
    left: 40%;
    top: 0;
    border-radius: 0;
}

.timing-feedback {
    position: relative;
    margin: 0 auto 10px;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    color: #3498db;
    min-height: 24px;
}

.timing-feedback.perfect {
    color: #e74c3c;
    animation: pulse 0.5s ease-in-out;
}

.timing-feedback.good {
    color: #2ecc71;
}

.timing-feedback.early, .timing-feedback.late {
    color: #f39c12;
}

.timing-popup {
    position: absolute;
    font-size: 18px;
    font-weight: bold;
    animation: fadeOutUp 0.8s forwards;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
}

.timing-popup.perfect {
    color: #e74c3c;
}

.timing-popup.good {
    color: #2ecc71;
}

.timing-popup.early, .timing-popup.late {
    color: #f39c12;
}

#auto-mode-btn {
    background-color: #3498db;
}

#auto-mode-btn:hover {
    background-color: #2980b9;
}

#auto-mode-btn.active {
    background-color: #2ecc71;
}

/* 守備側の投球コントロールパネル */
.pitching-controls {
    position: relative; /* absoluteからrelativeに変更 */
    margin: 15px auto 20px; /* マージンを追加 */
    background-color: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 25;
    display: none; /* 初期状態では非表示 */
    flex-direction: column;
    gap: 8px;
    text-align: center;
    width: 300px;
    /* bottom, left, transformプロパティを削除 */
}

/* 現在選択中の球種情報も同様に修正 */
.current-pitch-info {
    text-align: center;
    margin: 10px auto; /* auto marginで中央配置 */
    font-size: 0.9em;
    font-weight: bold;
    color: #2c3e50;
    display: none; /* 初期状態では非表示 */
}

/* 各球種ごとの軌道アニメーション */
@keyframes pitchCurve {
    0% { 
        top: 65%; /* 45%から65%に修正 */
        left: 50%;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        top: 65%;
        left: 45%;
        transform: translate(-50%, -50%) scale(0.9);
    }
    100% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

@keyframes pitchSlider {
    0% { 
        top: 65%; /* 45%から65%に修正 */
        left: 50%;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        top: 65%;
        left: 55%;
        transform: translate(-50%, -50%) scale(0.9);
    }
    100% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

@keyframes pitchChangeup {
    0% { 
        top: 65%; /* 45%から65%に修正 */
        left: 50%;
        transform: translate(-50%, -50%) scale(1);
    }
    100% { 
        top: 85%; 
        left: 50%;
        transform: translate(-50%, -50%) scale(0.8);
        animation-timing-function: ease-out;
    }
}

/* レスポンシブデザイン */
@media (max-width: 600px) {
    .game-container {
        padding: 10px;
    }
    
    .field {
        width: 280px;
        height: 280px;
    }
    
    .diamond {
        width: 160px;
        height: 160px;
    }
    
    .controls {
        flex-wrap: wrap;
    }
    
    button {
        flex: 1 0 40%;
        margin-bottom: 10px;
    }
}

/* より横長のレイアウトのための追加スタイル */
@media (min-width: 800px) {
    .game-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .count {
        flex: 1;
        justify-content: center;
    }
    
    .inning {
        min-width: 120px;
        text-align: left;
        margin-bottom: 0;
    }
    
    .difficulty-selector {
        min-width: 120px;
        margin-top: 0;
    }
    
    /* 投球コントロールパネルを横長に */
    .pitching-controls {
        width: 400px;
    }
    
    .pitch-type-selector {
        display: flex;
        justify-content: space-between;
    }
}
