/* General Styles from index.html */
:root {
    --cell-size: var(--dynamic-cell-size, 40px); /* Fallback to 40px if JS not loaded */
    --grid-gap: 2px;
}
body {
    font-family: monospace;
    background-color: #1a1a1a;
    color: #eee;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Changed from center to flex-start */
    min-height: 100vh; /* Changed from height to min-height */
    margin: 0;
    touch-action: manipulation; /* Disable double-tap to zoom */
    overflow-y: auto; /* Allow vertical scrolling if content overflows */
}
#game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    padding: 10px;
    box-sizing: border-box;
}
#game-container {
    width: 100%;
    border: 1px solid #555;
    padding: 10px;
    background-color: #222;
    box-sizing: border-box;
    /* position: relative; */ /* REMOVED */
    display: flex; /* NEW: 子要素をflexboxで配置 */
    flex-direction: column; /* NEW: 子要素を縦に並べる */
    align-items: center; /* NEW: 子要素を中央揃え */
}
h1 {
    font-size: 1.5em;
    text-align: center;
    margin-top: 0;
    margin-bottom: 10px;
}
#game-status {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 5px;
    border: 1px solid #444;
    font-size: 0.9em;
}
#game-grid {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}
#controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
}
.control-btn {
    padding: 15px 10px;
    font-size: 1.2em;
    font-weight: bold;
    background-color: #444;
    color: #eee;
    border: 1px solid #666;
    border-radius: 5px;
    cursor: pointer;
    user-select: none; /* Prevent text selection on tap */
    text-align: center;
}
.control-btn:active {
    background-color: #555;
}
#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-inventory { grid-column: 2; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 3; }

/* Item Selection Screen Styles */
#item-selection-screen {
    padding: 10px;
    text-align: center;
}
#item-selection-screen h2 {
    margin-top: 0;
    font-size: 1.2em;
}
.item-choice-btn {
    display: block;
    width: 100%;
    padding: 15px 10px;
    margin-bottom: 10px;
    font-size: 1em;
    background-color: #3a3a3a;
    color: #eee;
    border: 1px solid #666;
    border-radius: 5px;
    cursor: pointer;
    text-align: left;
    box-sizing: border-box;
}
.item-choice-btn:hover {
    background-color: #4a4a4a;
}
.item-choice-btn.selected {
    border-color: #FFC107;
    background-color: #5a5a5a;
}
.item-choice-btn strong {
    display: block;
    margin-bottom: 5px;
    font-size: 1.1em;
}

/* Inventory Screen */
#inventory-screen {
    padding: 10px;
    text-align: center;
}
#inventory-screen h2 {
    margin-top: 0;
    font-size: 1.2em;
}
.inventory-item-btn {
     display: block;
    width: 100%;
    padding: 15px 10px;
    margin-bottom: 10px;
    font-size: 1em;
    background-color: #3a3a3a;
    color: #eee;
    border: 1px solid #666;
    border-radius: 5px;
    cursor: pointer;
    text-align: left;
    box-sizing: border-box;
}
.inventory-item-btn:hover {
    background-color: #4a4a4a;
}
#inventory-cancel-btn {
    background-color: #6c757d;
}

/* Grid styles previously in browser_io.js */
.game-table {
    border-collapse: separate;
    border-spacing: var(--grid-gap);
}

.game-cell {
    width: var(--dynamic-cell-size);
    height: var(--dynamic-cell-size);
    text-align: center;
    vertical-align: middle;
    cursor: default;
    border-radius: 3px;
    position: relative;
    font-weight: bold;
    color: #FFFFFF;
    box-sizing: border-box;
}

