* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    min-height: 100vh;
    background: radial-gradient(ellipse at bottom, #0d1b2a 0%, #1b263b 50%, #0f172a 100%);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    position: relative;
}

/* Background stars animation */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, #eee, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.5), transparent),
        radial-gradient(1px 1px at 90px 40px, #fff, transparent),
        radial-gradient(1px 1px at 130px 80px, rgba(255,255,255,0.6), transparent),
        radial-gradient(2px 2px at 160px 30px, rgba(255,255,255,0.4), transparent);
    background-repeat: repeat;
    background-size: 200px 100px;
    animation: twinkle 3s infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 0.4; }
}

/* ヘッダースタイル */
.main-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px 0;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.header-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    font-weight: 600;
    color: white;
    text-decoration: none;
    font-size: 1.1rem;
    transition: color 0.3s ease;
}

.header-link:hover {
    color: #60a5fa;
}

.header-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.container {
    width: 100%;
    max-width: 900px;
    position: relative;
    z-index: 1;
    margin: auto;
    padding-top: 60px; /* ヘッダーの高さ分の余白 */
}

.header {
    text-align: center;
    margin-bottom: 32px;
}

h1 {
    font-size: 48px;
    font-weight: bold;
    color: #f1f5f9;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3), 0 4px 6px rgba(0, 0, 0, 0.5);
    background: linear-gradient(45deg, #fbbf24, #f59e0b, #fbbf24);
    background-size: 200% 200%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: starGlow 2s ease-in-out infinite alternate;
}

@keyframes starGlow {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}

.subtitle {
    color: rgba(241, 245, 249, 0.8);
    font-size: 18px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.game-card {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-radius: 24px;
    box-shadow: 
        0 0 60px rgba(59, 130, 246, 0.15),
        0 20px 25px -5px rgba(0, 0, 0, 0.3), 
        0 10px 10px -5px rgba(0, 0, 0, 0.04);
    padding: 32px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.canvas-container {
    position: relative;
    margin-bottom: 24px;
}

#canvas {
    width: 100%;
    border-radius: 16px;
    box-shadow: 
        inset 0 0 60px rgba(0, 0, 0, 0.8),
        0 0 30px rgba(59, 130, 246, 0.2),
        0 10px 15px -3px rgba(0, 0, 0, 0.3);
    background: radial-gradient(ellipse at center, #0f172a 0%, #020617 100%);
}

.loading-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 16px;
    color: white;
    font-size: 20px;
}

.controls {
    margin-bottom: 24px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.slider-label {
    color: white;
    font-size: 18px;
    font-weight: 500;
}

.slider-wrapper {
    width: 100%;
    max-width: 400px;
}

.slider {
    width: 100%;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right, #dc2626 0%, #fbbf24 50%, #059669 100%);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: radial-gradient(circle, #fbbf24 0%, #f59e0b 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 
        0 0 15px rgba(251, 191, 36, 0.6),
        0 4px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 
        0 0 25px rgba(251, 191, 36, 0.8),
        0 4px 6px rgba(0, 0, 0, 0.3);
}

.slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: radial-gradient(circle, #fbbf24 0%, #f59e0b 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 
        0 0 15px rgba(251, 191, 36, 0.6),
        0 4px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
    border: none;
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 
        0 0 25px rgba(251, 191, 36, 0.8),
        0 4px 6px rgba(0, 0, 0, 0.3);
}

.slider-scale {
    display: flex;
    justify-content: space-between;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    margin-top: 8px;
}

.result-card {
    background: rgba(15, 23, 42, 0.8);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    display: none;
    animation: fadeIn 0.5s ease-out;
    border: 1px solid rgba(59, 130, 246, 0.2);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.1);
}

.result-card.show {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.result-item {
    text-align: center;
}

.result-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    margin-bottom: 4px;
}

.result-value {
    font-size: 28px;
    font-weight: bold;
}

.result-value.green {
    color: #10b981;
}

.result-value.yellow {
    color: #fbbf24;
}

.score-display {
    text-align: center;
}

.score-value {
    font-size: 36px;
    font-weight: bold;
    color: white;
}

.submit-btn {
    width: 100%;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 50%, #1e40af 100%);
    color: white;
    font-weight: bold;
    font-size: 18px;
    padding: 16px 24px;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 
        0 0 30px rgba(59, 130, 246, 0.3),
        0 10px 15px -3px rgba(59, 130, 246, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
}

.submit-btn:hover {
    transform: scale(1.05);
    box-shadow: 
        0 0 40px rgba(59, 130, 246, 0.5),
        0 20px 25px -5px rgba(59, 130, 246, 0.3);
}

.submit-btn:active {
    transform: scale(0.98);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.stat-card {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 1px solid rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.05);
}

.stat-icon {
    width: 20px;
    height: 20px;
    margin: 0 auto 8px;
}

.stat-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: white;
}

/* Icons */
.icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    vertical-align: middle;
}

@media (max-width: 640px) {
    body {
        padding: 10px;
        align-items: flex-start;
    }
    
    h1 {
        font-size: 36px;
    }
    
    .game-card {
        padding: 20px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .container {
        margin-top: 10px;
        margin-bottom: 10px;
    }
}

/* Progress Container */
.progress-container {
    margin: 20px 0;
    padding: 15px;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 12px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.progress-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 500;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(30, 41, 59, 0.8);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.95));
    border-radius: 20px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5), 0 0 50px rgba(59, 130, 246, 0.2);
    padding: 30px;
    max-width: 500px;
    width: 90%;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-card {
    transform: scale(1) translateY(0);
}

