body {
    margin: 0;
    overflow: hidden;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    /* #infoの位置基準用 */
}

/* Three.jsのCanvasがコンテナいっぱいに広がるように */

canvas {
    display: block;
}

#info {
    position: absolute;
    bottom: 10px;
    right: 10px;
    color: white;
    font-family: sans-serif;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 5px;
    pointer-events: none;
    /* マウス操作を透過させる */
    z-index: 10;
    /* Canvasの上に表示 */

}

#player-stats {
    position: absolute;
    bottom: 10px;
    left: 10px;
    color: white;
    font-family: sans-serif;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 5px;
    z-index: 10;
    width: 200px;

}

#atk-def-combined-row {
    display: flex;
    justify-content: center;
    /* 中央に配置 */
    gap: 25px;
    /* ATKとDEFの間隔 */
    width: 100%;
    margin-top: 5px;
    /* 上の要素との間隔 */
}

.atk-def-item {
    display: flex;
    align-items: center;
}

.stat-row {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.stat-row:last-child {

    margin-bottom: 0;
}

.stat-row span {
    min-width: 35px;
}

.bar-container {
    flex-grow: 1;
    height: 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    border: 1px solid #555;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.bar {
    height: 100%;
    border-radius: 6px;
    transition: width 0.2s ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
}

#hp-bar {
    background-color: #ff4757;
    width: 100%;
}

#energy-bar {
    background-color: #ff4757;
    width: 100%;
}

#energy-bar {
    background-color: #2ed573;
    width: 100%;
}

#exp-bar {
    background-color: #f1c40f;
    width: 0%;
}

#hp-value,
#energy-value,
#exp-value {
    position: relative;
    z-index: 1;
    font-size: 11px;
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

#inventory {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 250px;
    max-height: calc(100vh - 160px);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-family: sans-serif;
    border-radius: 5px;
    padding: 10px;
    z-index: 10;
    display: none;
    /* 初期状態は非表示 */
    flex-direction: column;
}

#inventory h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    text-align: center;
}

#inventory-grid {
    display: block;
    /* gridからblockへ変更 */
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 5px;
    overflow-y: auto;
    max-height: none;
    flex: 1;
}

.inventory-slot {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px;
    box-sizing: border-box;
    font-size: 10px;
    word-wrap: break-word;
}

.inventory-slot {
    width: auto;
    /* Full width of inventory panel */
    height: auto;
    /* Auto height for text */
    padding: 8px 10px;
    /* More padding for text */
    border: none;
    /* Remove border */
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    /* Separator */
    border-radius: 0;
    /* No border radius */
    font-size: 14px;
    /* Larger font */
    cursor: pointer;
    white-space: nowrap;
    /* Prevent wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
    background: transparent;
    /* Transparent background */
    transition: background 0.1s;
}

.inventory-slot:hover {
    background: rgba(255, 255, 255, 0.1);
}

.inventory-slot.focused {
    background: rgba(0, 150, 255, 0.3);
    /* Highlight focused item */
    border-left: 3px solid #00e5ff;
    padding-left: 7px;
    /* Adjust padding due to border */
}

.inventory-slot.temporary-item {
    background-color: #5a2a2a;
    /* 暗い赤色 */
    border-left: 3px solid #ff4757;
    /* 赤いボーダー */
    color: #ffdddd;
    /* 少しピンクがかった白 */
}

.inventory-slot.temporary-item.focused {
    background-color: #8a3a3a;
    /* フォーカス時はさらに明るく */
}

#item-description {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #444;
    font-size: 13px;
    color: #ddd;
    min-height: 1.5em;
    /* 1行分の高さを確保 */
    text-align: center;
}

.slime-ui {
    position: absolute;
    top: 0;
    left: 0;
    transform: translate(-50%, -100%);
    /* 中央上部に配置 */
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: sans-serif;
    font-size: 12px;

    text-align: center;
    width: auto;
    white-space: nowrap;
    pointer-events: none;
    visibility: hidden;
    /* 最初は非表示 */
    transition: opacity 0.2s;
}

.slime-hp-bar-container {
    width: 100%;
    height: 4px;
    background: #555;
    margin-top: 2px;
}

.slime-hp-bar {
    width: 100%;
    height: 100%;
    background: #ff4757;
}

#game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: sans-serif;
    z-index: 100;
}

#game-over h1 {
    font-size: 3em;
    margin-bottom: 20px;
}

#retry-button {
    padding: 10px 20px;
    font-size: 1.5em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#retry-button:hover {
    background-color: #367c39;
}

/* --- タッチ操作用UI --- */
#touch-controls-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* デフォルトではイベントを透過 */
    z-index: 20;
    display: none;
    /* デフォルトでは非表示 */
}

/* スマートフォンなどのタッチデバイスでのみ表示 */
@media (hover: none) and (pointer: coarse) {
    #touch-controls-container {
        display: block;
    }

    #info {
        /* PC用の操作説明は非表示に */
        display: none;
    }
}

/* style.css に追加または修正 */

/* --- タッチUI --- */
/* 右下のアクションボタンコンテナ */
#action-buttons-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: grid;
    /* 2x2のグリッドレイアウト */
    grid-template-columns: repeat(2, 65px);
    grid-template-rows: repeat(2, 65px);
    gap: 15px;
}

/* 各ボタンのグリッド配置順序を指定 */
#attack-button {
    grid-area: 2 / 2 / 3 / 3;
    /* 右下 */
}

#defend-button {
    grid-area: 1 / 2 / 2 / 3;
    /* 右上 */
}

#inventory-button {
    grid-area: 2 / 1 / 3 / 2;
    /* 左下 */
}

#fullscreen-button {
    grid-area: 1 / 1 / 2 / 2;
    /* 左上 */
}

/* アクションボタンの共通スタイル */
.action-button {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    border-radius: 50%;
    /* 丸い形にする */
    font-size: 28px;
    /* アイコンのサイズ調整 */
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: background-color 0.2s;
}

.action-button:active,
.action-button.active {
    background-color: rgba(255, 255, 255, 0.3);
}


.touch-ui-element {
    position: absolute;
    pointer-events: auto;
    /* UI要素はイベントを受け取る */
    background-color: transparent;
    border-radius: 50%;
    box-sizing: border-box;
}

#joystick-container {
    bottom: 40px;
    left: 40px;
    width: 150px;
    height: 150px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

#joystick-thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    background-color: rgba(200, 200, 200, 0.6);
    transform: translate(-50%, -50%);
    border-radius: 50%;
}

#action-buttons-container {
    bottom: 40px;
    right: 40px;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 15px;
}

.action-button {
    width: 60px;
    height: 60px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 14px;
    font-weight: bold;
    -webkit-user-select: none;
    /* テキスト選択無効 */
    user-select: none;
}

.action-button.active {
    background-color: rgba(255, 255, 255, 0.4);
}

#pause-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: sans-serif;
    z-index: 100;
}

#pause-screen h1 {
    font-size: 3em;
    margin-bottom: 20px;
}

#title-screen, #prologue-screen, #epilogue-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    display: none;
    z-index: 2000;
    cursor: pointer;
    /* Text positioning */
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    color: white;
    font-family: sans-serif;
    text-align: center;
}

.screen-prompt {
    padding-bottom: 5vh;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.screen-prompt p {
    margin: 0;
    font-size: 1.2em;
}

.screen-prompt h2 {
    margin: 5px 0 0 0;
    font-size: 2em;
}