/* --- 基本設定とiPad最適化 --- */
:root {
    --bg-color: #f4f7f6;
    --main-color: #ffffff;
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --text-color: #333;
    --locked-color: #ccc;
    --correct-color: #28a745;
    --incorrect-color: #dc3545;
    --underline-color: #999; /* ハードモードのアンダーバー色 */
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    /* ピンチズームの防止 */
    touch-action: manipulation;
}

/* --- アプリコンテナ (iPadの画面比を想定) --- */
#app-container {
    width: 100vw;
    height: 100vh;
    /* iPad (4:3) の横向きを最大サイズとする */
    max-width: 1024px;
    max-height: 768px;
    margin: auto;
    background: var(--main-color);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    display: flex; /* 子要素(.screen)がflexアイテムになるように */
}

/* --- 画面共通 --- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 3vmin;
    display: none; /* JSで .active をつけて表示 */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3vmin;
}

.screen.active {
    display: flex;
}

h1 {
    font-size: 7vmin;
    color: var(--primary-color);
}

h2 {
    font-size: 4vmin;
    text-align: center;
    margin-bottom: 1vmin;
}

/* --- ボタン共通 --- */
.btn {
    padding: 2vmin 4vmin;
    font-size: 2.5vmin;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    transition: background-color 0.2s;
    text-decoration: none;
    text-align: center;
    min-width: 200px;
}

.btn:hover {
    background-color: var(--primary-hover);
}

.btn-back {
    background-color: #6c757d;
}
.btn-back:hover {
    background-color: #5a6268;
}

/* --- ホーム画面 --- */
.selection-container {
    width: 80%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 2vmin;
}

#course-grid {
    display: flex;
    flex-direction: column; /* 縦並び */
    gap: 1.5vmin;
    width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    padding: 1vmin;
    background: #f9f9f9;
    border-radius: 8px;
}

.course-btn {
    padding: 2vmin 3vmin; /* 上下/左右のパディング調整 */
    font-size: 2vmin;
    min-width: auto;
    width: 100%; /* 横幅いっぱい */
    text-align: left; /* テキスト左寄せ */
}

.course-btn.locked {
    background-color: var(--locked-color);
    cursor: not-allowed;
}

/* --- ゲーム画面 --- */
#game-header {
    width: 90%;
    display: flex;
    justify-content: space-between;
    font-size: 3vmin;
    font-weight: bold;
    position: absolute;
    top: 3vmin;
}

#problem-area {
    width: 90%;
    text-align: center;
}

#ja-text {
    font-size: 3vmin;
    margin-bottom: 3vmin;
    color: #555;
    height: 4vmin; /* 領域確保 */
}

#en-text {
    font-size: 4vmin;
    font-weight: bold;
    letter-spacing: 1px;
    height: 5vmin; /* 領域確保 */
}

/* ハードモードのスタイル */
#en-text-hard {
    font-size: 4vmin;
    font-weight: bold;
    letter-spacing: 1px;
    height: 5vmin; /* 領域確保 */
    display: flex;
    justify-content: center;
    flex-wrap: wrap; /* 長い文章の折り返し */
    color: var(--text-color); /* タイプ成功時の文字色 */
}

#en-text-hard span {
    min-width: 1.5vmin; /* 'i'などの細い文字用の最小幅 */
    color: var(--underline-color); /* アンダーバーの色 */
}


#input-box {
    width: 90%;
    max-width: 800px;
    padding: 2vmin;
    text-align: center;
    border: 2px solid #ccc;
    border-radius: 8px;
    /* iOSでの自動ズームを防ぐ＆サイズを2倍に */
    font-size: 32px; /* ★ 16pxから32pxに変更 */
}

#home-btn {
    position: absolute;
    bottom: 3vmin;
    right: 3vmin;
    padding: 1.5vmin 3vmin;
    font-size: 2vmin;
    min-width: auto;
    background-color: #dc3545;
}
#home-btn:hover {
    background-color: #c82333;
}

/* --- 結果画面 --- */
#result-title {
    font-size: 5vmin;
}
#result-message {
    font-size: 3.5vmin;
    font-weight: bold;
}
#result-message.clear {
    color: var(--correct-color);
}
#result-message.fail {
    color: var(--incorrect-color);
}

#result-details {
    font-size: 3vmin;
    line-height: 1.8;
}
/* （これまでのCSSはそのまま保持し、以下を追加・修正してください） */

/* --- ホーム画面：ランク表示 --- */
#rank-display {
    background-color: #fff;
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    padding: 1.5vmin 3vmin;
    margin-bottom: 2vmin;
    text-align: center;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.rank-label {
    font-size: 2vmin;
    color: #777;
}

#player-rank-name {
    font-size: 4vmin;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0.5vmin 0;
}

.rank-exp {
    font-size: 2vmin;
    color: #555;
}

/* --- ゲーム画面：モンスターエリア --- */
#monster-area {
    position: relative;
    width: 100%;
    height: 30vh; /* ★変更: 25vh -> 40vh に拡大 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 2vmin;
}

#monster-img {
    height: 90%; /* ★変更: エリアいっぱいに表示 */
    width: auto;
    object-fit: contain;
    transition: transform 0.1s;
    
}

/* ダメージを受けた時の振動アニメーション */
.shake {
    animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* 倒された時のフェードアウト */
.defeated {
    opacity: 0;
    transform: scale(1.5);
    transition: opacity 0.5s, transform 0.5s;
}

/* HPバー */
#hp-bar-container {
    width: 60%;
    max-width: 400px;
    height: 1.5vmin;
    background-color: #ddd;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 1vmin;
    border: 1px solid #bbb;
}

#hp-bar-fill {
    width: 100%; /* 初期値満タン */
    height: 100%;
    background-color: var(--incorrect-color); /* HPなので赤や緑 */
    transition: width 0.2s ease-out, background-color 0.3s;
}

/* ダメージ数値エフェクト */
#damage-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5vmin;
    font-weight: bold;
    color: red;
    opacity: 0;
    pointer-events: none;
}

.damage-pop {
    animation: damagePop 0.5s ease-out;
}

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

/* レイアウト調整 */
#problem-area {
    margin-top: 0; /* モンスターの下になるのでマージン調整 */
}