:root {
    --bg-color: #050505;
    --panel-bg: rgba(10, 10, 15, 0.65);
    --text-color: #f8fafc;
    --accent-color: #ff2a5f;
    --border-color: rgba(255, 42, 95, 0.3);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    background-image: url('bg.jpg');
    background-size: cover;
    background-position: center;
    overflow-y: auto;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: -1;
}

.app-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 20px 0;
}

.game-container {
    display: grid;
    grid-template-columns: 160px 420px 90px;
    grid-template-rows: auto auto;
    grid-template-areas:
        "left  center right"
        ".     ctrls  .    ";
    gap: 20px;
    padding: 20px;
    background: rgba(10, 10, 15, 0.4);
    backdrop-filter: blur(8px);
    border-radius: 24px;
    border: 1px solid var(--border-color);
    box-shadow: 0 0 40px rgba(255, 42, 95, 0.2);
}

.left-wrapper  { grid-area: left; }
.center-panel  { grid-area: center; }
.right-panel   { grid-area: right; }

.panel {
    background: var(--panel-bg);
    border-radius: 16px;
    padding: 24px;
    width: 160px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 0 20px rgba(255, 42, 95, 0.1);
}

.left-wrapper {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.left-panel, .character-panel, .stats-panel {
    align-items: center;
    justify-content: flex-start;
}

.char-name {
    font-size: 0.9rem;
    color: var(--accent-color);
    letter-spacing: 1px;
    margin-bottom: 5px;
    text-shadow: 0 0 10px rgba(255, 42, 95, 0.5);
    white-space: nowrap;
}

.right-panel {
    align-items: center;
    justify-content: flex-start;
    width: 90px;
}

h2 {
    font-size: 1rem;
    color: #cbd5e1;
    letter-spacing: 2px;
    margin-bottom: 8px;
    margin-top: 20px;
}

h2:first-child {
    margin-top: 0;
}

.value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 15px rgba(255, 42, 95, 0.8);
}

#lives.value {
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.center-panel {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 42, 95, 0.4);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 15px rgba(255, 42, 95, 0.3);
}

.center-panel::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 60%;
    background-image: url('watermark.jpg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.12;
    z-index: 1;
    pointer-events: none;
}

canvas {
    display: block;
    position: relative;
    z-index: 2;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 15, 0.88);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    z-index: 10;
}

.hidden {
    display: none !important;
}

.overlay h1 {
    font-size: 2rem;
    margin-bottom: 30px;
    color: #fff;
    text-shadow: 0 0 15px #ff2a5f, 0 0 30px #ff2a5f;
    letter-spacing: 2px;
}

.overlay p {
    margin-bottom: 30px;
    line-height: 1.8;
    color: #e2e8f0;
    font-size: 0.9rem;
}

