body {
    margin: 0;
    overflow: hidden; /* スクロールバーを非表示にする */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: #333;
    color: #eee;
    font-family: 'Press Start 2P', cursive;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

#game-container {
    position: relative;
    border: 2px solid #555;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
}

#info-panel {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    box-sizing: border-box;
    background-color: #222;
    border-bottom: 1px solid #555;
    font-size: 12px;
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

#left-info {
    min-width: 0;
}

#hp-display,
#skill-level-display,
#stats-display,
#score-display,
#exp-display,
#depth-display,
#highest-depth-display,
#layer-display,
#digging-points-display {
    color: #eee; /* すべてのパラメータの文字色を白に戻す */
}

canvas {
    background-color: #000;
    display: block;
}

#message-box {
    position: absolute;
    bottom: 10px; /* ゲーム画面の下側に表示 */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 1em;
    text-align: center;
    z-index: 1000;
    display: none; /* 初期状態では非表示 */
    width: 65%;
    max-width: calc(100% - 20px);
    box-sizing: border-box;
}

#game-over-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3em;
    color: red;
    background-color: rgba(0, 0, 0, 0.8);
    padding: 20px;
    border-radius: 10px;
    z-index: 1001;
    display: none; /* 初期状態では非表示 */
}

/* Inventory Overlay */
#inventory-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1500;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
}

#inventory-overlay.is-open {
    display: flex;
}

/* Settings Overlay (same layer as inventory) */
#settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1500;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
}

#settings-overlay.is-open {
    display: flex;
}

#settings-window {
    width: auto;
    height: auto;
    background: rgba(0, 0, 0, 0.92);
    color: #fff;
    box-sizing: border-box;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.18);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#settings-title {
    font-size: 16px;
}

#settings-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: rgba(255,255,255,0.85);
}

#settings-language-buttons {
    display: flex;
    gap: 10px;
}

#settings-language-buttons button,
#settings-close {
    padding: 10px 18px;
    font-size: 12px;
    background-color: #555;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
}

#settings-language-buttons button.is-active {
    background-color: #4CAF50;
}

#settings-language-buttons button:hover,
#settings-close:hover {
    background-color: #666;
}

#inventory-window {
    width: auto;
    height: auto;
    background: rgba(0, 0, 0, 0.92);
    color: #fff;
    box-sizing: border-box;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.18);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#inventory-title {
    font-size: 16px;
    margin-top: 0;
}

#collection-preview-wrap {
    width: 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255,255,255,0.25);
    background: rgba(0,0,0,0.35);
    border-radius: 8px;
}

#collection-preview {
    width: 96px;
    height: 96px;
    image-rendering: pixelated;
    display: none; /* 未選択/未入手の時は非表示 */
}

#inventory-content {
    width: auto;
    flex: 0;
    margin-top: 0;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: rgba(255,255,255,0.7);
}

#collection-grid {
    /* 8列 + gap(6px)×7 の実幅に合わせる */
    width: calc(32px * 8 + 6px * 7);
    display: grid;
    grid-template-columns: repeat(8, 32px);
    grid-template-rows: repeat(4, 32px);
    gap: 6px;
    margin-top: 4px;
    margin-bottom: 8px;
}

.collection-slot {
    width: 32px;
    height: 32px;
    box-sizing: border-box;
    border: 2px solid rgba(255,255,255,0.25);
    background-color: rgba(0,0,0,0.35);
    background-image: url('images/unacuired.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: pixelated;
    cursor: pointer;
}

.collection-slot.is-owned {
    border-color: rgba(255,255,255,0.55);
}

.collection-slot.is-selected {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

#collection-desc {
    /* コレクションボックス（グリッド）と同じ横幅 */
    width: calc(32px * 8 + 6px * 7);
    /* 常に一定行数ぶんの高さ（+ padding/border 分） */
    /* 英語は折り返しで行数が増えやすいので、2行分増やす */
    height: calc(1em * 1.6 * 6 + 24px);
    overflow: hidden;
    background: rgba(0,0,0,0.45);
    border: 2px solid rgba(255,255,255,0.25);
    padding: 10px;
    box-sizing: border-box;
    line-height: 1.6;
    color: #fff;
    white-space: pre-line; /* \n を改行として表示 */
}

#collection-complete {
    margin-top: 10px;
    font-size: 16px;
    color: #fff;
}

#inventory-back {
    margin-bottom: 0;
    padding: 12px 24px;
    font-size: 14px;
    background-color: #555;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
}

#inventory-back:hover {
    background-color: #666;
}

#d-pad-container {
    display: grid;
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 5px;
    margin-top: 0;
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 1100;
}

.d-pad-button {
    background-color: #555;
    border: 2px solid #777;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation; /* タッチ操作の最適化 */
}

.d-pad-button:active {
    background-color: #777;
}

#d-pad-up { grid-area: up; }
#d-pad-left { grid-area: left; }
#d-pad-right { grid-area: right; }
#d-pad-down { grid-area: down; }

.d-pad-button svg {
    fill: white;
    width: 40px;
    height: 40px;
}

/* Start Screen Styles */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    color: white;
}

#start-screen h1 {
    font-size: 2.5em;
    margin-bottom: 30px;
    text-align: center;
}

#start-button {
    padding: 15px 30px;
    font-size: 1.5em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
}

#start-button:hover {
    background-color: #45a049;
}

#new-game-button {
    padding: 12px 24px;
    font-size: 1.1em;
    background-color: #555;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    margin-top: 12px;
    display: none; /* セーブがあるときだけ表示 */
}

#new-game-button:hover {
    background-color: #666;
}

/* Initially hide game elements */
#game-container, #controls, #d-pad-container, #message-box, #game-over-display {
    display: none;
}

/* Show game elements when game starts */
body.game-started #game-container,
body.game-started #controls {
    display: flex;
}

/* controls text inside game screen */
#controls {
    position: absolute;
    left: 10px;
    bottom: 205px;
    z-index: 1100;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.8);
    pointer-events: none;
}

#controls p {
    margin: 0;
}

body.game-started #message-box {
    display: none; /* 表示/非表示はJS側(showMessage)で制御 */
}

body.game-started #game-over-display {
    display: none;
}


/* FPS Display (optional) */
/*
#fps-display {
    position: absolute;
    top: 10px;
    right: 10px;
    color: yellow;
    font-size: 12px;
    z-index: 1000;
}
*/