/* ============================================
   STP SIMULATOR v3 - Professional, clean
   ============================================ */

/* --- Topology Selector --- */
.topology-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}
@media (max-width: 700px) { .topology-selector { grid-template-columns: 1fr; } }

.topo-card {
    position: relative;
    background: var(--learn-bg);
    border: 2px solid #E2E8F0;
    border-radius: var(--learn-radius);
    padding: 24px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    overflow: hidden;
}
.topo-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--learn-primary), var(--learn-primary-light));
    transform: scaleX(0);
    transition: transform 0.3s ease;
}
.topo-card:hover { border-color: var(--learn-primary); box-shadow: 0 8px 24px rgba(42,158,166,0.12); transform: translateY(-2px); }
.topo-card:hover::before, .topo-card.active::before { transform: scaleX(1); }
.topo-card.active { border-color: var(--learn-primary); background: var(--learn-primary-bg); }
.topo-card-icon {
    width: 64px; height: 64px; margin: 0 auto 12px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    transition: transform 0.3s ease;
}
.topo-card:hover .topo-card-icon { transform: scale(1.1); }
.topo-card-icon.easy { background: linear-gradient(135deg, #D1FAE5, #A7F3D0); color: #065F46; }
.topo-card-icon.medium { background: linear-gradient(135deg, #FEF3C7, #FDE68A); color: #92400E; }
.topo-card-icon.hard { background: linear-gradient(135deg, #FEE2E2, #FECACA); color: #991B1B; }
.topo-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.topo-card .topo-desc { font-size: 0.85rem; color: var(--learn-text-muted); line-height: 1.5; }
.topo-card .topo-badge {
    display: inline-block; margin-top: 10px; padding: 3px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.topo-badge.easy { background: #D1FAE5; color: #065F46; }
.topo-badge.medium { background: #FEF3C7; color: #92400E; }
.topo-badge.hard { background: #FEE2E2; color: #991B1B; }

/* --- Simulator Container --- */
.stp-sim-container {
    display: none;
    border: 2px solid #E2E8F0;
    border-radius: var(--learn-radius);
    overflow: hidden;
    background: var(--learn-bg);
    box-shadow: var(--learn-shadow);
    animation: simFadeIn 0.5s ease;
}
.stp-sim-container.visible { display: block; }
@keyframes simFadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* --- Toolbar --- */
.stp-toolbar {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 20px; background: #F8FAFC; border-bottom: 1px solid #E2E8F0; flex-wrap: wrap;
}
.stp-toolbar-title { font-weight: 700; font-size: 0.95rem; color: var(--learn-text); margin-right: auto; }

.stp-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border: 1px solid #E2E8F0; border-radius: 8px;
    background: white; color: var(--learn-text); font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s ease; font-family: inherit;
}
.stp-btn:hover { border-color: var(--learn-primary); color: var(--learn-primary); background: var(--learn-primary-bg); }
.stp-btn.primary { background: var(--learn-primary); color: white; border-color: var(--learn-primary); }
.stp-btn.primary:hover { background: var(--learn-primary-dark); color: white; }
.stp-btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.stp-btn svg { width: 16px; height: 16px; }

.stp-speed-control {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.8rem; color: var(--learn-text-muted); font-weight: 500;
}
.stp-speed-control select {
    padding: 4px 8px; border: 1px solid #E2E8F0; border-radius: 6px;
    font-size: 0.8rem; font-family: inherit; background: white; cursor: pointer;
}

/* --- Canvas --- */
.stp-canvas-wrap {
    position: relative; width: 100%;
    background: #0c111d;
    min-height: 640px;
    overflow: hidden;
}
.stp-canvas-wrap svg { width: 100%; display: block; }
/* Subtle dot grid */
.stp-canvas-wrap::before {
    content: ''; position: absolute; inset: 0;
    background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none; z-index: 1;
}

/* ---- SVG Elements ---- */

/* Links - default state: neutral gray, NOT red */
.stp-link {
    stroke: #2d3a4d; stroke-width: 2.5; fill: none; stroke-linecap: round;
    transition: all 0.6s ease;
}
.stp-link.forwarding {
    stroke: #10B981; stroke-width: 3;
    filter: drop-shadow(0 0 5px rgba(16,185,129,0.35));
}
.stp-link.blocking {
    stroke: #EF4444; stroke-width: 2; stroke-dasharray: 8 6; opacity: 0.65;
}
.stp-link.evaluating {
    stroke: #F59E0B; stroke-width: 3;
    animation: linkPulse 1.2s ease-in-out infinite;
}
@keyframes linkPulse { 0%,100% { opacity: 0.35; } 50% { opacity: 1; } }

/* Cost pill on link midpoint */
.cost-pill-bg { fill: #182031; stroke: #2d3a4d; stroke-width: 1; }
.cost-pill-text {
    font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 700;
    fill: #94A3B8; text-anchor: middle;
}

/* Port indicators */
.port-dot {
    r: 6; fill: #2d3a4d; stroke: #0c111d; stroke-width: 2;
    transition: all 0.5s ease; cursor: default;
}
.port-dot.root { fill: #10B981; filter: drop-shadow(0 0 5px rgba(16,185,129,0.5)); }
.port-dot.designated { fill: #3B82F6; filter: drop-shadow(0 0 5px rgba(59,130,246,0.5)); }
.port-dot.blocking { fill: #EF4444; filter: drop-shadow(0 0 5px rgba(239,68,68,0.5)); }

/* Port role tags */
.port-tag-bg { opacity: 0; transition: opacity 0.4s ease; }
.port-tag-bg.visible { opacity: 1; }
.port-tag-bg.root { fill: #064E3B; }
.port-tag-bg.designated { fill: #1E3A5F; }
.port-tag-bg.blocking { fill: #7F1D1D; }

.port-tag {
    font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700;
    text-anchor: middle; letter-spacing: 0.3px;
    opacity: 0; transition: opacity 0.4s ease;
}
.port-tag.visible { opacity: 1; }
.port-tag.root { fill: #6EE7B7; }
.port-tag.designated { fill: #93C5FD; }
.port-tag.blocking { fill: #FCA5A5; }

/* BPDU packets */
.bpdu-packet { opacity: 0; }
.bpdu-packet.visible { opacity: 1; }
.bpdu-body { fill: #F59E0B; rx: 4; filter: drop-shadow(0 0 6px rgba(245,158,11,0.5)); }
.bpdu-text {
    fill: #0F172A; font-family: 'JetBrains Mono', monospace;
    font-size: 8px; font-weight: 800; text-anchor: middle;
}

/* Traffic packets */
.traffic-packet { opacity: 0; }
.traffic-packet.visible { opacity: 1; }
.traffic-body { fill: #8B5CF6; rx: 4; filter: drop-shadow(0 0 6px rgba(139,92,246,0.5)); }
.traffic-text {
    fill: white; font-family: 'JetBrains Mono', monospace;
    font-size: 8px; font-weight: 700; text-anchor: middle;
}

/* ---- Cisco Switch Icon ---- */
.stp-switch { cursor: pointer; }
.stp-switch:hover { filter: brightness(1.15); }

/* Root bridge styling */
.stp-switch.root-bridge .sw-chassis { stroke: #F59E0B; stroke-width: 2.5; }
@keyframes rootGlow {
    0%,100% { filter: drop-shadow(0 0 8px rgba(245,158,11,0.25)); }
    50% { filter: drop-shadow(0 0 20px rgba(245,158,11,0.6)); }
}
.stp-switch.root-bridge { animation: rootGlow 2.5s ease-in-out infinite; }
.sw-crown { opacity: 0; transition: opacity 0.5s ease; }
.stp-switch.root-bridge .sw-crown { opacity: 1; }
.sw-root-tag { opacity: 0; transition: opacity 0.5s ease; }
.stp-switch.root-bridge .sw-root-tag { opacity: 1; }

.sw-name {
    fill: #F1F5F9; font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 800;
    text-anchor: middle; pointer-events: none;
}
.sw-pri {
    fill: #64748B; font-family: 'JetBrains Mono', monospace; font-size: 10px;
    text-anchor: middle; pointer-events: none;
}
.sw-mac {
    fill: #475569; font-family: 'JetBrains Mono', monospace; font-size: 9px;
    text-anchor: middle; pointer-events: none;
}

/* ---- In-canvas Config Popup (HTML overlay) ---- */
.stp-popup-overlay {
    position: absolute; inset: 0; z-index: 20;
    display: none; align-items: center; justify-content: center;
}
.stp-popup-overlay.visible { display: flex; }
.stp-popup-backdrop {
    position: absolute; inset: 0; background: rgba(0,0,0,0.4); cursor: pointer;
}
.stp-popup {
    position: relative; z-index: 21;
    background: #111827; border: 1px solid #334155; border-radius: 14px;
    padding: 24px 28px; min-width: 320px; max-width: 380px;
    color: #E2E8F0;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: popupIn 0.25s ease;
}
@keyframes popupIn { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.stp-popup h4 {
    font-size: 1rem; font-weight: 700; margin-bottom: 16px;
    display: flex; align-items: center; gap: 10px; color: white;
}
.stp-popup .popup-close {
    margin-left: auto; background: none; border: none; color: #64748B;
    font-size: 1.4rem; cursor: pointer; padding: 0 4px; line-height: 1;
}
.stp-popup .popup-close:hover { color: white; }

.popup-field { margin-bottom: 14px; }
.popup-field label {
    display: block; font-size: 0.78rem; font-weight: 600; color: #94A3B8;
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.popup-field .field-row {
    display: flex; align-items: center; gap: 10px;
}
.popup-field input[type="range"] {
    flex: 1; accent-color: var(--learn-primary); height: 6px; cursor: pointer;
}
.popup-field .range-val {
    font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; font-weight: 700;
    color: white; min-width: 52px; text-align: right;
}
.popup-field input[type="text"] {
    width: 100%; padding: 8px 12px;
    background: #1E293B; border: 1px solid #334155; border-radius: 8px;
    color: white; font-family: 'JetBrains Mono', monospace; font-size: 0.88rem;
}
.popup-field input[type="text"]:focus {
    outline: none; border-color: var(--learn-primary);
    box-shadow: 0 0 0 3px rgba(42,158,166,0.15);
}
.popup-field input[type="text"].invalid { border-color: #EF4444; }
.popup-field .field-hint {
    font-size: 0.72rem; color: #64748B; margin-top: 4px;
}
.popup-field select {
    width: 100%; padding: 8px 12px;
    background: #1E293B; border: 1px solid #334155; border-radius: 8px;
    color: white; font-family: inherit; font-size: 0.88rem; cursor: pointer;
}
.popup-field select:focus { outline: none; border-color: var(--learn-primary); }

.popup-field .cost-result {
    display: inline-block; margin-top: 6px; padding: 4px 12px;
    background: rgba(42,158,166,0.12); border-radius: 6px;
    font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; color: var(--learn-primary); font-weight: 700;
}

/* ---- Info Panel (side) ---- */
.stp-info-panel {
    position: absolute; top: 16px; right: 16px; width: 310px;
    max-height: calc(100% - 32px); overflow-y: auto;
    background: rgba(10,15,30,0.96); backdrop-filter: blur(16px);
    border: 1px solid rgba(71,85,105,0.4); border-radius: 14px;
    padding: 20px; z-index: 10;
    opacity: 0; transform: translateX(16px);
    transition: all 0.35s ease; pointer-events: none;
}
.stp-info-panel.visible { opacity: 1; transform: translateX(0); pointer-events: all; }

.stp-info-panel h3 {
    color: white; font-size: 0.95rem; font-weight: 700; margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px;
}
.stp-info-panel h3 .step-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--learn-primary); color: white;
    font-size: 0.75rem; font-weight: 800; flex-shrink: 0;
}
.stp-info-panel p { color: #CBD5E1; font-size: 0.85rem; line-height: 1.6; margin-bottom: 10px; }
.stp-info-panel .hl {
    background: rgba(42,158,166,0.1); border-left: 3px solid var(--learn-primary);
    padding: 10px 12px; border-radius: 0 8px 8px 0; margin: 12px 0;
}
.stp-info-panel .hl p { margin: 0; color: #E2E8F0; font-size: 0.82rem; }
.stp-info-panel code {
    background: rgba(30,41,59,0.8); color: #7DD3FC; padding: 2px 6px;
    border-radius: 4px; font-size: 0.8rem; font-family: 'JetBrains Mono', monospace;
}
.stp-info-panel table {
    width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.8rem;
}
.stp-info-panel th {
    text-align: left; color: #94A3B8; font-weight: 600; padding: 5px 6px;
    border-bottom: 1px solid #334155; font-size: 0.72rem;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.stp-info-panel td {
    color: #E2E8F0; padding: 5px 6px;
    border-bottom: 1px solid rgba(51,65,85,0.35);
    font-family: 'JetBrains Mono', monospace; font-size: 0.78rem;
}
.stp-info-panel tr.win td { color: #6EE7B7; font-weight: 700; }
.stp-info-panel .close-btn {
    position: absolute; top: 12px; right: 12px;
    background: none; border: none; color: #64748B;
    cursor: pointer; font-size: 1.2rem; padding: 2px 6px; border-radius: 4px;
}
.stp-info-panel .close-btn:hover { color: white; background: rgba(255,255,255,0.08); }

/* ---- Progress ---- */
.stp-progress {
    display: flex; align-items: center; padding: 14px 20px;
    background: #F8FAFC; border-top: 1px solid #E2E8F0; gap: 4px;
}
.stp-step { display: flex; align-items: center; gap: 6px; flex: 1; }
.stp-step:not(:last-child)::after {
    content: ''; flex: 1; height: 2px; background: #E2E8F0; margin: 0 8px;
    transition: background 0.4s;
}
.stp-step.done:not(:last-child)::after { background: var(--learn-primary); }
.stp-step-dot {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700; background: #E2E8F0; color: #94A3B8;
    transition: all 0.4s; flex-shrink: 0;
}
.stp-step.active .stp-step-dot {
    background: var(--learn-primary); color: white;
    box-shadow: 0 0 0 4px rgba(42,158,166,0.2);
    animation: sPulse 2s ease-in-out infinite;
}
.stp-step.done .stp-step-dot { background: var(--learn-primary); color: white; }
@keyframes sPulse { 0%,100% { box-shadow: 0 0 0 4px rgba(42,158,166,0.2); } 50% { box-shadow: 0 0 0 8px rgba(42,158,166,0.08); } }
.stp-step-label {
    font-size: 0.75rem; font-weight: 600; color: #94A3B8; white-space: nowrap;
}
.stp-step.active .stp-step-label, .stp-step.done .stp-step-label { color: var(--learn-primary); }
@media (max-width: 700px) {
    .stp-step-label { display: none; }
    .stp-info-panel { width: calc(100% - 32px); max-width: 300px; font-size: 0.82rem; }
}

/* ---- Legend ---- */
.stp-legend {
    display: flex; align-items: center; gap: 18px; padding: 10px 20px;
    background: #F8FAFC; border-top: 1px solid #E2E8F0; flex-wrap: wrap; font-size: 0.78rem;
}
.stp-legend-item { display: flex; align-items: center; gap: 5px; color: var(--learn-text-muted); font-weight: 500; }
.lg-line { width: 20px; height: 3px; border-radius: 1px; }
.lg-line.fwd { background: #10B981; }
.lg-line.blk { height: 0; border-top: 2px dashed #EF4444; width: 20px; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; }
.lg-dot.root-bridge { background: #F59E0B; }
.lg-dot.rp { background: #10B981; }
.lg-dot.dp { background: #3B82F6; }
.lg-dot.bp { background: #EF4444; }
.lg-rect { width: 14px; height: 10px; border-radius: 2px; background: #F59E0B; }

/* ---- Status bar ---- */
.stp-status-bar {
    display: flex; align-items: center; gap: 10px; padding: 10px 20px;
    background: #0F172A; color: #94A3B8; font-size: 0.78rem;
    font-family: 'JetBrains Mono', monospace;
    border-radius: 0 0 var(--learn-radius) var(--learn-radius);
}
.stp-status-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #334155; flex-shrink: 0;
    transition: all 0.3s;
}
.stp-status-dot.running { background: #10B981; animation: stBlink 1.5s ease-in-out infinite; }
.stp-status-dot.converged { background: #3B82F6; }
@keyframes stBlink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.stp-status-text { flex: 1; }

/* ---- Converged overlay ---- */
.stp-converged-overlay {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(10,15,30,0.7); z-index: 15;
    opacity: 0; transition: opacity 0.4s; pointer-events: none;
}
.stp-converged-overlay.visible { opacity: 1; pointer-events: all; }
.stp-converged-card {
    background: #111827; border: 2px solid var(--learn-primary); border-radius: 16px;
    padding: 32px 44px; text-align: center;
    animation: cvBounce 0.4s ease;
}
@keyframes cvBounce { 0% { transform: scale(0.85); opacity: 0; } 70% { transform: scale(1.03); } 100% { transform: scale(1); opacity: 1; } }
.stp-converged-card h3 { color: white; font-size: 1.25rem; margin-bottom: 6px; }
.stp-converged-card p { color: #94A3B8; font-size: 0.88rem; margin-bottom: 16px; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .stp-toolbar { padding: 10px 14px; }
    .stp-canvas-wrap { min-height: 440px; }
}