/* Cell background colors by state */
.game-cell--hidden { background-color: #616161; }
.game-cell--flagged { background-color: #616161; color: #BEB4B4; } /* Same bg as hidden, reddish-grey for symbol */
.game-cell--revealed { background-color: #9E9E9E; }
.game-cell--trap { background-color: #F44336; }
.game-cell--item { background-color: #FFC107; } /* Yellow */
.game-cell--exit { background-color: #4CAF50; } /* Green */
.game-cell--player { background-color: #F48FB1; } /* Light Pink */

/* Spans inside the cell */
.cell-number, .cell-entity, .cell-player-icon {
    position: absolute;
    font-weight: bold;
}

/* Number styling (default is centered) */
.cell-number {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--dynamic-cell-size) * 0.6);
}

/* Number when player is on the same tile (moves to top-left) */
.cell-number.cell-number--player-present {
    top: 1px;
    left: 3px;
    width: auto;
    height: auto;
    display: inline;
    font-size: calc(var(--dynamic-cell-size) * 0.4);
}

/* Entity (I, E) in corner */
.cell-entity {
    top: 1px;
    right: 3px;
    font-size: calc(var(--dynamic-cell-size) * 0.4);
    color: rgba(255, 255, 255, 0.9);
}

/* Player icon (@) centered */
.cell-player-icon {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--dynamic-cell-size) * 0.7);
}

/* Pop-up Notification Styles */
.game-popup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(26, 26, 26, 0.9);
    color: #eee;
    padding: 12px 24px;
    border-radius: 8px;
    border: 1px solid #555;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
    text-align: center;
    max-width: 90%;
}

.game-popup.fade-out {
    opacity: 0;
}

/* NEW: Modal Dialog Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background-color: #2c2c2c;
    padding: 25px;
    border-radius: 8px;
    border: 1px solid #777;
    text-align: center;
    max-width: 80%;
    max-width: 400px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.modal-content h3 {
    margin-top: 0;
    color: #FFC107; /* Yellow to match item color */
}

.modal-content p {
    margin-bottom: 20px;
}

.modal-content button {
    padding: 10px 20px;
    font-size: 1em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.modal-content button:hover {
    background-color: #45a049;
}

/* Action Prompt Styles */
#action-prompt {
    padding: 8px;
    margin-bottom: 10px;
    background-color: #333;
    border: 1px solid #555;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    display: none; /* Hidden by default */
}

/* Flash Red Effect */
.flash-red {
    animation: flashRed 0.2s ease-out;
}

@keyframes flashRed {
    0% { background-color: #1a1a1a; }
    50% { background-color: rgba(255, 0, 0, 0.5); }
    100% { background-color: #1a1a1a; }
}

/* NEW: Result Screen Styles */
#result-screen {
    padding: 10px;
    text-align: center;
    display: flex; /* NEW: Flexコンテナとして扱う */
    flex-direction: column; /* NEW: 子要素を縦に並べる */
    align-items: center; /* NEW: 子要素を中央揃えにする (任意) */
    background-color: transparent; /* 半透明の背景を透明に */
    margin-top: 20px; /* 盤面との間にスペースを設ける */
}

#result-screen h2 {
    margin-top: 0;
    font-size: 1.5em;
    margin-bottom: 15px;
}

#result-screen div {
    margin-bottom: 8px;
}

#floor-revelation-rates {
    margin-top: 15px; /* 上の要素との間にスペースを設ける */
}

#result-screen ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#result-screen li {
    margin-bottom: 4px;
}

#btn-reset {
    padding: 10px 20px;
    font-size: 1.2em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 20px;
}

#btn-reset:hover {
    background-color: #45a049;
}

/* Confirmation Dialog Styles */
#controls.confirm-dialog {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
    gap: 10px;
}

.confirm-prompt-message {
    font-size: 1.1em;
    margin-bottom: 5px;
    color: #FFC107; /* Yellow to stand out */
    text-align: center;
}

.confirm-btn {
    width: 80%;
    padding: 12px;
    font-size: 1.1em;
    border: 1px solid #666;
    background-color: #3a3a3a;
    color: white;
    cursor: pointer;
    border-radius: 5px;
}

.confirm-btn.selected {
    background-color: #5a5a5a;
    border-color: #FFC107;
}