.modal-header h2 {
    text-align: center;
    color: #ffffff;
    margin-bottom: 25px;
    font-size: 28px;
    background: linear-gradient(45deg, #3b82f6, #60a5fa, #fbbf24);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.set-results {
    margin-bottom: 25px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(59, 130, 246, 0.1);
}

.result-row:last-child {
    border-bottom: none;
}

.result-row.best-score {
    background: rgba(251, 191, 36, 0.1);
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.result-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 16px;
}

.result-value {
    color: #ffffff;
    font-weight: 600;
    font-size: 16px;
}

.result-value.large {
    font-size: 24px;
    color: #3b82f6;
}

.result-value.gold {
    color: #fbbf24;
    font-size: 20px;
}

.ranking-info {
    margin-top: 20px;
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    border-left: 3px solid #3b82f6;
    text-align: center;
}

.ranking-info-text {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-style: italic;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.modal-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.modal-btn.primary {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.modal-btn.primary:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.modal-btn.secondary {
    background: rgba(51, 65, 85, 0.8);
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.modal-btn.secondary:hover {
    background: rgba(71, 85, 105, 0.8);
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .modal-card {
        padding: 20px;
        margin: 20px;
    }
    
    .modal-buttons {
        flex-direction: column;
    }
    
    .modal-btn {
        width: 100%;
    }
}

/* ランキングパネルスタイル */
.ranking-panel {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 25px;
    margin-top: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.ranking-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.ranking-title {
    color: #ffffff;
    font-size: 1.5rem;
    margin: 0;
    font-weight: 600;
}

.ranking-period {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.ranking-loading {
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    padding: 30px;
    font-size: 1.1rem;
}

.ranking-error {
    text-align: center;
    color: #ef4444;
    padding: 20px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.ranking-item:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.ranking-item.my-rank {
    background: rgba(59, 130, 246, 0.1);
    border-left-color: #3b82f6;
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

/* TOP3の特別スタイル */
.ranking-item:nth-child(1) {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1), rgba(255, 255, 255, 0.05));
    border-left-color: #ffd700;
}

.ranking-item:nth-child(2) {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.1), rgba(255, 255, 255, 0.05));
    border-left-color: #c0c0c0;
}

.ranking-item:nth-child(3) {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.1), rgba(255, 255, 255, 0.05));
    border-left-color: #cd7f32;
}

.ranking-rank {
    font-weight: bold;
    width: 50px;
    text-align: center;
    font-size: 1.2rem;
    color: white;
}

.rank-1 { 
    color: #ffd700; 
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    font-size: 1.4rem;
}

.rank-2 { 
    color: #c0c0c0; 
    text-shadow: 0 0 10px rgba(192, 192, 192, 0.5);
    font-size: 1.3rem;
}

.rank-3 { 
    color: #cd7f32; 
    text-shadow: 0 0 10px rgba(205, 127, 50, 0.5);
    font-size: 1.3rem;
}

.ranking-nickname {
    flex: 1;
    margin-left: 15px;
    font-weight: 600;
    color: white;
    font-size: 1.1rem;
}

.ranking-score {
    font-weight: bold;
    color: #60a5fa;
    font-size: 1.1rem;
}

.ranking-details {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
    margin-left: 50px;
    margin-top: 5px;
}

.my-best-record {
    margin-top: 20px;
    padding: 15px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    display: none;
}

.my-best-record h4 {
    margin: 0 0 10px 0;
    color: #60a5fa;
    font-size: 1.1rem;
}

/* モーダル内のランキング登録セクション */
.modal-ranking-section {
    margin-top: 20px;
}

.ranking-separator {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    margin: 20px 0;
}

.ranking-modal-title {
    color: #ffd700;
    font-size: 1.2rem;
    margin: 0 0 15px 0;
    text-align: center;
    font-weight: 600;
}

.modal-nickname-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    margin-bottom: 10px;
}

.modal-nickname-input {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 1rem;
    color: white;
    width: 100%;
    max-width: 280px;
    transition: all 0.3s ease;
}

.modal-nickname-input:focus {
    outline: none;
    border-color: #ffd700;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.1);
}

.modal-nickname-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.modal-register-btn {
    background: linear-gradient(135deg, #ffd700, #ffb700);
    color: #1e293b;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
    width: 100%;
    max-width: 280px;
}

.modal-register-btn:hover {
    background: linear-gradient(135deg, #ffb700, #ff8f00);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4);
}

.modal-register-btn:disabled {
    background: rgba(75, 85, 99, 0.5);
    color: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.modal-ranking-status {
    text-align: center;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
}

@media (max-width: 768px) {
    .ranking-panel {
        padding: 20px;
        margin-top: 20px;
    }
    
    .ranking-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .ranking-title {
        font-size: 1.3rem;
    }
    
    .ranking-item {
        padding: 12px;
    }
    
    .ranking-rank {
        width: 40px;
        font-size: 1rem;
    }
    
    .rank-1 { font-size: 1.2rem; }
    .rank-2, .rank-3 { font-size: 1.1rem; }
    
    .ranking-nickname {
        font-size: 1rem;
        margin-left: 10px;
    }
    
    .ranking-score {
        font-size: 1rem;
    }
    
    .ranking-details {
        margin-left: 40px;
        font-size: 0.8rem;
    }
    
    /* ヘッダーのモバイル対応 */
    .header-link {
        padding: 0 15px;
        font-size: 1rem;
        gap: 10px;
    }
    
    .header-logo {
        width: 28px;
        height: 28px;
    }
    
    .container {
        padding-top: 55px; /* モバイルでヘッダー高さを若干縮小 */
    }
}

/* トースト通知 */
.toast {
    position: fixed;
    top: 80px;
    right: 20px;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    max-width: 350px;
    min-width: 280px;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.toast-message {
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;
}

.toast.success {
    border-left: 4px solid #10b981;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(0, 0, 0, 0.9));
}

.toast.error {
    border-left: 4px solid #ef4444;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(0, 0, 0, 0.9));
}

/* モバイルでのトースト調整 */
@media (max-width: 768px) {
    .toast {
        top: 60px;
        right: 15px;
        left: 15px;
        max-width: none;
        min-width: auto;
    }
}
