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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.home-btn-container {
    max-width: 600px;
    margin: 0 auto 20px;
}

.home-btn {
    display: inline-block;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-decoration: none;
    border-radius: 20px;
    font-size: 14px;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.home-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.container {
    max-width: 600px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

h1 {
    text-align: center;
    color: #333;
    font-size: 2rem;
    margin-bottom: 5px;
}

.subtitle {
    text-align: center;
    color: #888;
    margin-bottom: 25px;
    font-size: 0.95rem;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 12px;
}

.level-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.level-label {
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

.level-name {
    font-size: 0.9rem;
    color: #666;
}

.game-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: #555;
}

.stat-icon {
    font-size: 1rem;
}

.game-area {
    position: relative;
    background: #fafafa;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    border: 2px dashed #e0e0e0;
}

#gameCanvas {
    width: 100%;
    height: auto;
    display: block;
    touch-action: none;
    cursor: pointer;
}

.edge {
    stroke: #ccc;
    stroke-width: 4;
    stroke-linecap: round;
    fill: none;
    transition: stroke 0.3s;
}

.edge.drawn {
    stroke: #667eea;
    stroke-width: 5;
}

.edge.active {
    stroke: #764ba2;
    stroke-width: 5;
    stroke-dasharray: 10, 5;
    animation: dash 0.5s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -15;
    }
}

.vertex {
    fill: #fff;
    stroke: #667eea;
    stroke-width: 3;
    cursor: pointer;
    transition: all 0.2s;
}

.vertex:hover {
    fill: #667eea;
    r: 14;
}

.vertex.start {
    fill: #764ba2;
    stroke: #764ba2;
}

.vertex.current {
    fill: #f5576c;
    stroke: #f5576c;
    r: 14;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { r: 12; }
    50% { r: 16; }
}

.vertex.odd {
    stroke: #f5576c;
    stroke-width: 4;
    stroke-dasharray: 4, 2;
}

.vertex-label {
    font-size: 10px;
    fill: #999;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

.hint-box {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.hint-box.error {
    background: rgba(245, 87, 108, 0.9);
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(-50%); }
    25% { transform: translateX(calc(-50% - 5px)); }
    75% { transform: translateX(calc(-50% + 5px)); }
}

.hint-icon {
    font-size: 1rem;
}

.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    justify-content: center;
}

.ctrl-btn {
    flex: 1;
    min-width: 100px;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    color: white;
}

.ctrl-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.ctrl-btn:active {
    transform: translateY(0);
}

.reset-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.hint-btn {
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
}

.demo-btn {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}

.level-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.knowledge-card {
    background: linear-gradient(135deg, #fff5f5 0%, #ffe8e8 100%);
    border-radius: 12px;
    padding: 20px;
    border-left: 4px solid #f5576c;
}

.knowledge-card h3 {
    color: #f5576c;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.knowledge-card p {
    color: #666;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.knowledge-card ul {
    padding-left: 20px;
    color: #555;
    font-size: 0.85rem;
    line-height: 1.8;
}

.knowledge-card strong {
    color: #f5576c;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.level-item {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
}

.level-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.5);
}

.level-item.completed {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.level-item.locked {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.7;
}

.level-item.locked:hover {
    transform: none;
    box-shadow: none;
}

.level-item.completed::after {
    content: '✓';
    font-size: 0.8rem;
    margin-top: 2px;
}

.level-item .level-num {
    font-size: 1.3rem;
}

.level-item .level-title {
    font-size: 0.65rem;
    font-weight: normal;
    margin-top: 2px;
    opacity: 0.9;
}

.close-btn {
    display: block;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: #eee;
    color: #666;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
}

.close-btn:hover {
    background: #ddd;
}

.win-content {
    text-align: center;
}

.win-icon {
    font-size: 4rem;
    margin-bottom: 10px;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.win-content h2 {
    color: #38ef7d;
    margin-bottom: 10px;
}

.win-content p {
    color: #666;
    margin-bottom: 8px;
}

.win-stats {
    font-size: 1.1rem;
    color: #333 !important;
    margin-bottom: 20px !important;
}

.win-stats span {
    color: #f5576c;
    font-weight: bold;
}

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

.win-buttons .ctrl-btn {
    flex: 1;
    max-width: 150px;
}

.next-btn {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

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

    h1 {
        font-size: 1.5rem;
    }

    .game-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .game-stats {
        flex-direction: row;
        gap: 15px;
        align-items: center;
    }

    .controls {
        flex-direction: column;
    }

    .ctrl-btn {
        width: 100%;
    }

    .level-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
