:root {
    --panel-bg: #1e293b;
    --text-color: #f8fafc;
    --accent-color: #38bdf8;
}

body {
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    box-sizing: border-box;
    background-color: #000;
    background-image: repeating-linear-gradient(
        45deg,
        #000 0px,
        #000 4px,
        #fff 4px,
        #fff 8px
    );
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 {
    margin-bottom: 15px;
    color: var(--accent-color);
    text-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    max-width: 800px;
    width: 100%;
}

#endingPlayerSprite {
    position: fixed;
    pointer-events: none;
    z-index: 10001;
}

#endingOverlay {
    position: fixed; /* .overlayのabsoluteを上書き。盤面座標でなく画面全体基準にする */
    z-index: 10001;
}

#canvas-wrapper {
    position: relative;
    background-color: transparent;
    background-image: url('assets/background.png');
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    /* 実際の幅・高さは game.js の sizeCanvasWrapper() が
       キャンバスの内部解像度（盤面＋上下マージン）の比率に合わせて
       毎回ピクセル指定で設定する。ここはJS実行前の一瞬だけ使われる暫定値。 */
    width: min(92vw, 640px);
    aspect-ratio: 1 / 1;
}

#canvas-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    backdrop-filter: brightness(var(--bg-tint-brightness, 0));
    pointer-events: none;
    transition: backdrop-filter 0.4s ease;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: transparent;
    position: relative;
    /* スワイプ操作中にブラウザ側のスクロール／ズーム・ジェスチャーが
       割り込まないようにする。 */
    touch-action: none;
}

/* ---------------------------------------------------------------------
   スマホ用操作領域（縦長ウインドウのときだけ、盤面の下の余白いっぱいに
   Q/E入力用の領域を表示する。見た目はボタンではなく、ただの領域＋文字）
   --------------------------------------------------------------------- */
.mobile-controls {
    display: none;
}

@media (orientation: portrait) {
    html, body {
        height: 100dvh;
    }

    .game-container {
        height: 100%;
        max-height: 100dvh;
        justify-content: flex-start;
    }

    .mobile-controls {
        display: flex;
        flex: 1 1 auto;
        width: 100%;
        max-width: none;
        min-height: 60px;
        gap: 0;
    }

    .mobile-btn {
        flex: 1;
        margin: 0;
        padding: 0;
        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        color: #000;
        font-family: inherit;
        font-weight: 700;
        font-size: clamp(1.75rem, 10vw, 3.5rem);
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
    }

    .mobile-btn:active {
        opacity: 0.5;
    }
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.overlay-title {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 10px;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.overlay button {
    background-color: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid #475569;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
}
.overlay button:hover {
    border-color: var(--accent-color);
    background-color: #273549;
}
/* ---------------------------------------------------------------------
   タイトル画面（title.jsが描画するcanvas 2枚を全画面に重ねる）
   --------------------------------------------------------------------- */
html, body {
    margin: 0;
    overflow: hidden;
    height: 100%;
    background-color: #000;
}

#titleScreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    cursor: pointer;
    opacity: 1;
    transition: opacity .6s ease;
}
#titleScreen.hidden {
    opacity: 0;
    pointer-events: none;
}
#titleScreen canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}
#titleView { z-index: 1; }
#titleUI { z-index: 2; }
