* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "游ゴシック", "Yu Gothic", sans-serif;
    background: linear-gradient(135deg, #E60012 0%, #003DA5 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

/* ヘッダーのスタイル */
.top-header {
    background-color: #1f2937;
    color: white;
    padding: 8px 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.top-header a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    font-weight: bold;
    color: white;
    text-decoration: none;
    font-size: 18px;
}

.top-header img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

/* メインコンテンツエリア */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 56px 20px 20px;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 100%;
}

h1 {
    text-align: center;
    color: #E60012;
    margin-bottom: 30px;
    font-size: 2.5em;
}

/* スマホ表示用のレスポンシブ設定 */
@media (max-width: 768px) {
    .main-content {
        padding: 56px 10px 10px;
    }
    
    .container {
        padding: 30px 20px;
    }
    
    h1 {
        font-size: 2em;
    }
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* スタート画面 */
.start-screen {
    text-align: center;
}

.start-screen p {
    font-size: 1.2em;
    margin-bottom: 30px;
    line-height: 1.8;
    color: #555;
}

.start-btn, .next-btn, .restart-btn {
    background: linear-gradient(135deg, #E60012 0%, #003DA5 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.3em;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
}

.start-btn:hover, .next-btn:hover, .restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(230, 0, 18, 0.4);
}

/* ゲーム画面 */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 1.1em;
    font-weight: bold;
    color: #003DA5;
    flex-wrap: wrap;
    gap: 10px;
}

.back-to-title-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 0.9em;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    font-weight: bold;
}

.back-to-title-btn:hover {
    transform: translateY(-1px);
    background: #5a6268;
}

.cards-grid {
    display: grid;
    gap: 15px;
    margin-bottom: 20px;
    justify-content: center;
}

.cards-grid.level-1 { grid-template-columns: repeat(3, 120px); }
.cards-grid.level-2 { grid-template-columns: repeat(4, 120px); }
.cards-grid.level-3 { grid-template-columns: repeat(5, 110px); }
.cards-grid.level-4 { grid-template-columns: repeat(4, 120px); }

.card {
    width: 120px;
    height: 140px;
    perspective: 1000px;
    cursor: pointer;
}

.cards-grid.level-3 .card {
    width: 110px;
    height: 130px;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card.matched {
    opacity: 0.5;
    pointer-events: none;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3em;
    font-weight: bold;
}

.card-front {
    background: linear-gradient(135deg, #E60012 0%, #003DA5 100%);
    color: white;
}

.card-back {
    background: white;
    border: 3px solid #003DA5;
    transform: rotateY(180deg);
    color: #333;
}

/* 結果画面 */
.result-screen {
    text-align: center;
    position: relative;
    overflow: hidden;
}

.result-screen.active {
    animation: zoomIn 0.6s ease-out;
}

.result-screen h2 {
    background: linear-gradient(45deg, #E60012, #FF6B00, #FFD700, #E60012);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 30px;
    font-size: 2.5em;
    animation: rainbowShine 3s ease-in-out infinite, bounce 1s ease-out;
    text-shadow: 0 0 30px rgba(230, 0, 18, 0.5);
}

.result-time {
    font-size: 3.5em;
    background: linear-gradient(135deg, #E60012, #003DA5, #FFD700);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: bold;
    margin: 30px 0;
    animation: scaleIn 0.8s ease-out 0.3s backwards, gradientFlow 3s ease infinite;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.result-details {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: left;
}

.result-details div {
    padding: 10px;
    font-size: 1.1em;
    color: #555;
    border-bottom: 1px solid #e0e0e0;
}

.result-details div:last-child {
    border-bottom: none;
}

.level-complete-message {
    text-align: center;
    margin: 20px 0;
    font-size: 1.5em;
    color: #E60012;
    font-weight: bold;
}

.celebrating {
    animation: pulse 0.5s ease-in-out;
}

/* ベストタイム表示 */
.best-times {
    margin: 30px 0;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.best-times h3 {
    color: #E60012;
    font-size: 1.3em;
    margin-bottom: 15px;
    text-align: center;
}

.best-times-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.best-time-item {
    display: flex;
    flex-direction: column;
    padding: 12px 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.best-time-item:hover {
    transform: translateX(5px);
}

.best-time-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.best-time-item .rank {
    font-weight: bold;
    color: #003DA5;
    font-size: 1.1em;
    min-width: 50px;
}

.best-time-item .time {
    font-weight: bold;
    color: #555;
    font-size: 1.2em;
}

.best-time-item:nth-child(1) .rank {
    color: #FFD700;
    font-size: 1.3em;
}

.best-time-item:nth-child(2) .rank {
    color: #C0C0C0;
}

.best-time-item:nth-child(3) .rank {
    color: #CD7F32;
}

.level-times-detail {
    font-size: 0.85em;
    color: #888;
    padding-top: 5px;
    border-top: 1px solid #f0f0f0;
}

/* 新記録バッジ */
.new-record-badge {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: white;
    font-size: 1.8em;
    font-weight: bold;
    padding: 15px 30px;
    border-radius: 50px;
    margin: 20px auto;
    display: inline-block;
    animation: recordPulse 1s ease-in-out infinite, recordShine 2s linear infinite;
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.6);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* 新記録バッジ */
.new-record-badge {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: white;
    font-size: 1.8em;
    font-weight: bold;
    padding: 15px 30px;
    border-radius: 50px;
    margin: 20px auto;
    display: inline-block;
    animation: recordPulse 1s ease-in-out infinite, recordShine 2s linear infinite;
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.6);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* 星評価 */
.star-rating {
    margin: 25px 0;
    text-align: center;
}

.stars {
    font-size: 4em;
    letter-spacing: 10px;
    margin-bottom: 10px;
}

.star-1 {
    color: #95a5a6;
}

.star-2 {
    color: #3498db;
}

.star-3 {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8));
}

.star-message {
    font-size: 1.5em;
    font-weight: bold;
    color: #E60012;
    margin-top: 10px;
}

.star-appear {
    animation: starZoom 0.6s ease-out;
}

@keyframes starZoom {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }
    50% {
        transform: scale(1.3) rotate(10deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes recordPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes recordShine {
    0% { filter: brightness(1) hue-rotate(0deg); }
    50% { filter: brightness(1.2) hue-rotate(10deg); }
    100% { filter: brightness(1) hue-rotate(0deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.celebrating {
    animation: pulse 0.5s ease-in-out;
}

@keyframes zoomIn {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-20px); }
    60% { transform: translateY(-10px); }
}

@keyframes scaleIn {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes rainbowShine {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #E60012;
    animation: confetti-fall linear forwards;
    pointer-events: none;
}
