:root {
    --bg-color: #0d0d13;
    --panel-bg: rgba(20, 20, 30, 0.85);
    --border-color: rgba(184, 134, 11, 0.4);
    --gold: #d4af37;
    --gold-hover: #f3e5ab;
    --text-color: #e5e5e9;
    --font-family: '游明朝', 'YuMincho', 'ヒラギノ明朝 ProN', 'Hiragino Mincho ProN', 'MS Mincho', serif;
    --damage-color: #ff3b30;
    --heal-color: #4cd964;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    overflow: hidden;
}

#game-container {
    width: 100%;
    max-width: 1280px;
    height: 100dvh;
    max-height: 720px;
    aspect-ratio: 16 / 9;
    position: relative;
    border: 2px solid var(--border-color);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    background-color: #050508;
    overflow: hidden;
}

/* メッセージ表示エリア（#ui-area）を画像の上に切り替えるレイアウト */
#game-container.ui-top #image-area {
    order: 2;
    border-bottom: none;
    border-top: 2px solid var(--border-color);
}

#game-container.ui-top #ui-area {
    order: 1;
    border-top: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Image Area */
#image-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    border-bottom: 2px solid var(--border-color);
}

#scene-image {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: background-image 0.5s ease-in-out;
}

#fx-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    background: transparent;
    transition: background 0.1s ease-out;
}

#fx-overlay.damage {
    animation: flash-red 0.4s ease-out;
}

#fx-overlay.heal {
    animation: flash-green 0.4s ease-out;
}

@keyframes flash-red {
    0% {
        background: rgba(255, 0, 0, 0.4);
    }

    100% {
        background: transparent;
    }
}

@keyframes flash-green {
    0% {
        background: rgba(0, 255, 0, 0.3);
    }

    100% {
        background: transparent;
    }
}

/* Status Panels */
#status-panel,
#enemy-panel {
    position: absolute;
    top: 20px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    padding: 12px 18px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    width: 250px; /* 日本語ラベル幅の増加に伴い、パネル自体の横幅を220pxから250pxに拡張 */
    z-index: 5;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

#status-panel {
    left: 20px;
}

#enemy-panel {
    right: 20px;
    border-color: rgba(220, 20, 60, 0.5);
}

.status-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gold);
    margin-bottom: 8px;
    text-shadow: 1px 1px 2px black;
}

.status-bar-container {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.status-bar-container:last-child {
    margin-bottom: 0;
}

.status-label {
    width: 65px; /* 「体力」「手がかり」が改行されずに収まるよう 25px から 65px に拡張 */
    font-weight: bold;
    color: #ccc;
}

.status-bar-bg {
    flex: 1;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-bar-fill {
    height: 100%;
    width: 100%;
    transition: width 0.3s ease-in-out;
}

.hp-fill {
    background: linear-gradient(90deg, #ff416c, #ff4b2b);
}

.mp-fill {
    /* 「手がかり」にふさわしい、知的なインディゴブルーのグラデーションに変更 */
    background: linear-gradient(90deg, #1e3c72, #2a5298);
}

.enemy-hp-fill {
    background: linear-gradient(90deg, #b22222, #8b0000);
}

.status-value {
    width: 48px; /* 「10/10」などの数値が余裕を持って右寄せ表示できるように微調整 */
    text-align: right;
    font-size: 0.8rem;
    color: #ccc;
}

/* UI Area (Text only — Choices now overlay the image area, see #choice-box) */
#ui-area {
    height: 160px;
    background: #111116;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

#text-box {
    flex: 1;
    overflow-y: auto;
    font-size: 1.1rem;
    line-height: 1.8;
    color: #e5e5e9;
    padding-right: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(212, 175, 55, 0.6) rgba(0, 0, 0, 0.3);
}

/* Custom Scrollbar for text box */
#text-box::-webkit-scrollbar {
    width: 8px;
}

#text-box::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

#text-box::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.5);
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease-in-out;
}

#text-box::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 175, 55, 0.85);
}

#choice-box {
    position: absolute;
    top: 83.33%; /* 画像を縦に3分割した一番下の段の中央 */
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(85%, 480px);
    max-height: 30%; /* 下段（画像の下から1/3）に収まる高さの目安 */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 6;
    scrollbar-width: thin;
    scrollbar-color: rgba(212, 175, 55, 0.6) rgba(0, 0, 0, 0.3);
}

/* Custom Scrollbar for choice box (webkit) */
#choice-box::-webkit-scrollbar {
    width: 6px;
}

#choice-box::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

#choice-box::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.5);
    border-radius: 3px;
}

.choice-btn {
    background: rgba(10, 10, 14, 0.78);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px 15px;
    text-align: left;
    font-family: var(--font-family);
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.choice-btn:hover {
    background: rgba(212, 175, 55, 0.15);
    border-color: var(--gold);
    color: var(--gold-hover);
    padding-left: 20px;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.15);
}

.hidden {
    display: none !important;
}

/* Dice Roll Modal */
#dice-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dice-container {
    background: #14141c;
    border: 2px solid var(--gold);
    padding: 30px 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    max-width: 320px;
    width: 90%;
}

.dice-title {
    font-size: 1.2rem;
    color: var(--gold);
    margin-bottom: 20px;
    letter-spacing: 2px;
}

.dice-animation {
    font-size: 5rem;
    margin: 15px 0;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dice-animation.rolling {
    animation: spin 0.15s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg) scale(1);
    }

    50% {
        transform: rotate(180deg) scale(1.1);
    }

    100% {
        transform: rotate(360deg) scale(1);
    }
}

