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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #4a90e2 100%);
    background-size: 300% 300%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(29, 78, 216, 0.15) 0%, transparent 50%);
    animation: float 20s ease-in-out infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(1deg); }
    66% { transform: translateY(10px) rotate(-1deg); }
}

.container {
    text-align: center;
    width: 100%;
    max-width: 900px;
    padding: 20px;
    position: relative;
    z-index: 1;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 30px;
    /* 色弱対応：グラデーションを削除し、高コントラストの単色に変更 */
    color: white;
    text-shadow:
        2px 2px 4px rgba(0, 0, 0, 0.8),
        0 0 10px rgba(255, 255, 255, 0.3);
    animation: titleGlow 3s ease-in-out infinite alternate;
    font-weight: 700;
    letter-spacing: 1px;
}

@keyframes titleGlow {
    0% {
        filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
        transform: scale(1);
    }
    100% {
        filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.6));
        transform: scale(1.02);
    }
}

.controls {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.level-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.direction-toggle {
    display: flex;
    align-items: center;
}

.toggle-btn {
    position: relative;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 30px;
    padding: 10px 18px 10px 55px;
    cursor: pointer;
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(15px);
    min-width: 95px;
    overflow: hidden;
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.toggle-btn:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.15));
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
    box-shadow:
        0 8px 25px rgba(0, 0, 0, 0.15),
        0 0 20px rgba(255, 255, 255, 0.3);
}

.toggle-btn.outward {
    background: linear-gradient(135deg, rgba(74, 172, 254, 0.3), rgba(29, 78, 216, 0.2));
    border-color: rgba(74, 172, 254, 0.8);
    box-shadow:
        0 6px 20px rgba(74, 172, 254, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.toggle-slider {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #ffffff, #f8fafc);
    border-radius: 50%;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.toggle-btn.outward {
    padding: 10px 50px 10px 18px;
    text-align: left;
}

.toggle-btn.outward .toggle-slider {
    transform: translateY(-50%);
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    left: auto;
    right: 8px;
    box-shadow:
        0 4px 15px rgba(74, 172, 254, 0.4),
        0 0 20px rgba(74, 172, 254, 0.3);
}

.toggle-text {
    transition: all 0.3s ease;
}

.edge-mode-toggle {
    display: flex;
    align-items: center;
}

.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    color: white;
    gap: 10px;
    transition: all 0.3s ease;
}

.checkbox-container:hover {
    transform: scale(1.02);
    filter: brightness(1.1);
}

.checkbox-container input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(15px);
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.checkbox-container input[type="checkbox"]:checked + .checkmark {
    /* 色弱対応：より高コントラストで識別しやすい色に変更 */
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.9), rgba(15, 23, 42, 0.8));
    border-color: rgba(30, 64, 175, 1);
    box-shadow:
        0 6px 20px rgba(30, 64, 175, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.checkmark::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.checkbox-container input[type="checkbox"]:checked + .checkmark::after {
    opacity: 1;
}

.checkbox-text {
    user-select: none;
}

.level-btn {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(15px);
    min-width: 50px;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.level-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.level-btn:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.15));
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-3px) scale(1.05);
    box-shadow:
        0 8px 25px rgba(0, 0, 0, 0.15),
        0 0 20px rgba(255, 255, 255, 0.3);
}

.level-btn:hover::before {
    left: 100%;
}

.level-btn.active {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.3));
    border-color: white;
    box-shadow:
        0 6px 20px rgba(0, 0, 0, 0.25),
        0 0 30px rgba(255, 255, 255, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    animation: activeButton 2s ease-in-out infinite;
    /* 色弱対応：視覚的な差別化のためのパターン追加 */
    border-style: solid;
    border-width: 3px;
}

@keyframes activeButton {
    0%, 100% { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2), 0 0 30px rgba(255, 255, 255, 0.4); }
    50% { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2), 0 0 40px rgba(255, 255, 255, 0.6); }
}

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border-radius: 20px;
    padding: 25px;
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow:
        0 20px 40px rgba(0, 0, 0, 0.15),
        0 10px 20px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    width: fit-content;
    margin: 0 auto;
    position: relative;
    transition: all 0.3s ease;
}

.canvas-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
    border-radius: 22px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.canvas-container:hover::before {
    opacity: 1;
}

#kochCanvas {
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.95));
    border-radius: 15px;
    box-shadow:
        0 8px 25px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        inset 0 0 20px rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

#kochCanvas:hover {
    transform: scale(1.01);
    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        inset 0 0 25px rgba(255, 255, 255, 0.4);
}

.toast {
    position: absolute;
    top: calc(100% + 50px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    /* 色弱対応：赤系を避け、濃い青系に変更（高コントラスト） */
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.95), rgba(15, 23, 42, 0.9));
    color: white;
    padding: 15px 30px;
    border-radius: 30px;
    font-weight: bold;
    backdrop-filter: blur(15px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1000;
    box-shadow:
        0 8px 25px rgba(30, 64, 175, 0.4),
        0 4px 15px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    animation: toastPulse 2s ease-in-out infinite;
}

@keyframes toastPulse {
    0%, 100% {
        box-shadow:
            0 8px 25px rgba(30, 64, 175, 0.4),
            0 4px 15px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow:
            0 12px 35px rgba(30, 64, 175, 0.6),
            0 6px 20px rgba(0, 0, 0, 0.35);
    }
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.spinner-hexagon {
    width: 60px;
    height: 60px;
    position: relative;
}

.spinner-hexagon::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #667eea, #764ba2, #4a90e2);
    clip-path: polygon(25% 6.7%, 75% 6.7%, 100% 50%, 75% 93.3%, 25% 93.3%, 0% 50%);
    animation: hexagonSpin 2s linear infinite;
}

.spinner-hexagon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    background: rgba(255, 255, 255, 0.9);
    clip-path: polygon(25% 6.7%, 75% 6.7%, 100% 50%, 75% 93.3%, 25% 93.3%, 0% 50%);
}

@keyframes hexagonSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-text {
    font-size: 1rem;
    font-weight: bold;
    color: #667eea;
    animation: textPulse 1.5s ease-in-out infinite;
}

@keyframes textPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

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

    h1 {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    .level-btn {
        padding: 10px 16px;
        font-size: 1rem;
        min-width: 45px;
    }

    .canvas-container {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.3rem;
    }

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

    .level-controls {
        gap: 8px;
    }

    .level-btn {
        padding: 8px 14px;
        font-size: 0.9rem;
        min-width: 40px;
    }

    .canvas-container {
        padding: 10px;
    }
}