html {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background-color: #222;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
    letter-spacing: 0.05em;
    /* ダブルタップによるズームを防止 */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#game-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    max-width: 100%;
    position: relative;
    width: 100%;
    max-height: 100vh;
    justify-content: center;
    flex-wrap: wrap;
    overflow: hidden;
}

#container {
    width: 100%;
    max-width: 800px;
    aspect-ratio: 1;
    border: 2px solid #00D9FF;
    position: relative;
    /* タッチ操作の制御 */
    touch-action: manipulation;
}

#container canvas.game-over-blur {
    filter: blur(3px);
    transition: filter 0.2s ease;
}

/* Modal Overlay Styles */
.modal-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 26, 62, 0.95);
    border: 2px solid #00D9FF;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    z-index: 1000;
}

#game-over {
    display: none;
}

/* Game Title Styles */
.game-title {
    margin: 0 0 50px 0;
}

#gameover-block-title {
    margin: 0 0 40px 0;
}

/* Action Button Styles */
.action-btn {
    background: linear-gradient(135deg, #00D9FF, #0099CC);
    color: white;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0, 217, 255, 0.3);
    letter-spacing: 0.1em;
}

.action-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 8px rgba(0, 217, 255, 0.5);
}

.action-btn-primary {
    padding: 20px 60px;
    font-size: 24px;
}

.action-btn-secondary {
    padding: 15px 40px;
    font-size: 20px;
}

/* Score Summary Styles */
.score-summary {
    color: white;
    margin-bottom: 40px;
}

.score-item {
    font-size: 20px;
    margin: 10px 0;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.score-label {
    text-align: right;
    width: 70px;
}

.score-value {
    font-weight: bold;
    text-align: left;
    width: 80px;
}

.score-gold {
    color: #FFD700;
}

.score-green {
    color: #50E3C2;
}

.score-red {
    color: #FF6B6B;
}

.score-blue {
    color: #00D9FF;
}

.score-purple {
    color: #B794F4;
}

/* Ghost Toggle Icon */
.ghost-toggle-icon {
    display: block;
    margin: auto;
}

#info-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    z-index: 1;
}

.info-box {
    background-color: #1a1a3e;
    padding: 15px;
    border-radius: 5px;
    border: 1px solid #00D9FF;
    box-sizing: border-box;
}

.info-box h3 {
    margin: 0 0 10px 0;
    color: #00D9FF;
    letter-spacing: 0.1em;
}

#next-piece {
    width: 100px;
    height: 100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#score {
    font-size: 24px;
    font-weight: bold;
    color: #FFD700;
}

#lines {
    font-size: 24px;
    font-weight: bold;
    color: #50E3C2;
}

#level {
    font-size: 24px;
    font-weight: bold;
    color: #FF6B6B;
}

.controls {
    font-size: 12px;
    line-height: 1.5;
}

#continue-btn:hover, #start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0, 217, 255, 0.5);
}

#container canvas.game-not-started {
    filter: blur(2px);
    opacity: 0.7;
}

/* ゴーストピース切り替えボタン */
.ghost-toggle-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(26, 26, 62, 0.8);
    border: 1px solid #00D9FF;
    color: #00D9FF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    z-index: 100;
    padding: 0;
    outline: none;
}

.ghost-toggle-btn:focus {
    outline: none;
}

.ghost-toggle-btn:hover {
    background: rgba(0, 217, 255, 0.2);
    transform: scale(1.1);
}

.ghost-toggle-btn.active {
    background: rgba(0, 217, 255, 0.4);
    color: #ffffff;
}

/* モバイルコントロール */
.mobile-controls {
    display: none;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    padding: 0px;
    order: 3;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 10px 0;
}

.control-row:last-child {
    margin-top: 20px;
}

.control-btn {
    width: 60px;
    height: 60px;
    font-size: 28px;
    background: rgba(26, 26, 62, 0.95);
    color: #00D9FF;
    border: 2px solid #00D9FF;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* 左右のボタンを横長に */
#left-btn, #right-btn {
    width: 100px;
}

.control-btn:active {
    background: #00D9FF;
    color: #1a1a3e;
    transform: scale(0.95);
}

.control-btn.wide {
    width: 155px;  /* 上の行の合計幅に合わせる (100+60+100+10*2=280, 280/2+5=145) */
}

/* メディアクエリ - タブレット対応 */
@media (max-width: 1024px) {
    #game-wrapper {
        flex-direction: column;
        align-items: center;
    }
    
    #container {
        max-width: 600px;
    }
    
    #info-panel {
        flex-direction: row;
        width: 100%;
        max-width: 600px;
        justify-content: space-between;
    }
    
    .info-box {
        flex: 1;
    }
}

