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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column; /* 縦並び */
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: #333;
}

/* ここで縦並び */
.page {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 100%;
}

header h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 20px;
    font-size: 2.5em;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.difficulty-btn {
    padding: 10px 20px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.difficulty-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.difficulty-btn.active {
    background: #667eea;
    color: white;
}

.game-info {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8f9fa;
    padding: 8px 15px;
    border-radius: 10px;
}

.info-label {
    font-weight: 600;
    color: #666;
}

.info-value {
    font-weight: 700;
    color: #667eea;
    font-size: 18px;
}

.mode-btn {
    padding: 8px 15px;
    border: 2px solid #667eea;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    width: 60px;
    height: 40px;
    transition: all 0.3s ease;
}

.mode-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    transition: opacity 0.3s ease;
}

.mode-btn.active-dig .dig-icon {
    opacity: 1;
}

.mode-btn.active-dig .flag-icon {
    opacity: 0;
}

.mode-btn.active-flag .dig-icon {
    opacity: 0;
}

.mode-btn.active-flag .flag-icon {
    opacity: 1;
}

.mode-btn.active-flag {
    background: #667eea;
}

.reset-btn {
    padding: 10px 20px;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    background: #ff5252;
    transform: scale(1.05);
}

main {
    position: relative;
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.game-board {
    display: inline-grid;
    gap: 2px;
    background: #ccc;
    padding: 2px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.cell {
    width: 30px;
    height: 30px;
    background: linear-gradient(145deg, #e6e6e6, #ffffff);
    border: 1px solid #999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s ease;
    position: relative;
    transform-style: preserve-3d;
}

.cell:hover:not(.revealed):not(.game-over) {
    background: linear-gradient(145deg, #d0d0d0, #f0f0f0);
    transform: scale(1.05);
}

.cell.revealed {
    background: white;
    border-color: #ddd;
    cursor: default;
    animation: cell-reveal 0.3s ease-out;
}

.cell.flagged::before {
    content: '🚩';
    font-size: 18px;
    animation: flag-place 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cell.mine {
    background: #ff6b6b;
}

.cell.mine::after {
    content: '💣';
    font-size: 20px;
    animation: bomb-explode 0.5s ease-out;
}

.cell.exploded {
    background: #ff3838;
    animation: shake 0.5s ease-in-out;
}

/* 数字の色分け */
.cell[data-count="1"] { color: #0000ff; }
.cell[data-count="2"] { color: #00aa00; }
.cell[data-count="3"] { color: #ff0000; }
.cell[data-count="4"] { color: #000080; }
.cell[data-count="5"] { color: #800000; }
.cell[data-count="6"] { color: #008080; }
.cell[data-count="7"] { color: #000000; }
.cell[data-count="8"] { color: #808080; }

/* アニメーション定義 */
@keyframes cell-reveal {
    0% {
        transform: rotateY(0deg);
        opacity: 0.8;
    }
    100% {
        transform: rotateY(180deg) rotateY(0deg);
        opacity: 1;
    }
}

@keyframes flag-place {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes bomb-explode {
    0%, 100% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.3);
    }
    50% {
        transform: scale(0.9);
    }
    75% {
        transform: scale(1.2);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.game-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.98);
    padding: 30px 50px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    z-index: 1000;
    animation: message-appear 0.3s ease-out;
}

.game-message.hidden {
    display: none;
}

.game-message.win {
    color: #4caf50;
    border: 3px solid #4caf50;
}

.game-message.lose {
    color: #ff6b6b;
    border: 3px solid #ff6b6b;
}

@keyframes message-appear {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

footer {
    text-align: center;
    margin-top: 20px;
}

.stats-toggle {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.stats-toggle:hover {
    background: #5568d3;
    transform: scale(1.05);
}

.stats-panel {
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    transition: all 0.3s ease;
}

.stats-panel.hidden {
    display: none;
}

.stats-panel h2 {
    color: #667eea;
    margin-bottom: 15px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.stat-item {
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-item h3 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 18px;
}

.stat-item p {
    margin: 5px 0;
    color: #666;
}

.stat-item span {
    font-weight: 700;
    color: #333;
}

.reset-stats-btn {
    padding: 8px 16px;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.reset-stats-btn:hover {
    background: #ff5252;
}

#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #f0f;
    animation: confetti-fall 3s linear forwards;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }

    .difficulty-btn {
        padding: 8px 12px;
        font-size: 14px;
    }

    .game-info {
        gap: 8px;
    }

    .info-item {
        padding: 6px 10px;
        font-size: 14px;
    }

    .info-value {
        font-size: 16px;
    }

    .cell {
        width: 25px;
        height: 25px;
        font-size: 14px;
    }

    .cell.flagged::before {
        font-size: 14px;
    }

    .cell.mine::after {
        font-size: 16px;
    }

    .game-message {
        padding: 20px 30px;
        font-size: 18px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .mode-btn {
        width: 50px;
        height: 35px;
    }

    .mode-icon {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .cell {
        width: 20px;
        height: 20px;
        font-size: 12px;
    }

    .cell.flagged::before {
        font-size: 12px;
    }

    .cell.mine::after {
        font-size: 14px;
    }

    header h1 {
        font-size: 1.5em;
    }

    .difficulty-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* モバイル用カーソル */
@media (hover: none) and (pointer: coarse) {
    .cell:hover:not(.revealed) {
        transform: none;
    }

    .mode-btn,
    .difficulty-btn,
    .reset-btn,
    .stats-toggle {
        min-height: 44px;
    }
}
