/* ===================================
   ゲーム画面 (game.css)
   盤面・スコア表示・操作ボタン・ゲーム中の演出

   盤面の大きさは main.ts の layoutGame() が画面に合わせて計算し、
   .board の幅と高さ、--cell（1マスの大きさ）として設定する。
   画面が縦長で狭いときは .game--stacked が付き、スコア類が盤面の上に横並びになる。
   =================================== */

.app {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
}

.screen {
    width: 100%;
}

/* ===== 全体のレイアウト ===== */

.game {
    /* 左右のスコア欄の幅（layoutGame() が読み取る） */
    --hud-w: 124px;
    /* スコア欄を上に並べたときの高さ */
    --hud-row-h: 64px;
    --gap: 12px;
    --cell: 24px;

    display: flex;
    flex-direction: column;
    align-items: center;
    /* ヘッダーは上、操作ボタンは下、盤面はその間の中央に置く */
    justify-content: space-between;
    gap: 8px;
    height: 100dvh;
    max-height: 1000px;
    padding: 8px;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* スマホ（縦向き、または横向きで高さが足りない場合）は余白とスコア欄を小さくする */
@media (max-width: 480px), (orientation: landscape) and (max-height: 500px) {
    .game {
        --hud-w: 62px;
        --gap: 6px;
        gap: 6px;
        padding: 6px;
    }
}

.game__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex: none;
    width: 100%;
    max-width: 640px;
}

.game__header-buttons {
    display: flex;
    gap: 4px;
}

/* ゲーム中の認証状態表示 */
.player-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    margin: var(--px);
    padding: 4px 8px;
    background: var(--c-panel-lo);
    color: var(--c-text-dim);
    box-shadow: var(--outline);
}

.player-tag__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game__main {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: var(--gap);
    flex: none;
    width: 100%;
}

.board-area {
    flex: none;
}

/* ===== スコア表示 ===== */

.hud {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: none;
    width: var(--hud-w);
}

.hud__box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    margin: var(--px);
    padding: 8px 2px;
    background: var(--c-panel);
    text-align: center;
    box-shadow:
        var(--outline),
        inset var(--px) var(--px) 0 0 var(--c-panel-hi),
        inset calc(var(--px) * -1) calc(var(--px) * -1) 0 0 var(--c-panel-lo);
}

.hud__label {
    color: var(--c-text-mute);
    line-height: 1;
}

.hud__value {
    font-family: var(--font-en);
    font-size: 16px;
    line-height: 1;
    text-shadow: 2px 2px 0 var(--c-ink);
}

.hud__box--time .hud__value {
    color: var(--c-yellow);
}

/* 残り10秒を切ったら赤く点滅 */
.hud__box--time.is-warning .hud__value {
    color: var(--c-red-hi);
    animation: blink 0.5s steps(2) infinite;
}

.next-canvas {
    display: block;
    width: 32px;
    height: 32px;
}

@media (max-width: 480px), (orientation: landscape) and (max-height: 500px) {
    .hud__value {
        /* 幅が狭いので、数字は日本語フォントの半角（8px幅）で表示する */
        font-family: var(--font-jp);
    }
}

/* ----- スコア欄を盤面の上に横並びにするレイアウト ----- */

.game--stacked .game__main {
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 6px 2px;
    max-width: 480px;
}

.game--stacked .hud {
    display: contents;
}

.game--stacked .hud__box {
    flex: 1 1 0;
    gap: 4px;
    height: calc(var(--hud-row-h) - var(--px) * 2);
    padding: 2px;
}

.game--stacked .board-area {
    display: flex;
    justify-content: center;
    flex: 0 0 100%;
    order: 1;
}

.game--stacked .hud__value {
    font-family: var(--font-jp);
}

/* ===== 盤面 ===== */

.board {
    position: relative;
    /* 幅と高さは layoutGame() が設定する */
    width: calc(var(--cell) * 10);
    height: calc(var(--cell) * 20);
    margin: calc(var(--px) * 2);
    background: #16132a;
    box-shadow:
        0 0 0 var(--px) var(--c-line),
        0 0 0 calc(var(--px) * 2) var(--c-ink);
}