/* メディアクエリ - タブレット・スマートフォン対応 */
@media (max-width: 1024px) {
    body {
        padding: 10px;
        padding-top: 10px;
        align-items: center;
        justify-content: center;
        height: 100vh;
        overflow: hidden;
    }
    
    #game-wrapper {
        gap: 10px; /* 間隔を調整 */
        flex-direction: column; /* 通常の縦並び（info-panelが先、containerが後） */
        align-items: center;
        justify-content: center;
        margin-top: 0;
    }
    
    .mobile-controls {
        display: block !important;
    }
    
    #controls-info {
        display: none !important; /* PCコントロール説明を非表示 */
    }
    
    /* スタート画面とゲームオーバー画面のサイズ調整 */
    #game-start, #game-over {
        width: 80% !important;
        max-width: 400px !important;
        padding: 25px 35px !important;
        box-sizing: border-box !important;
    }
    
    #block-title, #gameover-block-title {
        margin: 0 0 25px 0 !important;
        transform: scale(0.9);
    }
    
    #start-btn, #continue-btn {
        padding: 18px 50px !important;
        font-size: 22px !important;
    }
    
    #container {
        width: calc(100vw - 20px);
        height: calc((100vw - 20px) * 1.15); /* 1:1.15 ratio (15%縦長) */
        max-width: 500px;
        max-height: 575px; /* 500 * 1.15 */
        order: 2; /* containerを2番目に */
        flex-shrink: 0; /* 縮小を防ぐ */
        margin: 0 auto;
    }
    
    #info-panel {
        flex-direction: row;
        width: calc(100vw - 20px);
        max-width: 500px;
        justify-content: space-between;
        align-items: stretch; /* 高さを揃える */
        gap: 10px;
        order: 1; /* info-panelを1番目に */
        height: 80px; /* NEXTピースに合わせた高さ */
        flex-shrink: 0; /* 縮小を防ぐ */
        box-sizing: border-box;
        margin: 0 auto;
    }
    
    .info-box {
        padding: 5px 10px;
        flex: 1;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 100%;
    }
    
    /* スマホ時はNEXTを一番右に配置 */
    .score-box {
        order: 1;
    }
    
    .lines-box {
        order: 2;
    }
    
    .level-box {
        order: 3;
    }
    
    .next-box {
        order: 4; /* 一番右 */
    }
    
    .info-box h3 {
        font-size: 12px;
        margin: 0 0 5px 0;
    }
    
    #score, #lines, #level {
        font-size: 16px;
    }
    
    #next-piece {
        width: 80px;  /* スマホ時は横長 */
        height: 50px; /* 縦を短く */
        margin: 0 auto;
    }
    
    .controls {
        display: none;
    }
}

/* タブレット用の追加調整（iPadなど） */
@media (min-width: 768px) and (max-width: 1024px) {
    #container {
        width: 450px;
        height: 450px;
    }
    
    #info-panel {
        width: 450px;
        height: 90px;
    }
    
    #game-wrapper {
        padding-top: 20px;
    }
}

/* スマートフォン用の追加調整 */
@media (max-width: 767px) {
    #container {
        width: calc(100vw - 20px);
        height: calc((100vw - 20px) * 1.2); /* 1:1.2 ratio (20%縦長) */
        max-width: 450px;
        max-height: 540px; /* 450 * 1.2 */
    }
    
    #info-panel {
        flex-direction: row;
        width: calc(100vw - 20px);
        max-width: 500px;
        justify-content: space-between;
        align-items: stretch;
        gap: 10px;
        order: 1;
        height: 80px;
    }
}

/* さらに小さい画面用 */
@media (max-width: 480px) {
    body {
        padding: 0;
        padding-top: 5px;
        align-items: flex-start;
        height: 100vh;
        overflow: hidden;
    }
    
    .ghost-toggle-btn {
        width: 35px;
        height: 35px;
        top: 5px;
        right: 5px;
    }
    
    .ghost-toggle-btn svg {
        width: 25px;
        height: 25px;
    }
    
    #game-wrapper {
        gap: 7px; /* 間隔を確保 */
        align-items: center;
    }
    
    /* スタート画面とゲームオーバー画面をさらに小さく */
    #game-start, #game-over {
        width: 95% !important;
        max-width: 320px !important;
        padding: 25px 35px !important;
    }
    
    #block-title, #gameover-block-title {
        transform: scale(0.7);
        margin: 0 0 30px 0 !important;
    }
    
    #start-btn, #continue-btn {
        padding: 12px 30px !important;
        font-size: 18px !important;
    }
    
    #container {
        width: calc(100vw - 10px);
        height: calc((100vw - 10px) * 1.1); /* 1:1.1 ratio (少し縦長) */
        max-width: 400px;
        max-height: 440px; /* 400 * 1.1 */
        border-width: 1px;
        flex-shrink: 0; /* 縮小を防ぐ */
        margin: 0 auto;
    }
    
    #info-panel {
        width: calc(100vw - 10px);
        max-width: 400px;
        gap: 5px;
        height: 60px; /* 小画面では60pxに */
        flex-shrink: 0; /* 縮小を防ぐ */
        margin: 0 auto;
    }
    
    .info-box {
        padding: 5px;
    }
    
    .info-box h3 {
        font-size: 10px;
        margin: 0 0 3px 0;
    }
    
    #score, #lines, #level {
        font-size: 14px;
    }
    
    #next-piece {
        width: 65px;  /* 横長に変更 */
        height: 40px; /* 縦を短く */
    }
}