:root {
    /* Smart Agriculture Theme */
    --app-bg: #f0f9f0;
    --sidebar-bg: rgba(240, 255, 240, 0.9);
    --glass-border: rgba(39, 201, 63, 0.2);
    --text-primary: #1a4d1a;
    --text-secondary: #4a7a4a;

    --accent-green: #27c93f;
    --accent-gold: #ffb400;
    --accent-red: #ff3b30;
    --accent-blue: #007aff;

    --node-root: #1a4d1a;
    --node-region: #27c93f;
    --node-sensor: #ffb400;

    --edge-default: rgba(39, 201, 63, 0.2);
    --edge-active: #27c93f;
    --edge-visited: #1a4d1a;

    --shadow-sm: 0 2px 8px rgba(39, 201, 63, 0.1);
    --shadow-md: 0 8px 24px rgba(39, 201, 63, 0.15);
    --shadow-lg: 0 20px 40px rgba(39, 201, 63, 0.2);

    --font-family: "Outfit", "Noto Serif SC", sans-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-1625246333195-78d9c38ad449?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(245, 255, 245, 0.9);
    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: 360px;
    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;
    z-index: 20;
}

.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;
}

.dot.yellow {
    background: #ffbd2e;
}

.dot.green {
    background: #27c93f;
}

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-green);
}

.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;
}

.mode-buttons {
    display: flex;
    gap: 10px;
}

.apple-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 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;
    flex: 1;
}

.primary-btn {
    background: var(--accent-green);
    color: white;
    box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
    background: #1ea332;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.secondary-btn {
    background: white;
    color: var(--accent-green);
    border: 1px solid var(--accent-green);
}

.secondary-btn:hover {
    background: rgba(39, 201, 63, 0.1);
}

.danger-btn {
    background: rgba(255, 59, 48, 0.1);
    color: var(--accent-red);
    width: 100%;
}

.danger-btn:hover {
    background: rgba(255, 59, 48, 0.2);
}

.apple-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

input[type=range] {
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--accent-green);
    cursor: pointer;
    margin-top: -7px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border: 2px solid #fff;
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(39, 201, 63, 0.2);
    border-radius: 2px;
}

.info-panel {
    background: rgba(255, 255, 255, 0.6);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--text-primary);
    border: 1px solid rgba(39, 201, 63, 0.1);
}

#statusText {
    font-weight: 700;
    color: var(--accent-green);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(39, 201, 63, 0.1);
}

.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: 8px 10px;
    background: rgba(255, 255, 255, 0.8);
    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.safe {
    color: var(--accent-green);
}

.stat-value.warning {
    color: var(--accent-gold);
}

.stat-value.danger {
    color: var(--accent-red);
}

.log-container {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    padding: 8px;
    height: 150px;
    display: flex;
    flex-direction: column;
}

.log-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.log-content {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.75rem;
    font-family: monospace;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.log-entry {
    padding: 4px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.8);
    border-left: 2px solid var(--accent-green);
}

.log-entry.dfs {
    border-color: var(--accent-blue);
}

.log-entry.bfs {
    border-color: var(--accent-gold);
}

.info-box {
    background: linear-gradient(135deg, rgba(39, 201, 63, 0.1), rgba(255, 180, 0, 0.1));
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(39, 201, 63, 0.2);
}

.info-box h3 {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-family: var(--font-family);
}

.info-box p {
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-secondary);
    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.2);
    position: relative;
}

.glass-pane {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.6);
    position: relative;
    overflow: hidden;
}

.farm-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.1;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M0,80 Q25,70 50,80 T100,80" fill="none" stroke="%2327c93f" stroke-width="0.5"/><path d="M0,85 Q25,75 50,85 T100,85" fill="none" stroke="%2327c93f" stroke-width="0.5"/><path d="M0,90 Q25,80 50,90 T100,90" fill="none" stroke="%2327c93f" stroke-width="0.5"/></svg>');
    background-size: cover;
    pointer-events: none;
}

.graph-title {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: rgba(255, 255, 255, 0.9);
    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(--text-primary);
    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-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.legend-dot.root {
    background: var(--node-root);
}

.legend-dot.region {
    background: var(--node-region);
}

.legend-dot.sensor {
    background: var(--node-sensor);
}

.legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
    background: var(--edge-default);
}

.legend-line.active {
    background: var(--edge-active);
    animation: pulse-line 1s infinite;
}

.decision-popup {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--accent-green);
    z-index: 100;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 300px;
    text-align: center;
}

.decision-popup.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.popup-header {
    font-weight: 700;
    color: var(--accent-green);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.popup-content {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Graph Elements */
.edge-line {
    stroke: var(--edge-default);
    stroke-width: 2px;
    transition: all 0.3s ease;
    stroke-linecap: round;
}

.edge-line.active {
    stroke: var(--edge-active);
    stroke-width: 4px;
    animation: flow 1s linear infinite;
    stroke-dasharray: 10, 5;
}

.edge-line.visited {
    stroke: var(--edge-visited);
    stroke-width: 3px;
    opacity: 0.6;
}

@keyframes flow {
    to {
        stroke-dashoffset: -15;
    }
}

.node-group {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.node-group:hover {
    transform: scale(1.1);
}

.node-circle {
    fill: white;
    stroke-width: 3px;
    transition: all 0.3s ease;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
}

.node-circle.root {
    stroke: var(--node-root);
}

.node-circle.region {
    stroke: var(--node-region);
}

.node-circle.sensor {
    stroke: var(--node-sensor);
}

.node-circle.active {
    fill: var(--accent-green);
    stroke: white;
    stroke-width: 4px;
    animation: pulse-node 1s infinite;
}

.node-circle.visited {
    fill: #f0f9f0;
    stroke-width: 4px;
}

@keyframes pulse-node {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(39, 201, 63, 0.7);
    }

    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 10px rgba(39, 201, 63, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(39, 201, 63, 0);
    }
}

.node-icon {
    font-size: 18px;
    pointer-events: none;
    user-select: none;
}

.node-label {
    font-family: var(--font-family);
    font-size: 11px;
    font-weight: 700;
    fill: var(--text-primary);
    pointer-events: none;
    user-select: none;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9);
}

.node-value {
    font-family: monospace;
    font-size: 10px;
    fill: var(--text-secondary);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.node-group:hover .node-value,
.node-group.active .node-value {
    opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-green);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #1ea332;
}