:root {
  --primary: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #059669;
  --warning: #b45309;
  --danger: #dc2626;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --card-bg: #fff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --sc-color: #3b82f6;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background: #f8fafc; color: var(--text-primary); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
code { font-family: monospace; background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; color: var(--primary); }

/* ===== NAV ===== */
.top-nav { background: rgba(255,255,255,0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); padding: 0 20px; position: sticky; top: 0; z-index: 300; }
.top-nav-inner { height: 52px; max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.nav-back { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); padding: 6px 12px; border: 1px solid var(--border); border-radius: 20px; white-space: nowrap; transition: all 0.15s; }
.nav-back:hover { color: var(--primary); border-color: var(--primary); }
.nav-title { font-size: 0.9rem; font-weight: 800; color: var(--text-primary); flex: 1; }

/* ===== HERO ===== */
.tool-hero { background: linear-gradient(135deg, #0f2d6b 0%, #1d4ed8 55%, #3b82f6 100%); color: #fff; padding: 28px 20px 24px; text-align: center; }
.tool-hero h1 { font-size: 1.45rem; font-weight: 900; margin-bottom: 6px; }
.tool-hero p { font-size: 0.85rem; opacity: 0.88; line-height: 1.6; }
.hero-concept { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.hero-chip { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 20px; padding: 4px 12px; font-size: 0.75rem; font-weight: 600; }

/* ===== OUTER WRAP ===== */
.viz-wrap-outer { max-width: 1100px; margin: 0 auto; padding: 14px 12px 80px; display: flex; flex-direction: column; gap: 14px; }

/* ===== SCENARIO TABS ===== */
.sc-tabs-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.sc-tabs { display: flex; gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.sc-tabs::-webkit-scrollbar { display: none; }
.sc-tab {
  flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 16px; border: none; border-bottom: 3px solid transparent;
  background: none; cursor: pointer; transition: all 0.15s;
  min-width: 90px; color: var(--text-muted); font-weight: 700;
}
.sc-tab:hover { color: var(--text-secondary); background: #f8fafc; }
.sc-tab.active { color: var(--sc-color); border-bottom-color: var(--sc-color); background: #f8fafc; }
.sc-tab-icon { font-size: 1.4rem; line-height: 1; }
.sc-tab-name { font-size: 0.7rem; white-space: nowrap; }
.sc-desc { padding: 8px 14px; font-size: 0.78rem; color: var(--text-secondary); border-top: 1px solid var(--border); background: #f8fafc; line-height: 1.6; }

/* ===== MAIN LAYOUT ===== */
.viz-layout { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 860px) { .viz-layout { grid-template-columns: 3fr 2fr; } }

/* ===== VISUALIZER PANEL ===== */
.viz-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.viz-panel-header { padding: 10px 16px; font-size: 0.85rem; font-weight: 800; border-bottom: 1px solid var(--border); background: #f8fafc; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.viz-panel-header .step-counter { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); }

/* SVG Area */
.svg-container { position: relative; width: 100%; background: #f8fafc; overflow: hidden; }
#visSvg { display: block; width: 100%; height: auto; }

/* Packet overlay (HTML element over SVG) */
#vizPacketOverlay {
  position: absolute; top: 0; left: 0; pointer-events: none; z-index: 20;
  white-space: nowrap; font-size: 10px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px; color: #fff;
  transform: translate(-50%, -50%); opacity: 0;
  border: 1.5px solid rgba(255,255,255,0.4);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: left 1.3s ease-in-out, top 1.3s ease-in-out;
}
#vizPacketOverlay.visible { opacity: 1; }

/* Step dots */
.step-dots { display: flex; gap: 6px; justify-content: center; padding: 10px 16px; flex-wrap: wrap; }
.step-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); cursor: pointer; transition: all 0.2s;
  border: 2px solid transparent;
}
.step-dot.done { background: #bfdbfe; }
.step-dot.active { background: var(--sc-color, var(--primary)); transform: scale(1.3); border-color: rgba(0,0,0,0.1); }
.step-dot:hover:not(.active) { background: #94a3b8; }

/* Step controls */
.step-controls { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: #f8fafc; flex-wrap: wrap; }
.ctrl-btn {
  font-size: 0.8rem; font-weight: 700; padding: 8px 16px; border-radius: 8px;
  border: 1.5px solid var(--border); background: var(--card-bg);
  color: var(--text-secondary); cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.ctrl-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.ctrl-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ctrl-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.ctrl-btn.primary:hover:not(:disabled) { background: #1e40af; }
.ctrl-btn.reset { font-size: 0.75rem; margin-left: auto; }

/* Step description card */
.step-desc-card { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.step-desc { font-size: 0.85rem; line-height: 1.75; color: var(--text-primary); }
.step-side { font-size: 0.78rem; color: var(--text-muted); line-height: 1.6; background: #f8fafc; border-left: 3px solid var(--sc-color, var(--primary)); padding: 6px 10px; border-radius: 0 6px 6px 0; }

/* Packet info badge */
.packet-info { display: none; align-items: center; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border); background: #f1f5f9; font-size: 0.8rem; }
.packet-badge { padding: 3px 12px; border-radius: 20px; color: #fff; font-size: 0.78rem; font-weight: 700; }

/* SVG node highlight effect */
.vis-node.highlighted .node-bg {
  stroke: var(--sc-color, #3b82f6);
  stroke-width: 3;
  animation: node-glow 1.8s ease-in-out infinite;
}
@keyframes node-glow {
  0%, 100% { filter: drop-shadow(0 0 3px var(--sc-color, #3b82f6)); }
  50%       { filter: drop-shadow(0 0 10px var(--sc-color, #3b82f6)); }
}

/* ===== INFO PANEL ===== */
.info-panel { display: flex; flex-direction: column; gap: 10px; }
.info-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.info-card.warn { background: #fffbeb; border-color: #fde68a; }
.info-card.exam { background: var(--primary-light, #eff6ff); border-color: #bfdbfe; }
.info-card-label { font-size: 0.75rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.info-card-text { font-size: 0.82rem; line-height: 1.7; color: var(--text-secondary); }
.info-card ul { padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.info-card ul li { font-size: 0.8rem; line-height: 1.6; color: var(--text-secondary); }

/* ===== SVG STYLES ===== */
.vis-node { cursor: default; }
.node-bg { transition: stroke 0.2s, stroke-width 0.2s; }
.zone-label { font-size: 10px; fill: #64748b; font-weight: 700; text-anchor: middle; pointer-events: none; }
.node-label { font-size: 10px; fill: #1e293b; font-weight: 700; text-anchor: middle; pointer-events: none; }
.node-sublabel { font-size: 8.5px; fill: #64748b; text-anchor: middle; pointer-events: none; }
.edge-label { font-size: 9px; fill: #64748b; text-anchor: middle; pointer-events: none; }

/* ===== BLOCKED PACKET ANIMATION ===== */
@keyframes blocked-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.blocked { animation: blocked-shake 0.4s ease-in-out 2; }

/* ===== TOAST ===== */
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); background: #1e293b; color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 0.82rem; font-weight: 600; opacity: 0; transition: all 0.25s; z-index: 999; white-space: nowrap; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== SCROLLBAR HIDDEN ===== */
.sc-tabs::-webkit-scrollbar { display: none; }
