:root {
    /* Red Culture Theme */
    --app-bg: #fdfbf7;
    --sidebar-bg: rgba(255, 248, 240, 0.8);
    --glass-border: rgba(214, 59, 29, 0.2);
    --text-primary: #8b0000;
    --text-secondary: #a05a5a;
    --accent-red: #d63b1d;
    --accent-gold: #ffb400;
    --accent-hover: #b32b12;
    --danger-red: #ff3b30;
    --success-green: #27c93f;

    /* Planar Graph Colors */
    --node-fill: #fff;
    --node-border: #d63b1d;
    --edge-safe: #27c93f;
    --edge-danger: #ff3b30;
    --edge-default: rgba(139, 0, 0, 0.2);

    --shadow-sm: 0 2px 8px rgba(139, 0, 0, 0.08);
    --shadow-md: 0 8px 24px rgba(139, 0, 0, 0.12);
    --shadow-lg: 0 20px 40px rgba(139, 0, 0, 0.15);

    --font-family: "Noto Serif SC", "Outfit", serif;
    --font-title: "Ma Shan Zheng", cursive;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--app-bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url('https://images.unsplash.com/photo-1480714378408-67cf0d13bc1b?q=80&w=2670&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
}

.app-container {
    width: 90vw;
    height: 85vh;
    max-width: 1400px;
    background: rgba(255, 252, 245, 0.85);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    overflow: hidden;
}

.sidebar {
    width: 340px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.2rem;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.window-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 0.5rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.red {
    background: #ff5f56;
    border: 1px solid #e0443e;
}

.dot.yellow {
    background: #ffbd2e;
    border: 1px solid #dea123;
}

.dot.green {
    background: #27c93f;
    border: 1px solid #1aab29;
}

h1 {
    font-family: var(--font-title);
    font-size: 2rem;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: -5px;
}

.highlight {
    color: var(--accent-red);
}

.controls-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-grow: 1;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.apple-select {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(139, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.7);
    font-family: var(--font-family);
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.apple-select:hover {
    border-color: var(--accent-red);
}

.apple-select:focus {
    outline: none;
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(214, 59, 29, 0.1);
}

.apple-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: var(--font-family);
    gap: 6px;
}

.primary-btn {
    background: #fff;
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
    box-shadow: var(--shadow-sm);
    width: 100%;
}

.primary-btn:hover {
    background: var(--accent-red);
    color: #fff;
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}

.action-btn {
    background: var(--accent-red);
    color: white;
    width: 100%;
    box-shadow: var(--shadow-md);
}

.action-btn:hover {
    background: var(--accent-hover);
}

.info-panel {
    background: rgba(255, 255, 255, 0.5);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--text-primary);
    border: 1px solid rgba(139, 0, 0, 0.1);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(139, 0, 0, 0.1);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: all 0.3s ease;
}

.status-dot.safe {
    background: var(--success-green);
    box-shadow: 0 0 8px var(--success-green);
}

.status-dot.danger {
    background: var(--danger-red);
    box-shadow: 0 0 8px var(--danger-red);
}

#statusText {
    font-weight: 700;
    font-size: 0.95rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-value.danger {
    color: var(--danger-red);
}

.stat-value.safe {
    color: var(--success-green);
}

.euler-formula {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    padding: 8px;
}

.formula-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-align: center;
}

.formula-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    font-family: monospace;
    font-size: 1.1rem;
}

.f-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.f-val {
    font-weight: 700;
}

.f-val.result {
    color: var(--accent-gold);
}

.f-label {
    font-size: 0.6rem;
    color: var(--text-secondary);
}

.f-op {
    color: var(--text-secondary);
    font-weight: 300;
}

.info-box {
    background: linear-gradient(135deg, rgba(255, 180, 0, 0.1), rgba(214, 59, 29, 0.1));
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(214, 59, 29, 0.2);
}

.info-box h3 {
    font-size: 0.9rem;
    color: var(--accent-red);
    margin-bottom: 0.5rem;
    font-family: var(--font-family);
}

.info-box p {
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.visualizer-stage {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
}

.glass-pane {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.4);
    position: relative;
    overflow: hidden;
}

.graph-title {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: rgba(255, 255, 255, 0.95);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    z-index: 10;
    pointer-events: none;
}

.graph-title h2 {
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--accent-red);
    margin: 0;
}

.graph-title p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 4px 0 0 0;
}

.legend {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

.legend-line.safe {
    background: var(--edge-safe);
}

.legend-line.danger {
    background: var(--edge-danger);
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.game-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.success-message {
    background: white;
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--accent-gold);
    transform: scale(0.8);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-overlay.active .success-message {
    transform: scale(1);
}

.success-message h2 {
    color: var(--accent-red);
    margin-bottom: 0.5rem;
}

.success-message p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Graph Elements */
.edge-line {
    stroke-width: 3px;
    stroke-linecap: round;
    transition: stroke 0.3s ease;
}

.edge-line.safe {
    stroke: var(--edge-safe);
    opacity: 0.6;
}

.edge-line.danger {
    stroke: var(--edge-danger);
    stroke-width: 4px;
    opacity: 0.8;
    animation: pulse-line 1s infinite;
}

@keyframes pulse-line {

    0%,
    100% {
        stroke-opacity: 0.8;
        stroke-width: 4px;
    }

    50% {
        stroke-opacity: 1;
        stroke-width: 6px;
    }
}

.node-group {
    cursor: grab;
    transition: transform 0.1s linear;
}

.node-group:active {
    cursor: grabbing;
}

.node-circle {
    fill: var(--node-fill);
    stroke: var(--node-border);
    stroke-width: 3px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
    transition: all 0.2s ease;
}

.node-group:hover .node-circle {
    stroke-width: 5px;
    transform: scale(1.1);
}

.node-icon {
    font-size: 20px;
    pointer-events: none;
    user-select: none;
}

.node-label {
    font-family: var(--font-family);
    font-size: 12px;
    fill: var(--text-primary);
    font-weight: 700;
    pointer-events: none;
    user-select: none;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(139, 0, 0, 0.05);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--accent-red);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--accent-hover);
}