.dice-result {
    font-size: 3rem;
    font-weight: bold;
    color: #fff;
    margin-bottom: 10px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.dice-message {
    font-size: 1rem;
    margin-bottom: 20px;
    min-height: 24px;
}

.dice-message.success {
    color: var(--heal-color);
}

.dice-message.fail {
    color: var(--damage-color);
}

#dice-close-btn {
    background: transparent;
    border: 1px solid var(--gold);
    color: var(--gold);
    padding: 8px 25px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-family);
    transition: all 0.2s;
}

#dice-close-btn:hover {
    background: var(--gold);
    color: #000;
}

/* --- Responsive Media Queries --- */

/* Tablets and Smartphones (Portrait) */
@media (max-width: 768px) {
    #game-container {
        max-width: none;
        max-height: none;
        height: 100dvh;
        border: none;
        box-shadow: none;
    }

    #ui-area {
        height: 20dvh;
        min-height: 110px;
        max-height: 150px;
        padding: 15px;
    }

    #text-box {
        font-size: 0.95rem;
        line-height: 1.6;
    }

    #choice-box {
        width: 90%;
    }

    .choice-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .choice-btn:hover {
        padding-left: 15px;
    }

    /* Prevent status panel overlapping on narrow screens */
    #status-panel,
    #enemy-panel {
        top: 12px;
        width: calc(50% - 16px);
        padding: 8px 10px;
        font-size: 0.85rem;
        border-radius: 6px;
    }

    #status-panel {
        left: 12px;
    }

    #enemy-panel {
        right: 12px;
    }

    .status-name {
        font-size: 0.95rem;
        margin-bottom: 4px;
    }

    .status-bar-container {
        margin-bottom: 4px;
    }

    .status-bar-bg {
        margin: 0 4px;
        height: 6px;
    }

    .status-value {
        width: 38px;
        font-size: 0.75rem;
    }
}

/* Smartphones Landscape (Horizontal) */
@media (max-height: 500px) and (orientation: landscape) {
    #game-container {
        flex-direction: row;
        max-width: none;
        max-height: none;
        height: 100dvh;
        border: none;
        box-shadow: none;
    }

    #image-area {
        flex: 1.3;
        height: 100%;
        border-bottom: none;
        border-right: 1px solid var(--border-color);
    }

    #ui-area {
        flex: 1;
        height: 100%;
        min-height: 0;
        max-height: none;
        width: auto;
        border-top: none;
        padding: 12px 15px;
    }

    /* 横持ちレイアウトでは左右の入れ替えとして扱う */
    #game-container.ui-top #image-area {
        order: 2;
        border-top: none;
        border-right: none;
        border-left: 1px solid var(--border-color);
    }

    #game-container.ui-top #ui-area {
        order: 1;
        border-bottom: none;
    }

    #text-box {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    #choice-box {
        width: 80%;
        max-height: 32%;
    }

    .choice-btn {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .choice-btn:hover {
        padding-left: 12px;
    }

    #status-panel,
    #enemy-panel {
        top: 8px;
        width: calc(50% - 12px);
        padding: 6px 8px;
        font-size: 0.8rem;
        border-radius: 6px;
    }

    #status-panel {
        left: 8px;
    }

    #enemy-panel {
        right: 8px;
    }

    .status-name {
        font-size: 0.85rem;
        margin-bottom: 2px;
    }

    .status-bar-container {
        margin-bottom: 2px;
    }

    .status-bar-bg {
        margin: 0 4px;
        height: 5px;
    }

    .status-value {
        width: 35px;
        font-size: 0.7rem;
    }
}

/* Scaling down the dice container on small vertical viewports to prevent overflow */
@media (max-height: 500px) {
    .dice-container {
        padding: 15px 25px;
        max-width: 280px;
    }

    .dice-title {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    .dice-animation {
        font-size: 3rem;
        margin: 5px 0;
        height: 60px;
    }

    .dice-result {
        font-size: 2.2rem;
        margin-bottom: 5px;
    }

    .dice-message {
        font-size: 0.85rem;
        margin-bottom: 12px;
        min-height: 18px;
    }

    #dice-close-btn {
        padding: 5px 20px;
        font-size: 0.85rem;
    }
}

/* --- Audio Settings UI --- */

#audio-control-container {
    position: absolute;
    bottom: 15px;
    right: 15px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#bottom-controls-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

#audio-toggle-btn,
#layout-toggle-btn {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    color: var(--gold);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    transition: all 0.2s ease-in-out;
}

#audio-toggle-btn:hover,
#layout-toggle-btn:hover {
    background: rgba(212, 175, 55, 0.2);
    border-color: var(--gold);
    transform: scale(1.08);
}

#audio-settings-popup {
    margin-bottom: 10px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: 10px;
    backdrop-filter: blur(12px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.7);
    width: 210px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.audio-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.audio-label {
    font-size: 0.85rem;
    color: #c5c5c9;
    font-weight: 600;
    width: 45px;
    text-shadow: 1px 1px 2px black;
}

#audio-settings-popup input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.15);
    height: 6px;
    border-radius: 3px;
    outline: none;
}

#audio-settings-popup input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--gold);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
    transition: background 0.15s, transform 0.1s;
}

#audio-settings-popup input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--gold-hover);
    transform: scale(1.15);
}

.audio-info {
    font-size: 0.75rem;
    color: #aaa;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 1px 1px 2px black;
}

/* Responsive adjustment for small screens */
@media (max-width: 768px) {
    #audio-control-container {
        bottom: 12px;
        right: 12px;
    }
    #audio-toggle-btn,
    #layout-toggle-btn {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }
    #audio-settings-popup {
        width: 180px;
        padding: 10px 12px;
        gap: 8px;
    }
    .audio-label {
        font-size: 0.8rem;
        width: 35px;
    }
}