.board__canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.board__overlay {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

/* 得点のポップアップ */
.score-popup {
    position: absolute;
    font-family: var(--font-en);
    font-size: 16px;
    line-height: 1;
    color: var(--c-text);
    white-space: nowrap;
    text-shadow:
        2px 0 0 var(--c-ink),
        -2px 0 0 var(--c-ink),
        0 2px 0 var(--c-ink),
        0 -2px 0 var(--c-ink);
    transform: translate(-50%, -50%);
    animation: popup-rise 1s steps(10) forwards;
}

@keyframes popup-rise {
    70% {
        opacity: 1;
    }
    to {
        transform: translate(-50%, calc(-50% - 40px));
        opacity: 0;
    }
}

/* コンボ表示（連鎖数が増えるほど色が強くなる） */
.combo-banner {
    position: absolute;
    top: 22%;
    left: 50%;
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 8px 12px;
    background: var(--c-ink);
    color: var(--c-text);
    font-family: var(--font-en);
    font-size: 8px;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 0 0 2px currentColor;
    transform: translateX(-50%);
    pointer-events: none;
    animation: banner-pop 0.2s steps(3);
}

.combo-banner__count {
    font-size: 24px;
}

.combo-banner[data-tier="2"] {
    color: var(--c-blue-hi);
}

.combo-banner[data-tier="3"] {
    color: var(--c-yellow);
}

.combo-banner[data-tier="4"] {
    color: var(--c-red-hi);
}

.combo-banner[data-tier="5"] {
    animation:
        banner-pop 0.2s steps(3),
        rainbow 0.6s steps(3) infinite;
}

@keyframes banner-pop {
    from {
        transform: translateX(-50%) scale(1.5);
    }
}

@keyframes rainbow {
    0% {
        color: var(--c-red-hi);
    }
    33% {
        color: var(--c-yellow);
    }
    66% {
        color: var(--c-blue-hi);
    }
}

/* レベルアップ表示 */
.levelup-banner {
    position: absolute;
    top: 42%;
    left: 50%;
    padding: 10px 12px;
    background: var(--c-yellow);
    color: var(--c-ink);
    font-family: var(--font-en);
    font-size: 16px;
    line-height: 1;
    white-space: nowrap;
    box-shadow:
        0 0 0 2px var(--c-ink),
        inset 0 2px 0 0 var(--c-yellow-hi),
        inset 0 -4px 0 0 var(--c-yellow-lo);
    transform: translateX(-50%);
    pointer-events: none;
    animation: levelup 2s steps(20) forwards;
}

@keyframes levelup {
    0% {
        transform: translateX(-50%) translateY(16px);
        opacity: 0;
    }
    10%,
    85% {
        transform: translateX(-50%);
        opacity: 1;
    }
    100% {
        transform: translateX(-50%) translateY(-16px);
        opacity: 0;
    }
}

/* タイムアタック残り10秒のカウントダウン */
.countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    font-family: var(--font-en);
    font-size: 64px;
    line-height: 1;
    color: var(--c-red-hi);
    opacity: 0.6;
    text-shadow: 4px 4px 0 var(--c-ink);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.countdown.is-tick {
    animation: countdown-tick 0.8s steps(8) forwards;
}

/* 時間切れ（最後のブロックを置くまで表示し続ける） */
.countdown.is-zero {
    color: var(--c-red);
    opacity: 0.85;
    animation: blink 0.6s steps(2) infinite;
}

@keyframes countdown-tick {
    from {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0.9;
    }
    60% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

@keyframes blink {
    50% {
        opacity: 0.25;
    }
}

/* 一時停止中は盤面上の演出も隠す */
.board.is-paused .board__overlay,
.board.is-paused .combo-banner,
.board.is-paused .levelup-banner,
.board.is-paused .countdown {
    visibility: hidden;
}

/* ===== 操作ボタン ===== */

.controls {
    display: flex;
    gap: 4px;
    flex: none;
    width: 100%;
    max-width: 420px;
}

.pad {
    flex: 1 1 0;
    min-width: 0;
    height: 52px;
    padding-inline: 4px;
    touch-action: none;
}

.pad--wide {
    flex-grow: 1.5;
}

.pad .px-icon {
    width: 24px;
    height: 24px;
}

.game__help {
    flex: none;
    color: var(--c-text-mute);
    text-align: center;
}

/* タッチ端末や高さの足りない画面ではキーボードの説明を出さない */
@media (hover: none), (max-height: 720px), (max-width: 480px) {
    .game__help {
        display: none;
    }
}

/* ===== スマホ横向き =====
   高さが足りないので、ヘッダーを左、操作ボタンを右に置いて盤面の高さを確保する
   （layoutGame() は並びの向きを見て、盤面に使える幅と高さを計算する） */

@media (orientation: landscape) and (max-height: 500px) {
    .game {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 12px;
    }

    .game__header {
        flex-direction: column;
        align-items: flex-start;
        align-self: flex-start;
        width: auto;
        max-width: 150px;
    }

    .game__main {
        width: auto;
    }

    .controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 176px;
    }

    .pad {
        height: 64px;
    }
}
