* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Helvetica Neue', 'Arial', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
    background-color: #1a1a1a;
    color: white;
    overflow: hidden;
}

#game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

#title-screen, #game-screen {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    height: 100%;
    max-height: 95vh;
    background-color: #000;
    border: 1px solid #444;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#title-screen {
    justify-content: center;
    align-items: center;
}

#title-image {
    max-width: 80%;
    height: auto;
}

#start-button {
    margin-top: 30px;
    padding: 15px 40px;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    border: 2px solid #fff;
    background-color: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 8px;
    transition: background-color 0.3s, color 0.3s;
}

#start-button:hover {
    background-color: #fff;
    color: #000;
}

#image-area {
    width: 100%;
    flex: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: #000; /* 画像の余白を黒に */
}

#scene-image {
    width: 100%;
    height: 100%;
    object-fit: contain; /* 画像全体を表示 */
    object-position: center;
}

#textbox-area {
    width: 100%;
    min-height: 180px;
    flex-shrink: 0;
    background-color: rgba(0, 0, 0, 0.75);
    padding: 20px 25px;
    border-top: 2px solid #333;
    display: flex;
    flex-direction: column;
    position: relative; /* ボタンを配置する基準点 */
}

#character-name {
    background-color: #3c3c3c;
    padding: 5px 15px;
    position: absolute;
    top: -32px;
    left: 25px;
    border-radius: 5px 5px 0 0;
    font-weight: bold;
    font-size: 1.1em;
}

#message-text {
    flex-grow: 1;
    font-size: 1.2em;
    line-height: 1.7;
    overflow-y: auto;
    padding-bottom: 40px; 
}

#choices-container {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-button {
    width: 100%;
    padding: 15px;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    text-align: left;
    cursor: pointer;
    font-size: 1.1em;
    border-radius: 5px;
    transition: background-color 0.2s;
}

.choice-button:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

#back-button {
    position: absolute;
    bottom: 10px;
    left: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 1.2em;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

#next-button {
    position: absolute;
    bottom: 10px;
    right: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 1.6em;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    animation: bounce 1.5s infinite;
}

#restart-button {
    position: absolute;
    bottom: 10px;
    right: 20px;
    padding: 8px 15px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid #fff;
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 5px;
    transition: background-color 0.3s;
}

#restart-button:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

#back-button:hover, #next-button:hover {
    opacity: 1;
}

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

.hidden {
    display: none !important;
}

/* ===== スマホ対応（レスポンシブデザイン） ===== */
@media screen and (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
    }
    
    #game-container {
        padding: 0;
        align-items: flex-start;
    }
    
    #title-screen, #game-screen {
        max-width: 100%;
        max-height: none;
        min-height: 100vh;
        border: none;
        box-shadow: none;
    }
    
    #title-image {
        max-width: 90%;
        max-height: 60vh;
        object-fit: contain;
    }
    
    #start-button {
        margin-top: 20px;
        padding: 12px 30px;
        font-size: 1.3em;
        width: 80%;
        max-width: 300px;
    }
    
    #image-area {
        flex: 2;
        min-height: 40vh;
        max-height: 50vh;
        background-color: #000; /* 画像の余白を黒に */
    }
    
    #scene-image {
        width: 100%;
        height: 100%;
        object-fit: contain; /* 画像全体を表示 */
        object-position: center;
        max-width: 100%;
        max-height: 100%;
    }
    
    #textbox-area {
        min-height: 200px;
        padding: 15px 20px;
        flex: 1;
    }
    
    #character-name {
        font-size: 1em;
        padding: 4px 12px;
        top: -28px;
        left: 20px;
    }
    
    #message-text {
        font-size: 1.1em;
        line-height: 1.6;
        padding-bottom: 50px;
    }
    
    .choice-button {
        padding: 12px;
        font-size: 1em;
        margin-bottom: 5px;
    }
    
    #back-button, #next-button {
        font-size: 1.4em;
        bottom: 15px;
    }
    
    #back-button {
        left: 15px;
    }
    
    #next-button {
        right: 15px;
    }
    
    #restart-button {
        bottom: 15px;
        right: 15px;
        font-size: 0.9em;
        padding: 6px 12px;
    }
}

/* ===== 小さなスマホ画面対応 ===== */
@media screen and (max-width: 480px) {
    #title-image {
        max-width: 95%;
        max-height: 50vh;
    }
    
    #start-button {
        font-size: 1.2em;
        padding: 10px 25px;
        width: 90%;
    }
    
    #image-area {
        min-height: 35vh;
        max-height: 45vh;
    }
    
    #textbox-area {
        min-height: 180px;
        padding: 12px 15px;
    }
    
    #character-name {
        font-size: 0.9em;
        left: 15px;
    }
    
    #message-text {
        font-size: 1em;
        padding-bottom: 45px;
    }
    
    .choice-button {
        font-size: 0.95em;
        padding: 10px;
    }
}

/* ===== 横向き表示対応 ===== */
@media screen and (max-width: 768px) and (orientation: landscape) {
    #title-screen, #game-screen {
        min-height: 100vh;
    }
    
    #image-area {
        flex: 1.5;
        min-height: 30vh;
        max-height: 40vh;
    }
    
    #textbox-area {
        min-height: 160px;
        flex: 1;
    }
    
    #message-text {
        font-size: 1em;
        line-height: 1.5;
    }
}