button {
    background: linear-gradient(135deg, #ff2a5f 0%, #ff8c00 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 42, 95, 0.4);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 42, 95, 0.6);
}

button:active {
    transform: translateY(1px);
}

.character-container {
    position: relative;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-character {
    width: 260px;
    height: auto;
    filter: drop-shadow(0 0 15px rgba(255, 42, 95, 0.6));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%   { transform: translateY(0px); }
    50%  { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

.speech-bubble {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    color: #1a1a24;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    min-width: 120px;
    margin-bottom: 15px;
    transition: opacity 0.3s;
    z-index: 100;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
}

.speech-bubble.hidden {
    opacity: 0;
    pointer-events: none;
}

/* BGMボタン */
.bgm-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 10px;
}

.bgm-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    cursor: pointer;
    border: 2px solid #ff2a5f;
    background: rgba(10, 10, 15, 0.9);
}

.bgm-label {
    font-size: 0.7rem;
    color: #cbd5e1;
    margin-top: 5px;
    letter-spacing: 1px;
    font-weight: bold;
}

/* PC: コントローラーをキャンバス真下に配置 */
.mobile-controls {
    grid-area: ctrls;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 0;
    width: 100%;
}

.d-pad {
    position: relative;
    width: 150px;
    height: 150px;
    flex-shrink: 0;
}

.control-btn {
    background: rgba(10, 10, 15, 0.9);
    border: 2px solid var(--accent-color);
    color: white;
    font-size: 1.1rem;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
    user-select: none;
    position: absolute;
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
}

.d-up    { top: 0;    left: 50px; }
.d-down  { bottom: 0; left: 50px; }
.d-left  { left: 0;   top: 50px; }
.d-right { right: 0;  top: 50px; }

.pause-btn {
    position: static;
    flex-shrink: 0;
    background: rgba(255, 42, 95, 0.2);
    border-color: #ff2a5f;
    border-radius: 12px;
    width: 50px;
    height: 50px;
    cursor: pointer;
}

.control-btn:hover {
    background: rgba(255, 42, 95, 0.25);
    transform: scale(1.08);
}

.control-btn:active {
    transform: scale(0.9);
    background: var(--accent-color);
}

/* ===================== */
/* スマホ対応             */
/* ===================== */
@media (max-width: 800px) {
    body {
        overflow: hidden;
        overscroll-behavior: none;
        height: 100dvh;
        width: 100vw;
        position: fixed;
    }

    .app-wrapper {
        height: 100dvh;
        max-height: 100dvh;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 5px;
        width: 100vw;
        overflow: hidden;
    }

    .game-container {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "left   right"
            "center center"
            "ctrls  ctrls";
        gap: 4px;
        padding: 4px;
        width: 100%;
        box-sizing: border-box;
        flex: 1;
        min-height: 0;
    }

    .panel {
        padding: 5px;
        border-radius: 10px;
    }

    /* 上段左：キャラ＋ステータス横並び */
    .left-wrapper {
        grid-area: left;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 5px;
        min-width: 0;
    }

    .character-panel {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        padding: 5px 8px;
        flex-shrink: 0;
    }

    .bubble-space { display: none; } /* スマホでは非表示 */

    .character-container {
        margin-top: 0;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }

    .stats-panel {
        display: flex;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 0 10px;
        padding: 5px 8px;
        flex: 1;
        min-width: 0;
    }

    .stat-box { text-align: center; min-width: 40px; }

    /* 上段右：BGMボタン */
    .right-panel {
        grid-area: right;
        display: flex;
        align-items: center;
        justify-content: center;
        width: auto;
        padding: 5px;
        align-self: center;
    }

    /* 下段：ゲーム画面フル幅 */
    .center-panel {
        grid-area: center;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
        min-height: 0;
        align-self: stretch;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    #game-board {
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 100%;
        aspect-ratio: 1 / 1;
        border: 2px solid rgba(255, 42, 95, 0.4);
        border-radius: 8px;
        object-fit: contain;
    }

    .char-name    { font-size: 0.65rem; margin-bottom: 2px; text-align: center; }
    .stat-box     { margin: 2px 0; text-align: left; }
    h2            { font-size: 0.6rem; margin: 0 0 2px 0; letter-spacing: 0; }
    .value        { font-size: 1rem; margin-bottom: 4px; }
    #lives.value  { font-size: 0.85rem; }

    #game-character {
        width: 100px;
        height: 100px;
        object-fit: contain;
    }

    .char-name    { font-size: 0.6rem; white-space: nowrap; }
    h2            { font-size: 0.55rem; margin: 0; letter-spacing: 0; }
    .value        { font-size: 0.9rem; margin-bottom: 0; }
    #lives.value  { font-size: 0.75rem; }

    .overlay h1  { font-size: 1.4rem; margin-bottom: 12px; }
    .overlay p   { font-size: 0.7rem; margin-bottom: 12px; }
    button       { padding: 8px 15px; font-size: 0.9rem; }

    /* スマホ向け上書き */
    .mobile-controls {
        grid-area: ctrls;
        justify-content: space-between;
        padding: 5px 15px env(safe-area-inset-bottom, 20px);
        flex-shrink: 0;
    }

    .bgm-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}
