/* ==========================================
   全体の基本設定（他のゲームと共通）
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Hiragino Maru Gothic ProN', 'Rounded M+ 1c', sans-serif;
}

body {
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
    user-select: none;
    -webkit-user-select: none;
}

/* ★修正：高さを100vh固定にせず、中身に合わせてキュッと締まるように変更 */
#app-container {
    width: 100%;
    max-width: 560px;
    height: auto;
    max-height: 98vh;
    background-color: white;
    border: 4px solid #81d4fa;
    border-radius: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* ★修正：space-between（均等配置）をやめ、適切な隙間（gap）で上から詰めて並べる */
.screen {
    display: none;
    width: 100%;
    padding: 20px 20px 24px;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 10px; /* 各パーツの上下の基本の隙間を10pxに統一 */
    position: relative;
}

.screen.active {
    display: flex;
}

/* タイトル文字（音ボタンや×ボタンと重ならない位置に調整） */
.title {
    color: #ef8f00;
    font-size: 34px;
    margin-top: 24px;
    margin-bottom: 2px;
    text-align: center;
    flex-shrink: 0;
    letter-spacing: 1px;
    line-height: 1.2;
}

.game-title {
    margin-top: 22px;
    margin-bottom: 0;
}

/* ==========================================
   左上の音ボタンと右上の×ボタン
   ========================================== */
.sound-toggle {
    position: absolute;
    top: 12px;
    left: 15px;
    background-color: #e69117;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 15px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 0 #b86f09;
    z-index: 100;
}

.btn-close-app {
    position: absolute;
    top: 12px;
    right: 15px;
    background-color: #9e9e9e;
    color: #ff5252;
    border: none;
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #757575;
    z-index: 100;
}

/* 共通ボタンスタイル */
button {
    cursor: pointer;
    transition: transform 0.1s;
    touch-action: manipulation;
}

button:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: none !important;
}

.btn-main {
    padding: 12px 20px;
    font-size: 20px;
    font-weight: bold;
    border-radius: 12px;
    border: none;
    color: white;
    width: 100%;
    max-width: 340px;
    background-color: #55d48b;
    box-shadow: 0 5px 0 #378e5b;
    flex-shrink: 0;
    margin-top: 4px;
}

.btn-main:disabled {
    background-color: #b0bec5;
    box-shadow: 0 5px 0 #90a4ae;
    cursor: not-allowed;
}

/* ==========================================
   3×3 パズル盤面のスタイル（3画面共通）
   ========================================== */
.puzzle-board {
    width: 100%;
    max-width: 370px;
    aspect-ratio: 1 / 1; /* つねに綺麗な正方形を保つ */
    background-color: #e6fbf6;
    border: 5px solid #7cb3e2;
    border-radius: 18px;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    margin: 4px 0; /* パズルの上下の余白をキュッと詰める */
    flex-shrink: 1;
}

/* 各マス（基本形） */
.puzzle-cell {
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 56px;
    font-weight: bold;
    transition: transform 0.08s ease, background-color 0.15s ease;
    touch-action: manipulation;
}

/* 空のマス（スタート画面の全マス・ゲーム中の空白マス） */
.cell-empty {
    background-color: #c5e6dc;
    border: 2px solid #b5dcd0;
    color: #e3f5ef; /* スタート画面の薄いお手本数字の色 */
    font-size: 62px;
    font-weight: normal;
    cursor: default;
}

/* 数字が入った青いコマ（ゲーム画面・終了画面） */
.cell-tile {
    background-color: #4a90e2;
    color: #ffffff;
    box-shadow: 0 5px 0 #2b5c94;
    cursor: default;
}

/* 終了画面の数字（少し優しいクリーム白） */
#result-grid .cell-tile {
    color: #e8f5e9;
    font-weight: normal;
    font-size: 60px;
}

/* ゲーム中、空白の隣にあって「動かせる青いコマ」 */
.cell-tile.movable {
    cursor: pointer;
}

.cell-tile.movable:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #2b5c94;
}

/* ==========================================
   スタート画面のパーツ（余白をコンパクトに調整）
   ========================================== */
.banner-text {
    color: #38a845;
    font-size: 19px;
    font-weight: bold;
    text-align: center;
    margin: 4px 0 0 0;
    line-height: 1.3;
    flex-shrink: 0;
}

.mode-selection-area {
    background-color: #f4f6f9;
    width: 100%;
    border-radius: 12px;
    padding: 12px 24px;
    margin: 0;
    flex-shrink: 0;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.mode-btn {
    padding: 9px 8px;
    font-size: 17px;
    background-color: white;
    border: 2px solid #cfd8dc;
    border-radius: 10px;
    font-weight: bold;
    color: #555555;
}

/* 選択された難易度ボタンの色 */
.mode-btn.selected {
    background-color: #5c6bc0;
    color: white;
    border-color: #3949ab;
}

/* ==========================================
   ゲーム画面・終了画面のテキストとボタン配置
   ========================================== */
.question-text {
    color: #a61c1c;
    font-size: 19px;
    font-weight: bold;
    text-align: center;
    margin: 0; /* 行間を詰めるため余白をゼロに */
    line-height: 1.3;
    flex-shrink: 0;
}

.status-bar {
    display: flex;
    justify-content: center;
    gap: 28px;
    width: 100%;
    font-size: 19px;
    font-weight: bold;
    color: #757575;
    margin: 0; /* 行間を詰めるため余白をゼロに */
    line-height: 1.3;
    flex-shrink: 0;
}

/* 回数や秒数の数字を見やすく少し強調 */
.stat-num {
    display: inline-block;
    min-width: 24px;
    text-align: right;
    color: #333;
}

.result-info {
    width: 100%;
    text-align: center;
    margin: 2px 0;
    flex-shrink: 0;
}

.complete-message {
    color: #b71c1c;
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 6px; /* 「かんせいです！」と下の回数表示の間を詰める */
    line-height: 1.3;
}

.result-status-bar {
    margin-top: 0;
}

.button-area {
    display: flex;
    justify-content: center;
    gap: 20px;
    width: 100%;
    margin-top: 4px;
    flex-shrink: 0;
}

.button-area .btn-main {
    max-width: 220px;
    flex: 1;
    margin-top: 0;
}

.single-button-area .btn-main {
    max-width: 340px;
}

/* ==========================================
   紙吹雪エフェクト（終了画面）
   ========================================== */
#confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 50;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00;
    animation: fall linear forwards;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(360deg);
    }
}