:root {
    color-scheme: dark;
    --bg: #101316;
    --panel: #181d20;
    --line: #354047;
    --text: #f4f0e8;
    --muted: #a9b1ae;
    --hero: #6fd3c4;
    --danger: #e85f5c;
    --goal: #f2c14e;
}

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

html, body {
    min-height: 100%;
    background: linear-gradient(135deg, #101316 0%, #171512 100%);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    /* モバイルのスクロール・バウンス防止 */
    overscroll-behavior: none;
    overflow-x: hidden;
}

/* ── Page layout ─────────────────────────────────────── */
.page {
    min-height: 100vh;
    width: min(640px, 100%);
    margin: 0 auto;
    padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-link {
    color: var(--muted);
    font-size: 0.78rem;
    text-decoration: none;
    flex-shrink: 0;
    transition: color 0.15s;
}

.back-link:hover {
    color: var(--hero);
}

.game-title {
    font-size: 1.1rem;
    letter-spacing: -0.01em;
}

/* ── Arena ───────────────────────────────────────────── */
.arena-wrap {
    position: relative;
    width: 100%;
    border: 2px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #0e1315;
}

.arena {
    display: block;
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ── Overlay ─────────────────────────────────────────── */
.overlay {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
}

.overlay.show {
    display: flex;
}

.overlay-text {
    font-size: clamp(1.4rem, 6vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: center;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.overlay-btn {
    padding: 10px 28px;
    border: 1px solid var(--goal);
    background: rgba(242, 193, 78, 0.15);
    color: var(--goal);
    border-radius: 8px;
    font: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}

.overlay-btn:hover {
    background: rgba(242, 193, 78, 0.3);
}

/* ── HUD ─────────────────────────────────────────────── */
.hud {
    display: flex;
    gap: 12px;
}

.fighter-hud {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.fighter-hud--right {
    flex-direction: row-reverse;
}

.fighter-name {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.06em;
    flex-shrink: 0;
    min-width: 28px;
}

.hp-bar-track {
    flex: 1;
    height: 10px;
    background: #1e2528;
    border: 1px solid var(--line);
    border-radius: 5px;
    overflow: hidden;
}

.hp-bar {
    height: 100%;
    border-radius: 5px;
    width: 100%;
    transition: width 0.12s ease-out, background 0.3s;
}

.hp-bar--player {
    background: var(--hero);
}

.hp-bar--enemy {
    background: var(--danger);
}

.hp-num {
    font-size: 0.7rem;
    color: var(--muted);
    min-width: 26px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ── Controls ────────────────────────────────────────── */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.btn-group {
    display: flex;
    gap: 8px;
}

.ctrl-btn {
    width: 56px;
    height: 56px;
    border: 1px solid var(--line);
    background: #1e2528;
    color: var(--text);
    border-radius: 10px;
    font-size: 1.3rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.08s, transform 0.06s;
}

.ctrl-btn:active,
.ctrl-btn.pressed {
    background: #2e3e44;
    transform: scale(0.92);
}

.ctrl-btn--action {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
    border-color: rgba(111, 211, 196, 0.4);
}

.ctrl-btn--attack {
    border-color: rgba(232, 95, 92, 0.5);
    background: #2a1a1a;
}

.ctrl-btn--attack:active,
.ctrl-btn--attack.pressed {
    background: #3e2222;
}

.ctrl-btn--grab {
    border-color: rgba(242, 193, 78, 0.5);
    background: #2a2210;
}

.ctrl-btn--grab:active,
.ctrl-btn--grab.pressed {
    background: #3e3318;
}

/* ── Stage badge ─────────────────────────────────────── */
.stage-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--goal);
    background: rgba(242, 193, 78, 0.12);
    border: 1px solid rgba(242, 193, 78, 0.35);
    border-radius: 6px;
    padding: 2px 8px;
    flex-shrink: 0;
    align-self: center;
    text-align: center;
    min-width: 64px;
}

/* ── Key hint ────────────────────────────────────────── */
.key-hint {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.72rem;
}

/* ── Jump button ─────────────────────────────────────── */
.ctrl-btn--jump {
    border-color: rgba(111, 211, 196, 0.6);
    background: #1a2828;
}

.ctrl-btn--jump:active,
.ctrl-btn--jump.pressed {
    background: #2a3838;
}

@media (max-width: 400px) {
    .ctrl-btn {
        width: 48px;
        height: 48px;
        font-size: 1.1rem;
    }

    .ctrl-btn--action {
        width: 56px;
        height: 56px;
        font-size: 1.3rem;
    }

    .key-hint {
        display: none;
    }
}

/* ── Landscape：全体をスケールダウンして1画面に収める ──── */
@media (orientation: landscape) and (max-height: 500px) {

    /* body を基準に .page 全体を縮小 */
    body {
        display: flex;
        align-items: flex-start;
        justify-content: center;
        height: 100dvh;
        overflow: hidden;
    }

    .page {
        /* 縦幅 100dvh に収まるよう transform-origin を上にして縮小 */
        transform-origin: top center;
        /* JS で動的にスケールを設定するためのフォールバック */
        width: min(640px, 100vw);
        min-height: unset;
        gap: 6px;
        padding-top: max(6px, env(safe-area-inset-top));
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
}