:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --text-color: #f8fafc;
    --accent-color: #38bdf8;
    --grid-color: rgba(255, 255, 255, 0.1);
    --triangle-border: rgba(255, 255, 255, 0.2);
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: row;
    gap: 2rem;
    padding: 2rem;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border-radius: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 100%;
}

.game-info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 200px;
}

h1 {
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--accent-color);
    text-transform: uppercase;
}

.scores-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.scores-row .score-box {
    flex: 1;
    margin-bottom: 0;
}

.scores-row .score-value {
    font-size: 1.2rem;
}

.score-box {
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.hi-score-box {
    border-color: rgba(241, 196, 15, 0.25);
    background: rgba(241, 196, 15, 0.05);
}

.stage-box {
    border-color: rgba(56, 189, 248, 0.3);
    background: rgba(56, 189, 248, 0.05);
}

.stage-value {
    color: var(--accent-color);
    font-size: 2rem;
}

.stage-progress {
    font-size: 0.8rem;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
    margin-top: 0.1rem;
}

.score-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.6;
    margin-bottom: 0.25rem;
}

.score-value {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.hi-score-value {
    color: #f1c40f;
}

.hi-score-value.new-record {
    animation: newRecord 0.6s ease-in-out infinite alternate;
}

@keyframes newRecord {
    from { color: #f1c40f; text-shadow: none; }
    to   { color: #fff;    text-shadow: 0 0 12px rgba(241, 196, 15, 0.9); }
}

.controls {
    font-size: 0.875rem;
    line-height: 1.6;
    opacity: 0.8;
}

.controls kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-family: inherit;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

canvas {
    background: #000;
    border-radius: 0.5rem;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
    display: block;
}

.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px) saturate(180%);
    padding: 3rem 2rem;
    border-radius: 2rem;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: none;
    z-index: 10;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    animation: fadeInScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 240px;
}

.stage-clear {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(16px) saturate(180%);
    padding: 2rem 3rem;
    border-radius: 2rem;
    text-align: center;
    border: 1px solid rgba(56, 189, 248, 0.4);
    display: none;
    z-index: 10;
    box-shadow: 0 0 40px rgba(56, 189, 248, 0.3);
    animation: fadeInScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stage-clear-label {
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--accent-color);
    text-shadow: 0 0 20px rgba(56, 189, 248, 0.6);
}

.stage-clear-num {
    font-size: 4rem;
    font-weight: 900;
    color: #fff;
    font-variant-numeric: tabular-nums;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.game-over h2 {
    margin: 0 0 0.5rem 0;
    color: #ff3b3b;
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: 2px;
    text-shadow: 0 0 20px rgba(255, 59, 59, 0.4);
}

.game-over p {
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.hi-score-result {
    color: #f1c40f !important;
    font-weight: 700;
    font-size: 1rem !important;
    margin-bottom: 2rem !important;
}

#finalScore {
    display: block;
    font-size: 3rem;
    color: #fff;
    font-weight: 800;
    margin-top: 0.5rem;
    font-family: 'Monaco', 'Consolas', monospace;
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.btn {
    background: linear-gradient(135deg, var(--accent-color), #00b4d8);
    color: #fff;
    border: none;
    padding: 1rem 2.5rem;
    border-radius: 1rem;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.touchpad {
    display: none; /* Hidden by default */
}

@media (max-width: 768px) {
    .container {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.5rem;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: transparent;
        height: 100dvh;
        width: 100vw;
        box-sizing: border-box;
        overflow: hidden;
    }

    .game-info {
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 1rem;
        flex: 0 0 auto;
    }

    h1 {
        font-size: 1.2rem;
        margin: 0;
    }

    .score-box {
        margin: 0;
        padding: 0.4rem 0.6rem;
    }

    /* モバイル: スコア行とステージをまとめて1行に */
    .game-info > div {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.4rem;
        flex-wrap: nowrap;
        width: 100%;
    }

    .scores-row {
        flex-direction: row;
        gap: 0.4rem;
        margin-bottom: 0;
    }

    .scores-row .score-box,
    .stage-box {
        flex: 0 0 auto;
        margin-bottom: 0;
        padding: 0.3rem 0.5rem;
        border-radius: 0.5rem;
    }

    .scores-row .score-value,
    .score-value {
        font-size: 0.95rem;
    }

    .score-label {
        font-size: 0.6rem;
        margin-bottom: 0.1rem;
    }

    .stage-value {
        font-size: 0.95rem;
    }

    .stage-progress {
        font-size: 0.65rem;
    }

    .controls {
        display: none !important;
    }

    .game-area {
        flex: 1;
        width: 100%;
        justify-content: flex-start;
    }

    canvas {
        max-width: 100%;
        height: auto;
    }

    .touchpad {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        flex: 1; /* 残りのスペースをすべて埋める */
        background: linear-gradient(to bottom, rgba(255, 255, 255, 0.05), transparent);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 2rem 2rem 0 0;
        margin-top: 0.5rem;
        padding-bottom: env(safe-area-inset-bottom);
        color: rgba(255, 255, 255, 0.3);
        font-weight: 700;
        font-size: 0.8rem;
        letter-spacing: 4px;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
    }
}
