* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

.screen {
    width: 100%;
    max-width: 500px;
    padding: 20px;
}

.hidden {
    display: none !important;
}

/* タイトル画面 */
.title {
    font-size: 4rem;
    color: #fff;
    text-align: center;
    margin-bottom: 2rem;
    text-shadow: 0 4px 8px rgba(0,0,0,0.3);
    font-weight: bold;
}

.mode-selection h2 {
    color: #fff;
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.5rem;
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mode-btn {
    background: linear-gradient(45deg, #ff6b6b, #ffa500);
    border: none;
    border-radius: 15px;
    padding: 1.5rem;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.mode-btn .size {
    font-weight: bold;
    font-size: 1.5rem;
}

.mode-btn .highscore {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-top: 0.5rem;
}

/* ゲーム画面 */
.header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 2rem;
}

.scores {
    display: flex;
    gap: 1rem;
}

.score-box {
    background: rgba(255,255,255,0.85);
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    min-width: 90px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.score-box span:first-child {
    font-size: 0.75rem;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-box span:last-child {
    font-weight: bold;
    font-size: 1.4rem;
    color: #333;
    margin-top: 0.2rem;
}

#grid-container {
    background: rgba(255,255,255,0.85);
    border-radius: 20px;
    padding: 1.2rem;
    display: grid;
    gap: 0.6rem;
    margin: 0 auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    position: relative;
}

.tile {
    background: rgba(0,0,0,0.1);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 2rem;
    transition: all 0.3s ease;
    aspect-ratio: 1;
    position: relative;
    overflow: hidden;
}

.tile-moving {
    transition: left 0.3s ease, top 0.3s ease;
}

.tile-new {
    animation: tileAppear 0.3s ease;
}

@keyframes tileAppear {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* タイルの色 */
.tile-2 { background: linear-gradient(45deg, #ff9a9e, #fecfef); color: #fff; }
.tile-4 { background: linear-gradient(45deg, #a8edea, #fed6e3); color: #fff; }
.tile-8 { background: linear-gradient(45deg, #ffecd2, #fcb69f); color: #fff; }
.tile-16 { background: linear-gradient(45deg, #ff8a80, #ff5722); color: #fff; }
.tile-32 { background: linear-gradient(45deg, #81c784, #4caf50); color: #fff; }
.tile-64 { background: linear-gradient(45deg, #64b5f6, #2196f3); color: #fff; }
.tile-128 { background: linear-gradient(45deg, #ffb74d, #ff9800); color: #fff; font-size: 1.7rem; }
.tile-256 { background: linear-gradient(45deg, #ba68c8, #9c27b0); color: #fff; font-size: 1.7rem; }
.tile-512 { background: linear-gradient(45deg, #f06292, #e91e63); color: #fff; font-size: 1.7rem; }
.tile-1024 { background: linear-gradient(45deg, #4db6ac, #009688); color: #fff; font-size: 1.5rem; }
.tile-2048 { background: linear-gradient(45deg, #ffd54f, #ffc107); color: #fff; font-size: 1.5rem; }
.tile-4096 { background: linear-gradient(45deg, #ff7043, #ff5722); color: #fff; font-size: 1.3rem; }
.tile-8192 { background: linear-gradient(45deg, #ab47bc, #8e24aa); color: #fff; font-size: 1.3rem; }

/* ゲームオーバー画面 */
#game-over {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.95);
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 1000;
    backdrop-filter: blur(5px);
}

#game-over h2 {
    color: #333;
    margin-bottom: 1rem;
    font-size: 2rem;
}

#game-over p {
    color: #666;
    margin-bottom: 2rem;
    font-size: 1.2rem;
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    justify-content: center;
}

.game-over-buttons button {
    padding: 1rem 2rem;
    font-size: 1rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.btn-title:hover {
    background: #5a6fd8;
}

.btn-retry {
    background: #ff6b6b;
    color: white;
}

.btn-retry:hover {
    background: #ff5252;
}

.congratulations {
    color: #ff6b6b;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 1rem 0;
    animation: celebrate 0.6s ease;
}

@keyframes celebrate {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* レスポンシブ */
@media (max-width: 600px) {
    .title { font-size: 3rem; }
    .header { justify-content: center; }
    .scores { order: -1; }
    .tile { font-size: 1.7rem; }
    .tile-128, .tile-256, .tile-512 { font-size: 1.4rem; }
    .tile-1024, .tile-2048 { font-size: 1.2rem; }
    .tile-4096, .tile-8192 { font-size: 1rem; }
}
